Remove invalid tests for image palettes in GdiPlusTest (#5671)
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestSystemPens.cs
1 // Tests for System.Drawing.SystemPens.cs
2 //
3 // Author: 
4 //     Ravindra (rkumar@novell.com)
5 //
6
7 //
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30
31 using NUnit.Framework;
32 using System;
33 using System.Drawing;
34 using System.Drawing.Drawing2D;
35 using System.Security.Permissions;
36
37 namespace MonoTests.System.Drawing
38 {
39         [TestFixture]
40         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
41         public class SystemPensTest
42         {
43                 [TearDown]
44                 public void TearDown () {}
45
46                 [SetUp]
47                 public void SetUp () {}
48
49                 [Test]
50                 public void TestActiveCaptionText ()
51                 {
52                         Pen pen;
53                         pen = SystemPens.ActiveCaptionText;
54                         CheckProperties (pen, "P1", SystemColors.ActiveCaptionText);
55                         CheckMethods (pen, "M1");
56                 }
57
58                 [Test]
59                 public void TestControl ()
60                 {
61                         Pen pen;
62                         pen = SystemPens.Control;
63                         CheckProperties (pen, "P2", SystemColors.Control);
64                         CheckMethods (pen, "M2");
65                 }
66
67                 [Test]
68                 public void TestControlDark ()
69                 {
70                         Pen pen;
71                         pen = SystemPens.ControlDark;
72                         CheckProperties (pen, "P3", SystemColors.ControlDark);
73                         CheckMethods (pen, "M3");
74                 }
75
76                 [Test]
77                 public void TestControlDarkDark ()
78                 {
79                         Pen pen;
80                         pen = SystemPens.ControlDarkDark;
81                         CheckProperties (pen, "P4", SystemColors.ControlDarkDark);
82                         CheckMethods (pen, "M4");
83                 }
84
85                 [Test]
86                 public void TestControlLight ()
87                 {
88                         Pen pen;
89                         pen = SystemPens.ControlLight;
90                         CheckProperties (pen, "P5", SystemColors.ControlLight);
91                         CheckMethods (pen, "M5");
92                 }
93
94                 [Test]
95                 public void TestControlLightLight ()
96                 {
97                         Pen pen;
98                         pen = SystemPens.ControlLightLight;
99                         CheckProperties (pen, "P6", SystemColors.ControlLightLight);
100                         CheckMethods (pen, "M6");
101                 }
102
103                 [Test]
104                 public void TestControlText ()
105                 {
106                         Pen pen;
107                         pen = SystemPens.ControlText;
108                         CheckProperties (pen, "P7", SystemColors.ControlText);
109                         CheckMethods (pen, "M7");
110                 }
111
112                 [Test]
113                 public void TestGrayText ()
114                 {
115                         Pen pen;
116                         pen = SystemPens.GrayText;
117                         CheckProperties (pen, "P8", SystemColors.GrayText);
118                         CheckMethods (pen, "M8");
119                 }
120
121                 [Test]
122                 public void TestHighlight ()
123                 {
124                         Pen pen;
125                         pen = SystemPens.Highlight;
126                         CheckProperties (pen, "P9", SystemColors.Highlight);
127                         CheckMethods (pen, "M9");
128                 }
129
130                 [Test]
131                 public void TestHighlightText ()
132                 {
133                         Pen pen;
134                         pen = SystemPens.HighlightText;
135                         CheckProperties (pen, "P10", SystemColors.HighlightText);
136                         CheckMethods (pen, "M10");
137                 }
138
139                 [Test]
140                 public void TestInactiveCaptionText ()
141                 {
142                         Pen pen;
143                         pen = SystemPens.InactiveCaptionText;
144                         CheckProperties (pen, "P11", SystemColors.InactiveCaptionText);
145                         CheckMethods (pen, "M11");
146                 }
147
148                 [Test]
149                 public void TestInfoText ()
150                 {
151                         Pen pen;
152                         pen = SystemPens.InfoText;
153                         CheckProperties (pen, "P12", SystemColors.InfoText);
154                         CheckMethods (pen, "M12");
155                 }
156
157                 [Test]
158                 public void TestMenuText ()
159                 {
160                         Pen pen;
161                         pen = SystemPens.MenuText;
162                         CheckProperties (pen, "P13", SystemColors.MenuText);
163                         CheckMethods (pen, "M13");
164                 }
165
166                 [Test]
167                 public void TestWindowFrame ()
168                 {
169                         Pen pen;
170                         pen = SystemPens.WindowFrame;
171                         CheckProperties (pen, "P14", SystemColors.WindowFrame);
172                         CheckMethods (pen, "M14");
173                 }
174
175                 [Test]
176                 public void TestWindowText ()
177                 {
178                         Pen pen;
179                         pen = SystemPens.WindowText;
180                         CheckProperties (pen, "P15", SystemColors.WindowText);
181                         CheckMethods (pen, "M15");
182                 }
183
184                 [Test]
185                 public void TestFromSystemColor ()
186                 {
187                         Pen pen;
188
189                         pen = SystemPens.FromSystemColor (SystemColors.MenuText);
190                         CheckProperties (pen, "P16", SystemColors.MenuText);
191                         CheckMethods (pen, "M16");
192
193                         try {
194                                 pen = SystemPens.FromSystemColor (Color.Red);
195                                 Assert.Fail ("M17: must throw ArgumentException");
196                         } catch (ArgumentException) {
197                                 Assert.IsTrue (true, "M17");
198                         }
199                 }
200
201                 // helper test functions
202                 void CheckProperties (Pen pen, String tag, Color sysColor)
203                 {
204                         // Try modifying properties of a SystemPen.
205                         // ArgumentException must be thrown.
206
207                         Assert.IsTrue (pen.Color.IsSystemColor, tag + "#1");
208                         Assert.AreEqual (sysColor, pen.Color, tag + "#1");
209
210                         try {
211                                 pen.Alignment = PenAlignment.Center;
212                                 Assert.Fail (tag + "#2: must throw ArgumentException");
213                         } catch (ArgumentException) {
214                                 Assert.IsTrue (true, tag + "#2");
215                         }
216
217                         try {
218                                 pen.Brush = new SolidBrush(Color.Red);
219                                 Assert.Fail (tag + "#3: must throw ArgumentException");
220                         } catch (ArgumentException) {
221                                 Assert.IsTrue (true, tag + "#3");
222                         }
223
224                         try {
225                                 pen.Color = Color.Red;
226                                 Assert.Fail (tag + "#4: must throw ArgumentException");
227                         } catch (ArgumentException) {
228                                 Assert.IsTrue (true, tag + "#4");
229                         }
230
231                         try {
232                                 pen.Color = sysColor;
233                                 Assert.Fail (tag + "#5" + ": must throw ArgumentException");
234                         } catch (ArgumentException) {
235                                 Assert.IsTrue (true, tag + "#5");
236                         }
237 /*
238                         try {
239                                 // NotImplemented
240                                 pen.CompoundArray = new float[2];
241                                 Assert.Fail (tag + "#6: must throw ArgumentException");
242                         } catch (ArgumentException) {
243                                 Assert.IsTrue (true, tag + "#6");
244                         }
245
246                         try {
247                                 // NotImplemented
248                                 pen.CustomEndCap = null;
249                                 Assert.Fail (tag + "#7: must throw ArgumentException");
250                         } catch (ArgumentException) {
251                                 Assert.IsTrue (true, tag + "#7");
252                         }
253
254                         try {
255                                 // NotImplemented
256                                 pen.CustomStartCap = null;
257                                 Assert.Fail (tag + "#8: must throw ArgumentException");
258                         } catch (ArgumentException) {
259                                 Assert.IsTrue (true, tag + "#8");
260                         }
261
262                         try {
263                                 // NotImplemented
264                                 pen.DashCap = DashCap.Flat;
265                                 Assert.Fail (tag + "#9: must throw ArgumentException");
266                         } catch (ArgumentException) {
267                                 Assert.IsTrue (true, tag + "#9");
268                         }
269 */
270                         try {
271                                 pen.DashOffset = 5.5F;
272                                 Assert.Fail (tag + "#10: must throw ArgumentException");
273                         } catch (ArgumentException) {
274                                 Assert.IsTrue (true, tag + "#10");
275                         }
276
277                         try {
278                                 pen.DashPattern = null;
279                                 Assert.Fail (tag + "#11: must throw ArgumentException");
280                         } catch (ArgumentException) {
281                                 Assert.IsTrue (true, tag + "#11");
282                         }
283
284                         try {
285                                 pen.DashStyle = DashStyle.Dot; // hangs!prob
286                                 Assert.Fail (tag + "#12: must throw ArgumentException");
287                         } catch (ArgumentException) {
288                                 Assert.IsTrue (true, tag + "#12");
289                         }
290 /*
291                         try {
292                                 // NotImplemented
293                                 pen.EndCap = LineCap.Round;
294                                 Assert.Fail (tag + "#13: must throw ArgumentException");
295                         } catch (ArgumentException) {
296                                 Assert.IsTrue (true, tag + "#13");
297                         }
298 */
299                         try {
300                                 pen.LineJoin = LineJoin.Round;
301                                 Assert.Fail (tag + "#14: must throw ArgumentException");
302                         } catch (ArgumentException) {
303                                 Assert.IsTrue (true, tag + "#14");
304                         }
305
306                         try {
307                                 pen.MiterLimit = 0.1f;
308                                 Assert.Fail (tag + "#15: must throw ArgumentException");
309                         } catch (ArgumentException) {
310                                 Assert.IsTrue (true, tag + "#15");
311                         }
312 /*
313                         try {
314                                 // NotImplemented
315                                 pen.StartCap = LineCap.Square;
316                                 Assert.Fail (tag + "#16: must throw ArgumentException");
317                         } catch (ArgumentException) {
318                                 Assert.IsTrue (true, tag + "#16");
319                         }
320 */
321                         try {
322                                 pen.Transform = new Matrix (); //Matrix hangs!problem
323                                 Assert.Fail (tag + "#17: must throw ArgumentException");
324                         } catch (ArgumentException) {
325                                 Assert.IsTrue (true, tag + "#17");
326                         }
327
328                         try {
329                                 pen.Width = 0.5F;
330                                 Assert.Fail (tag + "#18: must throw ArgumentException");
331                         } catch (ArgumentException) {
332                                 Assert.IsTrue (true, tag + "#18");
333                         }
334                 }
335
336                 void CheckMethods (Pen pen, String tag)
337                 {
338                         // Try modifying a SystemPen by calling methods.
339                         // ArgumentException must be thrown in some cases.
340 /*
341                         try {
342                                 // NotImplemented
343                                 pen.SetLineCap (LineCap.Flat, LineCap.Round, DashCap.Triangle);
344                                 Assert.Fail (tag + "#1: must throw ArgumentException");
345                         } catch (ArgumentException) {
346                                 Assert.IsTrue (tag + "#1", true);
347                         }
348 */
349                         pen.ResetTransform ();
350                         pen.RotateTransform (90);
351                         pen.ScaleTransform (2, 1);
352                         pen.TranslateTransform (10, 20);
353                         pen.MultiplyTransform (new Matrix ());
354                         pen.Clone ();
355
356                         try {
357                                 pen.Dispose ();
358                                 Assert.Fail (tag + "#8: must throw ArgumentException");
359                         } catch (ArgumentException) {
360                                 Assert.IsTrue (true, tag + "#8");
361                         }
362                 }
363         }
364 }