MarginsTest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. Assert.IsTrue (m == clone, "==");
  49. Assert.IsFalse (m != clone, "!=");
  50. }
  51. [Test]
  52. public void Ctor4Int ()
  53. {
  54. Margins m1 = new Margins (Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
  55. Assert.AreEqual (Int32.MaxValue, m1.Left, "Left");
  56. Assert.AreEqual (Int32.MaxValue, m1.Top, "Top");
  57. Assert.AreEqual (Int32.MaxValue, m1.Right, "Right");
  58. Assert.AreEqual (Int32.MaxValue, m1.Bottom, "Bottom");
  59. // right smaller than left
  60. Margins m2 = new Margins (Int32.MaxValue, 0, 10, 20);
  61. // bottom smaller than top
  62. Margins m3 = new Margins (10, 20, Int32.MaxValue, 0);
  63. Assert.IsFalse (m2.GetHashCode () == m3.GetHashCode (), "GetHashCode");
  64. Assert.IsTrue (m1 != m2, "m1 != m2");
  65. Assert.IsFalse (m1 == m2, "m1 == m2");
  66. }
  67. [Test]
  68. [ExpectedException (typeof (ArgumentException))]
  69. public void Ctor_BadLeft ()
  70. {
  71. new Margins (-1, 0, 0, 0);
  72. }
  73. [Test]
  74. [ExpectedException (typeof (ArgumentException))]
  75. public void Ctor_BadRight ()
  76. {
  77. new Margins (0, Int32.MinValue, 0, 0);
  78. }
  79. [Test]
  80. [ExpectedException (typeof (ArgumentException))]
  81. public void Ctor_BadTop ()
  82. {
  83. new Margins (0, 0, Int32.MinValue, 0);
  84. }
  85. [Test]
  86. [ExpectedException (typeof (ArgumentException))]
  87. public void Ctor_BadBottom ()
  88. {
  89. new Margins (0, 0, 0, -1);
  90. }
  91. [Test]
  92. public void Equals ()
  93. {
  94. Margins m = new Margins ();
  95. Assert.IsTrue (m.Equals (m), "Equals(m)");
  96. Assert.IsFalse (m.Equals (null), "Equals(null)");
  97. }
  98. [Test]
  99. public void OperatorsWithNulls ()
  100. {
  101. Margins m1 = null;
  102. Margins m2 = null;
  103. Assert.IsTrue (m1 == m2, "null==null");
  104. Assert.IsFalse (m1 != m2, "null!=null");
  105. }
  106. }
  107. }