2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Printing / PaperSizeTest.cs
1 //
2 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Author:
24 //      Andy Hume <andyhume32@yahoo.co.uk>
25 //
26
27 using NUnit.Framework;
28 using System;
29 using System.Drawing;
30 using System.Drawing.Printing;
31
32 namespace MonoTests.System.Drawing.Printing
33 {
34         [TestFixture]
35         public class PaperSizeTest
36         {
37 #if NET_2_0
38                 [Test]
39                 public void PaperSizeKindTest()
40                 {
41                         // set_RawKind seems to accept any value (no ArgEx seen), but get_Kind 
42                         // returns "Custom" when it's set to a value bigger than the biggest enum.
43                         //
44                         PaperSize ps = new PaperSize ("foo", 100, 100);
45
46                         //
47                         // Zero == Custom
48                         Assert.AreEqual(PaperKind.Custom, ps.Kind, "Kind #1");
49                         Assert.AreEqual(0, ps.RawKind, "RawKind #1");
50
51                         try {
52                                 ps.Height = 1;
53                                 Assert.AreEqual (1 , ps.Height, "get_Height #1");
54                         } catch (ArgumentException) {
55                                 Assert.Fail ("should not have thrown #1");
56                         }
57
58                         //
59                         // Well-known
60                         ps.RawKind = (int)PaperKind.A4;
61                         Assert.AreEqual (PaperKind.A4, ps.Kind, "Kind #2");
62                         Assert.AreEqual ((int)PaperKind.A4, ps.RawKind, "RawKind #2");
63
64                         try {
65                                 ps.Height = 2;
66                                 Assert.Fail("should have thrown #2");
67                         } catch (ArgumentException) {
68                         }
69
70                         //
71                         ps.RawKind = (int)PaperKind.JapaneseEnvelopeKakuNumber3;
72                         Assert.AreEqual (PaperKind.JapaneseEnvelopeKakuNumber3, ps.Kind, "Kind #3");
73                         Assert.AreEqual ((int)PaperKind.JapaneseEnvelopeKakuNumber3, ps.RawKind, "RawKind #3");
74
75                         //
76                         // Too Big
77                         ps.RawKind = 999999;
78                         Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #4");
79                         Assert.AreEqual (999999, ps.RawKind, "RawKind #4");
80
81                         // The properties can be changed only when the *real* Kind is Custom 
82                         // and not when is 'effectively' Custom.
83                         try {
84                                 ps.Height = 4;
85                                 Assert.Fail("should have thrown #4");
86                         } catch (ArgumentException) {
87                         }
88
89                         //
90                         ps.RawKind = int.MaxValue;
91                         Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #5");
92                         Assert.AreEqual (int.MaxValue, ps.RawKind, "RawKind #5");
93
94                         //
95                         // Negative -- Looks as if MSFT forgot to check for negative!
96                         ps.RawKind = -1;
97                         Assert.AreEqual ((PaperKind)(-1), ps.Kind, "Kind #6");
98                         Assert.AreEqual (-1, ps.RawKind, "RawKind #6");
99
100                         //
101                         ps.RawKind = int.MinValue;
102                         Assert.AreEqual ((PaperKind)(int.MinValue), ps.Kind, "Kind #7");
103                         Assert.AreEqual (int.MinValue, ps.RawKind, "RawKind #7");
104
105                         //
106                         // Where's the top limit?
107                         ps.RawKind = (int)PaperKind.PrcEnvelopeNumber10Rotated;
108                         Assert.AreEqual (PaperKind.PrcEnvelopeNumber10Rotated, ps.Kind, "Kind #8");
109                         Assert.AreEqual ((int)PaperKind.PrcEnvelopeNumber10Rotated, ps.RawKind, "RawKind #8");
110
111                         // +1
112                         ps.RawKind = 1 + (int)PaperKind.PrcEnvelopeNumber10Rotated;
113                         Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #9");
114                         Assert.AreEqual (1 + (int)PaperKind.PrcEnvelopeNumber10Rotated, ps.RawKind, "RawKind #9");
115
116                         try {
117                                 ps.Height = 9;
118                                 Assert.Fail("should have thrown #9");
119                         } catch (ArgumentException) {
120                         }
121
122                         // Set Custom
123                         ps.RawKind = (int)PaperKind.Custom;
124                         Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #1b");
125                         Assert.AreEqual (0, ps.RawKind, "RawKind #1b");
126
127                         try {
128                                 ps.Height = 1;
129                                 Assert.AreEqual (1 , ps.Height, "get_Height #1b");
130                         } catch (ArgumentException) {
131                                 Assert.Fail ("should not have thrown #1b");
132                         }
133                 }
134 #endif
135         
136         }
137 }
138