2 // SqlInt64Test.cs - NUnit Test Cases for System.Data.SqlTypes.SqlInt64
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;
36 using System.Data.SqlTypes;
38 namespace MonoTests.System.Data.SqlTypes
41 public class SqlInt64Test : Assertion {
47 SqlInt64 TestLong = new SqlInt64 (29);
48 AssertEquals ("#A01", (long)29, TestLong.Value);
50 TestLong = new SqlInt64 (-9000);
51 AssertEquals ("#A02", (long)-9000, TestLong.Value);
56 public void PublicFields()
58 AssertEquals ("#B01", (long)9223372036854775807, SqlInt64.MaxValue.Value);
59 AssertEquals ("#B02", (long)(-9223372036854775808), SqlInt64.MinValue.Value);
60 Assert ("#B03", SqlInt64.Null.IsNull);
61 AssertEquals ("#B04", (long)0, SqlInt64.Zero.Value);
66 public void Properties()
68 SqlInt64 Test5443 = new SqlInt64 (5443);
69 SqlInt64 Test1 = new SqlInt64 (1);
71 Assert ("#C01", SqlInt64.Null.IsNull);
72 AssertEquals ("#C02", (long)5443, Test5443.Value);
73 AssertEquals ("#C03", (long)1, Test1.Value);
79 public void ArithmeticMethods()
81 SqlInt64 Test64 = new SqlInt64 (64);
82 SqlInt64 Test0 = new SqlInt64 (0);
83 SqlInt64 Test164 = new SqlInt64 (164);
84 SqlInt64 TestMax = new SqlInt64 (SqlInt64.MaxValue.Value);
87 AssertEquals ("#D01", (long)64, SqlInt64.Add (Test64, Test0).Value);
88 AssertEquals ("#D02", (long)228, SqlInt64.Add (Test64, Test164).Value);
89 AssertEquals ("#D03", (long)164, SqlInt64.Add (Test0, Test164).Value);
90 AssertEquals ("#D04", (long)SqlInt64.MaxValue, SqlInt64.Add (TestMax, Test0).Value);
93 SqlInt64.Add (TestMax, Test64);
95 } catch (Exception e) {
96 AssertEquals ("#D06", typeof (OverflowException), e.GetType ());
100 AssertEquals ("#D07", (long)2, SqlInt64.Divide (Test164, Test64).Value);
101 AssertEquals ("#D08", (long)0, SqlInt64.Divide (Test64, Test164).Value);
104 SqlInt64.Divide(Test64, Test0);
106 } catch(Exception e) {
107 AssertEquals ("#D10", typeof (DivideByZeroException), e.GetType ());
111 AssertEquals ("#D11", (SqlInt64)36, SqlInt64.Mod (Test164, Test64));
112 AssertEquals ("#D12", (SqlInt64)64, SqlInt64.Mod (Test64, Test164));
115 AssertEquals ("#D13", (long)10496, SqlInt64.Multiply (Test64, Test164).Value);
116 AssertEquals ("#D14", (long)0, SqlInt64.Multiply (Test64, Test0).Value);
119 SqlInt64.Multiply (TestMax, Test64);
121 } catch(Exception e) {
122 AssertEquals ("#D16", typeof (OverflowException), e.GetType ());
126 AssertEquals ("#D17", (long)100, SqlInt64.Subtract (Test164, Test64).Value);
129 SqlInt64.Subtract (SqlInt64.MinValue, Test164);
131 } catch(Exception e) {
132 AssertEquals ("#D19", typeof (OverflowException), e.GetType ());
137 AssertEquals ("#D20", (SqlInt64)36, SqlInt64.Modulus (Test164, Test64));
138 AssertEquals ("#D21", (SqlInt64)64, SqlInt64.Modulus (Test64, Test164));
143 public void BitwiseMethods()
145 long MaxValue = SqlInt64.MaxValue.Value;
146 SqlInt64 TestInt = new SqlInt64 (0);
147 SqlInt64 TestIntMax = new SqlInt64 (MaxValue);
148 SqlInt64 TestInt2 = new SqlInt64 (10922);
149 SqlInt64 TestInt3 = new SqlInt64 (21845);
152 AssertEquals ("#E01", (long)21845, SqlInt64.BitwiseAnd (TestInt3, TestIntMax).Value);
153 AssertEquals ("#E02", (long)0, SqlInt64.BitwiseAnd (TestInt2, TestInt3).Value);
154 AssertEquals ("#E03", (long)10922, SqlInt64.BitwiseAnd (TestInt2, TestIntMax).Value);
157 AssertEquals ("#E04", (long)21845, SqlInt64.BitwiseOr (TestInt, TestInt3).Value);
158 AssertEquals ("#E05", (long)MaxValue, SqlInt64.BitwiseOr (TestIntMax, TestInt2).Value);
162 public void CompareTo()
164 SqlInt64 TestInt4000 = new SqlInt64 (4000);
165 SqlInt64 TestInt4000II = new SqlInt64 (4000);
166 SqlInt64 TestInt10 = new SqlInt64 (10);
167 SqlInt64 TestInt10000 = new SqlInt64 (10000);
168 SqlString TestString = new SqlString ("This is a test");
170 Assert ("#F01", TestInt4000.CompareTo (TestInt10) > 0);
171 Assert ("#F02", TestInt10.CompareTo (TestInt4000) < 0);
172 Assert ("#F03", TestInt4000II.CompareTo (TestInt4000) == 0);
173 Assert ("#F04", TestInt4000II.CompareTo (SqlInt64.Null) > 0);
176 TestInt10.CompareTo (TestString);
178 } catch(Exception e) {
179 AssertEquals ("#F06", typeof (ArgumentException), e.GetType ());
184 public void EqualsMethod()
186 SqlInt64 Test0 = new SqlInt64 (0);
187 SqlInt64 Test158 = new SqlInt64 (158);
188 SqlInt64 Test180 = new SqlInt64 (180);
189 SqlInt64 Test180II = new SqlInt64 (180);
191 Assert ("#G01", !Test0.Equals (Test158));
192 Assert ("#G01", !Test158.Equals (Test180));
193 Assert ("#G03", !Test180.Equals (new SqlString ("TEST")));
194 Assert ("#G04", Test180.Equals (Test180II));
198 public void StaticEqualsMethod()
200 SqlInt64 Test34 = new SqlInt64 (34);
201 SqlInt64 Test34II = new SqlInt64 (34);
202 SqlInt64 Test15 = new SqlInt64 (15);
204 Assert ("#H01", SqlInt64.Equals (Test34, Test34II).Value);
205 Assert ("#H02", !SqlInt64.Equals (Test34, Test15).Value);
206 Assert ("#H03", !SqlInt64.Equals (Test15, Test34II).Value);
210 public void GetHashCodeTest()
212 SqlInt64 Test15 = new SqlInt64 (15);
214 // FIXME: Better way to test HashCode
215 AssertEquals ("#I01", (int)15, Test15.GetHashCode ());
219 public void GetTypeTest()
221 SqlInt64 Test = new SqlInt64 (84);
222 AssertEquals ("#J01", "System.Data.SqlTypes.SqlInt64", Test.GetType ().ToString ());
226 public void Greaters()
228 SqlInt64 Test10 = new SqlInt64 (10);
229 SqlInt64 Test10II = new SqlInt64 (10);
230 SqlInt64 Test110 = new SqlInt64 (110);
233 Assert ("#K01", !SqlInt64.GreaterThan (Test10, Test110).Value);
234 Assert ("#K02", SqlInt64.GreaterThan (Test110, Test10).Value);
235 Assert ("#K03", !SqlInt64.GreaterThan (Test10II, Test10).Value);
237 // GreaterTharOrEqual ()
238 Assert ("#K04", !SqlInt64.GreaterThanOrEqual (Test10, Test110).Value);
239 Assert ("#K05", SqlInt64.GreaterThanOrEqual (Test110, Test10).Value);
240 Assert ("#K06", SqlInt64.GreaterThanOrEqual (Test10II, Test10).Value);
244 public void Lessers()
246 SqlInt64 Test10 = new SqlInt64 (10);
247 SqlInt64 Test10II = new SqlInt64 (10);
248 SqlInt64 Test110 = new SqlInt64 (110);
251 Assert ("#L01", SqlInt64.LessThan (Test10, Test110).Value);
252 Assert ("#L02", !SqlInt64.LessThan (Test110, Test10).Value);
253 Assert ("#L03", !SqlInt64.LessThan (Test10II, Test10).Value);
255 // LessThanOrEqual ()
256 Assert ("#L04", SqlInt64.LessThanOrEqual (Test10, Test110).Value);
257 Assert ("#L05", !SqlInt64.LessThanOrEqual (Test110, Test10).Value);
258 Assert ("#L06", SqlInt64.LessThanOrEqual (Test10II, Test10).Value);
259 Assert ("#L07", SqlInt64.LessThanOrEqual (Test10II, SqlInt64.Null).IsNull);
263 public void NotEquals()
265 SqlInt64 Test12 = new SqlInt64 (12);
266 SqlInt64 Test128 = new SqlInt64 (128);
267 SqlInt64 Test128II = new SqlInt64 (128);
269 Assert ("#M01", SqlInt64.NotEquals (Test12, Test128).Value);
270 Assert ("#M02", SqlInt64.NotEquals (Test128, Test12).Value);
271 Assert ("#M03", SqlInt64.NotEquals (Test128II, Test12).Value);
272 Assert ("#M04", !SqlInt64.NotEquals (Test128II, Test128).Value);
273 Assert ("#M05", !SqlInt64.NotEquals (Test128, Test128II).Value);
274 Assert ("#M06", SqlInt64.NotEquals (SqlInt64.Null, Test128II).IsNull);
275 Assert ("#M07", SqlInt64.NotEquals (SqlInt64.Null, Test128II).IsNull);
279 public void OnesComplement()
281 SqlInt64 Test12 = new SqlInt64(12);
282 SqlInt64 Test128 = new SqlInt64(128);
284 AssertEquals ("#N01", (SqlInt64)(-13), SqlInt64.OnesComplement (Test12));
285 AssertEquals ("#N02", (SqlInt64)(-129), SqlInt64.OnesComplement (Test128));
292 SqlInt64.Parse (null);
294 } catch (Exception e) {
295 AssertEquals ("#O02", typeof (ArgumentNullException), e.GetType ());
299 SqlInt64.Parse ("not-a-number");
301 } catch (Exception e) {
302 AssertEquals ("#O04", typeof (FormatException), e.GetType ());
306 SqlInt64.Parse ("1000000000000000000000000000");
308 } catch (Exception e) {
309 AssertEquals ("#O06", typeof (OverflowException), e.GetType ());
312 AssertEquals("#O07", (long)150, SqlInt64.Parse ("150").Value);
316 public void Conversions()
318 SqlInt64 Test12 = new SqlInt64 (12);
319 SqlInt64 Test0 = new SqlInt64 (0);
320 SqlInt64 TestNull = SqlInt64.Null;
321 SqlInt64 Test1000 = new SqlInt64 (1000);
322 SqlInt64 Test288 = new SqlInt64(288);
325 Assert ("#P01", Test12.ToSqlBoolean ().Value);
326 Assert ("#P02", !Test0.ToSqlBoolean ().Value);
327 Assert ("#P03", TestNull.ToSqlBoolean ().IsNull);
330 AssertEquals ("#P04", (byte)12, Test12.ToSqlByte ().Value);
331 AssertEquals ("#P05", (byte)0, Test0.ToSqlByte ().Value);
334 SqlByte b = (byte)Test1000.ToSqlByte ();
336 } catch (Exception e) {
337 AssertEquals ("#P07", typeof (OverflowException), e.GetType ());
341 AssertEquals ("#P08", (decimal)12, Test12.ToSqlDecimal ().Value);
342 AssertEquals ("#P09", (decimal)0, Test0.ToSqlDecimal ().Value);
343 AssertEquals ("#P10", (decimal)288, Test288.ToSqlDecimal ().Value);
346 AssertEquals ("#P11", (double)12, Test12.ToSqlDouble ().Value);
347 AssertEquals ("#P12", (double)0, Test0.ToSqlDouble ().Value);
348 AssertEquals ("#P13", (double)1000, Test1000.ToSqlDouble ().Value);
351 AssertEquals ("#P14", (int)12, Test12.ToSqlInt32 ().Value);
352 AssertEquals ("#P15", (int)0, Test0.ToSqlInt32 ().Value);
353 AssertEquals ("#P16", (int)288, Test288.ToSqlInt32().Value);
356 AssertEquals ("#P17", (short)12, Test12.ToSqlInt16 ().Value);
357 AssertEquals ("#P18", (short)0, Test0.ToSqlInt16 ().Value);
358 AssertEquals ("#P19", (short)288, Test288.ToSqlInt16 ().Value);
361 AssertEquals ("#P20", 12.0000M, Test12.ToSqlMoney ().Value);
362 AssertEquals ("#P21", (decimal)0, Test0.ToSqlMoney ().Value);
363 AssertEquals ("#P22", 288.0000M, Test288.ToSqlMoney ().Value);
366 AssertEquals ("#P23", (float)12, Test12.ToSqlSingle ().Value);
367 AssertEquals ("#P24", (float)0, Test0.ToSqlSingle ().Value);
368 AssertEquals ("#P25", (float)288, Test288.ToSqlSingle().Value);
371 AssertEquals ("#P26", "12", Test12.ToSqlString ().Value);
372 AssertEquals ("#P27", "0", Test0.ToSqlString ().Value);
373 AssertEquals ("#P28", "288", Test288.ToSqlString ().Value);
376 AssertEquals ("#P29", "12", Test12.ToString ());
377 AssertEquals ("#P30", "0", Test0.ToString ());
378 AssertEquals ("#P31", "288", Test288.ToString ());
384 SqlInt64 Test14 = new SqlInt64 (14);
385 SqlInt64 Test58 = new SqlInt64 (58);
386 SqlInt64 Test130 = new SqlInt64 (130);
387 SqlInt64 TestMax = new SqlInt64 (SqlInt64.MaxValue.Value);
388 SqlInt64 Test0 = new SqlInt64 (0);
390 AssertEquals ("#Q01", (long)52, SqlInt64.Xor (Test14, Test58).Value);
391 AssertEquals ("#Q02", (long)140, SqlInt64.Xor (Test14, Test130).Value);
392 AssertEquals ("#Q03", (long)184, SqlInt64.Xor (Test58, Test130).Value);
393 AssertEquals ("#Q04", (long)0, SqlInt64.Xor (TestMax, TestMax).Value);
394 AssertEquals ("#Q05", TestMax.Value, SqlInt64.Xor (TestMax, Test0).Value);
400 public void ArithmeticOperators()
402 SqlInt64 Test24 = new SqlInt64 (24);
403 SqlInt64 Test64 = new SqlInt64 (64);
404 SqlInt64 Test2550 = new SqlInt64 (2550);
405 SqlInt64 Test0 = new SqlInt64 (0);
408 AssertEquals ("#R01", (SqlInt64)2614,Test2550 + Test64);
410 SqlInt64 result = Test64 + SqlInt64.MaxValue;
412 } catch (Exception e) {
413 AssertEquals ("#R03", typeof (OverflowException), e.GetType ());
417 AssertEquals ("#R04", (SqlInt64)39, Test2550 / Test64);
418 AssertEquals ("#R05", (SqlInt64)0, Test24 / Test64);
421 SqlInt64 result = Test2550 / Test0;
423 } catch (Exception e) {
424 AssertEquals ("#R07", typeof (DivideByZeroException), e.GetType ());
428 AssertEquals ("#R08", (SqlInt64)1536, Test64 * Test24);
431 SqlInt64 test = (SqlInt64.MaxValue * Test64);
433 } catch (Exception e) {
434 AssertEquals ("#R08", typeof (OverflowException), e.GetType ());
438 AssertEquals ("#R09", (SqlInt64)2526, Test2550 - Test24);
441 SqlInt64 test = SqlInt64.MinValue - Test64;
443 } catch (Exception e) {
444 AssertEquals ("#R11", typeof (OverflowException), e.GetType ());
448 AssertEquals ("#R12", (SqlInt64)54, Test2550 % Test64);
449 AssertEquals ("#R13", (SqlInt64)24, Test24 % Test64);
450 AssertEquals ("#R14", (SqlInt64)0, new SqlInt64 (100) % new SqlInt64 (10));
454 public void BitwiseOperators()
456 SqlInt64 Test2 = new SqlInt64 (2);
457 SqlInt64 Test4 = new SqlInt64 (4);
459 SqlInt64 Test2550 = new SqlInt64 (2550);
462 AssertEquals ("#S01", (SqlInt64)0, Test2 & Test4);
463 AssertEquals ("#S02", (SqlInt64)2, Test2 & Test2550);
464 AssertEquals ("#S03", (SqlInt64)0, SqlInt64.MaxValue & SqlInt64.MinValue);
467 AssertEquals ("#S04", (SqlInt64)6,Test2 | Test4);
468 AssertEquals ("#S05", (SqlInt64)2550, Test2 | Test2550);
469 AssertEquals ("#S06", (SqlInt64)(-1), SqlInt64.MinValue | SqlInt64.MaxValue);
472 AssertEquals("#S07", (SqlInt64)2546, (Test2550 ^ Test4));
473 AssertEquals("#S08", (SqlInt64)6, (Test2 ^ Test4));
477 public void ThanOrEqualOperators()
479 SqlInt64 Test165 = new SqlInt64 (165);
480 SqlInt64 Test100 = new SqlInt64 (100);
481 SqlInt64 Test100II = new SqlInt64 (100);
482 SqlInt64 Test255 = new SqlInt64 (2550);
485 Assert ("#T01", (Test100 == Test100II).Value);
486 Assert ("#T02", !(Test165 == Test100).Value);
487 Assert ("#T03", (Test165 == SqlInt64.Null).IsNull);
490 Assert ("#T04", !(Test100 != Test100II).Value);
491 Assert ("#T05", (Test100 != Test255).Value);
492 Assert ("#T06", (Test165 != Test255).Value);
493 Assert ("#T07", (Test165 != SqlInt64.Null).IsNull);
496 Assert ("#T08", (Test165 > Test100).Value);
497 Assert ("#T09", !(Test165 > Test255).Value);
498 Assert ("#T10", !(Test100 > Test100II).Value);
499 Assert ("#T11", (Test165 > SqlInt64.Null).IsNull);
502 Assert ("#T12", !(Test165 >= Test255).Value);
503 Assert ("#T13", (Test255 >= Test165).Value);
504 Assert ("#T14", (Test100 >= Test100II).Value);
505 Assert ("#T15", (Test165 >= SqlInt64.Null).IsNull);
508 Assert ("#T16", !(Test165 < Test100).Value);
509 Assert ("#T17", (Test165 < Test255).Value);
510 Assert ("#T18", !(Test100 < Test100II).Value);
511 Assert ("#T19", (Test165 < SqlInt64.Null).IsNull);
514 Assert ("#T20", (Test165 <= Test255).Value);
515 Assert ("#T21", !(Test255 <= Test165).Value);
516 Assert ("#T22", (Test100 <= Test100II).Value);
517 Assert ("#T23", (Test165 <= SqlInt64.Null).IsNull);
521 public void OnesComplementOperator()
523 SqlInt64 Test12 = new SqlInt64 (12);
524 SqlInt64 Test128 = new SqlInt64 (128);
526 AssertEquals ("#V01", (SqlInt64)(-13), ~Test12);
527 AssertEquals ("#V02", (SqlInt64)(-129), ~Test128);
528 AssertEquals ("#V03", SqlInt64.Null, ~SqlInt64.Null);
532 public void UnaryNegation()
534 SqlInt64 Test = new SqlInt64 (2000);
535 SqlInt64 TestNeg = new SqlInt64 (-3000);
537 SqlInt64 Result = -Test;
538 AssertEquals ("#W01", (long)(-2000), Result.Value);
541 AssertEquals ("#W02", (long)3000, Result.Value);
545 public void SqlBooleanToSqlInt64()
547 SqlBoolean TestBoolean = new SqlBoolean (true);
550 Result = (SqlInt64)TestBoolean;
552 AssertEquals ("#X01", (long)1, Result.Value);
554 Result = (SqlInt64)SqlBoolean.Null;
555 Assert ("#X02", Result.IsNull);
559 public void SqlDecimalToSqlInt64()
561 SqlDecimal TestDecimal64 = new SqlDecimal (64);
562 SqlDecimal TestDecimal900 = new SqlDecimal (90000);
564 AssertEquals("#Y01", (long)64, ((SqlInt64)TestDecimal64).Value);
565 AssertEquals("#Y02", SqlInt64.Null, ((SqlInt64)SqlDecimal.Null));
568 SqlInt64 test = (SqlInt64)SqlDecimal.MaxValue;
570 } catch (Exception e) {
571 AssertEquals("#Y04", typeof(OverflowException), e.GetType());
576 public void SqlDoubleToSqlInt64()
578 SqlDouble TestDouble64 = new SqlDouble (64);
579 SqlDouble TestDouble900 = new SqlDouble (90000);
581 AssertEquals ("#Z01", (long)64, ((SqlInt64)TestDouble64).Value);
582 AssertEquals ("#Z02", SqlInt64.Null, ((SqlInt64)SqlDouble.Null));
585 SqlInt64 test = (SqlInt64)SqlDouble.MaxValue;
587 } catch (Exception e) {
588 AssertEquals("#Z04", typeof (OverflowException), e.GetType ());
593 public void Sql64IntToInt64()
595 SqlInt64 Test = new SqlInt64 (12);
596 Int64 Result = (Int64)Test;
597 AssertEquals ("#AA01", (long)12, Result);
601 public void SqlInt32ToSqlInt64()
603 SqlInt32 Test64 = new SqlInt32 (64);
604 AssertEquals ("#AB01", (long)64, ((SqlInt64)Test64).Value);
608 public void SqlInt16ToSqlInt64()
610 SqlInt16 Test64 = new SqlInt16 (64);
611 AssertEquals ("#AC01", (long)64, ((SqlInt64)Test64).Value);
615 public void SqlMoneyToSqlInt64()
617 SqlMoney TestMoney64 = new SqlMoney(64);
618 AssertEquals ("#AD01", (long)64, ((SqlInt64)TestMoney64).Value);
622 public void SqlSingleToSqlInt64()
624 SqlSingle TestSingle64 = new SqlSingle (64);
625 AssertEquals ("#AE01", (long)64, ((SqlInt64)TestSingle64).Value);
629 public void SqlStringToSqlInt64()
631 SqlString TestString = new SqlString ("Test string");
632 SqlString TestString100 = new SqlString ("100");
633 SqlString TestString1000 = new SqlString ("1000000000000000000000");
635 AssertEquals ("#AF01", (long)100, ((SqlInt64)TestString100).Value);
638 SqlInt64 test = (SqlInt64)TestString1000;
640 } catch(Exception e) {
641 AssertEquals ("#AF03", typeof (OverflowException), e.GetType ());
645 SqlInt64 test = (SqlInt64)TestString;
647 } catch(Exception e) {
648 AssertEquals ("#AF04", typeof (FormatException), e.GetType ());
653 public void ByteToSqlInt64()
655 short TestShort = 14;
656 AssertEquals ("#G01", (long)14, ((SqlInt64)TestShort).Value);