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