Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SqlInt32Test.cs « System.Data.SqlTypes « Test « System.Data « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4cd335ce17c70219736025a4a78d163884a36575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// SqlInt32Test.cs - NUnit Test Cases for System.Data.SqlTypes.SqlInt32
//
// Tim Coleman (tim@timcoleman.com)
//
// (C) Tim Coleman
// 

using NUnit.Framework;
using System;
using System.Data;
using System.Data.SqlTypes;

namespace MonoTests.System.Data.SqlTypes
{
	public class SqlInt32Test : TestCase 
	{
		
		public SqlInt32Test() : base ("System.Data.SqlTypes.SqlInt32") {}
		public SqlInt32Test(string name) : base(name) {}

		protected override void SetUp() {}

		protected override void TearDown() {}

		public static ITest Suite {
			get { 
				return new TestSuite(typeof(SqlInt32)); 
			}
		}

		public void TestCreate ()  
		{
			SqlInt32 foo = new SqlInt32 (5);
			AssertEquals ("Test explicit cast to int", (int)foo, 5);
		}

		public void TestAdd () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x;
			SqlInt32 y;
			SqlInt32 z;

			x = new SqlInt32 (a);
			y = new SqlInt32 (b);
			z = x + y;
			AssertEquals ("Addition operator does not work correctly", z.Value, a + b);
			z = SqlInt32.Add (x, y);
			AssertEquals ("Addition function does not work correctly", z.Value, a + b);
		}

		public void TestBitwiseAnd () 
		{
			int a = 5;
			int b = 7;
						
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x & y;
			AssertEquals ("Bitwise And operator does not work correctly", z.Value, a & b);
			z = SqlInt32.BitwiseAnd (x, y);
			AssertEquals ("Bitwise And function does not work correctly", z.Value, a & b);
		}

