[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlInt16Test.cs
1 //
2 // SqlInt16Test.cs - NUnit Test Cases for System.Data.SqlTypes.SqlInt16
3 //
4 // Authors:
5 //   Ville Palo (vi64pa@koti.soon.fi)
6 //   Martin Willemoes Hansen (mwh@sysrq.dk)
7 //
8 // (C) 2002 Ville Palo
9 // (C) 2003 Martin Willemoes Hansen
10 // 
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using NUnit.Framework;
35 using System;
36 using System.Xml;
37 using System.Data.SqlTypes;
38 #if TARGET_JVM
39 using DivideByZeroException = System.ArithmeticException;
40 #endif
41 #if NET_2_0
42 using System.Xml.Serialization;
43 using System.IO;
44 #endif
45
46 namespace MonoTests.System.Data.SqlTypes
47 {
48         [TestFixture]
49         public class SqlInt16Test
50         {
51                 // Test constructor
52                 [Test]
53                 public void Create ()
54                 {
55                         SqlInt16 TestShort = new SqlInt16 (29);
56                         Assert.AreEqual ((short) 29, TestShort.Value, "Test#1");
57
58                         TestShort = new SqlInt16 (-9000);
59                         Assert.AreEqual ((short) -9000, TestShort.Value, "Test#2");
60                 }
61
62                 // Test public fields
63                 [Test]
64                 public void PublicFields ()
65                 {
66                         Assert.AreEqual ((SqlInt16) 32767, SqlInt16.MaxValue, "Test#1");
67                         Assert.AreEqual ((SqlInt16) (-32768), SqlInt16.MinValue, "Test#2");
68                         Assert.IsTrue (SqlInt16.Null.IsNull, "Test#3");
69                         Assert.AreEqual ((short) 0, SqlInt16.Zero.Value, "Test#4");
70                 }
71
72                 // Test properties
73                 [Test]
74                 public void Properties ()
75                 {
76                         SqlInt16 Test5443 = new SqlInt16 (5443);
77                         SqlInt16 Test1 = new SqlInt16 (1);
78                         Assert.IsTrue (SqlInt16.Null.IsNull, "Test#1");
79                         Assert.AreEqual ((short) 5443, Test5443.Value, "Test#2");
80                         Assert.AreEqual ((short) 1, Test1.Value, "Test#3");
81                 }
82
83                 // PUBLIC METHODS
84
85                 [Test]
86                 public void ArithmeticMethods ()
87                 {
88                         SqlInt16 Test64 = new SqlInt16 (64);
89                         SqlInt16 Test0 = new SqlInt16 (0);
90                         SqlInt16 Test164 = new SqlInt16 (164);
91                         SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
92
93                         // Add()
94                         Assert.AreEqual ((short) 64, SqlInt16.Add (Test64, Test0).Value, "Test#1");
95                         Assert.AreEqual ((short) 228, SqlInt16.Add (Test64, Test164).Value, "Test#2");
96                         Assert.AreEqual ((short) 164, SqlInt16.Add (Test0, Test164).Value, "Test#3");
97                         Assert.AreEqual ((short) SqlInt16.MaxValue, SqlInt16.Add (TestMax, Test0).Value, "Test#4");
98
99                         try {
100                                 SqlInt16.Add (TestMax, Test64);
101                                 Assert.Fail ("Test#5");
102                         } catch (OverflowException e) {
103                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
104                         }
105
106                         // Divide()
107                         Assert.AreEqual ((short) 2, SqlInt16.Divide (Test164, Test64).Value, "Test#7");
108                         Assert.AreEqual ((short) 0, SqlInt16.Divide (Test64, Test164).Value, "Test#8");
109                         try {
110                                 SqlInt16.Divide (Test64, Test0);
111                                 Assert.Fail ("Test#9");
112                         } catch (DivideByZeroException e) {
113                                 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "Test#10");
114                         }
115
116                         // Mod()
117                         Assert.AreEqual ((SqlInt16) 36, SqlInt16.Mod (Test164, Test64), "Test#11");
118                         Assert.AreEqual ((SqlInt16) 64, SqlInt16.Mod (Test64, Test164), "Test#12");
119
120                         // Multiply()
121                         Assert.AreEqual ((short) 10496, SqlInt16.Multiply (Test64, Test164).Value, "Test#13");
122                         Assert.AreEqual ((short) 0, SqlInt16.Multiply (Test64, Test0).Value, "Test#14");
123
124                         try {
125                                 SqlInt16.Multiply (TestMax, Test64);
126                                 Assert.Fail ("Test#15");
127                         } catch (OverflowException e) {
128                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#16");
129                         }
130
131                         // Subtract()
132                         Assert.AreEqual ((short) 100, SqlInt16.Subtract (Test164, Test64).Value, "Test#17");
133
134                         try {
135                                 SqlInt16.Subtract (SqlInt16.MinValue, Test164);
136                                 Assert.Fail ("Test#18");
137                         } catch (OverflowException e) {
138                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#19");
139                         }
140
141 #if NET_2_0
142                         // Modulus ()
143                         Assert.AreEqual ((SqlInt16)36, SqlInt16.Modulus (Test164, Test64), "Test#20");
144                         Assert.AreEqual ((SqlInt16)64, SqlInt16.Modulus (Test64, Test164), "Test#21");
145 #endif
146                 }
147
148                 [Test]
149                 public void BitwiseMethods ()
150                 {
151                         short MaxValue = SqlInt16.MaxValue.Value;
152                         SqlInt16 TestInt = new SqlInt16 (0);
153                         SqlInt16 TestIntMax = new SqlInt16 (MaxValue);
154                         SqlInt16 TestInt2 = new SqlInt16 (10922);
155                         SqlInt16 TestInt3 = new SqlInt16 (21845);
156
157                         // BitwiseAnd
158                         Assert.AreEqual ((short) 21845, SqlInt16.BitwiseAnd (TestInt3, TestIntMax).Value, "Test#1");
159                         Assert.AreEqual ((short) 0, SqlInt16.BitwiseAnd (TestInt2, TestInt3).Value, "Test#2");
160                         Assert.AreEqual ((short) 10922, SqlInt16.BitwiseAnd (TestInt2, TestIntMax).Value, "Test#3");
161
162                         //BitwiseOr
163                         Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestInt2, TestInt3).Value, "Test#4");
164                         Assert.AreEqual ((short) 21845, SqlInt16.BitwiseOr (TestInt, TestInt3).Value, "Test#5");
165                         Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestIntMax, TestInt2).Value, "Test#6");
166                 }
167
168                 [Test]
169                 public void CompareTo ()
170                 {
171                         SqlInt16 TestInt4000 = new SqlInt16 (4000);
172                         SqlInt16 TestInt4000II = new SqlInt16 (4000);
173                         SqlInt16 TestInt10 = new SqlInt16 (10);
174                         SqlInt16 TestInt10000 = new SqlInt16 (10000);
175                         SqlString TestString = new SqlString ("This is a test");
176
177                         Assert.IsTrue (TestInt4000.CompareTo (TestInt10) > 0, "Test#1");
178                         Assert.IsTrue (TestInt10.CompareTo (TestInt4000) < 0, "Test#2");
179                         Assert.IsTrue (TestInt4000II.CompareTo (TestInt4000) == 0, "Test#3");
180                         Assert.IsTrue (TestInt4000II.CompareTo (SqlInt16.Null) > 0, "Test#4");
181
182                         try {
183                                 TestInt10.CompareTo (TestString);
184                                 Assert.Fail ("Test#5");
185                         } catch (ArgumentException e) {
186                                 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "Test#6");
187                         }
188                 }
189
190                 [Test]
191                 public void EqualsMethod ()
192                 {
193                         SqlInt16 Test0 = new SqlInt16 (0);
194                         SqlInt16 Test158 = new SqlInt16 (158);
195                         SqlInt16 Test180 = new SqlInt16 (180);
196                         SqlInt16 Test180II = new SqlInt16 (180);
197
198                         Assert.IsTrue (!Test0.Equals (Test158), "Test#1");
199                         Assert.IsTrue (!Test158.Equals (Test180), "Test#2");
200                         Assert.IsTrue (!Test180.Equals (new SqlString ("TEST")), "Test#3");
201                         Assert.IsTrue (Test180.Equals (Test180II), "Test#4");
202                 }
203
204                 [Test]
205                 public void StaticEqualsMethod ()
206                 {
207                         SqlInt16 Test34 = new SqlInt16 (34);
208                         SqlInt16 Test34II = new SqlInt16 (34);
209                         SqlInt16 Test15 = new SqlInt16 (15);
210
211                         Assert.IsTrue (SqlInt16.Equals (Test34, Test34II).Value, "Test#1");
212                         Assert.IsTrue (!SqlInt16.Equals (Test34, Test15).Value, "Test#2");
213                         Assert.IsTrue (!SqlInt16.Equals (Test15, Test34II).Value, "Test#3");
214                 }
215
216                 [Test]
217                 public void GetHashCodeTest ()
218                 {
219                         SqlInt16 Test15 = new SqlInt16 (15);
220
221                         // FIXME: Better way to test GetHashCode()-methods
222                         Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "Test#1");
223                 }
224
225                 [Test]
226                 public void GetTypeTest ()
227                 {
228                         SqlInt16 Test = new SqlInt16 (84);
229                         Assert.AreEqual ("System.Data.SqlTypes.SqlInt16", Test.GetType ().ToString (), "Test#1");
230                 }
231
232                 [Test]
233                 public void Greaters ()
234                 {
235                         SqlInt16 Test10 = new SqlInt16 (10);
236                         SqlInt16 Test10II = new SqlInt16 (10);
237                         SqlInt16 Test110 = new SqlInt16 (110);
238
239                         // GreateThan ()
240                         Assert.IsTrue (!SqlInt16.GreaterThan (Test10, Test110).Value, "Test#1");
241                         Assert.IsTrue (SqlInt16.GreaterThan (Test110, Test10).Value, "Test#2");
242                         Assert.IsTrue (!SqlInt16.GreaterThan (Test10II, Test10).Value, "Test#3");
243
244                         // GreaterTharOrEqual ()
245                         Assert.IsTrue (!SqlInt16.GreaterThanOrEqual (Test10, Test110).Value, "Test#4");
246                         Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test110, Test10).Value, "Test#5");
247                         Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test10II, Test10).Value, "Test#6");
248                 }
249
250                 [Test]
251                 public void Lessers ()
252                 {
253                         SqlInt16 Test10 = new SqlInt16 (10);
254                         SqlInt16 Test10II = new SqlInt16 (10);
255                         SqlInt16 Test110 = new SqlInt16 (110);
256
257                         // LessThan()
258                         Assert.IsTrue (SqlInt16.LessThan (Test10, Test110).Value, "Test#1");
259                         Assert.IsTrue (!SqlInt16.LessThan (Test110, Test10).Value, "Test#2");
260                         Assert.IsTrue (!SqlInt16.LessThan (Test10II, Test10).Value, "Test#3");
261
262                         // LessThanOrEqual ()
263                         Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10, Test110).Value, "Test#4");
264                         Assert.IsTrue (!SqlInt16.LessThanOrEqual (Test110, Test10).Value, "Test#5");
265                         Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, Test10).Value, "Test#6");
266                         Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, SqlInt16.Null).IsNull, "Test#7");
267                 }
268
269                 [Test]
270                 public void NotEquals ()
271                 {
272                         SqlInt16 Test12 = new SqlInt16 (12);
273                         SqlInt16 Test128 = new SqlInt16 (128);
274                         SqlInt16 Test128II = new SqlInt16 (128);
275
276                         Assert.IsTrue (SqlInt16.NotEquals (Test12, Test128).Value, "Test#1");
277                         Assert.IsTrue (SqlInt16.NotEquals (Test128, Test12).Value, "Test#2");
278                         Assert.IsTrue (SqlInt16.NotEquals (Test128II, Test12).Value, "Test#3");
279                         Assert.IsTrue (!SqlInt16.NotEquals (Test128II, Test128).Value, "Test#4");
280                         Assert.IsTrue (!SqlInt16.NotEquals (Test128, Test128II).Value, "Test#5");
281                         Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#6");
282                         Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#7");
283                 }
284
285                 [Test]
286                 public void OnesComplement ()
287                 {
288                         SqlInt16 Test12 = new SqlInt16 (12);
289                         SqlInt16 Test128 = new SqlInt16 (128);
290
291                         Assert.AreEqual ((SqlInt16) (-13), SqlInt16.OnesComplement (Test12), "Test#1");
292                         Assert.AreEqual ((SqlInt16) (-129), SqlInt16.OnesComplement (Test128), "Test#2");
293                 }
294
295                 [Test]
296                 public void Parse ()
297                 {
298                         try {
299                                 SqlInt16.Parse (null);
300                                 Assert.Fail ("Test#1");
301                         } catch (ArgumentNullException e) {
302                                 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "Test#2");
303                         }
304
305                         try {
306                                 SqlInt16.Parse ("not-a-number");
307                                 Assert.Fail ("Test#3");
308                         } catch (FormatException e) {
309                                 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
310                         }
311
312                         try {
313                                 int OverInt = (int) SqlInt16.MaxValue + 1;
314                                 SqlInt16.Parse (OverInt.ToString ());
315                                 Assert.Fail ("Test#5");
316                         } catch (OverflowException e) {
317                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
318                         }
319
320                         Assert.AreEqual ((short) 150, SqlInt16.Parse ("150").Value, "Test#7");
321                 }
322
323                 [Test]
324                 public void Conversions ()
325                 {
326                         SqlInt16 Test12 = new SqlInt16 (12);
327                         SqlInt16 Test0 = new SqlInt16 (0);
328                         SqlInt16 TestNull = SqlInt16.Null;
329                         SqlInt16 Test1000 = new SqlInt16 (1000);
330                         SqlInt16 Test288 = new SqlInt16 (288);
331
332                         // ToSqlBoolean ()
333                         Assert.IsTrue (Test12.ToSqlBoolean ().Value, "TestA#1");
334                         Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "TestA#2");
335                         Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "TestA#3");
336
337                         // ToSqlByte ()
338                         Assert.AreEqual ((byte) 12, Test12.ToSqlByte ().Value, "TestB#1");
339                         Assert.AreEqual ((byte) 0, Test0.ToSqlByte ().Value, "TestB#2");
340
341                         try {
342                                 SqlByte b = (byte) Test1000.ToSqlByte ();
343                                 Assert.Fail ("TestB#4");
344                         } catch (OverflowException e) {
345                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestB#5");
346                         }
347
348                         // ToSqlDecimal ()
349                         Assert.AreEqual ((decimal) 12, Test12.ToSqlDecimal ().Value, "TestC#1");
350                         Assert.AreEqual ((decimal) 0, Test0.ToSqlDecimal ().Value, "TestC#2");
351                         Assert.AreEqual ((decimal) 288, Test288.ToSqlDecimal ().Value, "TestC#3");
352
353                         // ToSqlDouble ()
354                         Assert.AreEqual ((double) 12, Test12.ToSqlDouble ().Value, "TestD#1");
355                         Assert.AreEqual ((double) 0, Test0.ToSqlDouble ().Value, "TestD#2");
356                         Assert.AreEqual ((double) 1000, Test1000.ToSqlDouble ().Value, "TestD#3");
357
358                         // ToSqlInt32 ()
359                         Assert.AreEqual ((int) 12, Test12.ToSqlInt32 ().Value, "TestE#1");
360                         Assert.AreEqual ((int) 0, Test0.ToSqlInt32 ().Value, "TestE#2");
361                         Assert.AreEqual ((int) 288, Test288.ToSqlInt32 ().Value, "TestE#3");
362
363                         // ToSqlInt64 ()
364                         Assert.AreEqual ((long) 12, Test12.ToSqlInt64 ().Value, "TestF#1");
365                         Assert.AreEqual ((long) 0, Test0.ToSqlInt64 ().Value, "TestF#2");
366                         Assert.AreEqual ((long) 288, Test288.ToSqlInt64 ().Value, "TestF#3");
367
368                         // ToSqlMoney ()
369                         Assert.AreEqual (12.0000M, Test12.ToSqlMoney ().Value, "TestG#1");
370                         Assert.AreEqual ((decimal) 0, Test0.ToSqlMoney ().Value, "TestG#2");
371                         Assert.AreEqual (288.0000M, Test288.ToSqlMoney ().Value, "TestG#3");
372
373                         // ToSqlSingle ()
374                         Assert.AreEqual ((float) 12, Test12.ToSqlSingle ().Value, "TestH#1");
375                         Assert.AreEqual ((float) 0, Test0.ToSqlSingle ().Value, "TestH#2");
376                         Assert.AreEqual ((float) 288, Test288.ToSqlSingle ().Value, "TestH#3");
377
378                         // ToSqlString ()
379                         Assert.AreEqual ("12", Test12.ToSqlString ().Value, "TestI#1");
380                         Assert.AreEqual ("0", Test0.ToSqlString ().Value, "TestI#2");
381                         Assert.AreEqual ("288", Test288.ToSqlString ().Value, "TestI#3");
382
383                         // ToString ()
384                         Assert.AreEqual ("12", Test12.ToString (), "TestJ#1");
385                         Assert.AreEqual ("0", Test0.ToString (), "TestJ#2");
386                         Assert.AreEqual ("288", Test288.ToString (), "TestJ#3");
387                 }
388
389                 [Test]
390                 public void Xor ()
391                 {
392                         SqlInt16 Test14 = new SqlInt16 (14);
393                         SqlInt16 Test58 = new SqlInt16 (58);
394                         SqlInt16 Test130 = new SqlInt16 (130);
395                         SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
396                         SqlInt16 Test0 = new SqlInt16 (0);
397
398                         Assert.AreEqual ((short) 52, SqlInt16.Xor (Test14, Test58).Value, "Test#1");
399                         Assert.AreEqual ((short) 140, SqlInt16.Xor (Test14, Test130).Value, "Test#2");
400                         Assert.AreEqual ((short) 184, SqlInt16.Xor (Test58, Test130).Value, "Test#3");
401                         Assert.AreEqual ((short) 0, SqlInt16.Xor (TestMax, TestMax).Value, "Test#4");
402                         Assert.AreEqual (TestMax.Value, SqlInt16.Xor (TestMax, Test0).Value, "Test#5");
403                 }
404
405                 // OPERATORS
406
407                 [Test]
408                 public void ArithmeticOperators ()
409                 {
410                         SqlInt16 Test24 = new SqlInt16 (24);
411                         SqlInt16 Test64 = new SqlInt16 (64);
412                         SqlInt16 Test2550 = new SqlInt16 (2550);
413                         SqlInt16 Test0 = new SqlInt16 (0);
414
415                         // "+"-operator
416                         Assert.AreEqual ((SqlInt16) 2614, Test2550 + Test64, "TestA#1");
417                         try {
418                                 SqlInt16 result = Test64 + SqlInt16.MaxValue;
419                                 Assert.Fail ("TestA#2");
420                         } catch (OverflowException e) {
421                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestA#3");
422                         }
423
424                         // "/"-operator
425                         Assert.AreEqual ((SqlInt16) 39, Test2550 / Test64, "TestB#1");
426                         Assert.AreEqual ((SqlInt16) 0, Test24 / Test64, "TestB#2");
427
428                         try {
429                                 SqlInt16 result = Test2550 / Test0;
430                                 Assert.Fail ("TestB#3");
431                         } catch (DivideByZeroException e) {
432                                 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "TestB#4");
433                         }
434
435                         // "*"-operator
436                         Assert.AreEqual ((SqlInt16) 1536, Test64 * Test24, "TestC#1");
437
438                         try {
439                                 SqlInt16 test = (SqlInt16.MaxValue * Test64);
440                                 Assert.Fail ("TestC#2");
441                         } catch (OverflowException e) {
442                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestC#3");
443                         }
444
445                         // "-"-operator
446                         Assert.AreEqual ((SqlInt16) 2526, Test2550 - Test24, "TestD#1");
447
448                         try {
449                                 SqlInt16 test = SqlInt16.MinValue - Test64;
450                                 Assert.Fail ("TestD#2");
451                         } catch (OverflowException e) {
452                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "OverflowException");
453                         }
454
455                         // "%"-operator
456                         Assert.AreEqual ((SqlInt16) 54, Test2550 % Test64, "TestE#1");
457                         Assert.AreEqual ((SqlInt16) 24, Test24 % Test64, "TestE#2");
458                         Assert.AreEqual ((SqlInt16) 0, new SqlInt16 (100) % new SqlInt16 (10), "TestE#1");
459                 }
460
461                 [Test]
462                 public void BitwiseOperators ()
463                 {
464                         SqlInt16 Test2 = new SqlInt16 (2);
465                         SqlInt16 Test4 = new SqlInt16 (4);
466                         SqlInt16 Test2550 = new SqlInt16 (2550);
467
468                         // & -operator
469                         Assert.AreEqual ((SqlInt16) 0, Test2 & Test4, "TestA#1");
470                         Assert.AreEqual ((SqlInt16) 2, Test2 & Test2550, "TestA#2");
471                         Assert.AreEqual ((SqlInt16) 0, SqlInt16.MaxValue & SqlInt16.MinValue, "TestA#3");
472
473                         // | -operator
474                         Assert.AreEqual ((SqlInt16) 6, Test2 | Test4, "TestB#1");
475                         Assert.AreEqual ((SqlInt16) 2550, Test2 | Test2550, "TestB#2");
476                         Assert.AreEqual ((SqlInt16) (-1), SqlInt16.MinValue | SqlInt16.MaxValue, "TestB#3");
477
478                         //  ^ -operator
479                         Assert.AreEqual ((SqlInt16) 2546, (Test2550 ^ Test4), "TestC#1");
480                         Assert.AreEqual ((SqlInt16) 6, (Test2 ^ Test4), "TestC#2");
481                 }
482
483                 [Test]
484                 public void ThanOrEqualOperators ()
485                 {
486                         SqlInt16 Test165 = new SqlInt16 (165);
487                         SqlInt16 Test100 = new SqlInt16 (100);
488                         SqlInt16 Test100II = new SqlInt16 (100);
489                         SqlInt16 Test255 = new SqlInt16 (2550);
490
491                         // == -operator
492                         Assert.IsTrue ((Test100 == Test100II).Value, "TestA#1");
493                         Assert.IsTrue (!(Test165 == Test100).Value, "TestA#2");
494                         Assert.IsTrue ((Test165 == SqlInt16.Null).IsNull, "TestA#3");
495
496                         // != -operator
497                         Assert.IsTrue (!(Test100 != Test100II).Value, "TestB#1");
498                         Assert.IsTrue ((Test100 != Test255).Value, "TestB#2");
499                         Assert.IsTrue ((Test165 != Test255).Value, "TestB#3");
500                         Assert.IsTrue ((Test165 != SqlInt16.Null).IsNull, "TestB#4");
501
502                         // > -operator
503                         Assert.IsTrue ((Test165 > Test100).Value, "TestC#1");
504                         Assert.IsTrue (!(Test165 > Test255).Value, "TestC#2");
505                         Assert.IsTrue (!(Test100 > Test100II).Value, "TestC#3");
506                         Assert.IsTrue ((Test165 > SqlInt16.Null).IsNull, "TestC#4");
507
508                         // >=  -operator
509                         Assert.IsTrue (!(Test165 >= Test255).Value, "TestD#1");
510                         Assert.IsTrue ((Test255 >= Test165).Value, "TestD#2");
511                         Assert.IsTrue ((Test100 >= Test100II).Value, "TestD#3");
512                         Assert.IsTrue ((Test165 >= SqlInt16.Null).IsNull, "TestD#4");
513
514                         // < -operator
515                         Assert.IsTrue (!(Test165 < Test100).Value, "TestE#1");
516                         Assert.IsTrue ((Test165 < Test255).Value, "TestE#2");
517                         Assert.IsTrue (!(Test100 < Test100II).Value, "TestE#3");
518                         Assert.IsTrue ((Test165 < SqlInt16.Null).IsNull, "TestE#4");
519
520                         // <= -operator
521                         Assert.IsTrue ((Test165 <= Test255).Value, "TestF#1");
522                         Assert.IsTrue (!(Test255 <= Test165).Value, "TestF#2");
523                         Assert.IsTrue ((Test100 <= Test100II).Value, "TestF#3");
524                         Assert.IsTrue ((Test165 <= SqlInt16.Null).IsNull, "TestF#4");
525                 }
526
527                 [Test]
528                 public void OnesComplementOperator ()
529                 {
530                         SqlInt16 Test12 = new SqlInt16 (12);
531                         SqlInt16 Test128 = new SqlInt16 (128);
532
533                         Assert.AreEqual ((SqlInt16) (-13), ~Test12, "Test#1");
534                         Assert.AreEqual ((SqlInt16) (-129), ~Test128, "Test#2");
535                         Assert.AreEqual (SqlInt16.Null, ~SqlInt16.Null, "Test#3");
536                 }
537
538                 [Test]
539                 public void UnaryNegation ()
540                 {
541                         SqlInt16 Test = new SqlInt16 (2000);
542                         SqlInt16 TestNeg = new SqlInt16 (-3000);
543
544                         SqlInt16 Result = -Test;
545                         Assert.AreEqual ((short) (-2000), Result.Value, "Test#1");
546
547                         Result = -TestNeg;
548                         Assert.AreEqual ((short) 3000, Result.Value, "Test#2");
549                 }
550
551                 [Test]
552                 public void SqlBooleanToSqlInt16 ()
553                 {
554                         SqlBoolean TestBoolean = new SqlBoolean (true);
555                         SqlInt16 Result;
556
557                         Result = (SqlInt16) TestBoolean;
558
559                         Assert.AreEqual ((short) 1, Result.Value, "Test#1");
560
561                         Result = (SqlInt16) SqlBoolean.Null;
562                         Assert.IsTrue (Result.IsNull, "Test#2");
563                 }
564
565                 [Test]
566                 public void SqlDecimalToSqlInt16 ()
567                 {
568                         SqlDecimal TestDecimal64 = new SqlDecimal (64);
569                         SqlDecimal TestDecimal900 = new SqlDecimal (90000);
570
571                         Assert.AreEqual ((short) 64, ((SqlInt16) TestDecimal64).Value, "Test#1");
572                         Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDecimal.Null), "Test#2");
573
574                         try {
575                                 SqlInt16 test = (SqlInt16) TestDecimal900;
576                                 Assert.Fail ("Test#3");
577                         } catch (OverflowException e) {
578                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
579                         }
580                 }
581
582                 [Test]
583                 public void SqlDoubleToSqlInt16 ()
584                 {
585                         SqlDouble TestDouble64 = new SqlDouble (64);
586                         SqlDouble TestDouble900 = new SqlDouble (90000);
587
588                         Assert.AreEqual ((short) 64, ((SqlInt16) TestDouble64).Value, "Test#1");
589                         Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDouble.Null), "Test#2");
590
591                         try {
592                                 SqlInt16 test = (SqlInt16) TestDouble900;
593                                 Assert.Fail ("Test#3");
594                         } catch (OverflowException e) {
595                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
596                         }
597                 }
598
599                 [Test]
600                 public void SqlIntToInt16 ()
601                 {
602                         SqlInt16 Test = new SqlInt16 (12);
603                         Int16 Result = (Int16) Test;
604                         Assert.AreEqual ((short) 12, Result, "Test#1");
605                 }
606
607                 [Test]
608                 public void SqlInt32ToSqlInt16 ()
609                 {
610                         SqlInt32 Test64 = new SqlInt32 (64);
611                         SqlInt32 Test900 = new SqlInt32 (90000);
612
613                         Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
614
615                         try {
616                                 SqlInt16 test = (SqlInt16) Test900;
617                                 Assert.Fail ("Test#2");
618                         } catch (OverflowException e) {
619                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
620                         }
621                 }
622
623                 [Test]
624                 public void SqlInt64ToSqlInt16 ()
625                 {
626                         SqlInt64 Test64 = new SqlInt64 (64);
627                         SqlInt64 Test900 = new SqlInt64 (90000);
628
629                         Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
630
631                         try {
632                                 SqlInt16 test = (SqlInt16) Test900;
633                                 Assert.Fail ("Test#2");
634                         } catch (OverflowException e) {
635                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
636                         }
637                 }
638
639                 [Test]
640                 public void SqlMoneyToSqlInt16 ()
641                 {
642                         SqlMoney TestMoney64 = new SqlMoney (64);
643                         SqlMoney TestMoney900 = new SqlMoney (90000);
644
645                         Assert.AreEqual ((short) 64, ((SqlInt16) TestMoney64).Value, "Test#1");
646
647                         try {
648                                 SqlInt16 test = (SqlInt16) TestMoney900;
649                                 Assert.Fail ("Test#2");
650                         } catch (OverflowException e) {
651                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "test#3");
652                         }
653                 }
654
655                 [Test]
656                 public void SqlSingleToSqlInt16 ()
657                 {
658                         SqlSingle TestSingle64 = new SqlSingle (64);
659                         SqlSingle TestSingle900 = new SqlSingle (90000);
660
661                         Assert.AreEqual ((short) 64, ((SqlInt16) TestSingle64).Value, "Test#1");
662
663                         try {
664                                 SqlInt16 test = (SqlInt16) TestSingle900;
665                                 Assert.Fail ("Test#2");
666                         } catch (OverflowException e) {
667                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
668                         }
669                 }
670
671                 [Test]
672                 public void SqlStringToSqlInt16 ()
673                 {
674                         SqlString TestString = new SqlString ("Test string");
675                         SqlString TestString100 = new SqlString ("100");
676                         SqlString TestString1000 = new SqlString ("100000");
677
678                         Assert.AreEqual ((short) 100, ((SqlInt16) TestString100).Value, "Test#1");
679
680                         try {
681                                 SqlInt16 test = (SqlInt16) TestString1000;
682                                 Assert.Fail ("Test#2");
683                         } catch (OverflowException e) {
684                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
685                         }
686
687                         try {
688                                 SqlInt16 test = (SqlInt16) TestString;
689                                 Assert.Fail ("Test#3");
690                         } catch (FormatException e) {
691                                 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
692                         }
693                 }
694
695                 [Test]
696                 public void ByteToSqlInt16 ()
697                 {
698                         short TestShort = 14;
699                         Assert.AreEqual ((short) 14, ((SqlInt16) TestShort).Value, "Test#1");
700                 }
701 #if NET_2_0
702                 [Test]
703                 public void GetXsdTypeTest ()
704                 {
705                         XmlQualifiedName qualifiedName = SqlInt16.GetXsdType (null);
706                         NUnit.Framework.Assert.AreEqual ("short", qualifiedName.Name, "#A01");
707                 }
708
709                 internal void ReadWriteXmlTestInternal (string xml, 
710                                                        short testval, 
711                                                        string unit_test_id)
712                 {
713                         SqlInt16 test;
714                         SqlInt16 test1;
715                         XmlSerializer ser;
716                         StringWriter sw;
717                         XmlTextWriter xw;
718                         StringReader sr;
719                         XmlTextReader xr;
720
721                         test = new SqlInt16 (testval);
722                         ser = new XmlSerializer(typeof(SqlInt16));
723                         sw = new StringWriter ();
724                         xw = new XmlTextWriter (sw);
725                         
726                         ser.Serialize (xw, test);
727
728                         // Assert.AreEqual (xml, sw.ToString (), unit_test_id);
729
730                         sr = new StringReader (xml);
731                         xr = new XmlTextReader (sr);
732                         test1 = (SqlInt16)ser.Deserialize (xr);
733
734                         Assert.AreEqual (testval, test1.Value, unit_test_id);
735                 }
736
737                 [Test]
738                 public void ReadWriteXmlTest ()
739                 {
740                         string xml1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>4556</short>";
741                         string xml2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>-6445</short>";
742                         string xml3 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>0x455687AB3E4D56F</short>";
743                         short test1 = 4556;
744                         short test2 = -6445;
745                         short test3 = 0x4F56;
746
747                         ReadWriteXmlTestInternal (xml1, test1, "BA01");
748                         ReadWriteXmlTestInternal (xml2, test2, "BA02");
749                 
750                         try {
751                                 ReadWriteXmlTestInternal (xml3, test3, "BA03");
752                                 Assert.Fail ("BA03");
753                         } catch (FormatException e) {
754                                 Assert.AreEqual (typeof (FormatException), e.GetType (), "#BA03");
755                         }
756                 }
757 #endif
758         }
759 }