MarginsTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // System.Drawing.Printing.Margins unit tests
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2007 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.Printing;
  31. using System.Security.Permissions;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Drawing.Printing {
  34. [TestFixture]
  35. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  36. public class MarginsTest {
  37. [Test]
  38. public void CtorDefault ()
  39. {
  40. Margins m = new Margins ();
  41. Assert.AreEqual (100, m.Left, "Left");
  42. Assert.AreEqual (100, m.Top, "Top");
  43. Assert.AreEqual (100, m.Right, "Right");
  44. Assert.AreEqual (100, m.Bottom, "Bottom");
  45. Assert.AreEqual ("[Margins Left=100 Right=100 Top=100 Bottom=100]", m.ToString (), "ToString");
  46. Margins clone = (Margins) m.Clone ();
  47. Assert.AreEqual (m, clone, "clone");
  48. #if NET_2_0
  49. Assert.IsTrue (m == clone, "==");
  50. Assert.IsFalse (m != clone, "!=");
  51. #endif
  52. }
  53. [Test]
  54. public void Ctor4Int ()
  55. {
  56. Margins m1 = new Margins (Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
  57. Assert.AreEqual (Int32.MaxValue, m1.Left, "Left");
  58. Assert.AreEqual (Int32.MaxValue, m1.Top, "Top");
  59. Assert.AreEqual (Int32.MaxValue, m1.Right, "Right");
  60. Assert.AreEqual (Int32.MaxValue, m1.Bottom, "Bottom");
  61. // right smaller than left
  62. Margins m2 = new Margins (Int32.MaxValue, 0, 10, 20);
  63. // bottom smaller than top
  64. Margins m3 = new Margins (10, 20, Int32.MaxValue, 0);
  65. Assert.IsFalse (m2.GetHashCode () == m3.GetHashCode (), "GetHashCode");
  66. #if NET_2_0
  67. Assert.IsTrue (m1 != m2, "m1 != m2");
  68. Assert.IsFalse (m1 == m2, "m1 == m2");
  69. #endif
  70. }
  71. [Test]
  72. [ExpectedException (typeof (ArgumentException))]
  73. public void Ctor_BadLeft ()
  74. {
  75. new Margins (-1, 0, 0, 0);
  76. }
  77. [Test]
  78. [ExpectedException (typeof (ArgumentException))]
  79. public void Ctor_BadRight ()
  80. {
  81. new Margins (0, Int32.MinValue, 0, 0);
  82. }
  83. [Test]
  84. [ExpectedException (typeof (ArgumentException))]
  85. public void Ctor_BadTop ()
  86. {
  87. new Margins (0, 0, Int32.MinValue, 0);
  88. }
  89. [Test]
  90. [ExpectedException (typeof (ArgumentException))]
  91. public void Ctor_BadBottom ()
  92. {
  93. new Margins (0, 0, 0, -1);
  94. }
  95. [Test]
  96. public void Equals ()
  97. {
  98. Margins m = new Margins ();
  99. Assert.IsTrue (m.Equals (m), "Equals(m)");
  100. Assert.IsFalse (m.Equals (null), "Equals(null)");
  101. }
  102. [Test]
  103. public void OperatorsWithNulls ()
  104. {
  105. Margins m1 = null;
  106. Margins m2 = null;
  107. #if NET_2_0
  108. Assert.IsTrue (m1 == m2, "null==null");
  109. Assert.IsFalse (m1 != m2, "null!=null");
  110. #endif
  111. }
  112. }
  113. }