PaintEventArgsTest.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Windows.Forms.PaintEventArgs unit tests
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using System;
  29. using System.Drawing;
  30. using System.Drawing.Drawing2D;
  31. using System.Windows.Forms;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Windows.Forms {
  34. [TestFixture]
  35. public class PaintEventArgsTest {
  36. private Graphics default_graphics;
  37. private Rectangle default_rect;
  38. [TestFixtureSetUp]
  39. public void FixtureSetUp ()
  40. {
  41. Bitmap bmp = new Bitmap (200, 200);
  42. default_graphics = Graphics.FromImage (bmp);
  43. default_rect = new Rectangle (Int32.MinValue, Int32.MinValue, Int32.MaxValue, Int32.MaxValue);
  44. }
  45. #if NET_2_0
  46. [Test]
  47. [ExpectedException (typeof (ArgumentNullException))]
  48. public void Constructor_NullGraphics ()
  49. {
  50. new PaintEventArgs (null, default_rect);
  51. }
  52. #else
  53. [Test]
  54. public void Constructor_NullGraphics ()
  55. {
  56. PaintEventArgs pea = new PaintEventArgs (null, default_rect);
  57. Assert.IsNull (pea.Graphics, "Graphics");
  58. Assert.AreEqual (default_rect, pea.ClipRectangle);
  59. }
  60. #endif
  61. [Test]
  62. public void Constructor ()
  63. {
  64. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  65. Assert.AreSame (default_graphics, pea.Graphics, "Graphics");
  66. Assert.AreEqual (default_rect, pea.ClipRectangle);
  67. }
  68. [Test]
  69. #if NET_2_0
  70. [Category ("NotWorking")] // not working under Mono (see #)
  71. #else
  72. [ExpectedException (typeof (ArgumentException))]
  73. #endif
  74. public void Dispose ()
  75. {
  76. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  77. pea.Dispose ();
  78. // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
  79. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  80. }
  81. [Test]
  82. #if NET_2_0
  83. [Category ("NotWorking")]
  84. #else
  85. [ExpectedException (typeof (ArgumentException))]
  86. #endif
  87. public void IDisposable_IDispose ()
  88. {
  89. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  90. (pea as IDisposable).Dispose ();
  91. // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
  92. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
  93. }
  94. [Test]
  95. [ExpectedException (typeof (ArgumentException))]
  96. public void GraphicsDispose ()
  97. {
  98. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  99. pea.Graphics.Dispose ();
  100. // a disposed graphics won't accept to return it's transformation matrix
  101. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
  102. }
  103. public class PaintEventArgsTester: PaintEventArgs {
  104. public PaintEventArgsTester (Graphics graphics, Rectangle clipRect)
  105. : base (graphics, clipRect)
  106. {
  107. }
  108. public void DisposeBool (bool disposing)
  109. {
  110. base.Dispose (disposing);
  111. }
  112. }
  113. [Test]
  114. #if NET_2_0
  115. // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
  116. [Category ("NotDotNet")]
  117. #endif
  118. [ExpectedException (typeof (ArgumentException))]
  119. public void Dispose_True ()
  120. {
  121. PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
  122. pea.DisposeBool (true);
  123. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  124. }
  125. [Test]
  126. #if NET_2_0
  127. // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
  128. [Category ("NotDotNet")]
  129. #endif
  130. [ExpectedException (typeof (ArgumentException))]
  131. public void Dispose_False ()
  132. {
  133. PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
  134. pea.DisposeBool (false);
  135. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  136. }
  137. }
  138. }