PaintEventArgsTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 ONLY_1_1
  70. [ExpectedException (typeof (ArgumentException))]
  71. #endif
  72. public void Dispose ()
  73. {
  74. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  75. pea.Dispose ();
  76. // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
  77. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  78. }
  79. [Test]
  80. #if ONLY_1_1
  81. [ExpectedException (typeof (ArgumentException))]
  82. #endif
  83. public void IDisposable_IDispose ()
  84. {
  85. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  86. (pea as IDisposable).Dispose ();
  87. // uho, under 2.0 we not really disposing the stuff - it means it's not ours to dispose!
  88. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
  89. }
  90. [Test]
  91. [ExpectedException (typeof (ArgumentException))]
  92. public void GraphicsDispose ()
  93. {
  94. PaintEventArgs pea = new PaintEventArgs (default_graphics, default_rect);
  95. pea.Graphics.Dispose ();
  96. // a disposed graphics won't accept to return it's transformation matrix
  97. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics");
  98. }
  99. public class PaintEventArgsTester: PaintEventArgs {
  100. public PaintEventArgsTester (Graphics graphics, Rectangle clipRect)
  101. : base (graphics, clipRect)
  102. {
  103. }
  104. public void DisposeBool (bool disposing)
  105. {
  106. base.Dispose (disposing);
  107. }
  108. }
  109. [Test]
  110. #if NET_2_0
  111. // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
  112. [Category ("NotDotNet")]
  113. #endif
  114. [ExpectedException (typeof (ArgumentException))]
  115. public void Dispose_True ()
  116. {
  117. PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
  118. pea.DisposeBool (true);
  119. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  120. }
  121. [Test]
  122. #if NET_2_0
  123. // under MS runtime it throws an exception under nunit-console, but not when running under NUnit GUI
  124. [Category ("NotDotNet")]
  125. #endif
  126. [ExpectedException (typeof (ArgumentException))]
  127. public void Dispose_False ()
  128. {
  129. PaintEventArgsTester pea = new PaintEventArgsTester (default_graphics, default_rect);
  130. pea.DisposeBool (false);
  131. Assert.IsTrue (pea.Graphics.Transform.IsIdentity, "Graphics.Transform");
  132. }
  133. }
  134. }