2 // SqlBinaryTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlBinary
5 // Ville Palo (vi64pa@koti.soon.fi)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
9 // (C) 2003 Martin Willemoes Hansen
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using NUnit.Framework;
37 using System.Data.SqlTypes;
39 namespace MonoTests.System.Data.SqlTypes
42 public class SqlBinaryTest : Assertion {
49 public void GetReady()
51 byte [] b1 = new Byte [2];
52 byte [] b2 = new Byte [3];
53 byte [] b3 = new Byte [2];
63 Test1 = new SqlBinary(b1);
64 Test2 = new SqlBinary(b2);
65 Test3 = new SqlBinary(b3);
72 byte [] b = new byte [3];
73 SqlBinary Test = new SqlBinary (b);
74 Assert ("#A01", !(Test.IsNull));
79 public void PublicFields()
81 Assert ("#B01", SqlBinary.Null.IsNull);
86 public void Properties()
88 byte [] b = new byte [2];
92 SqlBinary TestBinary = new SqlBinary (b);
95 Assert ("#C01", SqlBinary.Null.IsNull);
98 AssertEquals ("#C02", (byte)128, TestBinary [1]);
99 AssertEquals ("#C03", (byte)64, TestBinary [0]);
101 // FIXME: MSDN says that should throw SqlNullValueException
102 // but throws IndexOutOfRangeException
104 byte test = TestBinary [TestBinary.Length];
106 } catch (Exception e) {
107 AssertEquals ("#C05", typeof (IndexOutOfRangeException),
112 byte test = SqlBinary.Null [2];
114 } catch (Exception e) {
115 AssertEquals ("#C07", typeof (SqlNullValueException),
120 AssertEquals ("#C08", 2, TestBinary.Length);
123 int test = SqlBinary.Null.Length;
125 } catch (Exception e) {
126 AssertEquals ("#C10", typeof (SqlNullValueException),
131 AssertEquals ("#C11", (byte)128, TestBinary [1]);
132 AssertEquals ("#C12", (byte)64, TestBinary [0]);
135 Byte [] test = SqlBinary.Null.Value;
137 } catch (Exception e) {
138 AssertEquals ("#C14", typeof (SqlNullValueException),
145 public void ComparisonMethods()
148 Assert ("#D01", SqlBinary.GreaterThan (Test1, Test2).Value);
149 Assert ("#D02", SqlBinary.GreaterThan (Test3, Test2).Value);
150 Assert ("#D03", !SqlBinary.GreaterThan (Test2, Test1).Value);
152 // GreaterThanOrEqual
153 Assert ("#D04", SqlBinary.GreaterThanOrEqual (Test1, Test2).Value);
154 Assert ("#D05", SqlBinary.GreaterThanOrEqual (Test1, Test2).Value);
155 Assert ("#D06", !SqlBinary.GreaterThanOrEqual (Test2, Test1).Value);
158 Assert ("#D07", !SqlBinary.LessThan (Test1, Test2).Value);
159 Assert ("#D08", !SqlBinary.LessThan (Test3, Test2).Value);
160 Assert ("#D09", SqlBinary.LessThan (Test2, Test1).Value);
163 Assert ("#D10", !SqlBinary.LessThanOrEqual (Test1, Test2).Value);
164 Assert ("#D11", SqlBinary.LessThanOrEqual (Test3, Test1).Value);
165 Assert ("#D12", SqlBinary.LessThanOrEqual (Test2, Test1).Value);
168 Assert ("#D13", !Test1.Equals (Test2));
169 Assert ("#D14", !Test3.Equals (Test2));
170 Assert ("#D15", Test3.Equals (Test1));
173 Assert ("#D16", SqlBinary.NotEquals (Test1, Test2).Value);
174 Assert ("#D17", !SqlBinary.NotEquals (Test3, Test1).Value);
175 Assert ("#D18", SqlBinary.NotEquals (Test2, Test1).Value);
179 public void CompareTo()
181 SqlString TestString = new SqlString ("This is a test");
183 Assert ("#E01", Test1.CompareTo(Test2) > 0);
184 Assert ("#E02", Test2.CompareTo(Test1) < 0);
185 Assert ("#E03", Test1.CompareTo(Test3) == 0);
188 Test1.CompareTo (TestString);
190 } catch(Exception e) {
191 AssertEquals ("#E05", typeof (ArgumentException), e.GetType ());
196 public void GetHashCodeTest()
198 AssertEquals ("#F01", Test1.GetHashCode (), Test1.GetHashCode ());
199 Assert ("#F02", Test2.GetHashCode () != Test1.GetHashCode ());
203 public void GetTypeTest()
205 AssertEquals("#G01", "System.Data.SqlTypes.SqlBinary",
206 Test1.GetType().ToString());
212 SqlBinary TestBinary;
214 TestBinary = SqlBinary.Concat (Test2, Test3);
215 AssertEquals ("H01", (byte)15, TestBinary [4]);
217 TestBinary = SqlBinary.Concat (Test1, Test2);
218 AssertEquals ("#H02", (byte)240, TestBinary [0]);
219 AssertEquals ("#H03", (byte)15, TestBinary [1]);
223 public void ToSqlGuid()
225 SqlBinary TestBinary = new SqlBinary (new byte [16]);
226 SqlGuid TestGuid = TestBinary.ToSqlGuid ();
227 Assert ("#I01", !TestGuid.IsNull);
231 public void ToStringTest()
233 AssertEquals ("#J01", "SqlBinary(3)", Test2.ToString ());
234 AssertEquals ("#J02", "SqlBinary(2)", Test1.ToString ());
239 public void AdditionOperator()
241 SqlBinary TestBinary = Test1 + Test2;
242 AssertEquals ("#K01", (byte)240, TestBinary [0]);
243 AssertEquals ("#K02", (byte)15, TestBinary [1]);
247 public void ComparisonOperators()
250 Assert ("#L01", !(Test1 == Test2).Value);
251 Assert ("#L02", (Test3 == Test1).Value);
254 Assert ("#L03", (Test1 > Test2).Value);
255 Assert ("#L04", !(Test3 > Test1).Value);
257 // Greater than or equal
258 Assert ("#L05", (Test1 >= Test2).Value);
259 Assert ("#L06", (Test3 >= Test2).Value);
262 Assert ("#L07", (Test1 != Test2).Value);
263 Assert ("#L08", !(Test3 != Test1).Value);
266 Assert ("#L09", !(Test1 < Test2).Value);
267 Assert ("#L10", !(Test3 < Test2).Value);
269 // Less than or equal
270 Assert ("#L11", !(Test1 <= Test2).Value);
271 Assert ("#L12", (Test3 <= Test1).Value);
275 public void SqlBinaryToByteArray()
277 byte [] TestByteArray = (Byte[])Test1;
278 AssertEquals ("#M01", (byte)240, TestByteArray[0]);
282 public void SqlGuidToSqlBinary()
284 byte [] TestByteArray = new Byte [16];
285 TestByteArray [0] = 15;
286 TestByteArray [1] = 200;
287 SqlGuid TestGuid = new SqlGuid (TestByteArray);
289 SqlBinary TestBinary = (SqlBinary)TestGuid;
290 AssertEquals ("#N01", (byte)15, TestBinary [0]);
294 public void ByteArrayToSqlBinary()
296 byte [] TestByteArray = new Byte [2];
297 TestByteArray [0] = 15;
298 TestByteArray [1] = 200;
299 SqlBinary TestBinary = (SqlBinary)TestByteArray;
300 AssertEquals ("#O1", (byte)15, TestBinary [0]);