(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System / GuidTest.cs
blob659fe22a93812981d5db50cac7d475b6957dab9f
1 //
2 // GuidTest.cs - NUnit Test Cases for the System.Guid struct
3 //
4 // author:
5 // Duco Fijma (duco@lorentz.xs4all.nl)
6 //
7 // (C) 2002 Duco Fijma
8 //
10 using NUnit.Framework;
11 using System;
13 namespace MonoTests.System
16 public class GuidTest : TestCase
18 public GuidTest () {}
20 public void TestCtor1 ()
22 Guid g = new Guid (new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f});
23 bool exception;
25 if (BitConverter.IsLittleEndian) {
26 AssertEquals ("A1", "03020100-0504-0706-0809-0a0b0c0d0e0f", g.ToString ());
28 else {
29 AssertEquals ("A1", "00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString ());
32 try {
33 Guid g1 = new Guid ((byte[]) null);
34 exception = false;
36 catch (ArgumentNullException) {
37 exception = true;
39 Assert ("A2", exception);
41 try {
42 Guid g1 = new Guid (new byte[] {0x00, 0x01, 0x02});
43 exception = false;
45 catch (ArgumentException) {
46 exception = true;
48 Assert ("A3", exception);
51 public void TestCtor2 ()
53 Guid g0 = new Guid ("000102030405060708090a0b0c0d0e0f");
54 Guid g1 = new Guid ("00010203-0405-0607-0809-0a0b0c0d0e0f");
55 Guid g2 = new Guid ("{00010203-0405-0607-0809-0A0B0C0D0E0F}");
56 Guid g3 = new Guid ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}");
57 Guid g4 = new Guid ("(00010203-0405-0607-0809-0A0B0C0D0E0F)");
58 Guid g5;
60 bool exception;
62 AssertEquals ("A0", "00010203-0405-0607-0809-0a0b0c0d0e0f", g0.ToString ());
63 AssertEquals ("A1", "00010203-0405-0607-0809-0a0b0c0d0e0f", g1.ToString ());
64 AssertEquals ("A2", "00010203-0405-0607-0809-0a0b0c0d0e0f", g2.ToString ());
65 AssertEquals ("A3", "00010203-0405-0607-0809-0a0b0c0d0e0f", g3.ToString ());
66 AssertEquals ("A4", "00010203-0405-0607-0809-0a0b0c0d0e0f", g4.ToString ());
68 try {
69 g4 = new Guid ((string) null);
70 exception = false;
72 catch (ArgumentNullException) {
73 exception = true;
75 Assert ("A4", exception);
77 try {
78 g5 = new Guid ("invalid");
79 exception = false;
81 catch (FormatException) {
82 exception = true;
84 Assert ("A5", exception);
86 try {
87 g5 = new Guid ("{000102030405060708090A0B0C0D0E0F}");
88 exception = false;
90 catch (FormatException) {
91 exception = true;
93 Assert ("A6", exception);
95 try {
96 g5 = new Guid ("000102030405-0607-0809-0a0b0c0d0e0f");
97 exception = false;
99 catch (FormatException) {
100 exception = true;
102 Assert ("A7", exception);
104 try {
105 g5 = new Guid ("(000102030405-0607-0809-0a0b0c0d0e0f}"); // open (, close }
106 exception = false;
108 catch (FormatException) {
109 exception = true;
111 Assert ("A8", exception);
115 public void TestCtor4 ()
117 Guid g1 = new Guid (0x00010203, (short) 0x0405, (short) 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
118 Guid g2 = new Guid (unchecked ((int) 0xffffffff), unchecked ((short) 0xffff), unchecked((short) 0xffff), 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
120 AssertEquals ("A1", "00010203-0405-0607-0809-0a0b0c0d0e0f", g1.ToString ());
121 AssertEquals ("A2", "ffffffff-ffff-ffff-ffff-ffffffffffff", g2.ToString ());
125 public void TestCtor5 ()
127 Guid g1 = new Guid (0x00010203u, (ushort) 0x0405u, (ushort) 0x0607u, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
128 Guid g2 = new Guid (0xffffffffu, (ushort) 0xffffu, (ushort) 0xffffu, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
130 AssertEquals ("A1", "00010203-0405-0607-0809-0a0b0c0d0e0f", g1.ToString ());
131 AssertEquals ("A2", "ffffffff-ffff-ffff-ffff-ffffffffffff", g2.ToString ());
135 public void TestEmpty ()
137 AssertEquals ("A1", "00000000-0000-0000-0000-000000000000", Guid.Empty.ToString ());
140 public void TestNewGuid ()
142 Guid g1 = Guid.NewGuid ();
143 Guid g2 = Guid.NewGuid ();
145 Assert ("A1", g1 != g2);
148 public void TestEqualityOp ()
150 Guid g1 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
151 Guid g2 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
152 Guid g3 = new Guid (0x11223344, 0x5566, 0x6677, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
154 AssertEquals ("A1", true, g1 == g1);
155 AssertEquals ("A2", true, g1 == g2);
156 AssertEquals ("A3", false, g1 == g3);
159 public void TestInequalityOp ()
161 Guid g1 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
162 Guid g2 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
163 Guid g3 = new Guid (0x11223344, 0x5566, 0x6677, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
165 AssertEquals ("A1", false, g1 != g1);
166 AssertEquals ("A2", false, g1 != g2);
167 AssertEquals ("A3", true, g1 != g3);
170 public void TestEquals ()
172 Guid g1 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
173 Guid g2 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
174 Guid g3 = new Guid (0x11223344, 0x5566, 0x6677, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
175 string s = "This is not a Guid!";
177 AssertEquals ("A1", true, g1.Equals (g1));
178 AssertEquals ("A2", true, g1.Equals (g2));
179 AssertEquals ("A3", false, g1.Equals (g3));
180 AssertEquals ("A4", false, g1.Equals (null));
181 AssertEquals ("A5", false, g1.Equals (s));
184 public void TestCompareTo ()
186 Guid g1 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
187 Guid g2 = new Guid (0x00010204, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
188 Guid g3 = new Guid (0x00010203, 0x0405, 0x0607, 0x09, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
189 Guid g4 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x1f);
190 bool exception;
192 Assert ("A1", g1.CompareTo (g2) < 0);
193 Assert ("A2", g1.CompareTo (g3) < 0);
194 Assert ("A3", g1.CompareTo (g4) < 0);
195 Assert ("A4", g2.CompareTo (g1) > 0);
196 Assert ("A5", g3.CompareTo (g1) > 0);
197 Assert ("A6", g4.CompareTo (g1) > 0);
198 Assert ("A7", g1.CompareTo (g1) == 0);
199 Assert ("A8", g1.CompareTo (null) > 0);
201 try {
202 g1.CompareTo ("Say what?");
203 exception = false;
205 catch (ArgumentException) {
206 exception = true;
208 Assert ("A9", exception);
211 public void TestGetHashCode ()
213 // We don't test anything but the availibility of this member
214 int res = Guid.NewGuid ().GetHashCode ();
216 Assert ("A1", true);
219 public void TestToByteArray ()
221 Guid g1 = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
222 byte[] b = g1.ToByteArray ();
224 AssertEquals ("A1", 0x00010203, BitConverter.ToInt32 (b, 0));
225 AssertEquals ("A2", (short) 0x0405, BitConverter.ToInt16 (b, 4));
226 AssertEquals ("A3", (short) 0x0607, BitConverter.ToInt16 (b, 6));
227 for (int i=8; i<16; ++i) {
228 AssertEquals ("A1", (byte) i, b [i]);
233 public void TestToString ()
235 Guid g = new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
236 bool exception;
238 AssertEquals ("A1", "00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString ());
239 AssertEquals ("A2", "000102030405060708090a0b0c0d0e0f", g.ToString ("N"));
240 AssertEquals ("A3", "00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString ("D"));
241 AssertEquals ("A4", "{00010203-0405-0607-0809-0a0b0c0d0e0f}", g.ToString ("B"));
242 AssertEquals ("A5", "(00010203-0405-0607-0809-0a0b0c0d0e0f)", g.ToString ("P"));
243 AssertEquals ("A6", "00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString (""));
244 AssertEquals ("A7", "00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString ((string)null));
246 try {
247 g.ToString ("X");
248 exception = false;
250 catch (FormatException) {
251 exception = true;
253 Assert ("A8", exception);
255 try {
256 g.ToString ("This is invalid");
257 exception = false;
259 catch (FormatException) {
260 exception = true;
262 Assert ("A9", exception);
264 AssertEquals ("A10", "{00010203-0405-0607-0809-0a0b0c0d0e0f}", g.ToString ("B", null));