		public void TestBitwiseOr () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x | y;
			AssertEquals ("Bitwise Or operator does not work correctly", z.Value, a | b);
			z = SqlInt32.BitwiseOr (x, y);
			AssertEquals ("Bitwise Or function does not work correctly", z.Value, a | b);
		}

		public void TestDivide () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x / y;
			AssertEquals ("Division operator does not work correctly", z.Value, a / b);
			z = SqlInt32.Divide (x, y);
			AssertEquals ("Division function does not work correctly", z.Value, a / b);
		}
		
		public void TestEquals ()
		{
			SqlInt32 x;
			SqlInt32 y;
			
			// Case 1: either is SqlInt32.Null
			x = SqlInt32.Null;
			y = new SqlInt32 (5);
			AssertEquals ("Equality operator didn't return Null when one was Null.", x == y, SqlBoolean.Null);
			AssertEquals ("Equality function didn't return Null when one was Null.", SqlInt32.Equals (x, y), SqlBoolean.Null);

			// Case 2: both are SqlInt32.Null
			y = SqlInt32.Null;
			AssertEquals ("Equality operator didn't return Null when both were Null.", x == y, SqlBoolean.Null);
			AssertEquals ("Equality function didn't return Null when both were Null.", SqlInt32.Equals (x, y), SqlBoolean.Null);

			// Case 3: both are equal
			x = new SqlInt32 (5);
			y = new SqlInt32 (5);
			AssertEquals ("Equality operator didn't return true when they were equal.", x == y, SqlBoolean.True);
			AssertEquals ("Equality function didn't return true when they were equal.", SqlInt32.Equals (x, y), SqlBoolean.True);

			// Case 4: inequality
			x = new SqlInt32 (5);
			y = new SqlInt32 (6);
			AssertEquals ("Equality operator didn't return false when they were not equal.", x == y, SqlBoolean.False);
			AssertEquals ("Equality function didn't return false when they were not equal.", SqlInt32.Equals (x, y), SqlBoolean.False);
		}

		public void TestGreaterThan ()
		{
			SqlInt32 x;
			SqlInt32 y;
			
			// Case 1: either is SqlInt32.Null
			x = SqlInt32.Null;
			y = new SqlInt32 (5);
			AssertEquals ("Greater Than operator didn't return Null when one was Null.", x > y, SqlBoolean.Null);
			AssertEquals ("Greater Than function didn't return Null when one was Null.", SqlInt32.GreaterThan (x, y), SqlBoolean.Null);

			// Case 2: both are SqlInt32.Null
			y = SqlInt32.Null;
			AssertEquals ("Greater Than operator didn't return Null when both were Null.", x > y, SqlBoolean.Null);
			AssertEquals ("Greater Than function didn't return Null when both were Null.", SqlInt32.GreaterThan (x, y), SqlBoolean.Null);

			// Case 3: x > y
			x = new SqlInt32 (5);
			y = new SqlInt32 (4);
			AssertEquals ("Greater than operator didn't return true when x > y.", x > y, SqlBoolean.True);
			AssertEquals ("Greater than function didn't return true when x > y.", SqlInt32.GreaterThan (x,y), SqlBoolean.True);

			// Case 4: x < y
			x = new SqlInt32 (5);
			y = new SqlInt32 (6);
			AssertEquals ("Greater than operator didn't return false when x < y.", x > y, SqlBoolean.False);
			AssertEquals ("Greater than function didn't return false when x < y.", SqlInt32.GreaterThan (x,y), SqlBoolean.False);
		}

		public void TestGreaterThanOrEqual ()
		{
			SqlInt32 x;
			SqlInt32 y;
			
			// Case 1: either is SqlInt32.Null
			x = SqlInt32.Null;
			y = new SqlInt32 (5);
			AssertEquals ("Greater Than Or Equal operator didn't return Null when one was Null.", x >= y, SqlBoolean.Null);
			AssertEquals ("Greater Than Or Equal function didn't return Null when one was Null.", SqlInt32.GreaterThanOrEqual (x, y), SqlBoolean.Null);

			// Case 2: both are SqlInt32.Null
			y = SqlInt32.Null;
			AssertEquals ("Greater Than Or Equal operator didn't return Null when both were Null.", x >= y, SqlBoolean.Null);
			AssertEquals ("Greater Than Or Equal function didn't return Null when both were Null.", SqlInt32.GreaterThanOrEqual (x, y), SqlBoolean.Null);

			// Case 3: x > y
			x = new SqlInt32 (5);
			y = new SqlInt32 (4);
			AssertEquals ("Greater than or equal operator didn't return true when x > y.", x >= y, SqlBoolean.True);
			AssertEquals ("Greater than or equal function didn't return true when x > y.", SqlInt32.GreaterThanOrEqual (x,y), SqlBoolean.True);

			// Case 4: x < y
			x = new SqlInt32 (5);
			y = new SqlInt32 (6);
			AssertEquals ("Greater than or equal operator didn't return false when x < y.", x >= y, SqlBoolean.False);
			AssertEquals ("Greater than or equal function didn't return false when x < y.", SqlInt32.GreaterThanOrEqual (x,y), SqlBoolean.False);

			// Case 5: x == y
			x = new SqlInt32 (5);
			y = new SqlInt32 (5);
			AssertEquals ("Greater than or equal operator didn't return true when x == y.", x >= y, SqlBoolean.True);
			AssertEquals ("Greater than or equal function didn't return true when x == y.", SqlInt32.GreaterThanOrEqual (x,y), SqlBoolean.True);
		}

		public void TestLessThan ()
		{
			SqlInt32 x;
			SqlInt32 y;
			
			// Case 1: either is SqlInt32.Null
			x = SqlInt32.Null;
			y = new SqlInt32 (5);
			AssertEquals ("Less Than operator didn't return Null when one was Null.", x < y, SqlBoolean.Null);
			AssertEquals ("Less Than function didn't return Null when one was Null.", SqlInt32.LessThan (x, y), SqlBoolean.Null);

			// Case 2: both are SqlInt32.Null
			y = SqlInt32.Null;
			AssertEquals ("Less Than operator didn't return Null when both were Null.", x < y, SqlBoolean.Null);
			AssertEquals ("Less Than function didn't return Null when both were Null.", SqlInt32.LessThan (x, y), SqlBoolean.Null);

			// Case 3: x > y
			x = new SqlInt32 (5);
			y = new SqlInt32 (4);
			AssertEquals ("Less than operator didn't return false when x > y.", x < y, SqlBoolean.False);
			AssertEquals ("Less than function didn't return false when x > y.", SqlInt32.LessThan (x,y), SqlBoolean.False);

			// Case 4: x < y
			x = new SqlInt32 (5);
			y = new SqlInt32 (6);
			AssertEquals ("Less than operator didn't return true when x < y.", x < y, SqlBoolean.True);
			AssertEquals ("Less than function didn't return true when x < y.", SqlInt32.LessThan (x,y), SqlBoolean.True);
		}

		public void TestLessThanOrEqual ()
		{
			SqlInt32 x;
			SqlInt32 y;
			
			// Case 1: either is SqlInt32.Null
			x = SqlInt32.Null;
			y = new SqlInt32 (5);
			AssertEquals ("Less Than Or Equal operator didn't return Null when one was Null.", x <= y, SqlBoolean.Null);
			AssertEquals ("Less Than Or Equal function didn't return Null when one was Null.", SqlInt32.LessThanOrEqual (x, y), SqlBoolean.Null);

			// Case 2: both are SqlInt32.Null
			y = SqlInt32.Null;
			AssertEquals ("Less Than Or Equal operator didn't return Null when both were Null.", x <= y, SqlBoolean.Null);
			AssertEquals ("Less Than Or Equal function didn't return Null when both were Null.", SqlInt32.LessThanOrEqual (x, y), SqlBoolean.Null);

			// Case 3: x > y
			x = new SqlInt32 (5);
			y = new SqlInt32 (4);
			AssertEquals ("Less than or equal operator didn't return false when x > y.", x <= y, SqlBoolean.False);
			AssertEquals ("Less than or equal function didn't return false when x > y.", SqlInt32.LessThanOrEqual (x,y), SqlBoolean.False);

			// Case 4: x < y
			x = new SqlInt32 (5);
			y = new SqlInt32 (6);
			AssertEquals ("Less than or equal operator didn't return true when x < y.", x <= y, SqlBoolean.True);
			AssertEquals ("Less than or equal function didn't return true when x < y.", SqlInt32.LessThanOrEqual (x,y), SqlBoolean.True);

			// Case 5: x == y
			x = new SqlInt32 (5);
			y = new SqlInt32 (5);
			AssertEquals ("Less than or equal operator didn't return true when x == y.", x <= y, SqlBoolean.True);
			AssertEquals ("Less than or equal function didn't return true when x == y.", SqlInt32.LessThanOrEqual (x,y), SqlBoolean.True);
		}

		public void TestMod () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x % y;
			AssertEquals ("Modulus operator does not work correctly", z.Value, a % b);
			z = SqlInt32.Mod (x, y);
			AssertEquals ("Modulus function does not work correctly", z.Value, a % b);
		}

		public void TestMultiply () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x * y;
			AssertEquals ("Multiplication operator does not work correctly", z.Value, a * b);
			z = SqlInt32.Multiply (x, y);
			AssertEquals ("Multiplication function does not work correctly", z.Value, a * b);
		}

		public void TestNotEquals () 
		{
			SqlInt32 x;
			SqlInt32 y;

			x = new SqlInt32 (5);
			y = SqlInt32.Null;

			AssertEquals ("Not Equals operator does not return null when one or both of the parameters is Null.", x != y, SqlBoolean.Null);
			AssertEquals ("Not Equals function does not return null when one or both of the parameters is Null.", SqlInt32.NotEquals (x, y), SqlBoolean.Null);

			y = new SqlInt32 (5);
			AssertEquals ("Not Equals operator does not return false when x == y.", x != y, SqlBoolean.False);
			AssertEquals ("Not Equals function does not return false when x == y.", SqlInt32.NotEquals (x, y), SqlBoolean.False);

			y = new SqlInt32 (6);
			AssertEquals ("Not Equals operator does not return true when x != y.", x != y, SqlBoolean.True);
			AssertEquals ("Not Equals function does not return true when x != y.", SqlInt32.NotEquals (x, y), SqlBoolean.True);
		}
	
		public void TestOnesComplement () 
		{
			int a = 5;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 z = ~x;
			AssertEquals ("Ones Complement operator does not work correctly", z.Value, ~a);
			z = SqlInt32.OnesComplement (x);
			AssertEquals ("Ones Complement function does not work correctly", z.Value, ~a);
		}
		
		public void TestIsNullProperty ()
		{
			SqlInt32 n = SqlInt32.Null;
			Assert ("Null is not defined correctly", n.IsNull);
		}
	
		public void TestSubtract () 
		{
			int a = 7;
			int b = 5;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x - y;
			AssertEquals ("Subtraction operator does not work correctly", z.Value, a - b);
			z = SqlInt32.Subtract (x, y);
			AssertEquals ("Subtraction function does not work correctly", z.Value, a - b);
		}

		public void TestConversionMethods ()
		{
			SqlInt32 x;

			// Case 1: SqlInt32.Null -> SqlBoolean == SqlBoolean.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlBoolean does not yield SqlBoolean.Null.", x.ToSqlBoolean (), SqlBoolean.Null );

			// Case 2: SqlInt32.Zero -> SqlBoolean == False
			x = SqlInt32.Zero;
			AssertEquals ("SqlInt32.Zero -> SqlBoolean does not yield SqlBoolean.False.", x.ToSqlBoolean (), SqlBoolean.False );
		
			// Case 3: SqlInt32(nonzero) -> SqlBoolean == True
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlBoolean does not yield SqlBoolean.True.", x.ToSqlBoolean (), SqlBoolean.True );
		
			// Case 4: SqlInt32.Null -> SqlByte == SqlByte.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlByte does not yield SqlByte.Null.", x.ToSqlByte (), SqlByte.Null );

			// Case 5: Test non-null conversion to SqlByte
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlByte does not yield a value of 27", x.ToSqlByte ().Value, (byte)27);

			// Case 6: SqlInt32.Null -> SqlDecimal == SqlDecimal.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlDecimal does not yield SqlDecimal.Null.", x.ToSqlDecimal (), SqlDecimal.Null );

			// Case 7: Test non-null conversion to SqlDecimal
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlDecimal does not yield a value of 27", x.ToSqlDecimal ().Value, (decimal)27);

			// Case 8: SqlInt32.Null -> SqlDouble == SqlDouble.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlDouble does not yield SqlDouble.Null.", x.ToSqlDouble (), SqlDouble.Null );

			// Case 9: Test non-null conversion to SqlDouble
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlDouble does not yield a value of 27", x.ToSqlDouble ().Value, (double)27);

			// Case 10: SqlInt32.Null -> SqlInt16 == SqlInt16.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlInt16 does not yield SqlInt16.Null.", x.ToSqlInt16 (), SqlInt16.Null );

			// Case 11: Test non-null conversion to SqlInt16
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlInt16 does not yield a value of 27", x.ToSqlInt16 ().Value, (short)27);

			// Case 12: SqlInt32.Null -> SqlInt64 == SqlInt64.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlInt64 does not yield SqlInt64.Null.", x.ToSqlInt64 (), SqlInt64.Null );

			// Case 13: Test non-null conversion to SqlInt64
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlInt64 does not yield a value of 27", x.ToSqlInt64 ().Value, (long)27);

			// Case 14: SqlInt32.Null -> SqlMoney == SqlMoney.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlMoney does not yield SqlMoney.Null.", x.ToSqlMoney (), SqlMoney.Null );

			// Case 15: Test non-null conversion to SqlMoney
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlMoney does not yield a value of 27", x.ToSqlMoney ().Value, (decimal)27);

			// Case 16: SqlInt32.Null -> SqlSingle == SqlSingle.Null
			x = SqlInt32.Null;
			AssertEquals ("SqlInt32.Null -> SqlSingle does not yield SqlSingle.Null.", x.ToSqlSingle (), SqlSingle.Null );

			// Case 17: Test non-null conversion to SqlSingle
			x = new SqlInt32 (27);
			AssertEquals ("SqlInt32 (27) -> SqlSingle does not yield a value of 27", x.ToSqlSingle ().Value, (float)27);
		}
	
		public void TestXor () 
		{
			int a = 5;
			int b = 7;
			
			SqlInt32 x = new SqlInt32 (a);
			SqlInt32 y = new SqlInt32 (b);
			SqlInt32 z = x ^ y;
			AssertEquals ("Xor operator does not work correctly", z.Value, a ^ b);
			z = SqlInt32.Xor (x, y);
			AssertEquals ("Xor function does not work correctly", z.Value, a ^ b);
		}
			
	}
}