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