forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolboxBitmapAttributeTests.cs
More file actions
212 lines (188 loc) · 8.69 KB
/
Copy pathToolboxBitmapAttributeTests.cs
File metadata and controls
212 lines (188 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Diagnostics;
using Xunit;
#pragma warning disable CA1050 // Declare types in namespaces
public class ClassWithNoNamespace { }
#pragma warning restore CA1050
namespace System.Drawing.Tests
{
public class bitmap_173x183_indexed_8bit { }
public class Icon_toolboxBitmapAttributeTest { }
[ActiveIssue("https://github.com/dotnet/runtime/issues/34591", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
public class ToolboxBitmapAttributeTests
{
private static Size DefaultSize = new Size(16, 16);
private void AssertDefaultSize(Image image)
{
try
{
Assert.Equal(DefaultSize, image.Size);
}
catch (Exception ex)
{
// On .NET Framework sometimes the size might be default or it might
// be disposed in which case Size property throws an ArgumentException
// so allow both cases see https://github.com/dotnet/runtime/issues/25144.
if (PlatformDetection.IsNetFramework && ex is ArgumentException)
{
return;
}
throw;
}
}
public static IEnumerable<object[]> Ctor_FileName_TestData()
{
yield return new object[] { null, new Size(0, 0) };
yield return new object[] { Helpers.GetTestBitmapPath("bitmap_173x183_indexed_8bit.bmp"), new Size(173, 183) };
yield return new object[] { Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"), new Size(16, 16) };
yield return new object[] { Helpers.GetTestBitmapPath("invalid.ico"), new Size(0, 0) };
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(Ctor_FileName_TestData))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public void Ctor_FileName(string fileName, Size size)
{
var attribute = new ToolboxBitmapAttribute(fileName);
using (Image image = attribute.GetImage(null))
{
if (size == Size.Empty)
{
AssertDefaultSize(image);
}
else
{
Assert.Equal(size, image.Size);
}
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[InlineData(null, -1, -1)]
[InlineData(typeof(ClassWithNoNamespace), -1, -1)]
[InlineData(typeof(bitmap_173x183_indexed_8bit), 173, 183)]
[InlineData(typeof(ToolboxBitmapAttributeTests), -1, -1)]
public void Ctor_Type(Type type, int width, int height)
{
var attribute = new ToolboxBitmapAttribute(type);
using (Image image = attribute.GetImage(type))
{
if (width == -1 && height == -1)
{
AssertDefaultSize(image);
}
else
{
Assert.Equal(new Size(width, height), image.Size);
}
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[InlineData(null, null, -1, -1)]
[InlineData(null, "invalid.ico", -1, -1)]
[InlineData(typeof(ClassWithNoNamespace), null, -1, -1)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "", -1, -1)]
[InlineData(typeof(ToolboxBitmapAttributeTests), null, -1, -1)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "invalid.ico", -1, -1)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "48x48_multiple_entries_4bit", 16, 16)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "48x48_multiple_entries_4bit.ico", 16, 16)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "empty.file", -1, -1)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit", 173, 183)]
[InlineData(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit.bmp", 173, 183)]
public void Ctor_Type_String(Type type, string fileName, int width, int height)
{
var attribute = new ToolboxBitmapAttribute(type, fileName);
using (Image image = attribute.GetImage(type, fileName, false))
{
if (width == -1 && height == -1)
{
AssertDefaultSize(image);
}
else
{
Assert.Equal(new Size(width, height), image.Size);
}
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[InlineData("bitmap_173x183_indexed_8bit.bmp", 173, 183)]
[InlineData("48x48_multiple_entries_4bit.ico", 16, 16)]
public void GetImage_TypeFileNameBool_ReturnsExpected(string fileName, int width, int height)
{
var attribute = new ToolboxBitmapAttribute((string)null);
using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), fileName, large: true))
{
Assert.Equal(new Size(32, 32), image.Size);
}
using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), fileName, large: false))
{
Assert.Equal(new Size(width, height), image.Size);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void GetImage_NullComponent_ReturnsNull()
{
var attribute = new ToolboxBitmapAttribute((string)null);
Assert.Null(attribute.GetImage((object)null));
Assert.Null(attribute.GetImage((object)null, true));
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void GetImage_Component_ReturnsExpected()
{
ToolboxBitmapAttribute attribute = new ToolboxBitmapAttribute((string)null);
using (Image smallImage = attribute.GetImage(new bitmap_173x183_indexed_8bit(), large: false))
{
Assert.Equal(new Size(173, 183), smallImage.Size);
using (Image largeImage = attribute.GetImage(new bitmap_173x183_indexed_8bit(), large: true))
{
Assert.Equal(new Size(32, 32), largeImage.Size);
}
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void GetImage_Default_ReturnsExpected()
{
ToolboxBitmapAttribute attribute = ToolboxBitmapAttribute.Default;
using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit", large: true))
{
Assert.Equal(new Size(32, 32), image.Size);
}
using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit", large: false))
{
Assert.Equal(new Size(173, 183), image.Size);
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Logical name with no extension is not supported in .NET Framework")]
[InlineData(typeof(Icon_toolboxBitmapAttributeTest), 256, 256)]
public void GetImage_NoExtension(Type type, int width, int height)
{
var attribute = new ToolboxBitmapAttribute(type);
using (Image image = attribute.GetImage(type))
{
if (width == -1 && height == -1)
{
AssertDefaultSize(image);
}
else
{
Assert.Equal(new Size(width, height), image.Size);
}
}
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { ToolboxBitmapAttribute.Default, ToolboxBitmapAttribute.Default, true };
yield return new object[] { ToolboxBitmapAttribute.Default, new ToolboxBitmapAttribute(typeof(ToolboxBitmapAttribute), "bitmap_173x183_indexed_8bit"), true };
yield return new object[] { ToolboxBitmapAttribute.Default, new object(), false };
yield return new object[] { ToolboxBitmapAttribute.Default, null, false };
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(Equals_TestData))]
public void Equals_Other_ReturnsExpected(ToolboxBitmapAttribute attribute, object other, bool expected)
{
Assert.Equal(expected, attribute.Equals(other));
Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode());
}
}
}