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;
35 using System.Security.Permissions;
37 namespace MonoTests.System.Drawing
40 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
41 public class SystemPensTest : Assertion
44 public void TearDown () {}
47 public void SetUp () {}
50 public void TestActiveCaptionText ()
53 pen = SystemPens.ActiveCaptionText;
54 CheckProperties (pen, "P1", SystemColors.ActiveCaptionText);
55 CheckMethods (pen, "M1");
59 public void TestControl ()
62 pen = SystemPens.Control;
63 CheckProperties (pen, "P2", SystemColors.Control);
64 CheckMethods (pen, "M2");
68 public void TestControlDark ()
71 pen = SystemPens.ControlDark;
72 CheckProperties (pen, "P3", SystemColors.ControlDark);
73 CheckMethods (pen, "M3");
77 public void TestControlDarkDark ()
80 pen = SystemPens.ControlDarkDark;
81 CheckProperties (pen, "P4", SystemColors.ControlDarkDark);
82 CheckMethods (pen, "M4");
86 public void TestControlLight ()
89 pen = SystemPens.ControlLight;
90 CheckProperties (pen, "P5", SystemColors.ControlLight);
91 CheckMethods (pen, "M5");
95 public void TestControlLightLight ()
98 pen = SystemPens.ControlLightLight;
99 CheckProperties (pen, "P6", SystemColors.ControlLightLight);
100 CheckMethods (pen, "M6");
104 public void TestControlText ()
107 pen = SystemPens.ControlText;
108 CheckProperties (pen, "P7", SystemColors.ControlText);
109 CheckMethods (pen, "M7");
113 public void TestGrayText ()
116 pen = SystemPens.GrayText;
117 CheckProperties (pen, "P8", SystemColors.GrayText);
118 CheckMethods (pen, "M8");
122 public void TestHighlight ()
125 pen = SystemPens.Highlight;
126 CheckProperties (pen, "P9", SystemColors.Highlight);
127 CheckMethods (pen, "M9");
131 public void TestHighlightText ()
134 pen = SystemPens.HighlightText;
135 CheckProperties (pen, "P10", SystemColors.HighlightText);
136 CheckMethods (pen, "M10");
140 public void TestInactiveCaptionText ()
143 pen = SystemPens.InactiveCaptionText;
144 CheckProperties (pen, "P11", SystemColors.InactiveCaptionText);
145 CheckMethods (pen, "M11");
149 public void TestInfoText ()
152 pen = SystemPens.InfoText;
153 CheckProperties (pen, "P12", SystemColors.InfoText);
154 CheckMethods (pen, "M12");
158 public void TestMenuText ()
161 pen = SystemPens.MenuText;
162 CheckProperties (pen, "P13", SystemColors.MenuText);
163 CheckMethods (pen, "M13");
167 public void TestWindowFrame ()
170 pen = SystemPens.WindowFrame;
171 CheckProperties (pen, "P14", SystemColors.WindowFrame);
172 CheckMethods (pen, "M14");
176 public void TestWindowText ()
179 pen = SystemPens.WindowText;
180 CheckProperties (pen, "P15", SystemColors.WindowText);
181 CheckMethods (pen, "M15");
185 public void TestFromSystemColor ()
189 pen = SystemPens.FromSystemColor (SystemColors.MenuText);
190 CheckProperties (pen, "P16", SystemColors.MenuText);
191 CheckMethods (pen, "M16");
194 pen = SystemPens.FromSystemColor (Color.Red);
195 Fail ("M17: must throw ArgumentException");
196 } catch (ArgumentException) {
197 Assert ("M17", true);
201 // helper test functions
202 void CheckProperties (Pen pen, String tag, Color sysColor)
204 // Try modifying properties of a SystemPen.
205 // ArgumentException must be thrown.
207 Assert (tag + "#1", pen.Color.IsSystemColor);
208 AssertEquals (tag + "#1", sysColor, pen.Color);
211 pen.Alignment = PenAlignment.Center;
212 Fail (tag + "#2: must throw ArgumentException");
213 } catch (ArgumentException) {
214 Assert (tag + "#2", true);
218 pen.Brush = new SolidBrush(Color.Red);
219 Fail (tag + "#3: must throw ArgumentException");
220 } catch (ArgumentException) {
221 Assert (tag + "#3", true);
225 pen.Color = Color.Red;
226 Fail (tag + "#4: must throw ArgumentException");
227 } catch (ArgumentException) {
228 Assert (tag + "#4", true);
232 pen.Color = sysColor;
233 Fail (tag + "#5" + ": must throw ArgumentException");
234 } catch (ArgumentException) {
235 Assert (tag + "#5", true);
240 pen.CompoundArray = new float[2];
241 Fail (tag + "#6: must throw ArgumentException");
242 } catch (ArgumentException) {
243 Assert (tag + "#6", true);
248 pen.CustomEndCap = null;
249 Fail (tag + "#7: must throw ArgumentException");
250 } catch (ArgumentException) {
251 Assert (tag + "#7", true);
256 pen.CustomStartCap = null;
257 Fail (tag + "#8: must throw ArgumentException");
258 } catch (ArgumentException) {
259 Assert (tag + "#8", true);
264 pen.DashCap = DashCap.Flat;
265 Fail (tag + "#9: must throw ArgumentException");
266 } catch (ArgumentException) {
267 Assert (tag + "#9", true);
271 pen.DashOffset = 5.5F;
272 Fail (tag + "#10: must throw ArgumentException");
273 } catch (ArgumentException) {
274 Assert (tag + "#10", true);
278 pen.DashPattern = null;
279 Fail (tag + "#11: must throw ArgumentException");
280 } catch (ArgumentException) {
281 Assert (tag + "#11", true);
285 pen.DashStyle = DashStyle.Dot; // hangs!prob
286 Fail (tag + "#12: must throw ArgumentException");
287 } catch (ArgumentException) {
288 Assert (tag + "#12", true);
293 pen.EndCap = LineCap.Round;
294 Fail (tag + "#13: must throw ArgumentException");
295 } catch (ArgumentException) {
296 Assert (tag + "#13", true);
300 pen.LineJoin = LineJoin.Round;
301 Fail (tag + "#14: must throw ArgumentException");
302 } catch (ArgumentException) {
303 Assert (tag + "#14", true);
307 pen.MiterLimit = 0.1f;
308 Fail (tag + "#15: must throw ArgumentException");
309 } catch (ArgumentException) {
310 Assert (tag + "#15", true);
315 pen.StartCap = LineCap.Square;
316 Fail (tag + "#16: must throw ArgumentException");
317 } catch (ArgumentException) {
318 Assert (tag + "#16", true);
322 pen.Transform = new Matrix (); //Matrix hangs!problem
323 Fail (tag + "#17: must throw ArgumentException");
324 } catch (ArgumentException) {
325 Assert (tag + "#17", true);
330 Fail (tag + "#18: must throw ArgumentException");
331 } catch (ArgumentException) {
332 Assert (tag + "#18", true);
336 void CheckMethods (Pen pen, String tag)
338 // Try modifying a SystemPen by calling methods.
339 // ArgumentException must be thrown in some cases.
343 pen.SetLineCap (LineCap.Flat, LineCap.Round, DashCap.Triangle);
344 Fail (tag + "#1: must throw ArgumentException");
345 } catch (ArgumentException) {
346 Assert (tag + "#1", true);
349 pen.ResetTransform ();
350 pen.RotateTransform (90);
351 pen.ScaleTransform (2, 1);
352 pen.TranslateTransform (10, 20);
353 pen.MultiplyTransform (new Matrix ());
358 Fail (tag + "#8: must throw ArgumentException");
359 } catch (ArgumentException) {
360 Assert (tag + "#8", true);