TARGET_JVM: add SqlTypes tests and ignores to let them pass without failures
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlCharsTest.cs
1 //
2 // SqlCharsTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlChars
3 //
4 // Authors:
5 //   Nagappan A (anagappan@novell.com)
6 //
7 //
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31
32 using NUnit.Framework;
33 using System;
34 using System.IO;
35 using System.Data.SqlTypes;
36 using System.Threading;
37 using System.Globalization;
38
39 namespace MonoTests.System.Data.SqlTypes
40 {
41         [TestFixture]
42         public class SqlCharsTest
43         {
44                 [SetUp]
45                 public void SetUp ()
46                 {
47                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
48                 }
49
50                 // Test constructor
51                 [Test]
52                 public void SqlCharsItem ()
53                 {
54                         SqlChars chars = new SqlChars ();
55                         try {
56                                 Assert.AreEqual (chars [0], 0, "#1 Should throw SqlNullValueException");
57                                 Assert.Fail ("Should throw SqlNullValueException");
58                         } catch (Exception ex) {
59                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
60                         }
61                         char [] b = null;
62                         chars = new SqlChars (b);
63                         try {
64                                 Assert.AreEqual (chars [0], 0, "#2 Should throw SqlNullValueException");
65                                 Assert.Fail ("Should throw SqlNullValueException");
66                         } catch (Exception ex) {
67                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
68                         }
69                         b = new char [10];
70                         chars = new SqlChars (b);
71                         Assert.AreEqual (chars [0], 0, "");
72                         try {
73                                 Assert.AreEqual (chars [-1], 0, "");
74                                 Assert.Fail ("Should throw ArgumentOutOfRangeException");
75                         } catch (Exception ex) {
76                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
77                         }
78                         try {
79                                 Assert.AreEqual (chars [10], 0, "");
80                                 Assert.Fail ("Should throw ArgumentOutOfRangeException");
81                         } catch (Exception ex) {
82                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
83                         }
84                 }
85                 [Test]
86                 public void SqlCharsLength ()
87                 {
88                         char [] b = null;
89                         SqlChars chars = new SqlChars ();
90                         try {
91                                 Assert.AreEqual (chars.Length, 0, "#1 Should throw SqlNullValueException");
92                                 Assert.Fail ("Should throw SqlNullValueException");
93                         } catch (Exception ex) {
94                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
95                         }
96                         chars = new SqlChars (b);
97                         try {
98                                 Assert.AreEqual (chars.Length, 0, "#2 Should throw SqlNullValueException");
99                                 Assert.Fail ("Should throw SqlNullValueException");
100                         } catch (Exception ex) {
101                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
102                         }
103                         b = new char [10];
104                         chars = new SqlChars (b);
105                         Assert.AreEqual (chars.Length, 10, "#3 Should be 10");
106                 }
107                 [Test]
108                 public void SqlCharsMaxLength ()
109                 {
110                         char [] b = null;
111                         SqlChars chars = new SqlChars ();
112                         Assert.AreEqual (chars.MaxLength, -1, "#1 Should return -1");
113                         chars = new SqlChars (b);
114                         Assert.AreEqual (chars.MaxLength, -1, "#2 Should return -1");
115                         b = new char [10];
116                         chars = new SqlChars (b);
117                         Assert.AreEqual (chars.MaxLength, 10, "#3 Should return 10");
118                 }
119                 [Test]
120                 public void SqlCharsNull ()
121                 {
122                         char [] b = null;
123                         SqlChars chars = SqlChars.Null;
124                         Assert.AreEqual (chars.IsNull, true, "#1 Should return true");
125                 }
126                 [Test]
127                 public void SqlCharsStorage ()
128                 {
129                         char [] b = null;
130                         SqlChars chars = new SqlChars ();
131                         try {
132                                 Assert.AreEqual (chars.Storage, StorageState.Buffer, "#1 Should throw SqlNullValueException");
133                                 Assert.Fail ("Should throw SqlNullValueException");
134                         } catch (Exception ex) {
135                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
136                         }
137                         chars = new SqlChars (b);
138                         try {
139                                 Assert.AreEqual (chars.Storage, StorageState.Buffer, "#2 Should throw SqlNullValueException");
140                                 Assert.Fail ("Should throw SqlNullValueException");
141                         } catch (Exception ex) {
142                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
143                         }
144                         b = new char [10];
145                         chars = new SqlChars (b);
146                         Assert.AreEqual (chars.Storage, StorageState.Buffer, "#3 Should be StorageState.Buffer");
147                 }
148                 [Test]
149                 public void SqlCharsValue ()
150                 {
151                         char [] b1 = new char [10];
152                         SqlChars chars = new SqlChars (b1);
153                         char [] b2 = chars.Value;
154                         Assert.AreEqual (b1 [0], b2 [0], "#1 Should be same");
155                         b2 [0] = '1';
156                         Assert.AreEqual (b1 [0], 0, "#2 Should be same");
157                         Assert.AreEqual (b2 [0], '1', "#3 Should be same");
158                 }
159                 [Test]
160 #if TARGET_JVM
161                 [Ignore ("Array.Resize(null) is not supported")]
162 #endif
163                 public void SqlCharsSetLength ()
164                 {
165                         char [] b1 = new char [10];
166                         SqlChars chars = new SqlChars ();
167                         try {
168                                 chars.SetLength (20);
169                                 Assert.Fail ("Should throw SqlTypeException");
170                         } catch (Exception ex) {
171                                 Assert.AreEqual (typeof (SqlTypeException), ex.GetType (), "Should throw SqlTypeException");
172                         }
173                         chars = new SqlChars (b1);
174                         Assert.AreEqual (chars.Length, 10, "#1 Should be same");
175                         try {
176                                 chars.SetLength (-1);
177                                 Assert.Fail ("Should throw ArgumentOutOfRangeException");
178                         } catch (Exception ex) {
179                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
180                         }
181                         try {
182                                 chars.SetLength (11);
183                                 Assert.Fail ("Should throw ArgumentOutOfRangeException");
184                         } catch (Exception ex) {
185                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
186                         }
187                         chars.SetLength (2);
188                         Assert.AreEqual (chars.Length, 2, "#2 Should be same");
189                 }
190                 [Test]
191                 public void SqlCharsSetNull ()
192                 {
193                         char [] b1 = new char [10];
194                         SqlChars chars = new SqlChars (b1);
195                         Assert.AreEqual (chars.Length, 10, "#1 Should be same");
196                         chars.SetNull ();
197                         try {
198                                 Assert.AreEqual (chars.Length, 10, "#1 Should not be same");
199                                 Assert.Fail ("Should throw SqlNullValueException");
200                         } catch (Exception ex) {
201                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
202                         }
203                         Assert.AreEqual (true, chars.IsNull, "#2 Should be same");
204                 }
205         }
206 }
207
208 #endif