2 // SqlInt16Test.cs - NUnit Test Cases for System.Data.SqlTypes.SqlInt16
5 // Ville Palo (vi64pa@koti.soon.fi)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
9 // (C) 2003 Martin Willemoes Hansen
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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.
35 using NUnit.Framework;
37 using System.Data.SqlTypes;
39 using DivideByZeroException = System.ArithmeticException;
42 namespace MonoTests.System.Data.SqlTypes
45 public class SqlInt16Test {
51 SqlInt16 TestShort = new SqlInt16 (29);
52 Assert.AreEqual ((short)29, TestShort.Value, "Test#1");
54 TestShort = new SqlInt16 (-9000);
55 Assert.AreEqual ((short)-9000, TestShort.Value, "Test#2");
60 public void PublicFields()
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");
70 public void Properties()
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");
82 public void ArithmeticMethods()
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);
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");
96 SqlInt16.Add (TestMax, Test64);
97 Assert.Fail ("Test#5");
98 } catch (Exception e) {
99 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
103 Assert.AreEqual ((short)2, SqlInt16.Divide (Test164, Test64).Value, "Test#7");
104 Assert.AreEqual ((short)0, SqlInt16.Divide (Test64, Test164).Value, "Test#8");
106 SqlInt16.Divide(Test64, Test0);
107 Assert.Fail ("Test#9");
108 } catch(Exception e) {
109 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "Test#10");
113 Assert.AreEqual ((SqlInt16)36, SqlInt16.Mod (Test164, Test64), "Test#11");
114 Assert.AreEqual ((SqlInt16)64, SqlInt16.Mod (Test64, Test164), "Test#12");
117 Assert.AreEqual ((short)10496, SqlInt16.Multiply (Test64, Test164).Value, "Test#13");
118 Assert.AreEqual ((short)0, SqlInt16.Multiply (Test64, Test0).Value, "Test#14");
121 SqlInt16.Multiply (TestMax, Test64);
122 Assert.Fail ("Test#15");
123 } catch(Exception e) {
124 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#16");
128 Assert.AreEqual ((short)100, SqlInt16.Subtract (Test164, Test64).Value, "Test#17");
131 SqlInt16.Subtract (SqlInt16.MinValue, Test164);
132 Assert.Fail("Test#18");
133 } catch(Exception e) {
134 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#19");
139 Assert.AreEqual ((SqlInt16)36, SqlInt16.Modulus (Test164, Test64), "Test#20");
140 Assert.AreEqual ((SqlInt16)64, SqlInt16.Modulus (Test64, Test164), "Test#21");
147 public void BitwiseMethods()
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);
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");
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");
167 public void CompareTo()
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");
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");
181 TestInt10.CompareTo (TestString);
182 Assert.Fail ("Test#5");
183 } catch(Exception e) {
184 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "Test#6");
189 public void EqualsMethod()
191 SqlInt16 Test0 = new SqlInt16 (0);
192 SqlInt16 Test158 = new SqlInt16 (158);
193 SqlInt16 Test180 = new SqlInt16 (180);
194 SqlInt16 Test180II = new SqlInt16 (180);
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");
203 public void StaticEqualsMethod()
205 SqlInt16 Test34 = new SqlInt16 (34);
206 SqlInt16 Test34II = new SqlInt16 (34);
207 SqlInt16 Test15 = new SqlInt16 (15);
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");
215 public void GetHashCodeTest()
217 SqlInt16 Test15 = new SqlInt16 (15);
219 // FIXME: Better way to test GetHashCode()-methods
220 Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "Test#1");
224 public void GetTypeTest()
226 SqlInt16 Test = new SqlInt16 (84);
227 Assert.AreEqual ("System.Data.SqlTypes.SqlInt16", Test.GetType ().ToString (), "Test#1");
231 public void Greaters()
233 SqlInt16 Test10 = new SqlInt16 (10);
234 SqlInt16 Test10II = new SqlInt16 (10);
235 SqlInt16 Test110 = new SqlInt16 (110);
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");
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");
249 public void Lessers()
251 SqlInt16 Test10 = new SqlInt16 (10);
252 SqlInt16 Test10II = new SqlInt16 (10);
253 SqlInt16 Test110 = new SqlInt16 (110);
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");
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");
268 public void NotEquals()
270 SqlInt16 Test12 = new SqlInt16 (12);
271 SqlInt16 Test128 = new SqlInt16 (128);
272 SqlInt16 Test128II = new SqlInt16 (128);
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");
284 public void OnesComplement()
286 SqlInt16 Test12 = new SqlInt16(12);
287 SqlInt16 Test128 = new SqlInt16(128);
289 Assert.AreEqual ((SqlInt16)(-13), SqlInt16.OnesComplement (Test12), "Test#1");
290 Assert.AreEqual ((SqlInt16)(-129), SqlInt16.OnesComplement (Test128), "Test#2");
297 SqlInt16.Parse (null);
298 Assert.Fail ("Test#1");
299 } catch (Exception e) {
300 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "Test#2");
304 SqlInt16.Parse ("not-a-number");
305 Assert.Fail ("Test#3");
306 } catch (Exception e) {
307 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
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");
318 Assert.AreEqual((short)150, SqlInt16.Parse ("150").Value, "Test#7");
322 public void Conversions()
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);
331 Assert.IsTrue (Test12.ToSqlBoolean ().Value, "TestA#1");
332 Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "TestA#2");
333 Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "TestA#3");
336 Assert.AreEqual ((byte)12, Test12.ToSqlByte ().Value, "TestB#1");
337 Assert.AreEqual ((byte)0, Test0.ToSqlByte ().Value, "TestB#2");
340 SqlByte b = (byte)Test1000.ToSqlByte ();
341 Assert.Fail ("TestB#4");
342 } catch (Exception e) {
343 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestB#5");
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");
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");
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");
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");
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");
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");
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");
382 Assert.AreEqual ("12", Test12.ToString (), "TestJ#1");
383 Assert.AreEqual ("0", Test0.ToString (), "TestJ#2");
384 Assert.AreEqual ("288", Test288.ToString (), "TestJ#3");
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);
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");
406 public void ArithmeticOperators()
408 SqlInt16 Test24 = new SqlInt16 (24);
409 SqlInt16 Test64 = new SqlInt16 (64);
410 SqlInt16 Test2550 = new SqlInt16 (2550);
411 SqlInt16 Test0 = new SqlInt16 (0);
414 Assert.AreEqual ((SqlInt16)2614,Test2550 + Test64, "TestA#1");
416 SqlInt16 result = Test64 + SqlInt16.MaxValue;
417 Assert.Fail ("TestA#2");
418 } catch (Exception e) {
419 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestA#3");
423 Assert.AreEqual ((SqlInt16)39, Test2550 / Test64, "TestB#1");
424 Assert.AreEqual ((SqlInt16)0, Test24 / Test64, "TestB#2");
427 SqlInt16 result = Test2550 / Test0;
428 Assert.Fail ("TestB#3");
429 } catch (Exception e) {
430 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "TestB#4");
434 Assert.AreEqual ((SqlInt16)1536, Test64 * Test24, "TestC#1");
437 SqlInt16 test = (SqlInt16.MaxValue * Test64);
438 Assert.Fail ("TestC#2");
439 } catch (Exception e) {
440 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestC#3");
444 Assert.AreEqual ((SqlInt16)2526, Test2550 - Test24, "TestD#1");
447 SqlInt16 test = SqlInt16.MinValue - Test64;
448 Assert.Fail ("TestD#2");
449 } catch (Exception e) {
450 Assert.AreEqual (typeof (OverflowException), e.GetType (), "OverflowException");
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");
460 public void BitwiseOperators()
462 SqlInt16 Test2 = new SqlInt16 (2);
463 SqlInt16 Test4 = new SqlInt16 (4);
464 SqlInt16 Test2550 = new SqlInt16 (2550);
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");
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");
477 Assert.AreEqual((SqlInt16)2546, (Test2550 ^ Test4), "TestC#1");
478 Assert.AreEqual((SqlInt16)6, (Test2 ^ Test4), "TestC#2");
482 public void ThanOrEqualOperators()
484 SqlInt16 Test165 = new SqlInt16 (165);
485 SqlInt16 Test100 = new SqlInt16 (100);
486 SqlInt16 Test100II = new SqlInt16 (100);
487 SqlInt16 Test255 = new SqlInt16 (2550);
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");
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");
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");
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");
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");
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");
526 public void OnesComplementOperator()
528 SqlInt16 Test12 = new SqlInt16 (12);
529 SqlInt16 Test128 = new SqlInt16 (128);
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");
537 public void UnaryNegation()
539 SqlInt16 Test = new SqlInt16 (2000);
540 SqlInt16 TestNeg = new SqlInt16 (-3000);
542 SqlInt16 Result = -Test;
543 Assert.AreEqual ((short)(-2000), Result.Value, "Test#1");
546 Assert.AreEqual ((short)3000, Result.Value, "Test#2");
550 public void SqlBooleanToSqlInt16()
552 SqlBoolean TestBoolean = new SqlBoolean (true);
555 Result = (SqlInt16)TestBoolean;
557 Assert.AreEqual ((short)1, Result.Value, "Test#1");
559 Result = (SqlInt16)SqlBoolean.Null;
560 Assert.IsTrue (Result.IsNull, "Test#2");
564 public void SqlDecimalToSqlInt16()
566 SqlDecimal TestDecimal64 = new SqlDecimal (64);
567 SqlDecimal TestDecimal900 = new SqlDecimal (90000);
569 Assert.AreEqual ((short)64, ((SqlInt16)TestDecimal64).Value, "Test#1");
570 Assert.AreEqual (SqlInt16.Null, ((SqlInt16)SqlDecimal.Null), "Test#2");
573 SqlInt16 test = (SqlInt16)TestDecimal900;
574 Assert.Fail ("Test#3");
575 } catch (Exception e) {
576 Assert.AreEqual(typeof(OverflowException), e.GetType (), "Test#4");
581 public void SqlDoubleToSqlInt16()
583 SqlDouble TestDouble64 = new SqlDouble (64);
584 SqlDouble TestDouble900 = new SqlDouble (90000);
586 Assert.AreEqual ((short)64, ((SqlInt16)TestDouble64).Value, "Test#1");
587 Assert.AreEqual (SqlInt16.Null, ((SqlInt16)SqlDouble.Null), "Test#2");
590 SqlInt16 test = (SqlInt16)TestDouble900;
591 Assert.Fail ("Test#3");
592 } catch (Exception e) {
593 Assert.AreEqual(typeof (OverflowException), e.GetType (), "Test#4");
598 public void SqlIntToInt16()
600 SqlInt16 Test = new SqlInt16(12);
601 Int16 Result = (Int16)Test;
602 Assert.AreEqual((short)12, Result, "Test#1");
606 public void SqlInt32ToSqlInt16()
608 SqlInt32 Test64 = new SqlInt32 (64);
609 SqlInt32 Test900 = new SqlInt32 (90000);
611 Assert.AreEqual ((short)64, ((SqlInt16)Test64).Value, "Test#1");
614 SqlInt16 test = (SqlInt16)Test900;
615 Assert.Fail ("Test#2");
616 } catch (Exception e) {
617 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
622 public void SqlInt64ToSqlInt16()
624 SqlInt64 Test64 = new SqlInt64 (64);
625 SqlInt64 Test900 = new SqlInt64 (90000);
627 Assert.AreEqual ((short)64, ((SqlInt16)Test64).Value, "Test#1");
630 SqlInt16 test = (SqlInt16)Test900;
631 Assert.Fail ("Test#2");
632 } catch (Exception e) {
633 Assert.AreEqual(typeof (OverflowException), e.GetType (), "Test#3");
638 public void SqlMoneyToSqlInt16()
640 SqlMoney TestMoney64 = new SqlMoney(64);
641 SqlMoney TestMoney900 = new SqlMoney(90000);
643 Assert.AreEqual ((short)64, ((SqlInt16)TestMoney64).Value, "Test#1");
646 SqlInt16 test = (SqlInt16)TestMoney900;
647 Assert.Fail ("Test#2");
648 } catch (Exception e) {
649 Assert.AreEqual(typeof (OverflowException), e.GetType (), "test#3");
654 public void SqlSingleToSqlInt16()
656 SqlSingle TestSingle64 = new SqlSingle(64);
657 SqlSingle TestSingle900 = new SqlSingle(90000);
659 Assert.AreEqual((short)64, ((SqlInt16)TestSingle64).Value, "Test#1");
662 SqlInt16 test = (SqlInt16)TestSingle900;
663 Assert.Fail ("Test#2");
664 } catch (Exception e) {
665 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
670 public void SqlStringToSqlInt16()
672 SqlString TestString = new SqlString("Test string");
673 SqlString TestString100 = new SqlString("100");
674 SqlString TestString1000 = new SqlString("100000");
676 Assert.AreEqual ((short)100, ((SqlInt16)TestString100).Value, "Test#1");
679 SqlInt16 test = (SqlInt16)TestString1000;
680 Assert.Fail ("Test#2");
681 } catch(Exception e) {
682 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
686 SqlInt16 test = (SqlInt16)TestString;
687 Assert.Fail ("Test#3");
688 } catch(Exception e) {
689 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
694 public void ByteToSqlInt16()
696 short TestShort = 14;
697 Assert.AreEqual ((short)14, ((SqlInt16)TestShort).Value, "Test#1");