[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / corlib / Test / System / StringComparerTest.cs
1 //
2 // MonoTests.System.StringComparerTest
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (C) 2007 Gert Driesen
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if NET_2_0
30
31 using System;
32 using System.Globalization;
33 using System.IO;
34 using System.Runtime.Serialization.Formatters.Binary;
35 using System.Threading;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System
40 {
41         [TestFixture]
42         public class StringComparerTest
43         {
44                 private CultureInfo old_culture;
45
46 #if TARGET_JVM // BinaryFormatter is Java based under TARGET_JVM.
47                 private BinaryFormatter CreateBinaryFormatter()
48                 {
49                         return (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
50                 }
51 #else
52                 private BinaryFormatter CreateBinaryFormatter()
53                 {
54                         return new BinaryFormatter();
55                 }
56 #endif // TARGET_JVM
57
58                 [SetUp]
59                 public void SetUp ()
60                 {
61                         old_culture = Thread.CurrentThread.CurrentCulture;
62                 }
63
64                 [TearDown]
65                 public void TearDown ()
66                 {
67                         Thread.CurrentThread.CurrentCulture = old_culture;
68                 }
69
70                 [Test]
71                 public void Serialize_CurrentCulture ()
72                 {
73                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
74                         BinaryFormatter bf = CreateBinaryFormatter();
75                         MemoryStream ms = new MemoryStream ();
76                         bf.Serialize (ms, StringComparer.CurrentCulture);
77
78                         // Assert.AreEqual (_serializedCurrentCulture, buffer);
79                 }
80
81                 [Test]
82                 public void Deserialize_CurrentCulture ()
83                 {
84                         MemoryStream ms = new MemoryStream ();
85                         ms.Write (_serializedCurrentCulture, 0, _serializedCurrentCulture.Length);
86                         ms.Position = 0;
87
88                         BinaryFormatter bf = CreateBinaryFormatter();
89                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
90                         Assert.IsNotNull (sc);
91                 }
92
93                 [Test]
94                 public void Serialize_CurrentCultureIgnoreCase ()
95                 {
96                         BinaryFormatter bf = CreateBinaryFormatter();
97                         MemoryStream ms = new MemoryStream ();
98                         bf.Serialize (ms, StringComparer.CurrentCultureIgnoreCase);
99
100                         // Assert.AreEqual (_serializedCurrentCultureIgnoreCase, buffer);
101                 }
102
103                 [Test]
104                 public void Deserialize_CurrentCultureIgnoreCase ()
105                 {
106                         MemoryStream ms = new MemoryStream ();
107                         ms.Write (_serializedCurrentCultureIgnoreCase, 0, _serializedCurrentCultureIgnoreCase.Length);
108                         ms.Position = 0;
109
110                         BinaryFormatter bf = CreateBinaryFormatter();
111                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
112                         Assert.IsNotNull (sc);
113                 }
114
115                 [Test]
116                 public void Serialize_InvariantCulture ()
117                 {
118                         BinaryFormatter bf = CreateBinaryFormatter();
119                         MemoryStream ms = new MemoryStream ();
120                         bf.Serialize (ms, StringComparer.InvariantCulture);
121
122                         byte [] buffer = new byte [ms.Length];
123                         ms.Position = 0;
124                         ms.Read (buffer, 0, buffer.Length);
125
126                         // Assert.AreEqual (_serializedInvariantCulture, buffer);
127                 }
128
129                 [Test]
130                 public void Deserialize_InvariantCulture ()
131                 {
132                         MemoryStream ms = new MemoryStream ();
133                         ms.Write (_serializedInvariantCulture, 0, _serializedInvariantCulture.Length);
134                         ms.Position = 0;
135
136                         BinaryFormatter bf = CreateBinaryFormatter();
137                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
138                         Assert.IsNotNull (sc);
139                 }
140
141                 [Test]
142                 public void Serialize_InvariantCultureIgnoreCase ()
143                 {
144                         BinaryFormatter bf = CreateBinaryFormatter();
145                         MemoryStream ms = new MemoryStream ();
146                         bf.Serialize (ms, StringComparer.InvariantCultureIgnoreCase);
147
148                         byte [] buffer = new byte [ms.Length];
149                         ms.Position = 0;
150                         ms.Read (buffer, 0, buffer.Length);
151
152                         // Assert.AreEqual (_serializedInvariantCultureIgnoreCase, buffer);
153                 }
154
155                 [Test]
156                 public void Deserialize_InvariantCultureIgnoreCase ()
157                 {
158                         MemoryStream ms = new MemoryStream ();
159                         ms.Write (_serializedInvariantCultureIgnoreCase, 0, _serializedInvariantCultureIgnoreCase.Length);
160                         ms.Position = 0;
161
162                         BinaryFormatter bf = CreateBinaryFormatter();
163                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
164                         Assert.IsNotNull (sc);
165                 }
166
167                 [Test]
168                 public void Serialize_Ordinal ()
169                 {
170                         BinaryFormatter bf = CreateBinaryFormatter();
171                         MemoryStream ms = new MemoryStream ();
172                         bf.Serialize (ms, StringComparer.Ordinal);
173
174                         byte [] buffer = new byte [ms.Length];
175                         ms.Position = 0;
176                         ms.Read (buffer, 0, buffer.Length);
177
178                         Assert.AreEqual (_serializedOrdinal, buffer);
179                 }
180
181                 [Test]
182                 public void Deserialize_Ordinal ()
183                 {
184                         MemoryStream ms = new MemoryStream ();
185                         ms.Write (_serializedOrdinal, 0, _serializedOrdinal.Length);
186                         ms.Position = 0;
187
188                         BinaryFormatter bf = CreateBinaryFormatter();
189                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
190                         Assert.IsNotNull (sc);
191                 }
192
193                 [Test]
194                 public void Serialize_OrdinalIgnoreCase ()
195                 {
196                         BinaryFormatter bf = CreateBinaryFormatter();
197                         MemoryStream ms = new MemoryStream ();
198                         bf.Serialize (ms, StringComparer.OrdinalIgnoreCase);
199
200                         byte [] buffer = new byte [ms.Length];
201                         ms.Position = 0;
202                         ms.Read (buffer, 0, buffer.Length);
203
204                         Assert.AreEqual (_serializedOrdinalIgnoreCase, buffer);
205                 }
206
207                 [Test]
208                 public void Deserialize_OrdinalIgnoreCase ()
209                 {
210                         MemoryStream ms = new MemoryStream ();
211                         ms.Write (_serializedOrdinalIgnoreCase, 0, _serializedOrdinalIgnoreCase.Length);
212                         ms.Position = 0;
213
214                         BinaryFormatter bf = CreateBinaryFormatter();
215                         StringComparer sc = (StringComparer) bf.Deserialize (ms);
216                         Assert.IsNotNull (sc);
217                 }
218
219                 [Test]
220                 [ExpectedException (typeof (ArgumentNullException))]
221                 public void GetNullOrdinalHashCode ()
222                 {
223                         StringComparer.Ordinal.GetHashCode (null);
224                 }
225
226                 private static readonly byte [] _serializedCurrentCulture = new byte [] {
227                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
228                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
229                         0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x75, 0x6c,
230                         0x74, 0x75, 0x72, 0x65, 0x41, 0x77, 0x61, 0x72, 0x65, 0x43, 0x6f,
231                         0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x02, 0x00, 0x00, 0x00, 0x0c,
232                         0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x66,
233                         0x6f, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x43, 0x61,
234                         0x73, 0x65, 0x03, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
235                         0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x74,
236                         0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
237                         0x49, 0x6e, 0x66, 0x6f, 0x01, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00,
238                         0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65,
239                         0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61,
240                         0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72,
241                         0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09, 0x77,
242                         0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63, 0x75,
243                         0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61, 0x6d,
244                         0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x13, 0x08, 0x00, 0x00, 0x13,
245                         0x08, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x05, 0x6e, 0x6c,
246                         0x2d, 0x42, 0x45, 0x0b };
247
248                 private static readonly byte [] _serializedCurrentCultureIgnoreCase = new byte [] {
249                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
250                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
251                         0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x75, 0x6c,
252                         0x74, 0x75, 0x72, 0x65, 0x41, 0x77, 0x61, 0x72, 0x65, 0x43, 0x6f,
253                         0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x02, 0x00, 0x00, 0x00, 0x0c,
254                         0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x66,
255                         0x6f, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x43, 0x61,
256                         0x73, 0x65, 0x03, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
257                         0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x74,
258                         0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
259                         0x49, 0x6e, 0x66, 0x6f, 0x01, 0x09, 0x02, 0x00, 0x00, 0x00, 0x01,
260                         0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65,
261                         0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61,
262                         0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72,
263                         0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09, 0x77,
264                         0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63, 0x75,
265                         0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61, 0x6d,
266                         0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x13, 0x08, 0x00, 0x00, 0x13,
267                         0x08, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x05, 0x6e, 0x6c,
268                         0x2d, 0x42, 0x45, 0x0b };
269
270
271                 private static readonly byte [] _serializedInvariantCulture = new byte [] {
272                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
273                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
274                         0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x75, 0x6c,
275                         0x74, 0x75, 0x72, 0x65, 0x41, 0x77, 0x61, 0x72, 0x65, 0x43, 0x6f,
276                         0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x02, 0x00, 0x00, 0x00, 0x0c,
277                         0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x66,
278                         0x6f, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x43, 0x61,
279                         0x73, 0x65, 0x03, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
280                         0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x74,
281                         0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
282                         0x49, 0x6e, 0x66, 0x6f, 0x01, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00,
283                         0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65,
284                         0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61,
285                         0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72,
286                         0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09, 0x77,
287                         0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63, 0x75,
288                         0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61, 0x6d,
289                         0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00, 0x7f,
290                         0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0b };
291
292                 private static readonly byte [] _serializedInvariantCultureIgnoreCase = new byte [] {
293                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
294                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
295                         0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x75, 0x6c,
296                         0x74, 0x75, 0x72, 0x65, 0x41, 0x77, 0x61, 0x72, 0x65, 0x43, 0x6f,
297                         0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x02, 0x00, 0x00, 0x00, 0x0c,
298                         0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x66,
299                         0x6f, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x43, 0x61,
300                         0x73, 0x65, 0x03, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
301                         0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x74,
302                         0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
303                         0x49, 0x6e, 0x66, 0x6f, 0x01, 0x09, 0x02, 0x00, 0x00, 0x00, 0x01,
304                         0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65,
305                         0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a, 0x61,
306                         0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72,
307                         0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09, 0x77,
308                         0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63, 0x75,
309                         0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61, 0x6d,
310                         0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00, 0x7f,
311                         0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0b };
312
313                 private static readonly byte [] _serializedOrdinal = new byte [] {
314                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
315                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
316                         0x16, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4f, 0x72, 0x64,
317                         0x69, 0x6e, 0x61, 0x6c, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
318                         0x72, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f,
319                         0x72, 0x65, 0x43, 0x61, 0x73, 0x65, 0x00, 0x01, 0x00, 0x0b };
320
321                 private static readonly byte [] _serializedOrdinalIgnoreCase = new byte [] {
322                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
323                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
324                         0x16, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4f, 0x72, 0x64,
325                         0x69, 0x6e, 0x61, 0x6c, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
326                         0x72, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x5f, 0x69, 0x67, 0x6e, 0x6f,
327                         0x72, 0x65, 0x43, 0x61, 0x73, 0x65, 0x00, 0x01, 0x01, 0x0b };
328         }
329 }
330
331 #endif