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
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using NUnit.Framework;
37 using System.Data.SqlTypes;
39 using System.Xml.Serialization;
43 namespace MonoTests.System.Data.SqlTypes
46 public class SqlInt16Test
52 SqlInt16 TestShort = new SqlInt16 (29);
53 Assert.AreEqual ((short) 29, TestShort.Value, "Test#1");
55 TestShort = new SqlInt16 (-9000);
56 Assert.AreEqual ((short) -9000, TestShort.Value, "Test#2");
61 public void PublicFields ()
63 Assert.AreEqual ((SqlInt16) 32767, SqlInt16.MaxValue, "Test#1");
64 Assert.AreEqual ((SqlInt16) (-32768), SqlInt16.MinValue, "Test#2");
65 Assert.IsTrue (SqlInt16.Null.IsNull, "Test#3");
66 Assert.AreEqual ((short) 0, SqlInt16.Zero.Value, "Test#4");
71 public void Properties ()
73 SqlInt16 Test5443 = new SqlInt16 (5443);
74 SqlInt16 Test1 = new SqlInt16 (1);
75 Assert.IsTrue (SqlInt16.Null.IsNull, "Test#1");
76 Assert.AreEqual ((short) 5443, Test5443.Value, "Test#2");
77 Assert.AreEqual ((short) 1, Test1.Value, "Test#3");
83 public void ArithmeticMethods ()
85 SqlInt16 Test64 = new SqlInt16 (64);
86 SqlInt16 Test0 = new SqlInt16 (0);
87 SqlInt16 Test164 = new SqlInt16 (164);
88 SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
91 Assert.AreEqual ((short) 64, SqlInt16.Add (Test64, Test0).Value, "Test#1");
92 Assert.AreEqual ((short) 228, SqlInt16.Add (Test64, Test164).Value, "Test#2");
93 Assert.AreEqual ((short) 164, SqlInt16.Add (Test0, Test164).Value, "Test#3");
94 Assert.AreEqual ((short) SqlInt16.MaxValue, SqlInt16.Add (TestMax, Test0).Value, "Test#4");
97 SqlInt16.Add (TestMax, Test64);
98 Assert.Fail ("Test#5");
99 } catch (OverflowException e) {
100 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
104 Assert.AreEqual ((short) 2, SqlInt16.Divide (Test164, Test64).Value, "Test#7");
105 Assert.AreEqual ((short) 0, SqlInt16.Divide (Test64, Test164).Value, "Test#8");
107 SqlInt16.Divide (Test64, Test0);
108 Assert.Fail ("Test#9");
109 } catch (DivideByZeroException e) {
110 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "Test#10");
114 Assert.AreEqual ((SqlInt16) 36, SqlInt16.Mod (Test164, Test64), "Test#11");
115 Assert.AreEqual ((SqlInt16) 64, SqlInt16.Mod (Test64, Test164), "Test#12");
118 Assert.AreEqual ((short) 10496, SqlInt16.Multiply (Test64, Test164).Value, "Test#13");
119 Assert.AreEqual ((short) 0, SqlInt16.Multiply (Test64, Test0).Value, "Test#14");
122 SqlInt16.Multiply (TestMax, Test64);
123 Assert.Fail ("Test#15");
124 } catch (OverflowException e) {
125 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#16");
129 Assert.AreEqual ((short) 100, SqlInt16.Subtract (Test164, Test64).Value, "Test#17");
132 SqlInt16.Subtract (SqlInt16.MinValue, Test164);
133 Assert.Fail ("Test#18");
134 } catch (OverflowException e) {
135 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#19");
140 Assert.AreEqual ((SqlInt16)36, SqlInt16.Modulus (Test164, Test64), "Test#20");
141 Assert.AreEqual ((SqlInt16)64, SqlInt16.Modulus (Test64, Test164), "Test#21");
146 public void BitwiseMethods ()
148 short MaxValue = SqlInt16.MaxValue.Value;
149 SqlInt16 TestInt = new SqlInt16 (0);
150 SqlInt16 TestIntMax = new SqlInt16 (MaxValue);
151 SqlInt16 TestInt2 = new SqlInt16 (10922);
152 SqlInt16 TestInt3 = new SqlInt16 (21845);
155 Assert.AreEqual ((short) 21845, SqlInt16.BitwiseAnd (TestInt3, TestIntMax).Value, "Test#1");
156 Assert.AreEqual ((short) 0, SqlInt16.BitwiseAnd (TestInt2, TestInt3).Value, "Test#2");
157 Assert.AreEqual ((short) 10922, SqlInt16.BitwiseAnd (TestInt2, TestIntMax).Value, "Test#3");
160 Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestInt2, TestInt3).Value, "Test#4");
161 Assert.AreEqual ((short) 21845, SqlInt16.BitwiseOr (TestInt, TestInt3).Value, "Test#5");
162 Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestIntMax, TestInt2).Value, "Test#6");
166 public void CompareTo ()
168 SqlInt16 TestInt4000 = new SqlInt16 (4000);
169 SqlInt16 TestInt4000II = new SqlInt16 (4000);
170 SqlInt16 TestInt10 = new SqlInt16 (10);
171 SqlInt16 TestInt10000 = new SqlInt16 (10000);
172 SqlString TestString = new SqlString ("This is a test");
174 Assert.IsTrue (TestInt4000.CompareTo (TestInt10) > 0, "Test#1");
175 Assert.IsTrue (TestInt10.CompareTo (TestInt4000) < 0, "Test#2");
176 Assert.IsTrue (TestInt4000II.CompareTo (TestInt4000) == 0, "Test#3");
177 Assert.IsTrue (TestInt4000II.CompareTo (SqlInt16.Null) > 0, "Test#4");
180 TestInt10.CompareTo (TestString);
181 Assert.Fail ("Test#5");
182 } catch (ArgumentException e) {
183 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "Test#6");
188 public void EqualsMethod ()
190 SqlInt16 Test0 = new SqlInt16 (0);
191 SqlInt16 Test158 = new SqlInt16 (158);
192 SqlInt16 Test180 = new SqlInt16 (180);
193 SqlInt16 Test180II = new SqlInt16 (180);
195 Assert.IsTrue (!Test0.Equals (Test158), "Test#1");
196 Assert.IsTrue (!Test158.Equals (Test180), "Test#2");
197 Assert.IsTrue (!Test180.Equals (new SqlString ("TEST")), "Test#3");
198 Assert.IsTrue (Test180.Equals (Test180II), "Test#4");
202 public void StaticEqualsMethod ()
204 SqlInt16 Test34 = new SqlInt16 (34);
205 SqlInt16 Test34II = new SqlInt16 (34);
206 SqlInt16 Test15 = new SqlInt16 (15);
208 Assert.IsTrue (SqlInt16.Equals (Test34, Test34II).Value, "Test#1");
209 Assert.IsTrue (!SqlInt16.Equals (Test34, Test15).Value, "Test#2");
210 Assert.IsTrue (!SqlInt16.Equals (Test15, Test34II).Value, "Test#3");
214 public void GetHashCodeTest ()
216 SqlInt16 Test15 = new SqlInt16 (15);
218 // FIXME: Better way to test GetHashCode()-methods
219 Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "Test#1");
223 public void GetTypeTest ()
225 SqlInt16 Test = new SqlInt16 (84);
226 Assert.AreEqual ("System.Data.SqlTypes.SqlInt16", Test.GetType ().ToString (), "Test#1");
230 public void Greaters ()
232 SqlInt16 Test10 = new SqlInt16 (10);
233 SqlInt16 Test10II = new SqlInt16 (10);
234 SqlInt16 Test110 = new SqlInt16 (110);
237 Assert.IsTrue (!SqlInt16.GreaterThan (Test10, Test110).Value, "Test#1");
238 Assert.IsTrue (SqlInt16.GreaterThan (Test110, Test10).Value, "Test#2");
239 Assert.IsTrue (!SqlInt16.GreaterThan (Test10II, Test10).Value, "Test#3");
241 // GreaterTharOrEqual ()
242 Assert.IsTrue (!SqlInt16.GreaterThanOrEqual (Test10, Test110).Value, "Test#4");
243 Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test110, Test10).Value, "Test#5");
244 Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test10II, Test10).Value, "Test#6");
248 public void Lessers ()
250 SqlInt16 Test10 = new SqlInt16 (10);
251 SqlInt16 Test10II = new SqlInt16 (10);
252 SqlInt16 Test110 = new SqlInt16 (110);
255 Assert.IsTrue (SqlInt16.LessThan (Test10, Test110).Value, "Test#1");
256 Assert.IsTrue (!SqlInt16.LessThan (Test110, Test10).Value, "Test#2");
257 Assert.IsTrue (!SqlInt16.LessThan (Test10II, Test10).Value, "Test#3");
259 // LessThanOrEqual ()
260 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10, Test110).Value, "Test#4");
261 Assert.IsTrue (!SqlInt16.LessThanOrEqual (Test110, Test10).Value, "Test#5");
262 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, Test10).Value, "Test#6");
263 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, SqlInt16.Null).IsNull, "Test#7");
267 public void NotEquals ()
269 SqlInt16 Test12 = new SqlInt16 (12);
270 SqlInt16 Test128 = new SqlInt16 (128);
271 SqlInt16 Test128II = new SqlInt16 (128);
273 Assert.IsTrue (SqlInt16.NotEquals (Test12, Test128).Value, "Test#1");
274 Assert.IsTrue (SqlInt16.NotEquals (Test128, Test12).Value, "Test#2");
275 Assert.IsTrue (SqlInt16.NotEquals (Test128II, Test12).Value, "Test#3");
276 Assert.IsTrue (!SqlInt16.NotEquals (Test128II, Test128).Value, "Test#4");
277 Assert.IsTrue (!SqlInt16.NotEquals (Test128, Test128II).Value, "Test#5");
278 Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#6");
279 Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#7");
283 public void OnesComplement ()
285 SqlInt16 Test12 = new SqlInt16 (12);
286 SqlInt16 Test128 = new SqlInt16 (128);
288 Assert.AreEqual ((SqlInt16) (-13), SqlInt16.OnesComplement (Test12), "Test#1");
289 Assert.AreEqual ((SqlInt16) (-129), SqlInt16.OnesComplement (Test128), "Test#2");
296 SqlInt16.Parse (null);
297 Assert.Fail ("Test#1");
298 } catch (ArgumentNullException e) {
299 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "Test#2");
303 SqlInt16.Parse ("not-a-number");
304 Assert.Fail ("Test#3");
305 } catch (FormatException e) {
306 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
310 int OverInt = (int) SqlInt16.MaxValue + 1;
311 SqlInt16.Parse (OverInt.ToString ());
312 Assert.Fail ("Test#5");
313 } catch (OverflowException e) {
314 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
317 Assert.AreEqual ((short) 150, SqlInt16.Parse ("150").Value, "Test#7");
321 public void Conversions ()
323 SqlInt16 Test12 = new SqlInt16 (12);
324 SqlInt16 Test0 = new SqlInt16 (0);
325 SqlInt16 TestNull = SqlInt16.Null;
326 SqlInt16 Test1000 = new SqlInt16 (1000);
327 SqlInt16 Test288 = new SqlInt16 (288);
330 Assert.IsTrue (Test12.ToSqlBoolean ().Value, "TestA#1");
331 Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "TestA#2");
332 Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "TestA#3");
335 Assert.AreEqual ((byte) 12, Test12.ToSqlByte ().Value, "TestB#1");
336 Assert.AreEqual ((byte) 0, Test0.ToSqlByte ().Value, "TestB#2");
339 SqlByte b = (byte) Test1000.ToSqlByte ();
340 Assert.Fail ("TestB#4");
341 } catch (OverflowException e) {
342 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestB#5");
346 Assert.AreEqual ((decimal) 12, Test12.ToSqlDecimal ().Value, "TestC#1");
347 Assert.AreEqual ((decimal) 0, Test0.ToSqlDecimal ().Value, "TestC#2");
348 Assert.AreEqual ((decimal) 288, Test288.ToSqlDecimal ().Value, "TestC#3");
351 Assert.AreEqual ((double) 12, Test12.ToSqlDouble ().Value, "TestD#1");
352 Assert.AreEqual ((double) 0, Test0.ToSqlDouble ().Value, "TestD#2");
353 Assert.AreEqual ((double) 1000, Test1000.ToSqlDouble ().Value, "TestD#3");
356 Assert.AreEqual ((int) 12, Test12.ToSqlInt32 ().Value, "TestE#1");
357 Assert.AreEqual ((int) 0, Test0.ToSqlInt32 ().Value, "TestE#2");
358 Assert.AreEqual ((int) 288, Test288.ToSqlInt32 ().Value, "TestE#3");
361 Assert.AreEqual ((long) 12, Test12.ToSqlInt64 ().Value, "TestF#1");
362 Assert.AreEqual ((long) 0, Test0.ToSqlInt64 ().Value, "TestF#2");
363 Assert.AreEqual ((long) 288, Test288.ToSqlInt64 ().Value, "TestF#3");
366 Assert.AreEqual (12.0000M, Test12.ToSqlMoney ().Value, "TestG#1");
367 Assert.AreEqual ((decimal) 0, Test0.ToSqlMoney ().Value, "TestG#2");
368 Assert.AreEqual (288.0000M, Test288.ToSqlMoney ().Value, "TestG#3");
371 Assert.AreEqual ((float) 12, Test12.ToSqlSingle ().Value, "TestH#1");
372 Assert.AreEqual ((float) 0, Test0.ToSqlSingle ().Value, "TestH#2");
373 Assert.AreEqual ((float) 288, Test288.ToSqlSingle ().Value, "TestH#3");
376 Assert.AreEqual ("12", Test12.ToSqlString ().Value, "TestI#1");
377 Assert.AreEqual ("0", Test0.ToSqlString ().Value, "TestI#2");
378 Assert.AreEqual ("288", Test288.ToSqlString ().Value, "TestI#3");
381 Assert.AreEqual ("12", Test12.ToString (), "TestJ#1");
382 Assert.AreEqual ("0", Test0.ToString (), "TestJ#2");
383 Assert.AreEqual ("288", Test288.ToString (), "TestJ#3");
389 SqlInt16 Test14 = new SqlInt16 (14);
390 SqlInt16 Test58 = new SqlInt16 (58);
391 SqlInt16 Test130 = new SqlInt16 (130);
392 SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
393 SqlInt16 Test0 = new SqlInt16 (0);
395 Assert.AreEqual ((short) 52, SqlInt16.Xor (Test14, Test58).Value, "Test#1");
396 Assert.AreEqual ((short) 140, SqlInt16.Xor (Test14, Test130).Value, "Test#2");
397 Assert.AreEqual ((short) 184, SqlInt16.Xor (Test58, Test130).Value, "Test#3");
398 Assert.AreEqual ((short) 0, SqlInt16.Xor (TestMax, TestMax).Value, "Test#4");
399 Assert.AreEqual (TestMax.Value, SqlInt16.Xor (TestMax, Test0).Value, "Test#5");
405 public void ArithmeticOperators ()
407 SqlInt16 Test24 = new SqlInt16 (24);
408 SqlInt16 Test64 = new SqlInt16 (64);
409 SqlInt16 Test2550 = new SqlInt16 (2550);
410 SqlInt16 Test0 = new SqlInt16 (0);
413 Assert.AreEqual ((SqlInt16) 2614, Test2550 + Test64, "TestA#1");
415 SqlInt16 result = Test64 + SqlInt16.MaxValue;
416 Assert.Fail ("TestA#2");
417 } catch (OverflowException e) {
418 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestA#3");
422 Assert.AreEqual ((SqlInt16) 39, Test2550 / Test64, "TestB#1");
423 Assert.AreEqual ((SqlInt16) 0, Test24 / Test64, "TestB#2");
426 SqlInt16 result = Test2550 / Test0;
427 Assert.Fail ("TestB#3");
428 } catch (DivideByZeroException e) {
429 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "TestB#4");
433 Assert.AreEqual ((SqlInt16) 1536, Test64 * Test24, "TestC#1");
436 SqlInt16 test = (SqlInt16.MaxValue * Test64);
437 Assert.Fail ("TestC#2");
438 } catch (OverflowException e) {
439 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestC#3");
443 Assert.AreEqual ((SqlInt16) 2526, Test2550 - Test24, "TestD#1");
446 SqlInt16 test = SqlInt16.MinValue - Test64;
447 Assert.Fail ("TestD#2");
448 } catch (OverflowException e) {
449 Assert.AreEqual (typeof (OverflowException), e.GetType (), "OverflowException");
453 Assert.AreEqual ((SqlInt16) 54, Test2550 % Test64, "TestE#1");
454 Assert.AreEqual ((SqlInt16) 24, Test24 % Test64, "TestE#2");
455 Assert.AreEqual ((SqlInt16) 0, new SqlInt16 (100) % new SqlInt16 (10), "TestE#1");
459 public void BitwiseOperators ()
461 SqlInt16 Test2 = new SqlInt16 (2);
462 SqlInt16 Test4 = new SqlInt16 (4);
463 SqlInt16 Test2550 = new SqlInt16 (2550);
466 Assert.AreEqual ((SqlInt16) 0, Test2 & Test4, "TestA#1");
467 Assert.AreEqual ((SqlInt16) 2, Test2 & Test2550, "TestA#2");
468 Assert.AreEqual ((SqlInt16) 0, SqlInt16.MaxValue & SqlInt16.MinValue, "TestA#3");
471 Assert.AreEqual ((SqlInt16) 6, Test2 | Test4, "TestB#1");
472 Assert.AreEqual ((SqlInt16) 2550, Test2 | Test2550, "TestB#2");
473 Assert.AreEqual ((SqlInt16) (-1), SqlInt16.MinValue | SqlInt16.MaxValue, "TestB#3");
476 Assert.AreEqual ((SqlInt16) 2546, (Test2550 ^ Test4), "TestC#1");
477 Assert.AreEqual ((SqlInt16) 6, (Test2 ^ Test4), "TestC#2");
481 public void ThanOrEqualOperators ()
483 SqlInt16 Test165 = new SqlInt16 (165);
484 SqlInt16 Test100 = new SqlInt16 (100);
485 SqlInt16 Test100II = new SqlInt16 (100);
486 SqlInt16 Test255 = new SqlInt16 (2550);
489 Assert.IsTrue ((Test100 == Test100II).Value, "TestA#1");
490 Assert.IsTrue (!(Test165 == Test100).Value, "TestA#2");
491 Assert.IsTrue ((Test165 == SqlInt16.Null).IsNull, "TestA#3");
494 Assert.IsTrue (!(Test100 != Test100II).Value, "TestB#1");
495 Assert.IsTrue ((Test100 != Test255).Value, "TestB#2");
496 Assert.IsTrue ((Test165 != Test255).Value, "TestB#3");
497 Assert.IsTrue ((Test165 != SqlInt16.Null).IsNull, "TestB#4");
500 Assert.IsTrue ((Test165 > Test100).Value, "TestC#1");
501 Assert.IsTrue (!(Test165 > Test255).Value, "TestC#2");
502 Assert.IsTrue (!(Test100 > Test100II).Value, "TestC#3");
503 Assert.IsTrue ((Test165 > SqlInt16.Null).IsNull, "TestC#4");
506 Assert.IsTrue (!(Test165 >= Test255).Value, "TestD#1");
507 Assert.IsTrue ((Test255 >= Test165).Value, "TestD#2");
508 Assert.IsTrue ((Test100 >= Test100II).Value, "TestD#3");
509 Assert.IsTrue ((Test165 >= SqlInt16.Null).IsNull, "TestD#4");
512 Assert.IsTrue (!(Test165 < Test100).Value, "TestE#1");
513 Assert.IsTrue ((Test165 < Test255).Value, "TestE#2");
514 Assert.IsTrue (!(Test100 < Test100II).Value, "TestE#3");
515 Assert.IsTrue ((Test165 < SqlInt16.Null).IsNull, "TestE#4");
518 Assert.IsTrue ((Test165 <= Test255).Value, "TestF#1");
519 Assert.IsTrue (!(Test255 <= Test165).Value, "TestF#2");
520 Assert.IsTrue ((Test100 <= Test100II).Value, "TestF#3");
521 Assert.IsTrue ((Test165 <= SqlInt16.Null).IsNull, "TestF#4");
525 public void OnesComplementOperator ()
527 SqlInt16 Test12 = new SqlInt16 (12);
528 SqlInt16 Test128 = new SqlInt16 (128);
530 Assert.AreEqual ((SqlInt16) (-13), ~Test12, "Test#1");
531 Assert.AreEqual ((SqlInt16) (-129), ~Test128, "Test#2");
532 Assert.AreEqual (SqlInt16.Null, ~SqlInt16.Null, "Test#3");
536 public void UnaryNegation ()
538 SqlInt16 Test = new SqlInt16 (2000);
539 SqlInt16 TestNeg = new SqlInt16 (-3000);
541 SqlInt16 Result = -Test;
542 Assert.AreEqual ((short) (-2000), Result.Value, "Test#1");
545 Assert.AreEqual ((short) 3000, Result.Value, "Test#2");
549 public void SqlBooleanToSqlInt16 ()
551 SqlBoolean TestBoolean = new SqlBoolean (true);
554 Result = (SqlInt16) TestBoolean;
556 Assert.AreEqual ((short) 1, Result.Value, "Test#1");
558 Result = (SqlInt16) SqlBoolean.Null;
559 Assert.IsTrue (Result.IsNull, "Test#2");
563 public void SqlDecimalToSqlInt16 ()
565 SqlDecimal TestDecimal64 = new SqlDecimal (64);
566 SqlDecimal TestDecimal900 = new SqlDecimal (90000);
568 Assert.AreEqual ((short) 64, ((SqlInt16) TestDecimal64).Value, "Test#1");
569 Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDecimal.Null), "Test#2");
572 SqlInt16 test = (SqlInt16) TestDecimal900;
573 Assert.Fail ("Test#3");
574 } catch (OverflowException e) {
575 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
580 public void SqlDoubleToSqlInt16 ()
582 SqlDouble TestDouble64 = new SqlDouble (64);
583 SqlDouble TestDouble900 = new SqlDouble (90000);
585 Assert.AreEqual ((short) 64, ((SqlInt16) TestDouble64).Value, "Test#1");
586 Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDouble.Null), "Test#2");
589 SqlInt16 test = (SqlInt16) TestDouble900;
590 Assert.Fail ("Test#3");
591 } catch (OverflowException e) {
592 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
597 public void SqlIntToInt16 ()
599 SqlInt16 Test = new SqlInt16 (12);
600 Int16 Result = (Int16) Test;
601 Assert.AreEqual ((short) 12, Result, "Test#1");
605 public void SqlInt32ToSqlInt16 ()
607 SqlInt32 Test64 = new SqlInt32 (64);
608 SqlInt32 Test900 = new SqlInt32 (90000);
610 Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
613 SqlInt16 test = (SqlInt16) Test900;
614 Assert.Fail ("Test#2");
615 } catch (OverflowException e) {
616 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
621 public void SqlInt64ToSqlInt16 ()
623 SqlInt64 Test64 = new SqlInt64 (64);
624 SqlInt64 Test900 = new SqlInt64 (90000);
626 Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
629 SqlInt16 test = (SqlInt16) Test900;
630 Assert.Fail ("Test#2");
631 } catch (OverflowException e) {
632 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
637 public void SqlMoneyToSqlInt16 ()
639 SqlMoney TestMoney64 = new SqlMoney (64);
640 SqlMoney TestMoney900 = new SqlMoney (90000);
642 Assert.AreEqual ((short) 64, ((SqlInt16) TestMoney64).Value, "Test#1");
645 SqlInt16 test = (SqlInt16) TestMoney900;
646 Assert.Fail ("Test#2");
647 } catch (OverflowException e) {
648 Assert.AreEqual (typeof (OverflowException), e.GetType (), "test#3");
653 public void SqlSingleToSqlInt16 ()
655 SqlSingle TestSingle64 = new SqlSingle (64);
656 SqlSingle TestSingle900 = new SqlSingle (90000);
658 Assert.AreEqual ((short) 64, ((SqlInt16) TestSingle64).Value, "Test#1");
661 SqlInt16 test = (SqlInt16) TestSingle900;
662 Assert.Fail ("Test#2");
663 } catch (OverflowException e) {
664 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
669 public void SqlStringToSqlInt16 ()
671 SqlString TestString = new SqlString ("Test string");
672 SqlString TestString100 = new SqlString ("100");
673 SqlString TestString1000 = new SqlString ("100000");
675 Assert.AreEqual ((short) 100, ((SqlInt16) TestString100).Value, "Test#1");
678 SqlInt16 test = (SqlInt16) TestString1000;
679 Assert.Fail ("Test#2");
680 } catch (OverflowException e) {
681 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
685 SqlInt16 test = (SqlInt16) TestString;
686 Assert.Fail ("Test#3");
687 } catch (FormatException e) {
688 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
693 public void ByteToSqlInt16 ()
695 short TestShort = 14;
696 Assert.AreEqual ((short) 14, ((SqlInt16) TestShort).Value, "Test#1");
700 public void GetXsdTypeTest ()
702 XmlQualifiedName qualifiedName = SqlInt16.GetXsdType (null);
703 NUnit.Framework.Assert.AreEqual ("short", qualifiedName.Name, "#A01");
706 internal void ReadWriteXmlTestInternal (string xml,
718 test = new SqlInt16 (testval);
719 ser = new XmlSerializer(typeof(SqlInt16));
720 sw = new StringWriter ();
721 xw = new XmlTextWriter (sw);
723 ser.Serialize (xw, test);
725 // Assert.AreEqual (xml, sw.ToString (), unit_test_id);
727 sr = new StringReader (xml);
728 xr = new XmlTextReader (sr);
729 test1 = (SqlInt16)ser.Deserialize (xr);
731 Assert.AreEqual (testval, test1.Value, unit_test_id);
735 public void ReadWriteXmlTest ()
737 string xml1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>4556</short>";
738 string xml2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>-6445</short>";
739 string xml3 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>0x455687AB3E4D56F</short>";
742 short test3 = 0x4F56;
744 ReadWriteXmlTestInternal (xml1, test1, "BA01");
745 ReadWriteXmlTestInternal (xml2, test2, "BA02");
748 ReadWriteXmlTestInternal (xml3, test3, "BA03");
749 Assert.Fail ("BA03");
750 } catch (FormatException e) {
751 Assert.AreEqual (typeof (FormatException), e.GetType (), "#BA03");