Grasshopper project system now uses csproj extension
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlInt64Test.cs
1 //
2 // SqlInt64Test.cs - NUnit Test Cases for System.Data.SqlTypes.SqlInt64
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 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
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:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
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.
32 //
33
34 using NUnit.Framework;
35 using System;
36 using System.Data.SqlTypes;
37 #if TARGET_JVM
38 using DivideByZeroException = System.ArithmeticException;
39 #endif
40
41 namespace MonoTests.System.Data.SqlTypes
42 {
43         [TestFixture]
44         public class SqlInt64Test
45         {
46
47                 // Test constructor
48                 [Test]
49                 public void Create()
50                 {
51                         SqlInt64 TestLong = new SqlInt64 (29);
52                         Assert.AreEqual ((long)29, TestLong.Value, "#A01");
53
54                         TestLong = new SqlInt64 (-9000);
55                         Assert.AreEqual ((long)-9000, TestLong.Value, "#A02");
56                  }
57
58                 // Test public fields
59                 [Test]
60                 public void PublicFields()
61                 {
62                         Assert.AreEqual ((long)9223372036854775807, SqlInt64.MaxValue.Value, "#B01");
63                         Assert.AreEqual ((long)(-9223372036854775808), SqlInt64.MinValue.Value, "#B02");
64                         Assert.IsTrue (SqlInt64.Null.IsNull, "#B03");
65                         Assert.AreEqual ((long)0, SqlInt64.Zero.Value, "#B04");
66                 }
67
68                 // Test properties
69                 [Test]
70                 public void Properties()
71                 {
72                         SqlInt64 Test5443 = new SqlInt64 (5443);
73                         SqlInt64 Test1 = new SqlInt64 (1);
74
75                         Assert.IsTrue (SqlInt64.Null.IsNull, "#C01");
76                         Assert.AreEqual ((long)5443, Test5443.Value, "#C02");
77                         Assert.AreEqual ((long)1, Test1.Value, "#C03");
78                 }
79
80                 // PUBLIC METHODS
81
82                 [Test]
83                 public void ArithmeticMethods()
84                 {
85                         SqlInt64 Test64 = new SqlInt64 (64);
86                         SqlInt64 Test0 = new SqlInt64 (0);
87                         SqlInt64 Test164 = new SqlInt64 (164);
88                         SqlInt64 TestMax = new SqlInt64 (SqlInt64.MaxValue.Value);
89
90                         // Add()
91                         Assert.AreEqual ((long)64, SqlInt64.Add (Test64, Test0).Value, "#D01");
92                         Assert.AreEqual ((long)228, SqlInt64.Add (Test64, Test164).Value, "#D02");
93                         Assert.AreEqual ((long)164, SqlInt64.Add (Test0, Test164).Value, "#D03");
94                         Assert.AreEqual ((long)SqlInt64.MaxValue, SqlInt64.Add (TestMax, Test0).Value, "#D04");
95
96                         try {
97                                 SqlInt64.Add (TestMax, Test64);
98                                 Assert.Fail ("#D05");
99                         } catch (Exception e) {
100                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D06");
101                         }
102
103                         // Divide()
104                         Assert.AreEqual ((long)2, SqlInt64.Divide (Test164, Test64).Value, "#D07");
105                         Assert.AreEqual ((long)0, SqlInt64.Divide (Test64, Test164).Value, "#D08");
106
107                         try {
108                                 SqlInt64.Divide(Test64, Test0);
109                                 Assert.Fail ("#D09");
110                         } catch(Exception e) {
111                                 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "#D10");
112                         }
113
114                         // Mod()
115                         Assert.AreEqual ((SqlInt64)36, SqlInt64.Mod (Test164, Test64), "#D11");
116                         Assert.AreEqual ((SqlInt64)64, SqlInt64.Mod (Test64, Test164), "#D12");
117
118                         // Multiply()
119                         Assert.AreEqual ((long)10496, SqlInt64.Multiply (Test64, Test164).Value, "#D13");
120                         Assert.AreEqual ((long)0, SqlInt64.Multiply (Test64, Test0).Value, "#D14");
121
122                         try {
123                                 SqlInt64.Multiply (TestMax, Test64);
124                                 Assert.Fail ("#D15");
125                         } catch(Exception e) {
126                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D16");
127                         }
128
129                         // Subtract()
130                         Assert.AreEqual ((long)100, SqlInt64.Subtract (Test164, Test64).Value, "#D17");
131
132                         try {
133                                 SqlInt64.Subtract (SqlInt64.MinValue, Test164);
134                                 Assert.Fail ("#D18");
135                         } catch(Exception e) {
136                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D19");
137                         }
138
139                         #if NET_2_0
140                          // Modulus ()
141                         Assert.AreEqual ((SqlInt64)36, SqlInt64.Modulus (Test164, Test64), "#D20");
142                         Assert.AreEqual ((SqlInt64)64, SqlInt64.Modulus (Test64, Test164), "#D21");
143                         #endif
144                 }
145
146                 [Test]
147                 public void BitwiseMethods()
148                 {
149                         long MaxValue = SqlInt64.MaxValue.Value;
150                         SqlInt64 TestInt = new SqlInt64 (0);
151                         SqlInt64 TestIntMax = new SqlInt64 (MaxValue);
152                         SqlInt64 TestInt2 = new SqlInt64 (10922);
153                         SqlInt64 TestInt3 = new SqlInt64 (21845);
154
155                         // BitwiseAnd
156                         Assert.AreEqual ((long)21845, SqlInt64.BitwiseAnd (TestInt3, TestIntMax).Value, "#E01");
157                         Assert.AreEqual ((long)0, SqlInt64.BitwiseAnd (TestInt2, TestInt3).Value, "#E02");
158                         Assert.AreEqual ((long)10922, SqlInt64.BitwiseAnd (TestInt2, TestIntMax).Value, "#E03");
159
160                         //BitwiseOr
161                         Assert.AreEqual ((long)21845, SqlInt64.BitwiseOr (TestInt, TestInt3).Value, "#E04");
162                         Assert.AreEqual ((long)MaxValue, SqlInt64.BitwiseOr (TestIntMax, TestInt2).Value, "#E05");
163                 }
164
165                 [Test]
166                 public void CompareTo()
167                 {
168                         SqlInt64 TestInt4000 = new SqlInt64 (4000);
169                         SqlInt64 TestInt4000II = new SqlInt64 (4000);
170                         SqlInt64 TestInt10 = new SqlInt64 (10);
171                         SqlInt64 TestInt10000 = new SqlInt64 (10000);
172                         SqlString TestString = new SqlString ("This is a test");
173
174                         Assert.IsTrue (TestInt4000.CompareTo (TestInt10) > 0, "#F01");
175                         Assert.IsTrue (TestInt10.CompareTo (TestInt4000) < 0, "#F02");
176                         Assert.IsTrue (TestInt4000II.CompareTo (TestInt4000) == 0, "#F03");
177                         Assert.IsTrue (TestInt4000II.CompareTo (SqlInt64.Null) > 0, "#F04");
178
179                         try {
180                                 TestInt10.CompareTo (TestString);
181                                 Assert.Fail("#F05");
182                         } catch(Exception e) {
183                                 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "#F06");
184                         }
185                 }
186
187                 [Test]
188                 public void EqualsMethod()
189                 {
190                         SqlInt64 Test0 = new SqlInt64 (0);
191                         SqlInt64 Test158 = new SqlInt64 (158);
192                         SqlInt64 Test180 = new SqlInt64 (180);
193                         SqlInt64 Test180II = new SqlInt64 (180);
194
195                         Assert.IsTrue (!Test0.Equals (Test158), "#G01");
196                         Assert.IsTrue (!Test158.Equals (Test180), "#G01");
197                         Assert.IsTrue (!Test180.Equals (new SqlString ("TEST")), "#G03");
198                         Assert.IsTrue (Test180.Equals (Test180II), "#G04");
199                 }
200
201                 [Test]
202                 public void StaticEqualsMethod()
203                 {
204                         SqlInt64 Test34 = new SqlInt64 (34);
205                         SqlInt64 Test34II = new SqlInt64 (34);
206                         SqlInt64 Test15 = new SqlInt64 (15);
207
208                         Assert.IsTrue (SqlInt64.Equals (Test34, Test34II).Value, "#H01");
209                         Assert.IsTrue (!SqlInt64.Equals (Test34, Test15).Value, "#H02");
210                         Assert.IsTrue (!SqlInt64.Equals (Test15, Test34II).Value, "#H03");
211                 }
212
213                 [Test]
214                 public void GetHashCodeTest()
215                 {
216                         SqlInt64 Test15 = new SqlInt64 (15);
217
218                         // FIXME: Better way to test HashCode
219                         Assert.AreEqual ((int)15, Test15.GetHashCode (), "#I01");
220                 }
221
222                 [Test]
223                 public void GetTypeTest()
224                 {
225                         SqlInt64 Test = new SqlInt64 (84);
226                         Assert.AreEqual ("System.Data.SqlTypes.SqlInt64", Test.GetType ().ToString (), "#J01");
227                 }
228
229                 [Test]
230                 public void Greaters()
231                 {
232                         SqlInt64 Test10 = new SqlInt64 (10);
233                         SqlInt64 Test10II = new SqlInt64 (10);
234                         SqlInt64 Test110 = new SqlInt64 (110);
235
236                         // GreateThan ()
237                         Assert.IsTrue (!SqlInt64.GreaterThan (Test10, Test110).Value, "#K01");
238                         Assert.IsTrue (SqlInt64.GreaterThan (Test110, Test10).Value, "#K02");
239                         Assert.IsTrue (!SqlInt64.GreaterThan (Test10II, Test10).Value, "#K03");
240
241                         // GreaterTharOrEqual ()
242                         Assert.IsTrue (!SqlInt64.GreaterThanOrEqual (Test10, Test110).Value, "#K04");
243                         Assert.IsTrue (SqlInt64.GreaterThanOrEqual (Test110, Test10).Value, "#K05");
244                         Assert.IsTrue (SqlInt64.GreaterThanOrEqual (Test10II, Test10).Value, "#K06");
245                 }
246
247                 [Test]
248                 public void Lessers()
249                 {
250                         SqlInt64 Test10 = new SqlInt64 (10);
251                         SqlInt64 Test10II = new SqlInt64 (10);
252                         SqlInt64 Test110 = new SqlInt64 (110);
253
254                         // LessThan()
255                         Assert.IsTrue (SqlInt64.LessThan (Test10, Test110).Value, "#L01");
256                         Assert.IsTrue (!SqlInt64.LessThan (Test110, Test10).Value, "#L02");
257                         Assert.IsTrue (!SqlInt64.LessThan (Test10II, Test10).Value, "#L03");
258
259                         // LessThanOrEqual ()
260                         Assert.IsTrue (SqlInt64.LessThanOrEqual (Test10, Test110).Value, "#L04");
261                         Assert.IsTrue (!SqlInt64.LessThanOrEqual (Test110, Test10).Value, "#L05");
262                         Assert.IsTrue (SqlInt64.LessThanOrEqual (Test10II, Test10).Value, "#L06");
263                         Assert.IsTrue (SqlInt64.LessThanOrEqual (Test10II, SqlInt64.Null).IsNull, "#L07");
264                 }
265
266                 [Test]
267                 public void NotEquals()
268                 {
269                         SqlInt64 Test12 = new SqlInt64 (12);
270                         SqlInt64 Test128 = new SqlInt64 (128);
271                         SqlInt64 Test128II = new SqlInt64 (128);
272
273                         Assert.IsTrue (SqlInt64.NotEquals (Test12, Test128).Value, "#M01");
274                         Assert.IsTrue (SqlInt64.NotEquals (Test128, Test12).Value, "#M02");
275                         Assert.IsTrue (SqlInt64.NotEquals (Test128II, Test12).Value, "#M03");
276                         Assert.IsTrue (!SqlInt64.NotEquals (Test128II, Test128).Value, "#M04");
277                         Assert.IsTrue (!SqlInt64.NotEquals (Test128, Test128II).Value, "#M05");
278                         Assert.IsTrue (SqlInt64.NotEquals (SqlInt64.Null, Test128II).IsNull, "#M06");
279                         Assert.IsTrue (SqlInt64.NotEquals (SqlInt64.Null, Test128II).IsNull, "#M07");
280                 }
281
282                 [Test]
283                 public void OnesComplement()
284                 {
285                         SqlInt64 Test12 = new SqlInt64(12);
286                         SqlInt64 Test128 = new SqlInt64(128);
287
288                         Assert.AreEqual ((SqlInt64)(-13), SqlInt64.OnesComplement (Test12), "#N01");
289                         Assert.AreEqual ((SqlInt64)(-129), SqlInt64.OnesComplement (Test128), "#N02");
290                 }
291
292                 [Test]
293                 public void Parse()
294                 {
295                         try {
296                                 SqlInt64.Parse (null);
297                                 Assert.Fail ("#O01");
298                         } catch (Exception e) {
299                                 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#O02");
300                         }
301
302                         try {
303                                 SqlInt64.Parse ("not-a-number");
304                                 Assert.Fail ("#O03");
305                         } catch (Exception e) {
306                                 Assert.AreEqual (typeof (FormatException), e.GetType (), "#O04");
307                         }
308
309                         try {
310                                 SqlInt64.Parse ("1000000000000000000000000000");
311                                 Assert.Fail ("#O05");
312                         } catch (Exception e) {
313                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#O06");
314                         }
315
316                         Assert.AreEqual((long)150, SqlInt64.Parse ("150").Value, "#O07");
317                 }
318
319                 [Test]
320                 public void Conversions()
321                 {
322                         SqlInt64 Test12 = new SqlInt64 (12);
323                         SqlInt64 Test0 = new SqlInt64 (0);
324                         SqlInt64 TestNull = SqlInt64.Null;
325                         SqlInt64 Test1000 = new SqlInt64 (1000);
326                         SqlInt64 Test288 = new SqlInt64(288);
327
328                         // ToSqlBoolean ()
329                         Assert.IsTrue (Test12.ToSqlBoolean ().Value, "#P01");
330                         Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "#P02");
331                         Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "#P03");
332
333                         // ToSqlByte ()
334                         Assert.AreEqual ((byte)12, Test12.ToSqlByte ().Value, "#P04");
335                         Assert.AreEqual ((byte)0, Test0.ToSqlByte ().Value, "#P05");
336
337                         try {
338                                 SqlByte b = (byte)Test1000.ToSqlByte ();
339                                 Assert.Fail ("#P06");
340                         } catch (Exception e) {
341                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#P07");
342                         }
343
344                         // ToSqlDecimal ()
345                         Assert.AreEqual ((decimal)12, Test12.ToSqlDecimal ().Value, "#P08");
346                         Assert.AreEqual ((decimal)0, Test0.ToSqlDecimal ().Value, "#P09");
347                         Assert.AreEqual ((decimal)288, Test288.ToSqlDecimal ().Value, "#P10");
348
349                         // ToSqlDouble ()
350                         Assert.AreEqual ((double)12, Test12.ToSqlDouble ().Value, "#P11");
351                         Assert.AreEqual ((double)0, Test0.ToSqlDouble ().Value, "#P12");
352                         Assert.AreEqual ((double)1000, Test1000.ToSqlDouble ().Value, "#P13");
353
354                         // ToSqlInt32 ()
355                         Assert.AreEqual ((int)12, Test12.ToSqlInt32 ().Value, "#P14");
356                         Assert.AreEqual ((int)0, Test0.ToSqlInt32 ().Value, "#P15");
357                         Assert.AreEqual ((int)288, Test288.ToSqlInt32().Value, "#P16");
358
359                         // ToSqlInt16 ()
360                         Assert.AreEqual ((short)12, Test12.ToSqlInt16 ().Value, "#P17");
361                         Assert.AreEqual ((short)0, Test0.ToSqlInt16 ().Value, "#P18");
362                         Assert.AreEqual ((short)288, Test288.ToSqlInt16 ().Value, "#P19");
363
364                         // ToSqlMoney ()
365                         Assert.AreEqual (12.0000M, Test12.ToSqlMoney ().Value, "#P20");
366                         Assert.AreEqual ((decimal)0, Test0.ToSqlMoney ().Value, "#P21");
367                         Assert.AreEqual (288.0000M, Test288.ToSqlMoney ().Value, "#P22");
368
369                         // ToSqlSingle ()
370                         Assert.AreEqual ((float)12, Test12.ToSqlSingle ().Value, "#P23");
371                         Assert.AreEqual ((float)0, Test0.ToSqlSingle ().Value, "#P24");
372                         Assert.AreEqual ((float)288, Test288.ToSqlSingle().Value, "#P25");
373
374                         // ToSqlString ()
375                         Assert.AreEqual ("12", Test12.ToSqlString ().Value, "#P26");
376                         Assert.AreEqual ("0", Test0.ToSqlString ().Value, "#P27");
377                         Assert.AreEqual ("288", Test288.ToSqlString ().Value, "#P28");
378
379                         // ToString ()
380                         Assert.AreEqual ("12", Test12.ToString (), "#P29");
381                         Assert.AreEqual ("0", Test0.ToString (), "#P30");
382                         Assert.AreEqual ("288", Test288.ToString (), "#P31");
383                 }
384
385                 [Test]
386                 public void Xor()
387                 {
388                         SqlInt64 Test14 = new SqlInt64 (14);
389                         SqlInt64 Test58 = new SqlInt64 (58);
390                         SqlInt64 Test130 = new SqlInt64 (130);
391                         SqlInt64 TestMax = new SqlInt64 (SqlInt64.MaxValue.Value);
392                         SqlInt64 Test0 = new SqlInt64 (0);
393
394                         Assert.AreEqual ((long)52, SqlInt64.Xor (Test14, Test58).Value, "#Q01");
395                         Assert.AreEqual ((long)140, SqlInt64.Xor (Test14, Test130).Value, "#Q02");
396                         Assert.AreEqual ((long)184, SqlInt64.Xor (Test58, Test130).Value, "#Q03");
397                         Assert.AreEqual ((long)0, SqlInt64.Xor (TestMax, TestMax).Value, "#Q04");
398                         Assert.AreEqual (TestMax.Value, SqlInt64.Xor (TestMax, Test0).Value, "#Q05");
399                 }
400
401                 // OPERATORS
402
403                 [Test]
404                 public void ArithmeticOperators()
405                 {
406                         SqlInt64 Test24 = new SqlInt64 (24);
407                         SqlInt64 Test64 = new SqlInt64 (64);
408                         SqlInt64 Test2550 = new SqlInt64 (2550);
409                         SqlInt64 Test0 = new SqlInt64 (0);
410
411                         // "+"-operator
412                         Assert.AreEqual ((SqlInt64)2614,Test2550 + Test64, "#R01");
413                         try {
414                                 SqlInt64 result = Test64 + SqlInt64.MaxValue;
415                                 Assert.Fail ("#R02");
416                         } catch (Exception e) {
417                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#R03");
418                         }
419
420                         // "/"-operator
421                         Assert.AreEqual ((SqlInt64)39, Test2550 / Test64, "#R04");
422                         Assert.AreEqual ((SqlInt64)0, Test24 / Test64, "#R05");
423
424                         try {
425                                 SqlInt64 result = Test2550 / Test0;
426                                 Assert.Fail ("#R06");
427                         } catch (Exception e) {
428                                 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "#R07");
429                         }
430
431                         // "*"-operator
432                         Assert.AreEqual ((SqlInt64)1536, Test64 * Test24, "#R08");
433
434                         try {
435                                 SqlInt64 test = (SqlInt64.MaxValue * Test64);
436                                 Assert.Fail ("TestC#2");
437                         } catch (Exception e) {
438                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#R08");
439                         }
440
441                         // "-"-operator
442                         Assert.AreEqual ((SqlInt64)2526, Test2550 - Test24, "#R09");
443
444                         try {
445                                 SqlInt64 test = SqlInt64.MinValue - Test64;
446                                 Assert.Fail ("#R10");
447                         } catch (Exception e) {
448                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#R11");
449                         }
450
451                         // "%"-operator
452                         Assert.AreEqual ((SqlInt64)54, Test2550 % Test64, "#R12");
453                         Assert.AreEqual ((SqlInt64)24, Test24 % Test64, "#R13");
454                         Assert.AreEqual ((SqlInt64)0, new SqlInt64 (100) % new SqlInt64 (10), "#R14");
455                 }
456
457                 [Test]
458                 public void BitwiseOperators()
459                 {
460                         SqlInt64 Test2 = new SqlInt64 (2);
461                         SqlInt64 Test4 = new SqlInt64 (4);
462
463                         SqlInt64 Test2550 = new SqlInt64 (2550);
464
465                         // & -operator
466                         Assert.AreEqual ((SqlInt64)0, Test2 & Test4, "#S01");
467                         Assert.AreEqual ((SqlInt64)2, Test2 & Test2550, "#S02");
468                         Assert.AreEqual ((SqlInt64)0,  SqlInt64.MaxValue & SqlInt64.MinValue, "#S03");
469
470                         // | -operator
471                         Assert.AreEqual ((SqlInt64)6,Test2 | Test4, "#S04");
472                         Assert.AreEqual ((SqlInt64)2550, Test2 | Test2550, "#S05");
473                         Assert.AreEqual ((SqlInt64)(-1), SqlInt64.MinValue | SqlInt64.MaxValue, "#S06");
474
475                         //  ^ -operator
476                         Assert.AreEqual((SqlInt64)2546, (Test2550 ^ Test4), "#S07");
477                         Assert.AreEqual((SqlInt64)6, (Test2 ^ Test4), "#S08");
478                 }
479
480                 [Test]
481                 public void ThanOrEqualOperators()
482                 {
483                         SqlInt64 Test165 = new SqlInt64 (165);
484                         SqlInt64 Test100 = new SqlInt64 (100);
485                         SqlInt64 Test100II = new SqlInt64 (100);
486                         SqlInt64 Test255 = new SqlInt64 (2550);
487
488                         // == -operator
489                         Assert.IsTrue ((Test100 == Test100II).Value, "#T01");
490                         Assert.IsTrue (!(Test165 == Test100).Value, "#T02");
491                         Assert.IsTrue ((Test165 == SqlInt64.Null).IsNull, "#T03");
492
493                         // != -operator
494                         Assert.IsTrue (!(Test100 != Test100II).Value, "#T04");
495                         Assert.IsTrue ((Test100 != Test255).Value, "#T05");
496                         Assert.IsTrue ((Test165 != Test255).Value, "#T06");
497                         Assert.IsTrue ((Test165 != SqlInt64.Null).IsNull, "#T07");
498
499                         // > -operator
500                         Assert.IsTrue ((Test165 > Test100).Value, "#T08");
501                         Assert.IsTrue (!(Test165 > Test255).Value, "#T09");
502                         Assert.IsTrue (!(Test100 > Test100II).Value, "#T10");
503                         Assert.IsTrue ((Test165 > SqlInt64.Null).IsNull, "#T11");
504
505                         // >=  -operator
506                         Assert.IsTrue (!(Test165 >= Test255).Value, "#T12");
507                         Assert.IsTrue ((Test255 >= Test165).Value, "#T13");
508                         Assert.IsTrue ((Test100 >= Test100II).Value, "#T14");
509                         Assert.IsTrue ((Test165 >= SqlInt64.Null).IsNull, "#T15");
510
511                         // < -operator
512                         Assert.IsTrue (!(Test165 < Test100).Value, "#T16");
513                         Assert.IsTrue ((Test165 < Test255).Value, "#T17");
514                         Assert.IsTrue (!(Test100 < Test100II).Value, "#T18");
515                         Assert.IsTrue ((Test165 < SqlInt64.Null).IsNull, "#T19");
516
517                         // <= -operator
518                         Assert.IsTrue ((Test165 <= Test255).Value, "#T20");
519                         Assert.IsTrue (!(Test255 <= Test165).Value, "#T21");
520                         Assert.IsTrue ((Test100 <= Test100II).Value, "#T22");
521                         Assert.IsTrue ((Test165 <= SqlInt64.Null).IsNull, "#T23");
522                 }
523
524                 [Test]
525                 public void OnesComplementOperator()
526                 {
527                         SqlInt64 Test12 = new SqlInt64 (12);
528                         SqlInt64 Test128 = new SqlInt64 (128);
529
530                         Assert.AreEqual ((SqlInt64)(-13), ~Test12, "#V01");
531                         Assert.AreEqual ((SqlInt64)(-129), ~Test128, "#V02");
532                         Assert.AreEqual (SqlInt64.Null, ~SqlInt64.Null, "#V03");
533                 }
534
535                 [Test]
536                 public void UnaryNegation()
537                 {
538                         SqlInt64 Test = new SqlInt64 (2000);
539                         SqlInt64 TestNeg = new SqlInt64 (-3000);
540
541                         SqlInt64 Result = -Test;
542                         Assert.AreEqual ((long)(-2000), Result.Value, "#W01");
543
544                         Result = -TestNeg;
545                         Assert.AreEqual ((long)3000, Result.Value, "#W02");
546                 }
547
548                 [Test]
549                 public void SqlBooleanToSqlInt64()
550                 {
551                         SqlBoolean TestBoolean = new SqlBoolean (true);
552                         SqlInt64 Result;
553
554                         Result = (SqlInt64)TestBoolean;
555
556                         Assert.AreEqual ((long)1, Result.Value, "#X01");
557
558                         Result = (SqlInt64)SqlBoolean.Null;
559                         Assert.IsTrue (Result.IsNull, "#X02");
560                 }
561
562                 [Test]
563                 public void SqlDecimalToSqlInt64()
564                 {
565                         SqlDecimal TestDecimal64 = new SqlDecimal (64);
566                         SqlDecimal TestDecimal900 = new SqlDecimal (90000);
567
568                         Assert.AreEqual((long)64, ((SqlInt64)TestDecimal64).Value, "#Y01");
569                         Assert.AreEqual(SqlInt64.Null, ((SqlInt64)SqlDecimal.Null), "#Y02");
570
571                         try {
572                                 SqlInt64 test = (SqlInt64)SqlDecimal.MaxValue;
573                                 Assert.Fail("#Y03");
574                         } catch (Exception e) {
575                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "#Y04");
576                         }
577                 }
578
579                 [Test]
580                 public void SqlDoubleToSqlInt64()
581                 {
582                         SqlDouble TestDouble64 = new SqlDouble (64);
583                         SqlDouble TestDouble900 = new SqlDouble (90000);
584
585                         Assert.AreEqual ((long)64, ((SqlInt64)TestDouble64).Value, "#Z01");
586                         Assert.AreEqual (SqlInt64.Null, ((SqlInt64)SqlDouble.Null), "#Z02");
587
588                         try {
589                                 SqlInt64 test = (SqlInt64)SqlDouble.MaxValue;
590                                 Assert.Fail ("#Z03");
591                         } catch (Exception e) {
592                                 Assert.AreEqual(typeof (OverflowException), e.GetType (), "#Z04");
593                         }
594                 }
595
596                 [Test]
597                 public void Sql64IntToInt64()
598                 {
599                         SqlInt64 Test = new SqlInt64 (12);
600                         Int64 Result = (Int64)Test;
601                         Assert.AreEqual ((long)12, Result, "#AA01");
602                 }
603
604                 [Test]
605                 public void SqlInt32ToSqlInt64()
606                 {
607                         SqlInt32 Test64 = new SqlInt32 (64);
608                         Assert.AreEqual ((long)64, ((SqlInt64)Test64).Value, "#AB01");
609                 }
610
611                 [Test]
612                 public void SqlInt16ToSqlInt64()
613                 {
614                         SqlInt16 Test64 = new SqlInt16 (64);
615                         Assert.AreEqual ((long)64, ((SqlInt64)Test64).Value, "#AC01");
616                 }
617
618                 [Test]
619                 public void SqlMoneyToSqlInt64()
620                 {
621                         SqlMoney TestMoney64 = new SqlMoney(64);
622                         Assert.AreEqual ((long)64, ((SqlInt64)TestMoney64).Value, "#AD01");
623                 }
624
625                 [Test]
626                 public void SqlSingleToSqlInt64()
627                 {
628                         SqlSingle TestSingle64 = new SqlSingle (64);
629                         Assert.AreEqual ((long)64, ((SqlInt64)TestSingle64).Value, "#AE01");
630                 }
631
632                 [Test]
633                 public void SqlStringToSqlInt64()
634                 {
635                         SqlString TestString = new SqlString ("Test string");
636                         SqlString TestString100 = new SqlString ("100");
637                         SqlString TestString1000 = new SqlString ("1000000000000000000000");
638
639                         Assert.AreEqual ((long)100, ((SqlInt64)TestString100).Value, "#AF01");
640
641                         try {
642                                 SqlInt64 test = (SqlInt64)TestString1000;
643                                 Assert.Fail ("#AF02");
644                         } catch(Exception e) {
645                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#AF03");
646                         }
647
648                         try {
649                                 SqlInt64 test = (SqlInt64)TestString;
650                                 Assert.Fail ("#AF03");
651                         } catch(Exception e) {
652                                 Assert.AreEqual (typeof (FormatException), e.GetType (), "#AF04");
653                         }
654                 }
655
656                 [Test]
657                 public void ByteToSqlInt64()
658                 {
659                         short TestShort = 14;
660                         Assert.AreEqual ((long)14, ((SqlInt64)TestShort).Value, "#G01");
661                 }
662         }
663 }
664