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