6 namespace MonoTests.System.Text
9 public class UTF32EncodingTest
11 [Test] // GetByteCount (Char [])
12 public void GetByteCount1 ()
14 char [] chars = new char[] { 'z', 'a', '\u0306',
15 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
17 UTF32Encoding le = new UTF32Encoding (false, true);
18 Assert.AreEqual (24, le.GetByteCount (chars), "#A1");
19 Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");
21 UTF32Encoding be = new UTF32Encoding (true, true);
22 Assert.AreEqual (24, be.GetByteCount (chars), "#B1");
23 Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
26 [Test] // GetByteCount (Char [])
27 public void GetByteCount1_Chars_Null ()
29 UTF32Encoding enc = new UTF32Encoding ();
31 enc.GetByteCount ((Char []) null);
33 } catch (ArgumentNullException ex) {
34 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
35 Assert.IsNull (ex.InnerException, "#3");
36 Assert.IsNotNull (ex.Message, "#4");
37 Assert.AreEqual ("chars", ex.ParamName, "#5");
41 [Test] // GetByteCount (String)
42 public void GetByteCount2 ()
44 string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
46 UTF32Encoding le = new UTF32Encoding (false, true);
47 Assert.AreEqual (24, le.GetByteCount (s), "#A1");
48 Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");
50 UTF32Encoding be = new UTF32Encoding (true, true);
51 Assert.AreEqual (24, be.GetByteCount (s), "#B1");
52 Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
55 [Test] // GetByteCount (String)
56 public void GetByteCount2_S_Null ()
58 UTF32Encoding enc = new UTF32Encoding ();
60 enc.GetByteCount ((string) null);
62 } catch (ArgumentNullException ex) {
63 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
64 Assert.IsNull (ex.InnerException, "#3");
65 Assert.IsNotNull (ex.Message, "#4");
66 Assert.AreEqual ("s", ex.ParamName, "#5");
70 [Test] // GetByteCount (Char *)
71 public unsafe void GetByteCount3 ()
73 char [] chars = new char[] { 'z', 'a', '\u0306',
74 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
76 fixed (char* cp = chars) {
77 UTF32Encoding le = new UTF32Encoding (false, true);
78 Assert.AreEqual (12, le.GetByteCount (cp, 3), "#A1");
79 Assert.AreEqual (4, le.GetByteCount (cp, 1), "#A2");
80 Assert.AreEqual (0, le.GetByteCount (cp, 0), "#A3");
81 Assert.AreEqual (24, le.GetByteCount (cp, 6), "#A4");
82 //Assert.AreEqual (24, le.GetByteCount (cp, 7), "#A5");
84 UTF32Encoding be = new UTF32Encoding (true, true);
85 Assert.AreEqual (12, be.GetByteCount (cp, 3), "#B1");
86 Assert.AreEqual (4, be.GetByteCount (cp, 1), "#B2");
87 Assert.AreEqual (0, be.GetByteCount (cp, 0), "#B3");
88 Assert.AreEqual (24, be.GetByteCount (cp, 6), "#B4");
89 //Assert.AreEqual (24, be.GetByteCount (cp, 7), "#B5");
93 [Test] // GetByteCount (Char *)
94 public unsafe void GetByteCount3_Chars_Null ()
96 UTF32Encoding enc = new UTF32Encoding ();
98 enc.GetByteCount ((char *) null, 1);
100 } catch (ArgumentNullException ex) {
101 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
102 Assert.IsNull (ex.InnerException, "#3");
103 Assert.IsNotNull (ex.Message, "#4");
104 Assert.AreEqual ("chars", ex.ParamName, "#5");
108 [Test] // GetByteCount (Char [], Int32, Int32)
109 public void GetByteCount4 ()
111 char [] chars = new char[] { 'z', 'a', '\u0306',
112 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
114 UTF32Encoding le = new UTF32Encoding (false, true);
115 Assert.AreEqual (12, le.GetByteCount (chars, 0, 3), "#A1");
116 Assert.AreEqual (16, le.GetByteCount (chars, 2, 4), "#A2");
117 Assert.AreEqual (4, le.GetByteCount (chars, 4, 1), "#A3");
118 Assert.AreEqual (4, le.GetByteCount (chars, 6, 1), "#A4");
119 Assert.AreEqual (0, le.GetByteCount (chars, 6, 0), "#A5");
120 Assert.AreEqual (24, le.GetByteCount (chars, 0, 6), "#A6");
121 //Assert.AreEqual (24, le.GetByteCount (chars, 0, 7), "#A7");
123 UTF32Encoding be = new UTF32Encoding (true, true);
124 Assert.AreEqual (12, be.GetByteCount (chars, 0, 3), "#B1");
125 Assert.AreEqual (16, be.GetByteCount (chars, 2, 4), "#B2");
126 Assert.AreEqual (4, be.GetByteCount (chars, 4, 1), "#B3");
127 Assert.AreEqual (4, be.GetByteCount (chars, 6, 1), "#B4");
128 Assert.AreEqual (0, be.GetByteCount (chars, 6, 0), "#B5");
129 Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B6");
130 //Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B7");
133 [Test] // GetByteCount (Char [], Int32, Int32)
134 public void GetByteCount4_Chars_Null ()
136 UTF32Encoding enc = new UTF32Encoding ();
138 enc.GetByteCount ((Char []) null, 0, 1);
140 } catch (ArgumentNullException ex) {
141 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
142 Assert.IsNull (ex.InnerException, "#3");
143 Assert.IsNotNull (ex.Message, "#4");
144 Assert.AreEqual ("chars", ex.ParamName, "#5");
148 [Test] // GetByteCount (Char [], Int32, Int32)
149 public void GetByteCount4_Count_Negative ()
151 char [] chars = new char[] { 'z', 'a', '\u0306',
152 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
154 UTF32Encoding enc = new UTF32Encoding ();
156 enc.GetByteCount (chars, 1, -1);
158 } catch (ArgumentOutOfRangeException ex) {
159 // Non-negative number required
160 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
161 Assert.IsNull (ex.InnerException, "#3");
162 Assert.IsNotNull (ex.Message, "#4");
163 Assert.AreEqual ("count", ex.ParamName, "#5");
167 [Test] // GetByteCount (Char [], Int32, Int32)
168 public void GetByteCount4_Count_Overflow ()
170 char [] chars = new char[] { 'z', 'a', '\u0306',
171 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
173 UTF32Encoding enc = new UTF32Encoding ();
175 enc.GetByteCount (chars, 6, 2);
177 } catch (ArgumentOutOfRangeException ex) {
178 // Index and count must refer to a location
180 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
181 Assert.IsNull (ex.InnerException, "#3");
182 Assert.IsNotNull (ex.Message, "#4");
183 //Assert.AreEqual ("chars", ex.ParamName, "#5");
187 [Test] // GetByteCount (Char [], Int32, Int32)
188 public void GetByteCount4_Index_Negative ()
190 char [] chars = new char[] { 'z', 'a', '\u0306',
191 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
193 UTF32Encoding enc = new UTF32Encoding ();
195 enc.GetByteCount (chars, -1, 1);
197 } catch (ArgumentOutOfRangeException ex) {
198 // Non-negative number required
199 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
200 Assert.IsNull (ex.InnerException, "#3");
201 Assert.IsNotNull (ex.Message, "#4");
202 Assert.AreEqual ("index", ex.ParamName, "#5");
206 [Test] // GetByteCount (Char [], Int32, Int32)
207 public void GetByteCount4_Index_Overflow ()
209 char [] chars = new char[] { 'z', 'a', '\u0306',
210 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
212 UTF32Encoding enc = new UTF32Encoding ();
214 enc.GetByteCount (chars, 7, 1);
216 } catch (ArgumentOutOfRangeException ex) {
217 // Index and count must refer to a location
219 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
220 Assert.IsNull (ex.InnerException, "#3");
221 Assert.IsNotNull (ex.Message, "#4");
222 //Assert.AreEqual ("chars", ex.ParamName, "#5");
227 public void GetPreamble ()
229 byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
230 Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
232 byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
233 Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
237 public void IsBrowserDisplay ()
239 UTF32Encoding le = new UTF32Encoding (false, true);
240 Assert.IsFalse (le.IsBrowserDisplay, "#1");
242 UTF32Encoding be = new UTF32Encoding (true, true);
243 Assert.IsFalse (be.IsBrowserDisplay, "#2");
247 public void IsBrowserSave ()
249 UTF32Encoding le = new UTF32Encoding (false, true);
250 Assert.IsFalse (le.IsBrowserSave);
252 UTF32Encoding be = new UTF32Encoding (true, true);
253 Assert.IsFalse (be.IsBrowserSave, "#2");
257 public void IsMailNewsDisplay ()
259 UTF32Encoding le = new UTF32Encoding (false, true);
260 Assert.IsFalse (le.IsMailNewsDisplay);
262 UTF32Encoding be = new UTF32Encoding (true, true);
263 Assert.IsFalse (be.IsMailNewsDisplay, "#2");
267 public void IsMailNewsSave ()
269 UTF32Encoding le = new UTF32Encoding (false, true);
270 Assert.IsFalse (le.IsMailNewsSave);
272 UTF32Encoding be = new UTF32Encoding (true, true);
273 Assert.IsFalse (be.IsMailNewsSave, "#2");