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;
38 using System.Data.SqlTypes;
40 namespace MonoTests.System.Data.SqlTypes
43 public class SqlBinaryTest {
50 public void GetReady()
52 byte [] b1 = new Byte [2];
53 byte [] b2 = new Byte [3];
54 byte [] b3 = new Byte [2];
64 Test1 = new SqlBinary(b1);
65 Test2 = new SqlBinary(b2);
66 Test3 = new SqlBinary(b3);
73 byte [] b = new byte [3];
74 SqlBinary Test = new SqlBinary (b);
75 Assert.IsTrue (!(Test.IsNull) , "#A01");
80 public void PublicFields()
82 Assert.IsTrue (SqlBinary.Null.IsNull, "#B01");
87 public void Properties()
89 byte [] b = new byte [2];
93 SqlBinary TestBinary = new SqlBinary (b);
96 Assert.IsTrue (SqlBinary.Null.IsNull, "#C01");
99 Assert.AreEqual ((byte)128, TestBinary [1], "#C02");
100 Assert.AreEqual ((byte)64, TestBinary [0], "#C03");
102 // FIXME: MSDN says that should throw SqlNullValueException
103 // but throws IndexOutOfRangeException
105 byte test = TestBinary [TestBinary.Length];
106 Assert.Fail ("#C04");
107 } catch (Exception e) {
108 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "#C05");
112 byte test = SqlBinary.Null [2];
113 Assert.Fail ("#C06");
114 } catch (Exception e) {
115 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#C07");
119 Assert.AreEqual (2, TestBinary.Length, "#C08");
122 int test = SqlBinary.Null.Length;
123 Assert.Fail ("#C09");
124 } catch (Exception e) {
125 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#C10");
129 Assert.AreEqual ((byte)128, TestBinary [1], "#C11");
130 Assert.AreEqual ((byte)64, TestBinary [0], "#C12");
133 Byte [] test = SqlBinary.Null.Value;
134 Assert.Fail ("#C13");
135 } catch (Exception e) {
136 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#C14");
142 public void ComparisonMethods()
145 Assert.IsTrue (SqlBinary.GreaterThan (Test1, Test2).Value, "#D01");
146 Assert.IsTrue (SqlBinary.GreaterThan (Test3, Test2).Value, "#D02");
147 Assert.IsTrue (!SqlBinary.GreaterThan (Test2, Test1).Value, "#D03");
149 // GreaterThanOrEqual
150 Assert.IsTrue (SqlBinary.GreaterThanOrEqual (Test1, Test2).Value, "#D04");
151 Assert.IsTrue (SqlBinary.GreaterThanOrEqual (Test1, Test2).Value, "#D05");
152 Assert.IsTrue (!SqlBinary.GreaterThanOrEqual (Test2, Test1).Value, "#D06");
155 Assert.IsTrue (!SqlBinary.LessThan (Test1, Test2).Value, "#D07");
156 Assert.IsTrue (!SqlBinary.LessThan (Test3, Test2).Value, "#D08");
157 Assert.IsTrue (SqlBinary.LessThan (Test2, Test1).Value, "#D09");
160 Assert.IsTrue (!SqlBinary.LessThanOrEqual (Test1, Test2).Value, "#D10");
161 Assert.IsTrue (SqlBinary.LessThanOrEqual (Test3, Test1).Value, "#D11");
162 Assert.IsTrue (SqlBinary.LessThanOrEqual (Test2, Test1).Value, "#D12");
165 Assert.IsTrue (!Test1.Equals (Test2), "#D13");
166 Assert.IsTrue (!Test3.Equals (Test2), "#D14");
167 Assert.IsTrue (Test3.Equals (Test1), "#D15");
170 Assert.IsTrue (SqlBinary.NotEquals (Test1, Test2).Value, "#D16");
171 Assert.IsTrue (!SqlBinary.NotEquals (Test3, Test1).Value, "#D17");
172 Assert.IsTrue (SqlBinary.NotEquals (Test2, Test1).Value, "#D18");
176 public void CompareTo()
178 SqlString TestString = new SqlString ("This is a test");
180 Assert.IsTrue (Test1.CompareTo(Test2) > 0, "#E01");
181 Assert.IsTrue (Test2.CompareTo(Test1) < 0, "#E02");
182 Assert.IsTrue (Test1.CompareTo(Test3) == 0, "#E03");
185 Test1.CompareTo (TestString);
186 Assert.Fail ("#E04");
187 } catch(Exception e) {
188 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "#E05");
193 public void GetHashCodeTest()
195 Assert.AreEqual (Test1.GetHashCode (), Test1.GetHashCode (), "#F01");
196 Assert.IsTrue (Test2.GetHashCode () != Test1.GetHashCode (), "#F02");
200 public void GetTypeTest()
202 Assert.AreEqual ("System.Data.SqlTypes.SqlBinary", Test1.GetType().ToString(), "#G01");
208 SqlBinary TestBinary;
210 TestBinary = SqlBinary.Concat (Test2, Test3);
211 Assert.AreEqual ((byte)15, TestBinary [4], "H01");
213 TestBinary = SqlBinary.Concat (Test1, Test2);
214 Assert.AreEqual ((byte)240, TestBinary [0], "#H02");
215 Assert.AreEqual ((byte)15, TestBinary [1], "#H03");
219 public void ToSqlGuid()
221 SqlBinary TestBinary = new SqlBinary (new byte [16]);
222 SqlGuid TestGuid = TestBinary.ToSqlGuid ();
223 Assert.IsTrue (!TestGuid.IsNull, "#I01");
227 public void ToStringTest()
229 Assert.AreEqual ("SqlBinary(3)", Test2.ToString (), "#J01");
230 Assert.AreEqual ("SqlBinary(2)", Test1.ToString (), "#J02");
235 public void AdditionOperator()
237 SqlBinary TestBinary = Test1 + Test2;
238 Assert.AreEqual ((byte)240, TestBinary [0], "#K01");
239 Assert.AreEqual ((byte)15, TestBinary [1], "#K02");
243 public void ComparisonOperators()
246 Assert.IsTrue (!(Test1 == Test2).Value, "#L01");
247 Assert.IsTrue ((Test3 == Test1).Value, "#L02");
250 Assert.IsTrue ((Test1 > Test2).Value, "#L03");
251 Assert.IsTrue (!(Test3 > Test1).Value, "#L04");
253 // Greater than or equal
254 Assert.IsTrue ((Test1 >= Test2).Value, "#L05");
255 Assert.IsTrue ((Test3 >= Test2).Value, "#L06");
258 Assert.IsTrue ((Test1 != Test2).Value, "#L07");
259 Assert.IsTrue (!(Test3 != Test1).Value, "#L08");
262 Assert.IsTrue (!(Test1 < Test2).Value, "#L09");
263 Assert.IsTrue (!(Test3 < Test2).Value, "#L10");
265 // Less than or equal
266 Assert.IsTrue (!(Test1 <= Test2).Value, "#L11");
267 Assert.IsTrue ((Test3 <= Test1).Value, "#L12");
271 public void SqlBinaryToByteArray()
273 byte [] TestByteArray = (Byte[])Test1;
274 Assert.AreEqual ((byte)240, TestByteArray[0], "#M01");
278 public void SqlGuidToSqlBinary()
280 byte [] TestByteArray = new Byte [16];
281 TestByteArray [0] = 15;
282 TestByteArray [1] = 200;
283 SqlGuid TestGuid = new SqlGuid (TestByteArray);
285 SqlBinary TestBinary = (SqlBinary)TestGuid;
286 Assert.AreEqual ((byte)15, TestBinary [0], "#N01");
290 public void ByteArrayToSqlBinary()
292 byte [] TestByteArray = new Byte [2];
293 TestByteArray [0] = 15;
294 TestByteArray [1] = 200;
295 SqlBinary TestBinary = (SqlBinary)TestByteArray;
296 Assert.AreEqual ((byte)15, TestBinary [0], "#O1");
300 public void GetXsdTypeTest ()
302 XmlQualifiedName qualifiedName = SqlBinary.GetXsdType (null);
303 Assert.AreEqual ("base64Binary", qualifiedName.Name, "#A01");