7 namespace MonoTests.System.Text
10 public class UTF32EncodingTest
12 [Test] // GetByteCount (Char [])
13 [Category ("NotDotNet")] // A1/B1 return 24 on MS
14 public void GetByteCount1 ()
16 char [] chars = new char[] { 'z', 'a', '\u0306',
17 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
19 UTF32Encoding le = new UTF32Encoding (false, true);
20 Assert.AreEqual (28, le.GetByteCount (chars), "#A1");
21 Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");
23 UTF32Encoding be = new UTF32Encoding (true, true);
24 Assert.AreEqual (28, be.GetByteCount (chars), "#B1");
25 Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
28 [Test] // GetByteCount (Char [])
29 public void GetByteCount1_Chars_Null ()
31 UTF32Encoding enc = new UTF32Encoding ();
33 enc.GetByteCount ((Char []) null);
35 } catch (ArgumentNullException ex) {
36 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
37 Assert.IsNull (ex.InnerException, "#3");
38 Assert.IsNotNull (ex.Message, "#4");
39 Assert.AreEqual ("chars", ex.ParamName, "#5");
43 [Test] // GetByteCount (String)
44 [Category ("NotDotNet")] // A1/B1 return 24 on MS
45 public void GetByteCount2 ()
47 string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
49 UTF32Encoding le = new UTF32Encoding (false, true);
50 Assert.AreEqual (28, le.GetByteCount (s), "#A1");
51 Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");
53 UTF32Encoding be = new UTF32Encoding (true, true);
54 Assert.AreEqual (28, be.GetByteCount (s), "#B1");
55 Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
58 [Test] // GetByteCount (String)
59 public void GetByteCount2_S_Null ()
61 UTF32Encoding enc = new UTF32Encoding ();
63 enc.GetByteCount ((string) null);
65 } catch (ArgumentNullException ex) {
66 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
67 Assert.IsNull (ex.InnerException, "#3");
68 Assert.IsNotNull (ex.Message, "#4");
69 Assert.AreEqual ("s", ex.ParamName, "#5");
73 [Test] // GetByteCount (Char *)
74 public unsafe void GetByteCount3 ()
76 char [] chars = new char[] { 'z', 'a', '\u0306',
77 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
79 fixed (char* cp = chars) {
80 UTF32Encoding le = new UTF32Encoding (false, true);
81 Assert.AreEqual (12, le.GetByteCount (cp, 3), "#A1");
82 Assert.AreEqual (4, le.GetByteCount (cp, 1), "#A2");
83 Assert.AreEqual (0, le.GetByteCount (cp, 0), "#A3");
84 Assert.AreEqual (24, le.GetByteCount (cp, 6), "#A4");
85 //Assert.AreEqual (24, le.GetByteCount (cp, 7), "#A5");
87 UTF32Encoding be = new UTF32Encoding (true, true);
88 Assert.AreEqual (12, be.GetByteCount (cp, 3), "#B1");
89 Assert.AreEqual (4, be.GetByteCount (cp, 1), "#B2");
90 Assert.AreEqual (0, be.GetByteCount (cp, 0), "#B3");
91 Assert.AreEqual (24, be.GetByteCount (cp, 6), "#B4");
92 //Assert.AreEqual (24, be.GetByteCount (cp, 7), "#B5");
96 [Test] // GetByteCount (Char *)
97 public unsafe void GetByteCount3_Chars_Null ()
99 UTF32Encoding enc = new UTF32Encoding ();
101 enc.GetByteCount ((char *) null, 1);
103 } catch (ArgumentNullException ex) {
104 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
105 Assert.IsNull (ex.InnerException, "#3");
106 Assert.IsNotNull (ex.Message, "#4");
107 Assert.AreEqual ("chars", ex.ParamName, "#5");
111 [Test] // GetByteCount (Char [], Int32, Int32)
112 public void GetByteCount4 ()
114 char [] chars = new char[] { 'z', 'a', '\u0306',
115 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
117 UTF32Encoding le = new UTF32Encoding (false, true);
118 Assert.AreEqual (12, le.GetByteCount (chars, 0, 3), "#A1");
119 Assert.AreEqual (16, le.GetByteCount (chars, 2, 4), "#A2");
120 Assert.AreEqual (4, le.GetByteCount (chars, 4, 1), "#A3");
121 Assert.AreEqual (4, le.GetByteCount (chars, 6, 1), "#A4");
122 Assert.AreEqual (0, le.GetByteCount (chars, 6, 0), "#A5");
123 Assert.AreEqual (24, le.GetByteCount (chars, 0, 6), "#A6");
124 //Assert.AreEqual (24, le.GetByteCount (chars, 0, 7), "#A7");
126 UTF32Encoding be = new UTF32Encoding (true, true);
127 Assert.AreEqual (12, be.GetByteCount (chars, 0, 3), "#B1");
128 Assert.AreEqual (16, be.GetByteCount (chars, 2, 4), "#B2");
129 Assert.AreEqual (4, be.GetByteCount (chars, 4, 1), "#B3");
130 Assert.AreEqual (4, be.GetByteCount (chars, 6, 1), "#B4");
131 Assert.AreEqual (0, be.GetByteCount (chars, 6, 0), "#B5");
132 Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B6");
133 //Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B7");
136 [Test] // GetByteCount (Char [], Int32, Int32)
137 public void GetByteCount4_Chars_Null ()
139 UTF32Encoding enc = new UTF32Encoding ();
141 enc.GetByteCount ((Char []) null, 0, 1);
143 } catch (ArgumentNullException ex) {
144 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
145 Assert.IsNull (ex.InnerException, "#3");
146 Assert.IsNotNull (ex.Message, "#4");
147 Assert.AreEqual ("chars", ex.ParamName, "#5");
151 [Test] // GetByteCount (Char [], Int32, Int32)
152 public void GetByteCount4_Count_Negative ()
154 char [] chars = new char[] { 'z', 'a', '\u0306',
155 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
157 UTF32Encoding enc = new UTF32Encoding ();
159 enc.GetByteCount (chars, 1, -1);
161 } catch (ArgumentOutOfRangeException ex) {
162 // Non-negative number required
163 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
164 Assert.IsNull (ex.InnerException, "#3");
165 Assert.IsNotNull (ex.Message, "#4");
166 Assert.AreEqual ("count", ex.ParamName, "#5");
170 [Test] // GetByteCount (Char [], Int32, Int32)
171 public void GetByteCount4_Count_Overflow ()
173 char [] chars = new char[] { 'z', 'a', '\u0306',
174 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
176 UTF32Encoding enc = new UTF32Encoding ();
178 enc.GetByteCount (chars, 6, 2);
180 } catch (ArgumentOutOfRangeException ex) {
181 // Index and count must refer to a location
183 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
184 Assert.IsNull (ex.InnerException, "#3");
185 Assert.IsNotNull (ex.Message, "#4");
186 //Assert.AreEqual ("chars", ex.ParamName, "#5");
190 [Test] // GetByteCount (Char [], Int32, Int32)
191 public void GetByteCount4_Index_Negative ()
193 char [] chars = new char[] { 'z', 'a', '\u0306',
194 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
196 UTF32Encoding enc = new UTF32Encoding ();
198 enc.GetByteCount (chars, -1, 1);
200 } catch (ArgumentOutOfRangeException ex) {
201 // Non-negative number required
202 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
203 Assert.IsNull (ex.InnerException, "#3");
204 Assert.IsNotNull (ex.Message, "#4");
205 Assert.AreEqual ("index", ex.ParamName, "#5");
209 [Test] // GetByteCount (Char [], Int32, Int32)
210 public void GetByteCount4_Index_Overflow ()
212 char [] chars = new char[] { 'z', 'a', '\u0306',
213 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
215 UTF32Encoding enc = new UTF32Encoding ();
217 enc.GetByteCount (chars, 7, 1);
219 } catch (ArgumentOutOfRangeException ex) {
220 // Index and count must refer to a location
222 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
223 Assert.IsNull (ex.InnerException, "#3");
224 Assert.IsNotNull (ex.Message, "#4");
225 //Assert.AreEqual ("chars", ex.ParamName, "#5");
230 public void GetPreamble ()
232 byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
233 Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
235 byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
236 Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
240 public void IsBrowserDisplay ()
242 UTF32Encoding le = new UTF32Encoding (false, true);
243 Assert.IsFalse (le.IsBrowserDisplay, "#1");
245 UTF32Encoding be = new UTF32Encoding (true, true);
246 Assert.IsFalse (be.IsBrowserDisplay, "#2");
250 public void IsBrowserSave ()
252 UTF32Encoding le = new UTF32Encoding (false, true);
253 Assert.IsFalse (le.IsBrowserSave);
255 UTF32Encoding be = new UTF32Encoding (true, true);
256 Assert.IsFalse (be.IsBrowserSave, "#2");
260 public void IsMailNewsDisplay ()
262 UTF32Encoding le = new UTF32Encoding (false, true);
263 Assert.IsFalse (le.IsMailNewsDisplay);
265 UTF32Encoding be = new UTF32Encoding (true, true);
266 Assert.IsFalse (be.IsMailNewsDisplay, "#2");
270 public void IsMailNewsSave ()
272 UTF32Encoding le = new UTF32Encoding (false, true);
273 Assert.IsFalse (le.IsMailNewsSave);
275 UTF32Encoding be = new UTF32Encoding (true, true);
276 Assert.IsFalse (be.IsMailNewsSave, "#2");