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 DivideByZeroException = System.ArithmeticException;
42 using System.Xml.Serialization;
46 namespace MonoTests.System.Data.SqlTypes
49 public class SqlInt16Test
55 SqlInt16 TestShort = new SqlInt16 (29);
56 Assert.AreEqual ((short) 29, TestShort.Value, "Test#1");
58 TestShort = new SqlInt16 (-9000);
59 Assert.AreEqual ((short) -9000, TestShort.Value, "Test#2");
64 public void PublicFields ()
66 Assert.AreEqual ((SqlInt16) 32767, SqlInt16.MaxValue, "Test#1");
67 Assert.AreEqual ((SqlInt16) (-32768), SqlInt16.MinValue, "Test#2");
68 Assert.IsTrue (SqlInt16.Null.IsNull, "Test#3");
69 Assert.AreEqual ((short) 0, SqlInt16.Zero.Value, "Test#4");
74 public void Properties ()
76 SqlInt16 Test5443 = new SqlInt16 (5443);
77 SqlInt16 Test1 = new SqlInt16 (1);
78 Assert.IsTrue (SqlInt16.Null.IsNull, "Test#1");
79 Assert.AreEqual ((short) 5443, Test5443.Value, "Test#2");
80 Assert.AreEqual ((short) 1, Test1.Value, "Test#3");
86 public void ArithmeticMethods ()
88 SqlInt16 Test64 = new SqlInt16 (64);
89 SqlInt16 Test0 = new SqlInt16 (0);
90 SqlInt16 Test164 = new SqlInt16 (164);
91 SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
94 Assert.AreEqual ((short) 64, SqlInt16.Add (Test64, Test0).Value, "Test#1");
95 Assert.AreEqual ((short) 228, SqlInt16.Add (Test64, Test164).Value, "Test#2");
96 Assert.AreEqual ((short) 164, SqlInt16.Add (Test0, Test164).Value, "Test#3");
97 Assert.AreEqual ((short) SqlInt16.MaxValue, SqlInt16.Add (TestMax, Test0).Value, "Test#4");
100 SqlInt16.Add (TestMax, Test64);
101 Assert.Fail ("Test#5");
102 } catch (OverflowException e) {
103 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
107 Assert.AreEqual ((short) 2, SqlInt16.Divide (Test164, Test64).Value, "Test#7");
108 Assert.AreEqual ((short) 0, SqlInt16.Divide (Test64, Test164).Value, "Test#8");
110 SqlInt16.Divide (Test64, Test0);
111 Assert.Fail ("Test#9");
112 } catch (DivideByZeroException e) {
113 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "Test#10");
117 Assert.AreEqual ((SqlInt16) 36, SqlInt16.Mod (Test164, Test64), "Test#11");
118 Assert.AreEqual ((SqlInt16) 64, SqlInt16.Mod (Test64, Test164), "Test#12");
121 Assert.AreEqual ((short) 10496, SqlInt16.Multiply (Test64, Test164).Value, "Test#13");
122 Assert.AreEqual ((short) 0, SqlInt16.Multiply (Test64, Test0).Value, "Test#14");
125 SqlInt16.Multiply (TestMax, Test64);
126 Assert.Fail ("Test#15");
127 } catch (OverflowException e) {
128 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#16");
132 Assert.AreEqual ((short) 100, SqlInt16.Subtract (Test164, Test64).Value, "Test#17");
135 SqlInt16.Subtract (SqlInt16.MinValue, Test164);
136 Assert.Fail ("Test#18");
137 } catch (OverflowException e) {
138 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#19");
143 Assert.AreEqual ((SqlInt16)36, SqlInt16.Modulus (Test164, Test64), "Test#20");
144 Assert.AreEqual ((SqlInt16)64, SqlInt16.Modulus (Test64, Test164), "Test#21");
149 public void BitwiseMethods ()
151 short MaxValue = SqlInt16.MaxValue.Value;
152 SqlInt16 TestInt = new SqlInt16 (0);
153 SqlInt16 TestIntMax = new SqlInt16 (MaxValue);
154 SqlInt16 TestInt2 = new SqlInt16 (10922);
155 SqlInt16 TestInt3 = new SqlInt16 (21845);
158 Assert.AreEqual ((short) 21845, SqlInt16.BitwiseAnd (TestInt3, TestIntMax).Value, "Test#1");
159 Assert.AreEqual ((short) 0, SqlInt16.BitwiseAnd (TestInt2, TestInt3).Value, "Test#2");
160 Assert.AreEqual ((short) 10922, SqlInt16.BitwiseAnd (TestInt2, TestIntMax).Value, "Test#3");
163 Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestInt2, TestInt3).Value, "Test#4");
164 Assert.AreEqual ((short) 21845, SqlInt16.BitwiseOr (TestInt, TestInt3).Value, "Test#5");
165 Assert.AreEqual ((short) MaxValue, SqlInt16.BitwiseOr (TestIntMax, TestInt2).Value, "Test#6");
169 public void CompareTo ()
171 SqlInt16 TestInt4000 = new SqlInt16 (4000);
172 SqlInt16 TestInt4000II = new SqlInt16 (4000);
173 SqlInt16 TestInt10 = new SqlInt16 (10);
174 SqlInt16 TestInt10000 = new SqlInt16 (10000);
175 SqlString TestString = new SqlString ("This is a test");
177 Assert.IsTrue (TestInt4000.CompareTo (TestInt10) > 0, "Test#1");
178 Assert.IsTrue (TestInt10.CompareTo (TestInt4000) < 0, "Test#2");
179 Assert.IsTrue (TestInt4000II.CompareTo (TestInt4000) == 0, "Test#3");
180 Assert.IsTrue (TestInt4000II.CompareTo (SqlInt16.Null) > 0, "Test#4");
183 TestInt10.CompareTo (TestString);
184 Assert.Fail ("Test#5");
185 } catch (ArgumentException e) {
186 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "Test#6");
191 public void EqualsMethod ()
193 SqlInt16 Test0 = new SqlInt16 (0);
194 SqlInt16 Test158 = new SqlInt16 (158);
195 SqlInt16 Test180 = new SqlInt16 (180);
196 SqlInt16 Test180II = new SqlInt16 (180);
198 Assert.IsTrue (!Test0.Equals (Test158), "Test#1");
199 Assert.IsTrue (!Test158.Equals (Test180), "Test#2");
200 Assert.IsTrue (!Test180.Equals (new SqlString ("TEST")), "Test#3");
201 Assert.IsTrue (Test180.Equals (Test180II), "Test#4");
205 public void StaticEqualsMethod ()
207 SqlInt16 Test34 = new SqlInt16 (34);
208 SqlInt16 Test34II = new SqlInt16 (34);
209 SqlInt16 Test15 = new SqlInt16 (15);
211 Assert.IsTrue (SqlInt16.Equals (Test34, Test34II).Value, "Test#1");
212 Assert.IsTrue (!SqlInt16.Equals (Test34, Test15).Value, "Test#2");
213 Assert.IsTrue (!SqlInt16.Equals (Test15, Test34II).Value, "Test#3");
217 public void GetHashCodeTest ()
219 SqlInt16 Test15 = new SqlInt16 (15);
221 // FIXME: Better way to test GetHashCode()-methods
222 Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "Test#1");
226 public void GetTypeTest ()
228 SqlInt16 Test = new SqlInt16 (84);
229 Assert.AreEqual ("System.Data.SqlTypes.SqlInt16", Test.GetType ().ToString (), "Test#1");
233 public void Greaters ()
235 SqlInt16 Test10 = new SqlInt16 (10);
236 SqlInt16 Test10II = new SqlInt16 (10);
237 SqlInt16 Test110 = new SqlInt16 (110);
240 Assert.IsTrue (!SqlInt16.GreaterThan (Test10, Test110).Value, "Test#1");
241 Assert.IsTrue (SqlInt16.GreaterThan (Test110, Test10).Value, "Test#2");
242 Assert.IsTrue (!SqlInt16.GreaterThan (Test10II, Test10).Value, "Test#3");
244 // GreaterTharOrEqual ()
245 Assert.IsTrue (!SqlInt16.GreaterThanOrEqual (Test10, Test110).Value, "Test#4");
246 Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test110, Test10).Value, "Test#5");
247 Assert.IsTrue (SqlInt16.GreaterThanOrEqual (Test10II, Test10).Value, "Test#6");
251 public void Lessers ()
253 SqlInt16 Test10 = new SqlInt16 (10);
254 SqlInt16 Test10II = new SqlInt16 (10);
255 SqlInt16 Test110 = new SqlInt16 (110);
258 Assert.IsTrue (SqlInt16.LessThan (Test10, Test110).Value, "Test#1");
259 Assert.IsTrue (!SqlInt16.LessThan (Test110, Test10).Value, "Test#2");
260 Assert.IsTrue (!SqlInt16.LessThan (Test10II, Test10).Value, "Test#3");
262 // LessThanOrEqual ()
263 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10, Test110).Value, "Test#4");
264 Assert.IsTrue (!SqlInt16.LessThanOrEqual (Test110, Test10).Value, "Test#5");
265 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, Test10).Value, "Test#6");
266 Assert.IsTrue (SqlInt16.LessThanOrEqual (Test10II, SqlInt16.Null).IsNull, "Test#7");
270 public void NotEquals ()
272 SqlInt16 Test12 = new SqlInt16 (12);
273 SqlInt16 Test128 = new SqlInt16 (128);
274 SqlInt16 Test128II = new SqlInt16 (128);
276 Assert.IsTrue (SqlInt16.NotEquals (Test12, Test128).Value, "Test#1");
277 Assert.IsTrue (SqlInt16.NotEquals (Test128, Test12).Value, "Test#2");
278 Assert.IsTrue (SqlInt16.NotEquals (Test128II, Test12).Value, "Test#3");
279 Assert.IsTrue (!SqlInt16.NotEquals (Test128II, Test128).Value, "Test#4");
280 Assert.IsTrue (!SqlInt16.NotEquals (Test128, Test128II).Value, "Test#5");
281 Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#6");
282 Assert.IsTrue (SqlInt16.NotEquals (SqlInt16.Null, Test128II).IsNull, "Test#7");
286 public void OnesComplement ()
288 SqlInt16 Test12 = new SqlInt16 (12);
289 SqlInt16 Test128 = new SqlInt16 (128);
291 Assert.AreEqual ((SqlInt16) (-13), SqlInt16.OnesComplement (Test12), "Test#1");
292 Assert.AreEqual ((SqlInt16) (-129), SqlInt16.OnesComplement (Test128), "Test#2");
299 SqlInt16.Parse (null);
300 Assert.Fail ("Test#1");
301 } catch (ArgumentNullException e) {
302 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "Test#2");
306 SqlInt16.Parse ("not-a-number");
307 Assert.Fail ("Test#3");
308 } catch (FormatException e) {
309 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
313 int OverInt = (int) SqlInt16.MaxValue + 1;
314 SqlInt16.Parse (OverInt.ToString ());
315 Assert.Fail ("Test#5");
316 } catch (OverflowException e) {
317 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6");
320 Assert.AreEqual ((short) 150, SqlInt16.Parse ("150").Value, "Test#7");
324 public void Conversions ()
326 SqlInt16 Test12 = new SqlInt16 (12);
327 SqlInt16 Test0 = new SqlInt16 (0);
328 SqlInt16 TestNull = SqlInt16.Null;
329 SqlInt16 Test1000 = new SqlInt16 (1000);
330 SqlInt16 Test288 = new SqlInt16 (288);
333 Assert.IsTrue (Test12.ToSqlBoolean ().Value, "TestA#1");
334 Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "TestA#2");
335 Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "TestA#3");
338 Assert.AreEqual ((byte) 12, Test12.ToSqlByte ().Value, "TestB#1");
339 Assert.AreEqual ((byte) 0, Test0.ToSqlByte ().Value, "TestB#2");
342 SqlByte b = (byte) Test1000.ToSqlByte ();
343 Assert.Fail ("TestB#4");
344 } catch (OverflowException e) {
345 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestB#5");
349 Assert.AreEqual ((decimal) 12, Test12.ToSqlDecimal ().Value, "TestC#1");
350 Assert.AreEqual ((decimal) 0, Test0.ToSqlDecimal ().Value, "TestC#2");
351 Assert.AreEqual ((decimal) 288, Test288.ToSqlDecimal ().Value, "TestC#3");
354 Assert.AreEqual ((double) 12, Test12.ToSqlDouble ().Value, "TestD#1");
355 Assert.AreEqual ((double) 0, Test0.ToSqlDouble ().Value, "TestD#2");
356 Assert.AreEqual ((double) 1000, Test1000.ToSqlDouble ().Value, "TestD#3");
359 Assert.AreEqual ((int) 12, Test12.ToSqlInt32 ().Value, "TestE#1");
360 Assert.AreEqual ((int) 0, Test0.ToSqlInt32 ().Value, "TestE#2");
361 Assert.AreEqual ((int) 288, Test288.ToSqlInt32 ().Value, "TestE#3");
364 Assert.AreEqual ((long) 12, Test12.ToSqlInt64 ().Value, "TestF#1");
365 Assert.AreEqual ((long) 0, Test0.ToSqlInt64 ().Value, "TestF#2");
366 Assert.AreEqual ((long) 288, Test288.ToSqlInt64 ().Value, "TestF#3");
369 Assert.AreEqual (12.0000M, Test12.ToSqlMoney ().Value, "TestG#1");
370 Assert.AreEqual ((decimal) 0, Test0.ToSqlMoney ().Value, "TestG#2");
371 Assert.AreEqual (288.0000M, Test288.ToSqlMoney ().Value, "TestG#3");
374 Assert.AreEqual ((float) 12, Test12.ToSqlSingle ().Value, "TestH#1");
375 Assert.AreEqual ((float) 0, Test0.ToSqlSingle ().Value, "TestH#2");
376 Assert.AreEqual ((float) 288, Test288.ToSqlSingle ().Value, "TestH#3");
379 Assert.AreEqual ("12", Test12.ToSqlString ().Value, "TestI#1");
380 Assert.AreEqual ("0", Test0.ToSqlString ().Value, "TestI#2");
381 Assert.AreEqual ("288", Test288.ToSqlString ().Value, "TestI#3");
384 Assert.AreEqual ("12", Test12.ToString (), "TestJ#1");
385 Assert.AreEqual ("0", Test0.ToString (), "TestJ#2");
386 Assert.AreEqual ("288", Test288.ToString (), "TestJ#3");
392 SqlInt16 Test14 = new SqlInt16 (14);
393 SqlInt16 Test58 = new SqlInt16 (58);
394 SqlInt16 Test130 = new SqlInt16 (130);
395 SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value);
396 SqlInt16 Test0 = new SqlInt16 (0);
398 Assert.AreEqual ((short) 52, SqlInt16.Xor (Test14, Test58).Value, "Test#1");
399 Assert.AreEqual ((short) 140, SqlInt16.Xor (Test14, Test130).Value, "Test#2");
400 Assert.AreEqual ((short) 184, SqlInt16.Xor (Test58, Test130).Value, "Test#3");
401 Assert.AreEqual ((short) 0, SqlInt16.Xor (TestMax, TestMax).Value, "Test#4");
402 Assert.AreEqual (TestMax.Value, SqlInt16.Xor (TestMax, Test0).Value, "Test#5");
408 public void ArithmeticOperators ()
410 SqlInt16 Test24 = new SqlInt16 (24);
411 SqlInt16 Test64 = new SqlInt16 (64);
412 SqlInt16 Test2550 = new SqlInt16 (2550);
413 SqlInt16 Test0 = new SqlInt16 (0);
416 Assert.AreEqual ((SqlInt16) 2614, Test2550 + Test64, "TestA#1");
418 SqlInt16 result = Test64 + SqlInt16.MaxValue;
419 Assert.Fail ("TestA#2");
420 } catch (OverflowException e) {
421 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestA#3");
425 Assert.AreEqual ((SqlInt16) 39, Test2550 / Test64, "TestB#1");
426 Assert.AreEqual ((SqlInt16) 0, Test24 / Test64, "TestB#2");
429 SqlInt16 result = Test2550 / Test0;
430 Assert.Fail ("TestB#3");
431 } catch (DivideByZeroException e) {
432 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "TestB#4");
436 Assert.AreEqual ((SqlInt16) 1536, Test64 * Test24, "TestC#1");
439 SqlInt16 test = (SqlInt16.MaxValue * Test64);
440 Assert.Fail ("TestC#2");
441 } catch (OverflowException e) {
442 Assert.AreEqual (typeof (OverflowException), e.GetType (), "TestC#3");
446 Assert.AreEqual ((SqlInt16) 2526, Test2550 - Test24, "TestD#1");
449 SqlInt16 test = SqlInt16.MinValue - Test64;
450 Assert.Fail ("TestD#2");
451 } catch (OverflowException e) {
452 Assert.AreEqual (typeof (OverflowException), e.GetType (), "OverflowException");
456 Assert.AreEqual ((SqlInt16) 54, Test2550 % Test64, "TestE#1");
457 Assert.AreEqual ((SqlInt16) 24, Test24 % Test64, "TestE#2");
458 Assert.AreEqual ((SqlInt16) 0, new SqlInt16 (100) % new SqlInt16 (10), "TestE#1");
462 public void BitwiseOperators ()
464 SqlInt16 Test2 = new SqlInt16 (2);
465 SqlInt16 Test4 = new SqlInt16 (4);
466 SqlInt16 Test2550 = new SqlInt16 (2550);
469 Assert.AreEqual ((SqlInt16) 0, Test2 & Test4, "TestA#1");
470 Assert.AreEqual ((SqlInt16) 2, Test2 & Test2550, "TestA#2");
471 Assert.AreEqual ((SqlInt16) 0, SqlInt16.MaxValue & SqlInt16.MinValue, "TestA#3");
474 Assert.AreEqual ((SqlInt16) 6, Test2 | Test4, "TestB#1");
475 Assert.AreEqual ((SqlInt16) 2550, Test2 | Test2550, "TestB#2");
476 Assert.AreEqual ((SqlInt16) (-1), SqlInt16.MinValue | SqlInt16.MaxValue, "TestB#3");
479 Assert.AreEqual ((SqlInt16) 2546, (Test2550 ^ Test4), "TestC#1");
480 Assert.AreEqual ((SqlInt16) 6, (Test2 ^ Test4), "TestC#2");
484 public void ThanOrEqualOperators ()
486 SqlInt16 Test165 = new SqlInt16 (165);
487 SqlInt16 Test100 = new SqlInt16 (100);
488 SqlInt16 Test100II = new SqlInt16 (100);
489 SqlInt16 Test255 = new SqlInt16 (2550);
492 Assert.IsTrue ((Test100 == Test100II).Value, "TestA#1");
493 Assert.IsTrue (!(Test165 == Test100).Value, "TestA#2");
494 Assert.IsTrue ((Test165 == SqlInt16.Null).IsNull, "TestA#3");
497 Assert.IsTrue (!(Test100 != Test100II).Value, "TestB#1");
498 Assert.IsTrue ((Test100 != Test255).Value, "TestB#2");
499 Assert.IsTrue ((Test165 != Test255).Value, "TestB#3");
500 Assert.IsTrue ((Test165 != SqlInt16.Null).IsNull, "TestB#4");
503 Assert.IsTrue ((Test165 > Test100).Value, "TestC#1");
504 Assert.IsTrue (!(Test165 > Test255).Value, "TestC#2");
505 Assert.IsTrue (!(Test100 > Test100II).Value, "TestC#3");
506 Assert.IsTrue ((Test165 > SqlInt16.Null).IsNull, "TestC#4");
509 Assert.IsTrue (!(Test165 >= Test255).Value, "TestD#1");
510 Assert.IsTrue ((Test255 >= Test165).Value, "TestD#2");
511 Assert.IsTrue ((Test100 >= Test100II).Value, "TestD#3");
512 Assert.IsTrue ((Test165 >= SqlInt16.Null).IsNull, "TestD#4");
515 Assert.IsTrue (!(Test165 < Test100).Value, "TestE#1");
516 Assert.IsTrue ((Test165 < Test255).Value, "TestE#2");
517 Assert.IsTrue (!(Test100 < Test100II).Value, "TestE#3");
518 Assert.IsTrue ((Test165 < SqlInt16.Null).IsNull, "TestE#4");
521 Assert.IsTrue ((Test165 <= Test255).Value, "TestF#1");
522 Assert.IsTrue (!(Test255 <= Test165).Value, "TestF#2");
523 Assert.IsTrue ((Test100 <= Test100II).Value, "TestF#3");
524 Assert.IsTrue ((Test165 <= SqlInt16.Null).IsNull, "TestF#4");
528 public void OnesComplementOperator ()
530 SqlInt16 Test12 = new SqlInt16 (12);
531 SqlInt16 Test128 = new SqlInt16 (128);
533 Assert.AreEqual ((SqlInt16) (-13), ~Test12, "Test#1");
534 Assert.AreEqual ((SqlInt16) (-129), ~Test128, "Test#2");
535 Assert.AreEqual (SqlInt16.Null, ~SqlInt16.Null, "Test#3");
539 public void UnaryNegation ()
541 SqlInt16 Test = new SqlInt16 (2000);
542 SqlInt16 TestNeg = new SqlInt16 (-3000);
544 SqlInt16 Result = -Test;
545 Assert.AreEqual ((short) (-2000), Result.Value, "Test#1");
548 Assert.AreEqual ((short) 3000, Result.Value, "Test#2");
552 public void SqlBooleanToSqlInt16 ()
554 SqlBoolean TestBoolean = new SqlBoolean (true);
557 Result = (SqlInt16) TestBoolean;
559 Assert.AreEqual ((short) 1, Result.Value, "Test#1");
561 Result = (SqlInt16) SqlBoolean.Null;
562 Assert.IsTrue (Result.IsNull, "Test#2");
566 public void SqlDecimalToSqlInt16 ()
568 SqlDecimal TestDecimal64 = new SqlDecimal (64);
569 SqlDecimal TestDecimal900 = new SqlDecimal (90000);
571 Assert.AreEqual ((short) 64, ((SqlInt16) TestDecimal64).Value, "Test#1");
572 Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDecimal.Null), "Test#2");
575 SqlInt16 test = (SqlInt16) TestDecimal900;
576 Assert.Fail ("Test#3");
577 } catch (OverflowException e) {
578 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
583 public void SqlDoubleToSqlInt16 ()
585 SqlDouble TestDouble64 = new SqlDouble (64);
586 SqlDouble TestDouble900 = new SqlDouble (90000);
588 Assert.AreEqual ((short) 64, ((SqlInt16) TestDouble64).Value, "Test#1");
589 Assert.AreEqual (SqlInt16.Null, ((SqlInt16) SqlDouble.Null), "Test#2");
592 SqlInt16 test = (SqlInt16) TestDouble900;
593 Assert.Fail ("Test#3");
594 } catch (OverflowException e) {
595 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#4");
600 public void SqlIntToInt16 ()
602 SqlInt16 Test = new SqlInt16 (12);
603 Int16 Result = (Int16) Test;
604 Assert.AreEqual ((short) 12, Result, "Test#1");
608 public void SqlInt32ToSqlInt16 ()
610 SqlInt32 Test64 = new SqlInt32 (64);
611 SqlInt32 Test900 = new SqlInt32 (90000);
613 Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
616 SqlInt16 test = (SqlInt16) Test900;
617 Assert.Fail ("Test#2");
618 } catch (OverflowException e) {
619 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
624 public void SqlInt64ToSqlInt16 ()
626 SqlInt64 Test64 = new SqlInt64 (64);
627 SqlInt64 Test900 = new SqlInt64 (90000);
629 Assert.AreEqual ((short) 64, ((SqlInt16) Test64).Value, "Test#1");
632 SqlInt16 test = (SqlInt16) Test900;
633 Assert.Fail ("Test#2");
634 } catch (OverflowException e) {
635 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
640 public void SqlMoneyToSqlInt16 ()
642 SqlMoney TestMoney64 = new SqlMoney (64);
643 SqlMoney TestMoney900 = new SqlMoney (90000);
645 Assert.AreEqual ((short) 64, ((SqlInt16) TestMoney64).Value, "Test#1");
648 SqlInt16 test = (SqlInt16) TestMoney900;
649 Assert.Fail ("Test#2");
650 } catch (OverflowException e) {
651 Assert.AreEqual (typeof (OverflowException), e.GetType (), "test#3");
656 public void SqlSingleToSqlInt16 ()
658 SqlSingle TestSingle64 = new SqlSingle (64);
659 SqlSingle TestSingle900 = new SqlSingle (90000);
661 Assert.AreEqual ((short) 64, ((SqlInt16) TestSingle64).Value, "Test#1");
664 SqlInt16 test = (SqlInt16) TestSingle900;
665 Assert.Fail ("Test#2");
666 } catch (OverflowException e) {
667 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
672 public void SqlStringToSqlInt16 ()
674 SqlString TestString = new SqlString ("Test string");
675 SqlString TestString100 = new SqlString ("100");
676 SqlString TestString1000 = new SqlString ("100000");
678 Assert.AreEqual ((short) 100, ((SqlInt16) TestString100).Value, "Test#1");
681 SqlInt16 test = (SqlInt16) TestString1000;
682 Assert.Fail ("Test#2");
683 } catch (OverflowException e) {
684 Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#3");
688 SqlInt16 test = (SqlInt16) TestString;
689 Assert.Fail ("Test#3");
690 } catch (FormatException e) {
691 Assert.AreEqual (typeof (FormatException), e.GetType (), "Test#4");
696 public void ByteToSqlInt16 ()
698 short TestShort = 14;
699 Assert.AreEqual ((short) 14, ((SqlInt16) TestShort).Value, "Test#1");
703 public void GetXsdTypeTest ()
705 XmlQualifiedName qualifiedName = SqlInt16.GetXsdType (null);
706 NUnit.Framework.Assert.AreEqual ("short", qualifiedName.Name, "#A01");
709 internal void ReadWriteXmlTestInternal (string xml,
721 test = new SqlInt16 (testval);
722 ser = new XmlSerializer(typeof(SqlInt16));
723 sw = new StringWriter ();
724 xw = new XmlTextWriter (sw);
726 ser.Serialize (xw, test);
728 // Assert.AreEqual (xml, sw.ToString (), unit_test_id);
730 sr = new StringReader (xml);
731 xr = new XmlTextReader (sr);
732 test1 = (SqlInt16)ser.Deserialize (xr);
734 Assert.AreEqual (testval, test1.Value, unit_test_id);
738 public void ReadWriteXmlTest ()
740 string xml1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>4556</short>";
741 string xml2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>-6445</short>";
742 string xml3 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><short>0x455687AB3E4D56F</short>";
745 short test3 = 0x4F56;
747 ReadWriteXmlTestInternal (xml1, test1, "BA01");
748 ReadWriteXmlTestInternal (xml2, test2, "BA02");
751 ReadWriteXmlTestInternal (xml3, test3, "BA03");
752 Assert.Fail ("BA03");
753 } catch (FormatException e) {
754 Assert.AreEqual (typeof (FormatException), e.GetType (), "#BA03");