6 namespace MonoTests.System.Text
9 public class UTF32EncodingTest
11 [Test] // GetByteCount (Char [])
12 [Category ("NotDotNet")] // A1/B1 return 24 on MS
13 public void GetByteCount1 ()
15 char [] chars = new char[] { 'z', 'a', '\u0306',
16 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
18 UTF32Encoding le = new UTF32Encoding (false, true);
19 Assert.AreEqual (28, le.GetByteCount (chars), "#A1");
20 Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");
22 UTF32Encoding be = new UTF32Encoding (true, true);
23 Assert.AreEqual (28, be.GetByteCount (chars), "#B1");
24 Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
27 [Test] // GetByteCount (Char [])
28 public void GetByteCount1_Chars_Null ()
30 UTF32Encoding enc = new UTF32Encoding ();
32 enc.GetByteCount ((Char []) null);
34 } catch (ArgumentNullException ex) {
35 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
36 Assert.IsNull (ex.InnerException, "#3");
37 Assert.IsNotNull (ex.Message, "#4");
38 Assert.AreEqual ("chars", ex.ParamName, "#5");
42 [Test] // GetByteCount (String)
43 [Category ("NotDotNet")] // A1/B1 return 24 on MS
44 public void GetByteCount2 ()
46 string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
48 UTF32Encoding le = new UTF32Encoding (false, true);
49 Assert.AreEqual (28, le.GetByteCount (s), "#A1");
50 Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");
52 UTF32Encoding be = new UTF32Encoding (true, true);
53 Assert.AreEqual (28, be.GetByteCount (s), "#B1");
54 Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
57 [Test] // GetByteCount (String)
58 public void GetByteCount2_S_Null ()
60 UTF32Encoding enc = new UTF32Encoding ();
62 enc.GetByteCount ((string) null);
64 } catch (ArgumentNullException ex) {
65 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
66 Assert.IsNull (ex.InnerException, "#3");
67 Assert.IsNotNull (ex.Message, "#4");
68 Assert.AreEqual ("s", ex.ParamName, "#5");
72 [Test] // GetByteCount (Char *)
73 public unsafe void GetByteCount3 ()
75 char [] chars = new char[] { 'z', 'a', '\u0306',
76 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
78 fixed (char* cp = chars) {
79 UTF32Encoding le = new UTF32Encoding (false, true);
80 Assert.AreEqual (12, le.GetByteCount (cp, 3), "#A1");
81 Assert.AreEqual (4, le.GetByteCount (cp, 1), "#A2");
82 Assert.AreEqual (0, le.GetByteCount (cp, 0), "#A3");
83 Assert.AreEqual (24, le.GetByteCount (cp, 6), "#A4");
84 //Assert.AreEqual (24, le.GetByteCount (cp, 7), "#A5");
86 UTF32Encoding be = new UTF32Encoding (true, true);
87 Assert.AreEqual (12, be.GetByteCount (cp, 3), "#B1");
88 Assert.AreEqual (4, be.GetByteCount (cp, 1), "#B2");
89 Assert.AreEqual (0, be.GetByteCount (cp, 0), "#B3");
90 Assert.AreEqual (24, be.GetByteCount (cp, 6), "#B4");
91 //Assert.AreEqual (24, be.GetByteCount (cp, 7), "#B5");
95 [Test] // GetByteCount (Char *)
96 public unsafe void GetByteCount3_Chars_Null ()
98 UTF32Encoding enc = new UTF32Encoding ();
100 enc.GetByteCount ((char *) null, 1);
102 } catch (ArgumentNullException ex) {
103 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
104 Assert.IsNull (ex.InnerException, "#3");
105 Assert.IsNotNull (ex.Message, "#4");
106 Assert.AreEqual ("chars", ex.ParamName, "#5");
110 [Test] // GetByteCount (Char [], Int32, Int32)
111 public void GetByteCount4 ()
113 char [] chars = new char[] { 'z', 'a', '\u0306',
114 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
116 UTF32Encoding le = new UTF32Encoding (false, true);
117 Assert.AreEqual (12, le.GetByteCount (chars, 0, 3), "#A1");
118 Assert.AreEqual (16, le.GetByteCount (chars, 2, 4), "#A2");
119 Assert.AreEqual (4, le.GetByteCount (chars, 4, 1), "#A3");
120 Assert.AreEqual (4, le.GetByteCount (chars, 6, 1), "#A4");
121 Assert.AreEqual (0, le.GetByteCount (chars, 6, 0), "#A5");
122 Assert.AreEqual (24, le.GetByteCount (chars, 0, 6), "#A6");
123 //Assert.AreEqual (24, le.GetByteCount (chars, 0, 7), "#A7");
125 UTF32Encoding be = new UTF32Encoding (true, true);
126 Assert.AreEqual (12, be.GetByteCount (chars, 0, 3), "#B1");
127 Assert.AreEqual (16, be.GetByteCount (chars, 2, 4), "#B2");
128 Assert.AreEqual (4, be.GetByteCount (chars, 4, 1), "#B3");
129 Assert.AreEqual (4, be.GetByteCount (chars, 6, 1), "#B4");
130 Assert.AreEqual (0, be.GetByteCount (chars, 6, 0), "#B5");
131 Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B6");
132 //Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B7");
135 [Test] // GetByteCount (Char [], Int32, Int32)
136 public void GetByteCount4_Chars_Null ()
138 UTF32Encoding enc = new UTF32Encoding ();
140 enc.GetByteCount ((Char []) null, 0, 1);
142 } catch (ArgumentNullException ex) {
143 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
144 Assert.IsNull (ex.InnerException, "#3");
145 Assert.IsNotNull (ex.Message, "#4");
146 Assert.AreEqual ("chars", ex.ParamName, "#5");
150 [Test] // GetByteCount (Char [], Int32, Int32)
151 public void GetByteCount4_Count_Negative ()
153 char [] chars = new char[] { 'z', 'a', '\u0306',
154 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
156 UTF32Encoding enc = new UTF32Encoding ();
158 enc.GetByteCount (chars, 1, -1);
160 } catch (ArgumentOutOfRangeException ex) {
161 // Non-negative number required
162 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
163 Assert.IsNull (ex.InnerException, "#3");
164 Assert.IsNotNull (ex.Message, "#4");
165 Assert.AreEqual ("count", ex.ParamName, "#5");
169 [Test] // GetByteCount (Char [], Int32, Int32)
170 public void GetByteCount4_Count_Overflow ()
172 char [] chars = new char[] { 'z', 'a', '\u0306',
173 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
175 UTF32Encoding enc = new UTF32Encoding ();
177 enc.GetByteCount (chars, 6, 2);
179 } catch (ArgumentOutOfRangeException ex) {
180 // Index and count must refer to a location
182 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
183 Assert.IsNull (ex.InnerException, "#3");
184 Assert.IsNotNull (ex.Message, "#4");
185 //Assert.AreEqual ("chars", ex.ParamName, "#5");
189 [Test] // GetByteCount (Char [], Int32, Int32)
190 public void GetByteCount4_Index_Negative ()
192 char [] chars = new char[] { 'z', 'a', '\u0306',
193 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
195 UTF32Encoding enc = new UTF32Encoding ();
197 enc.GetByteCount (chars, -1, 1);
199 } catch (ArgumentOutOfRangeException ex) {
200 // Non-negative number required
201 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
202 Assert.IsNull (ex.InnerException, "#3");
203 Assert.IsNotNull (ex.Message, "#4");
204 Assert.AreEqual ("index", ex.ParamName, "#5");
208 [Test] // GetByteCount (Char [], Int32, Int32)
209 public void GetByteCount4_Index_Overflow ()
211 char [] chars = new char[] { 'z', 'a', '\u0306',
212 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
214 UTF32Encoding enc = new UTF32Encoding ();
216 enc.GetByteCount (chars, 7, 1);
218 } catch (ArgumentOutOfRangeException ex) {
219 // Index and count must refer to a location
221 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
222 Assert.IsNull (ex.InnerException, "#3");
223 Assert.IsNotNull (ex.Message, "#4");
224 //Assert.AreEqual ("chars", ex.ParamName, "#5");
229 public void GetPreamble ()
231 byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
232 Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
234 byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
235 Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
239 public void IsBrowserDisplay ()
241 UTF32Encoding le = new UTF32Encoding (false, true);
242 Assert.IsFalse (le.IsBrowserDisplay, "#1");
244 UTF32Encoding be = new UTF32Encoding (true, true);
245 Assert.IsFalse (be.IsBrowserDisplay, "#2");
249 public void IsBrowserSave ()
251 UTF32Encoding le = new UTF32Encoding (false, true);
252 Assert.IsFalse (le.IsBrowserSave);
254 UTF32Encoding be = new UTF32Encoding (true, true);
255 Assert.IsFalse (be.IsBrowserSave, "#2");
259 public void IsMailNewsDisplay ()
261 UTF32Encoding le = new UTF32Encoding (false, true);
262 Assert.IsFalse (le.IsMailNewsDisplay);
264 UTF32Encoding be = new UTF32Encoding (true, true);
265 Assert.IsFalse (be.IsMailNewsDisplay, "#2");
269 public void IsMailNewsSave ()
271 UTF32Encoding le = new UTF32Encoding (false, true);
272 Assert.IsFalse (le.IsMailNewsSave);
274 UTF32Encoding be = new UTF32Encoding (true, true);
275 Assert.IsFalse (be.IsMailNewsSave, "#2");