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