| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- #if NET_2_0
- using System;
- using System.Text;
- using NUnit.Framework;
- namespace MonoTests.System.Text
- {
- [TestFixture]
- public class UTF32EncodingTest
- {
- [Test] // GetByteCount (Char [])
- [Category ("NotDotNet")] // A1/B1 return 24 on MS
- public void GetByteCount1 ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.AreEqual (28, le.GetByteCount (chars), "#A1");
- Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.AreEqual (28, be.GetByteCount (chars), "#B1");
- Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
- }
- [Test] // GetByteCount (Char [])
- public void GetByteCount1_Chars_Null ()
- {
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount ((Char []) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("chars", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (String)
- [Category ("NotDotNet")] // A1/B1 return 24 on MS
- public void GetByteCount2 ()
- {
- string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.AreEqual (28, le.GetByteCount (s), "#A1");
- Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.AreEqual (28, be.GetByteCount (s), "#B1");
- Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
- }
- [Test] // GetByteCount (String)
- public void GetByteCount2_S_Null ()
- {
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount ((string) null);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("s", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char *)
- public unsafe void GetByteCount3 ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- fixed (char* cp = chars) {
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.AreEqual (12, le.GetByteCount (cp, 3), "#A1");
- Assert.AreEqual (4, le.GetByteCount (cp, 1), "#A2");
- Assert.AreEqual (0, le.GetByteCount (cp, 0), "#A3");
- Assert.AreEqual (24, le.GetByteCount (cp, 6), "#A4");
- //Assert.AreEqual (24, le.GetByteCount (cp, 7), "#A5");
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.AreEqual (12, be.GetByteCount (cp, 3), "#B1");
- Assert.AreEqual (4, be.GetByteCount (cp, 1), "#B2");
- Assert.AreEqual (0, be.GetByteCount (cp, 0), "#B3");
- Assert.AreEqual (24, be.GetByteCount (cp, 6), "#B4");
- //Assert.AreEqual (24, be.GetByteCount (cp, 7), "#B5");
- }
- }
- [Test] // GetByteCount (Char *)
- public unsafe void GetByteCount3_Chars_Null ()
- {
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount ((char *) null, 1);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("chars", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4 ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.AreEqual (12, le.GetByteCount (chars, 0, 3), "#A1");
- Assert.AreEqual (16, le.GetByteCount (chars, 2, 4), "#A2");
- Assert.AreEqual (4, le.GetByteCount (chars, 4, 1), "#A3");
- Assert.AreEqual (4, le.GetByteCount (chars, 6, 1), "#A4");
- Assert.AreEqual (0, le.GetByteCount (chars, 6, 0), "#A5");
- Assert.AreEqual (24, le.GetByteCount (chars, 0, 6), "#A6");
- //Assert.AreEqual (24, le.GetByteCount (chars, 0, 7), "#A7");
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.AreEqual (12, be.GetByteCount (chars, 0, 3), "#B1");
- Assert.AreEqual (16, be.GetByteCount (chars, 2, 4), "#B2");
- Assert.AreEqual (4, be.GetByteCount (chars, 4, 1), "#B3");
- Assert.AreEqual (4, be.GetByteCount (chars, 6, 1), "#B4");
- Assert.AreEqual (0, be.GetByteCount (chars, 6, 0), "#B5");
- Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B6");
- //Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B7");
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4_Chars_Null ()
- {
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount ((Char []) null, 0, 1);
- Assert.Fail ("#1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("chars", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4_Count_Negative ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount (chars, 1, -1);
- Assert.Fail ("#1");
- } catch (ArgumentOutOfRangeException ex) {
- // Non-negative number required
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("count", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4_Count_Overflow ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount (chars, 6, 2);
- Assert.Fail ("#1");
- } catch (ArgumentOutOfRangeException ex) {
- // Index and count must refer to a location
- // within the buffer
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- //Assert.AreEqual ("chars", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4_Index_Negative ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount (chars, -1, 1);
- Assert.Fail ("#1");
- } catch (ArgumentOutOfRangeException ex) {
- // Non-negative number required
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.AreEqual ("index", ex.ParamName, "#5");
- }
- }
- [Test] // GetByteCount (Char [], Int32, Int32)
- public void GetByteCount4_Index_Overflow ()
- {
- char [] chars = new char[] { 'z', 'a', '\u0306',
- '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
- UTF32Encoding enc = new UTF32Encoding ();
- try {
- enc.GetByteCount (chars, 7, 1);
- Assert.Fail ("#1");
- } catch (ArgumentOutOfRangeException ex) {
- // Index and count must refer to a location
- // within the buffer
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- //Assert.AreEqual ("chars", ex.ParamName, "#5");
- }
- }
- [Test]
- public void GetPreamble ()
- {
- byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
- Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
- byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
- Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
- }
- [Test]
- public void IsBrowserDisplay ()
- {
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.IsFalse (le.IsBrowserDisplay, "#1");
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.IsFalse (be.IsBrowserDisplay, "#2");
- }
- [Test]
- public void IsBrowserSave ()
- {
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.IsFalse (le.IsBrowserSave);
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.IsFalse (be.IsBrowserSave, "#2");
- }
- [Test]
- public void IsMailNewsDisplay ()
- {
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.IsFalse (le.IsMailNewsDisplay);
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.IsFalse (be.IsMailNewsDisplay, "#2");
- }
- [Test]
- public void IsMailNewsSave ()
- {
- UTF32Encoding le = new UTF32Encoding (false, true);
- Assert.IsFalse (le.IsMailNewsSave);
- UTF32Encoding be = new UTF32Encoding (true, true);
- Assert.IsFalse (be.IsMailNewsSave, "#2");
- }
- }
- }
- #endif
|