| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // System.Windows.Forms.PaintEventArgs unit tests
- //
- // Authors:
- // Sebastien Pouliot <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms {
- [TestFixture]
- public class PaintEventArgsTest {
- private Graphics default_graphics;
- private Rectangle default_rect;
- [TestFixtureSetUp]
- public void FixtureSetUp ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- default_graphics = Graphics.FromImage (bmp);
- default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
- }
- #if NET_2_0
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor_NullGraphics ()
- {
- new PaintEventArgs (null, default_rect);
- }
- #else
- [Test]
- public void Constructor_NullGraphics ()
- {
- PaintEventArgs pea = new PaintEventArgs (null, default_rect);
- Assert.IsNull (pea.Graphics, "Graphics");
- Assert.AreEqual (default_rect, pea.ClipRectangle);
- }
- #endif
- [Test]
- public void Constructor ()
- {
- PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
- Assert.AreSame (default_graphics, pea.Graphics, "Graphics");
- Assert.AreEqual (default_rect, pea.ClipRectangle);
- }
- [Test]
- #if NET_2_0
- [Category ("NotWorking")] // not working under Mono (see #)
- #else
- [ExpectedException (typeof (ArgumentException))]
- #endif
- public void Dispose ()
- {
- PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
- pea.Dispose ();
- // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
- Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
- }
- [Test]
- #if NET_2_0
- [Category ("NotWorking")]
- #else
- [ExpectedException (typeof (ArgumentException))]
- #endif
- public void IDisposable_IDispose ()
- {
- PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
- (pea as IDisposable).Dispose ();
- // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
- Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void GraphicsDispose ()
- {
- PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
- pea.Graphics.Dispose ();
- // a disposed graphics won't accept to return it's transformation matrix
- Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
- }
- public class PaintEventArgsTester: PaintEventArgs {
- public PaintEventArgsTester (Graphics graphics, Rectangle clipRect)
- : base (graphics, clipRect)
- {
- }
- public void DisposeBool (bool disposing)
- {
- base.Dispose (disposing);
- }
- }
- [Test]
- #if NET_2_0
- // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
- [Category ("NotDotNet")]
- #endif
- [ExpectedException (typeof (ArgumentException))]
- public void Dispose_True ()
- {
- PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
- pea.DisposeBool (true);
- Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
- }
- [Test]
- #if NET_2_0
- // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
- [Category ("NotDotNet")]
- #endif
- [ExpectedException (typeof (ArgumentException))]
- public void Dispose_False ()
- {
- PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
- pea.DisposeBool (false);
- Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
- }
- }
- }
|