2 // System.Windows.Forms.PaintEventArgs unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Drawing.Drawing2D;
32 using System.Windows.Forms;
33 using NUnit.Framework;
35 namespace MonoTests.System.Windows.Forms {
38 public class PaintEventArgsTest : TestHelper {
40 private Graphics default_graphics;
41 private Rectangle default_rect;
44 public void FixtureSetUp ()
46 Bitmap bmp = new Bitmap (200, 200);
47 default_graphics = Graphics.FromImage (bmp);
48 default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
52 [ExpectedException (typeof (ArgumentNullException))]
53 public void Constructor_NullGraphics ()
55 new PaintEventArgs (null, default_rect);
58 public void Constructor ()
60 PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
61 Assert.AreSame (default_graphics, pea.Graphics, "Graphics");
62 Assert.AreEqual (default_rect, pea.ClipRectangle);
66 public void Dispose ()
68 PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
70 // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
71 Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
75 public void IDisposable_IDispose ()
77 Bitmap bmp = new Bitmap (1, 1);
78 Graphics default_graphics = Graphics.FromImage (bmp);
79 Rectangle default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
81 PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
82 (pea as IDisposable).Dispose ();
83 // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
84 Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
88 [ExpectedException (typeof (ArgumentException))]
89 public void GraphicsDispose ()
91 PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
92 pea.Graphics.Dispose ();
93 // a disposed graphics won't accept to return it's transformation matrix
94 Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
97 public class PaintEventArgsTester: PaintEventArgs {
99 public PaintEventArgsTester (Graphics graphics, Rectangle clipRect)
100 : base (graphics, clipRect)
104 public void DisposeBool (bool disposing)
106 base.Dispose (disposing);
111 // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
112 [Category ("NotDotNet")]
113 [ExpectedException (typeof (ArgumentException))]
114 public void Dispose_True ()
116 Bitmap bmp = new Bitmap (1, 1);
117 Graphics default_graphics = Graphics.FromImage (bmp);
118 Rectangle default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
120 PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
121 pea.Graphics.Dispose ();
122 pea.DisposeBool (true);
123 Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
127 // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
128 [Category ("NotDotNet")]
129 [ExpectedException (typeof (ArgumentException))]
130 public void Dispose_False ()
132 Bitmap bmp = new Bitmap (1, 1);
133 Graphics default_graphics = Graphics.FromImage (bmp);
134 Rectangle default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
136 PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
137 pea.Graphics.Dispose ();
138 pea.DisposeBool (false);
139 Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");