1 // Tests for System.Drawing.SystemPens.cs
4 // Ravindra (rkumar@novell.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using NUnit
.Framework
;
34 using System
.Drawing
.Drawing2D
;
36 namespace MonoTests
.System
.Drawing
39 public class SystemPensTest
: Assertion
42 public void TearDown () {}
45 public void SetUp () {}
48 public void TestActiveCaptionText ()
51 pen
= SystemPens
.ActiveCaptionText
;
52 CheckProperties (pen
, "P1", SystemColors
.ActiveCaptionText
);
53 CheckMethods (pen
, "M1");
57 public void TestControl ()
60 pen
= SystemPens
.Control
;
61 CheckProperties (pen
, "P2", SystemColors
.Control
);
62 CheckMethods (pen
, "M2");
66 public void TestControlDark ()
69 pen
= SystemPens
.ControlDark
;
70 CheckProperties (pen
, "P3", SystemColors
.ControlDark
);
71 CheckMethods (pen
, "M3");
75 public void TestControlDarkDark ()
78 pen
= SystemPens
.ControlDarkDark
;
79 CheckProperties (pen
, "P4", SystemColors
.ControlDarkDark
);
80 CheckMethods (pen
, "M4");
84 public void TestControlLight ()
87 pen
= SystemPens
.ControlLight
;
88 CheckProperties (pen
, "P5", SystemColors
.ControlLight
);
89 CheckMethods (pen
, "M5");
93 public void TestControlLightLight ()
96 pen
= SystemPens
.ControlLightLight
;
97 CheckProperties (pen
, "P6", SystemColors
.ControlLightLight
);
98 CheckMethods (pen
, "M6");
102 public void TestControlText ()
105 pen
= SystemPens
.ControlText
;
106 CheckProperties (pen
, "P7", SystemColors
.ControlText
);
107 CheckMethods (pen
, "M7");
111 public void TestGrayText ()
114 pen
= SystemPens
.GrayText
;
115 CheckProperties (pen
, "P8", SystemColors
.GrayText
);
116 CheckMethods (pen
, "M8");
120 public void TestHighlight ()
123 pen
= SystemPens
.Highlight
;
124 CheckProperties (pen
, "P9", SystemColors
.Highlight
);
125 CheckMethods (pen
, "M9");
129 public void TestHighlightText ()
132 pen
= SystemPens
.HighlightText
;
133 CheckProperties (pen
, "P10", SystemColors
.HighlightText
);
134 CheckMethods (pen
, "M10");
138 public void TestInactiveCaptionText ()
141 pen
= SystemPens
.InactiveCaptionText
;
142 CheckProperties (pen
, "P11", SystemColors
.InactiveCaptionText
);
143 CheckMethods (pen
, "M11");
147 public void TestInfoText ()
150 pen
= SystemPens
.InfoText
;
151 CheckProperties (pen
, "P12", SystemColors
.InfoText
);
152 CheckMethods (pen
, "M12");
156 public void TestMenuText ()
159 pen
= SystemPens
.MenuText
;
160 CheckProperties (pen
, "P13", SystemColors
.MenuText
);
161 CheckMethods (pen
, "M13");
165 public void TestWindowFrame ()
168 pen
= SystemPens
.WindowFrame
;
169 CheckProperties (pen
, "P14", SystemColors
.WindowFrame
);
170 CheckMethods (pen
, "M14");
174 public void TestWindowText ()
177 pen
= SystemPens
.WindowText
;
178 CheckProperties (pen
, "P15", SystemColors
.WindowText
);
179 CheckMethods (pen
, "M15");
183 public void TestFromSystemColor ()
187 pen
= SystemPens
.FromSystemColor (SystemColors
.MenuText
);
188 CheckProperties (pen
, "P16", SystemColors
.MenuText
);
189 CheckMethods (pen
, "M16");
192 pen
= SystemPens
.FromSystemColor (Color
.Red
);
193 Fail ("M17: must throw ArgumentException");
194 } catch (Exception e
) {
195 Assert ("M17", e
is ArgumentException
);
199 // helper test functions
200 void CheckProperties (Pen pen
, String tag
, Color sysColor
)
202 // Try modifying properties of a SystemPen.
203 // ArgumentException must be thrown.
205 Assert (tag
+ "#1", pen
.Color
.IsSystemColor
);
206 AssertEquals (tag
+ "#1", sysColor
, pen
.Color
);
209 pen
.Alignment
= PenAlignment
.Center
;
210 Fail (tag
+ "#2: must throw ArgumentException");
211 } catch (Exception e
) {
212 Assert (tag
+ "#2", e
is ArgumentException
);
216 pen
.Brush
= new SolidBrush(Color
.Red
);
217 Fail (tag
+ "#3: must throw ArgumentException");
218 } catch (Exception e
) {
219 Assert (tag
+ "#3", e
is ArgumentException
);
223 pen
.Color
= Color
.Red
;
224 Fail (tag
+ "#4: must throw ArgumentException");
225 } catch (Exception e
) {
226 Assert (tag
+ "#4", e
is ArgumentException
);
230 pen
.Color
= sysColor
;
231 Fail (tag
+ "#5" + ": must throw ArgumentException");
232 } catch (Exception e
) {
233 Assert (tag
+ "#5", e
is ArgumentException
);
238 pen.CompoundArray = new float[2];
239 Fail (tag + "#6: must throw ArgumentException");
240 } catch (Exception e) {
241 Assert (tag + "#6", e is ArgumentException);
246 pen.CustomEndCap = null;
247 Fail (tag + "#7: must throw ArgumentException");
248 } catch (Exception e) {
249 Assert (tag + "#7", e is ArgumentException);
254 pen.CustomStartCap = null;
255 Fail (tag + "#8: must throw ArgumentException");
256 } catch (Exception e) {
257 Assert (tag + "#8", e is ArgumentException);
262 pen.DashCap = DashCap.Flat;
263 Fail (tag + "#9: must throw ArgumentException");
264 } catch (Exception e) {
265 Assert (tag + "#9", e is ArgumentException);
269 pen
.DashOffset
= 5.5F
;
270 Fail (tag
+ "#10: must throw ArgumentException");
271 } catch (Exception e
) {
272 Assert (tag
+ "#10", e
is ArgumentException
);
276 pen
.DashPattern
= null;
277 Fail (tag
+ "#11: must throw ArgumentException");
278 } catch (Exception e
) {
279 Assert (tag
+ "#11", e
is ArgumentException
);
283 pen
.DashStyle
= DashStyle
.Dot
; // hangs!prob
284 Fail (tag
+ "#12: must throw ArgumentException");
285 } catch (Exception e
) {
286 Assert (tag
+ "#12", e
is ArgumentException
);
291 pen.EndCap = LineCap.Round;
292 Fail (tag + "#13: must throw ArgumentException");
293 } catch (Exception e) {
294 Assert (tag + "#13", e is ArgumentException);
298 pen
.LineJoin
= LineJoin
.Round
;
299 Fail (tag
+ "#14: must throw ArgumentException");
300 } catch (Exception e
) {
301 Assert (tag
+ "#14", e
is ArgumentException
);
305 pen
.MiterLimit
= 0.1f
;
306 Fail (tag
+ "#15: must throw ArgumentException");
307 } catch (Exception e
) {
308 Assert (tag
+ "#15", e
is ArgumentException
);
313 pen.StartCap = LineCap.Square;
314 Fail (tag + "#16: must throw ArgumentException");
315 } catch (Exception e) {
316 Assert (tag + "#16", e is ArgumentException);
320 pen
.Transform
= new Matrix (); //Matrix hangs!problem
321 Fail (tag
+ "#17: must throw ArgumentException");
322 } catch (Exception e
) {
323 Assert (tag
+ "#17", e
is ArgumentException
);
328 Fail (tag
+ "#18: must throw ArgumentException");
329 } catch (Exception e
) {
330 Assert (tag
+ "#18", e
is ArgumentException
);
334 void CheckMethods (Pen pen
, String tag
)
336 // Try modifying a SystemPen by calling methods.
337 // ArgumentException must be thrown in some cases.
341 pen.SetLineCap (LineCap.Flat, LineCap.Round, DashCap.Triangle);
342 Fail (tag + "#1: must throw ArgumentException");
343 } catch (Exception e) {
344 Assert (tag + "#1", e is ArgumentException);
348 pen
.ResetTransform ();
350 Fail (tag
+ "#2: unexpected Exception");
354 pen
.RotateTransform (90);
356 Fail (tag
+ "#3: unexpected Exception");
360 pen
.ScaleTransform (2, 1);
362 Fail (tag
+ "#4: unexpected Exception");
366 pen
.TranslateTransform (10, 20);
368 Fail (tag
+ "#5: unexpected Exception");
372 pen
.MultiplyTransform (new Matrix ());
374 Fail (tag
+ "#6: unexpected Exception");
380 Fail (tag
+ "#7: unexpected Exception");
385 Fail (tag
+ "#8: must throw ArgumentException");
386 } catch (Exception e
) {
387 Assert (tag
+ "#8", e
is ArgumentException
);