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