#332515.
* UTF32Encoding.cs: IsBrowserSave returns false for both Big-Endian and
Little-Endian.
* TestEncoding.cs: Also make class available on 1.0 profile.
* EncodingTest.cs: Added tests for Is* properties.
* UTF7EncodingTest.cs: Added tests for Is* properties.
* UnicodeEncodingTest.cs: Added tests for Is* properties. Fixed
line endings.
* UTF8EncodingTest.cs: Added tests for Is* properties. Spaces to
tabs. Numbered tests.
* ASCIIEncodingTest.cs: Added tests for Is* properties. No longer
derive from TestCase class. Spaces to tabs.
* UTF32EncodingTest.cs: Added tests for Is* properties. No longer
derive from deprecated Assertion class.
svn path=/trunk/mcs/; revision=87593
body_name = "utf-32BE";
encoding_name = "UTF-32 (Big-Endian)";
header_name = "utf-32BE";
- is_browser_save = false;
web_name = "utf-32BE";
} else {
body_name = "utf-32";
encoding_name = "UTF-32";
header_name = "utf-32";
- is_browser_save = true;
web_name = "utf-32";
}
is_browser_save = true;
is_browser_display = true;
is_mail_news_display = true;
+ is_mail_news_save = true;
windows_code_page = UnicodeEncoding.UNICODE_CODE_PAGE;
}
//
// <c> 2002 Mike Kestner
-using NUnit.Framework;
-using System.Text;
using System;
+using System.Text;
+using NUnit.Framework;
-namespace MonoTests.System.Text {
-
- public class ASCIIEncodingTest : TestCase {
-
+namespace MonoTests.System.Text
+{
+ public class ASCIIEncodingTest
+ {
private char[] testchars;
private byte[] testbytes;
- protected override void SetUp ()
+ [SetUp]
+ public void SetUp ()
{
testchars = new char[4];
testchars[0] = 'T';
testbytes[3] = (byte) 't';
}
- // Test GetBytes(char[])
+ [Test]
+ public void IsBrowserDisplay ()
+ {
+ Assert.IsFalse (Encoding.ASCII.IsBrowserDisplay);
+ }
+
+ [Test]
+ public void IsBrowserSave ()
+ {
+ Assert.IsFalse (Encoding.ASCII.IsBrowserSave);
+ }
+
+ [Test]
+ public void IsMailNewsDisplay ()
+ {
+ Assert.IsFalse (Encoding.ASCII.IsMailNewsDisplay);
+ }
+
+ [Test]
+ public void IsMailNewsSave ()
+ {
+ Assert.IsFalse (Encoding.ASCII.IsMailNewsSave);
+ }
+
+ [Test] // Test GetBytes(char[])
public void TestGetBytes1 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = ascii_encoding.GetBytes(testchars);
for (int i = 0; i < testchars.Length; i++)
- AssertEquals (testchars[i], (char) bytes[i]);
- }
+ Assert.AreEqual (testchars[i], (char) bytes[i]);
+ }
- // Test GetBytes(char[], int, int)
+ [Test] // Test GetBytes(char[], int, int)
public void TestGetBytes2 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = ascii_encoding.GetBytes(testchars, 1, 1);
- AssertEquals (1, bytes.Length);
- AssertEquals (testchars[1], (char) bytes[0]);
- }
+ Assert.AreEqual (1, bytes.Length, "#1");
+ Assert.AreEqual (testchars [1], (char) bytes [0], "#2");
+ }
- // Test non-ASCII char in char[]
+ [Test] // Test non-ASCII char in char[]
public void TestGetBytes3 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
testchars[2] = (char) 0x80;
byte[] bytes = ascii_encoding.GetBytes(testchars);
- AssertEquals ('T', (char) bytes[0]);
- AssertEquals ('e', (char) bytes[1]);
- AssertEquals ('?', (char) bytes[2]);
- AssertEquals ('t', (char) bytes[3]);
- }
+ Assert.AreEqual ('T', (char) bytes [0], "#1");
+ Assert.AreEqual ('e', (char) bytes [1], "#2");
+ Assert.AreEqual ('?', (char) bytes [2], "#3");
+ Assert.AreEqual ('t', (char) bytes [3], "#4");
+ }
- // Test GetBytes(char[], int, int, byte[], int)
+ [Test] // Test GetBytes(char[], int, int, byte[], int)
public void TestGetBytes4 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = new Byte[1];
int cnt = ascii_encoding.GetBytes(testchars, 1, 1, bytes, 0);
- AssertEquals (1, cnt);
- AssertEquals (testchars[1], (char) bytes[0]);
- }
+ Assert.AreEqual (1, cnt, "#1");
+ Assert.AreEqual (testchars [1], (char) bytes [0], "#2");
+ }
- // Test GetBytes(string, int, int, byte[], int)
+ [Test] // Test GetBytes(string, int, int, byte[], int)
public void TestGetBytes5 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = new Byte[1];
int cnt = ascii_encoding.GetBytes("Test", 1, 1, bytes, 0);
- AssertEquals ('e', (char) bytes[0]);
- }
+ Assert.AreEqual ('e', (char) bytes [0], "#1");
+ }
- // Test GetBytes(string)
+ [Test] // Test GetBytes(string)
public void TestGetBytes6 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = ascii_encoding.GetBytes("Test");
for (int i = 0; i < testchars.Length; i++)
- AssertEquals (testchars[i], (char) bytes[i]);
- }
+ Assert.AreEqual (testchars [i], (char) bytes [i]);
+ }
- // Test GetChars(byte[])
+ [Test] // Test GetChars(byte[])
public void TestGetChars1 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
char[] chars = ascii_encoding.GetChars(testbytes);
for (int i = 0; i < testbytes.Length; i++)
- AssertEquals (testbytes[i], (byte) chars[i]);
- }
+ Assert.AreEqual (testbytes[i], (byte) chars[i]);
+ }
- // Test GetChars(byte[], int, int)
+ [Test] // Test GetChars(byte[], int, int)
public void TestGetChars2 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
char[] chars = ascii_encoding.GetChars(testbytes, 1, 1);
- AssertEquals (1, chars.Length);
- AssertEquals (testbytes[1], (byte) chars[0]);
- }
+ Assert.AreEqual (1, chars.Length, "#1");
+ Assert.AreEqual (testbytes [1], (byte) chars [0], "#2");
+ }
- // Test non-ASCII char in byte[]
+ [Test] // Test non-ASCII char in byte[]
public void TestGetChars3 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
testbytes[2] = 0x80;
char[] chars = ascii_encoding.GetChars(testbytes);
- AssertEquals ('T', chars[0]);
- AssertEquals ('e', chars[1]);
- AssertEquals ('?', chars[2]);
- AssertEquals ('t', chars[3]);
- }
+ Assert.AreEqual ('T', chars [0], "#1");
+ Assert.AreEqual ('e', chars [1], "#2");
+ Assert.AreEqual ('?', chars [2], "#3");
+ Assert.AreEqual ('t', chars [3], "#4");
+ }
- // Test GetChars(byte[], int, int, char[], int)
+ [Test] // Test GetChars(byte[], int, int, char[], int)
public void TestGetChars4 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
char[] chars = new char[1];
int cnt = ascii_encoding.GetChars(testbytes, 1, 1, chars, 0);
- AssertEquals (1, cnt);
- AssertEquals (testbytes[1], (byte) chars[0]);
- }
+ Assert.AreEqual (1, cnt, "#1");
+ Assert.AreEqual (testbytes [1], (byte) chars [0], "#2");
+ }
- // Test GetString(char[])
+ [Test] // Test GetString(char[])
public void TestGetString1 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
string str = ascii_encoding.GetString(testbytes);
- AssertEquals ("Test", str);
- }
+ Assert.AreEqual ("Test", str);
+ }
- // Test GetString(char[], int, int)
+ [Test] // Test GetString(char[], int, int)
public void TestGetString2 ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
string str = ascii_encoding.GetString(testbytes, 1, 2);
- AssertEquals ("es", str);
- }
+ Assert.AreEqual ("es", str);
+ }
- // Test invalid byte handling
+ [Test] // Test invalid byte handling
public void TestGetString3 ()
{
Encoding encoding = Encoding.ASCII;
byte [] bytes = new byte [] {0x61, 0xE1, 0xE2};
string s = encoding.GetString (bytes, 0, 3);
#if NET_2_0
- AssertEquals ("a??", s);
+ Assert.AreEqual ("a??", s);
#else
- AssertEquals ("aab", s);
+ Assert.AreEqual ("aab", s);
#endif
}
- // Test Decoder
+ [Test] // Test Decoder
public void TestDecoder ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
char[] chars = new char[1];
int cnt = ascii_encoding.GetDecoder().GetChars(testbytes, 1, 1, chars, 0);
- AssertEquals (1, cnt);
- AssertEquals (testbytes[1], (byte) chars[0]);
+ Assert.AreEqual (1, cnt, "#1");
+ Assert.AreEqual (testbytes [1], (byte) chars [0], "#2");
}
- // Test Decoder
+ [Test] // Test Decoder
public void TestEncoder ()
{
- Encoding ascii_encoding = Encoding.ASCII;
+ Encoding ascii_encoding = Encoding.ASCII;
byte[] bytes = new Byte[1];
int cnt = ascii_encoding.GetEncoder().GetBytes(testchars, 1, 1, bytes, 0, false);
- AssertEquals (1, cnt);
- AssertEquals (testchars[1], (char) bytes[0]);
+ Assert.AreEqual (1, cnt, "#1");
+ Assert.AreEqual (testchars [1], (char) bytes [0], "#2");
}
+ [Test]
public void TestZero ()
{
Encoding encoding = Encoding.ASCII;
- AssertEquals ("#01", encoding.GetString (new byte [0]), "");
- AssertEquals ("#02", encoding.GetString (new byte [0], 0, 0), "");
+ Assert.AreEqual (string.Empty, encoding.GetString (new byte [0]), "#1");
+ Assert.AreEqual (string.Empty, encoding.GetString (new byte [0], 0, 0), "#2");
}
#if NET_2_0
}
#endif
}
-
}
+2007-10-16 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * TestEncoding.cs: Also make class available on 1.0 profile.
+ * EncodingTest.cs: Added tests for Is* properties.
+ * UTF7EncodingTest.cs: Added tests for Is* properties.
+ * UnicodeEncodingTest.cs: Added tests for Is* properties. Fixed
+ line endings.
+ * UTF8EncodingTest.cs: Added tests for Is* properties. Spaces to
+ tabs. Numbered tests.
+ * ASCIIEncodingTest.cs: Added tests for Is* properties. No longer
+ derive from TestCase class. Spaces to tabs.
+ * UTF32EncodingTest.cs: Added tests for Is* properties. No longer
+ derive from deprecated Assertion class.
+
2007-07-06 Gert Driesen <drieseng@users.sourceforge.net>
* DecoderReplacementFallbackTest.cs: Fixed DontChangeReadOnlyCodePage-
[TestFixture]
public class EncodingTest
{
+ [Test]
+ [Category ("NotWorking")]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void IsBrowserDisplay ()
+ {
+ MyEncoding enc = new MyEncoding ();
+ Assert.IsFalse (enc.IsBrowserDisplay);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void IsBrowserSave ()
+ {
+ MyEncoding enc = new MyEncoding ();
+ Assert.IsFalse (enc.IsBrowserSave);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void IsMailNewsDisplay ()
+ {
+ MyEncoding enc = new MyEncoding ();
+ Assert.IsFalse (enc.IsMailNewsDisplay);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ [ExpectedException (typeof (NotSupportedException))]
+ public void IsMailNewsSave ()
+ {
+ MyEncoding enc = new MyEncoding ();
+ Assert.IsFalse (enc.IsMailNewsSave);
+ }
+
[Test]
public void GetEncoding_CodePage_Default ()
{
// Used for testing custom encoding.
//
-#if NET_2_0
-
using System;
using System.IO;
using System.Text;
+
using NUnit.Framework;
namespace MonoTests.System.Text
}
}
}
-
-#endif
-
-using NUnit.Framework;
+#if NET_2_0
using System;
using System.Text;
-#if NET_2_0
-
-namespace MonoTests.System.Text {
+using NUnit.Framework;
+namespace MonoTests.System.Text
+{
[TestFixture]
- public class UTF32EncodingTest : Assertion {
+ public class UTF32EncodingTest
+ {
+ [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");
+ }
[Test]
public void TestGetPreamble() {
byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
- if (!AreEqual(lePreamble, new byte[]{ 0xff, 0xfe, 0, 0 })) {
- Fail ("Little-endian UTF32 preamble is incorrect");
- }
+ Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
- if (!AreEqual(bePreamble, new byte[]{ 0, 0, 0xfe, 0xff })) {
- Fail ("Big-endian UTF32 preamble is incorrect");
- }
- }
-
- private bool AreEqual(byte[] a, byte[] b) {
- if (a.Length != b.Length)
- return false;
- for (int i = 0; i < a.Length; ++i) {
- if (a[i] != b[i])
- return false;
- }
- return true;
+ Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
}
}
}
-
#endif
-
[TestFixture]
public class UTF7EncodingTest : Assertion
{
+ [Test]
+ public void IsBrowserDisplay ()
+ {
+ UTF7Encoding utf7 = new UTF7Encoding ();
+ Assert (!utf7.IsBrowserDisplay);
+ }
+
+ [Test]
+ public void IsBrowserSave ()
+ {
+ UTF7Encoding utf7 = new UTF7Encoding ();
+ Assert (!utf7.IsBrowserSave);
+ }
+
+ [Test]
+ public void IsMailNewsDisplay ()
+ {
+ UTF7Encoding utf7 = new UTF7Encoding ();
+ Assert (utf7.IsMailNewsDisplay);
+ }
+
+ [Test]
+ public void IsMailNewsSave ()
+ {
+ UTF7Encoding utf7 = new UTF7Encoding ();
+ Assert (utf7.IsMailNewsSave);
+ }
+
[Test]
public void TestDirectlyEncoded1()
{
using AssertType = NUnit.Framework.Assert;
-namespace MonoTests.System.Text {
-
+namespace MonoTests.System.Text
+{
[TestFixture]
- public class UTF8EncodingTest : Assertion {
-
+ public class UTF8EncodingTest : Assertion
+ {
private UTF8Encoding utf8;
[SetUp]
utf8 = new UTF8Encoding (true, true);
}
- [Test]
- public void TestEncodingGetBytes1()
- {
- UTF8Encoding utf8Enc = new UTF8Encoding ();
- string UniCode = "\u0041\u2262\u0391\u002E";
-
- // "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E
- // see (RFC 2044)
- byte[] utf8Bytes = utf8Enc.GetBytes (UniCode);
-
- Assertion.AssertEquals ("UTF #1", 0x41, utf8Bytes [0]);
- Assertion.AssertEquals ("UTF #2", 0xE2, utf8Bytes [1]);
- Assertion.AssertEquals ("UTF #3", 0x89, utf8Bytes [2]);
- Assertion.AssertEquals ("UTF #4", 0xA2, utf8Bytes [3]);
- Assertion.AssertEquals ("UTF #5", 0xCE, utf8Bytes [4]);
- Assertion.AssertEquals ("UTF #6", 0x91, utf8Bytes [5]);
- Assertion.AssertEquals ("UTF #7", 0x2E, utf8Bytes [6]);
- }
-
- [Test]
- public void TestEncodingGetBytes2()
- {
- UTF8Encoding utf8Enc = new UTF8Encoding ();
- string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";
-
- // "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21
- // see (RFC 2044)
- byte[] utf8Bytes = new byte [11];
-
- int ByteCnt = utf8Enc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, utf8Bytes, 0);
-
- Assertion.AssertEquals ("UTF #1", 11, ByteCnt);
- Assertion.AssertEquals ("UTF #2", 0x48, utf8Bytes [0]);
- Assertion.AssertEquals ("UTF #3", 0x69, utf8Bytes [1]);
- Assertion.AssertEquals ("UTF #4", 0x20, utf8Bytes [2]);
- Assertion.AssertEquals ("UTF #5", 0x4D, utf8Bytes [3]);
- Assertion.AssertEquals ("UTF #6", 0x6F, utf8Bytes [4]);
- Assertion.AssertEquals ("UTF #7", 0x6D, utf8Bytes [5]);
- Assertion.AssertEquals ("UTF #8", 0x20, utf8Bytes [6]);
- Assertion.AssertEquals ("UTF #9", 0xE2, utf8Bytes [7]);
- Assertion.AssertEquals ("UTF #10", 0x98, utf8Bytes [8]);
- Assertion.AssertEquals ("UTF #11", 0xBA, utf8Bytes [9]);
- Assertion.AssertEquals ("UTF #12", 0x21, utf8Bytes [10]);
- }
-
- [Test]
- public void TestDecodingGetChars1()
- {
- UTF8Encoding utf8Enc = new UTF8Encoding ();
- // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>."
- // see (RFC 2044)
- byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
- char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
-
- Assertion.AssertEquals ("UTF #1", 0x0041, UniCodeChars [0]);
- Assertion.AssertEquals ("UTF #2", 0x2262, UniCodeChars [1]);
- Assertion.AssertEquals ("UTF #3", 0x0391, UniCodeChars [2]);
- Assertion.AssertEquals ("UTF #4", 0x002E, UniCodeChars [3]);
- }
-
- [Test]
+ [Test]
+ public void IsBrowserDisplay ()
+ {
+ Assert (utf8.IsBrowserDisplay);
+ }
+
+ [Test]
+ public void IsBrowserSave ()
+ {
+ Assert (utf8.IsBrowserSave);
+ }
+
+ [Test]
+ public void IsMailNewsDisplay ()
+ {
+ Assert (utf8.IsMailNewsDisplay);
+ }
+
+ [Test]
+ public void IsMailNewsSave ()
+ {
+ Assert (utf8.IsMailNewsSave);
+ }
+
+ [Test]
+ public void TestEncodingGetBytes1()
+ {
+ UTF8Encoding utf8Enc = new UTF8Encoding ();
+ string UniCode = "\u0041\u2262\u0391\u002E";
+
+ // "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E
+ // see (RFC 2044)
+ byte[] utf8Bytes = utf8Enc.GetBytes (UniCode);
+
+ Assertion.AssertEquals ("UTF #1", 0x41, utf8Bytes [0]);
+ Assertion.AssertEquals ("UTF #2", 0xE2, utf8Bytes [1]);
+ Assertion.AssertEquals ("UTF #3", 0x89, utf8Bytes [2]);
+ Assertion.AssertEquals ("UTF #4", 0xA2, utf8Bytes [3]);
+ Assertion.AssertEquals ("UTF #5", 0xCE, utf8Bytes [4]);
+ Assertion.AssertEquals ("UTF #6", 0x91, utf8Bytes [5]);
+ Assertion.AssertEquals ("UTF #7", 0x2E, utf8Bytes [6]);
+ }
+
+ [Test]
+ public void TestEncodingGetBytes2()
+ {
+ UTF8Encoding utf8Enc = new UTF8Encoding ();
+ string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";
+
+ // "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21
+ // see (RFC 2044)
+ byte[] utf8Bytes = new byte [11];
+
+ int ByteCnt = utf8Enc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, utf8Bytes, 0);
+ Assertion.AssertEquals ("UTF #1", 11, ByteCnt);
+ Assertion.AssertEquals ("UTF #2", 0x48, utf8Bytes [0]);
+ Assertion.AssertEquals ("UTF #3", 0x69, utf8Bytes [1]);
+ Assertion.AssertEquals ("UTF #4", 0x20, utf8Bytes [2]);
+ Assertion.AssertEquals ("UTF #5", 0x4D, utf8Bytes [3]);
+ Assertion.AssertEquals ("UTF #6", 0x6F, utf8Bytes [4]);
+ Assertion.AssertEquals ("UTF #7", 0x6D, utf8Bytes [5]);
+ Assertion.AssertEquals ("UTF #8", 0x20, utf8Bytes [6]);
+ Assertion.AssertEquals ("UTF #9", 0xE2, utf8Bytes [7]);
+ Assertion.AssertEquals ("UTF #10", 0x98, utf8Bytes [8]);
+ Assertion.AssertEquals ("UTF #11", 0xBA, utf8Bytes [9]);
+ Assertion.AssertEquals ("UTF #12", 0x21, utf8Bytes [10]);
+ }
+
+ [Test]
+ public void TestDecodingGetChars1()
+ {
+ UTF8Encoding utf8Enc = new UTF8Encoding ();
+ // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>."
+ // see (RFC 2044)
+ byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
+ char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
+
+ Assertion.AssertEquals ("UTF #1", 0x0041, UniCodeChars [0]);
+ Assertion.AssertEquals ("UTF #2", 0x2262, UniCodeChars [1]);
+ Assertion.AssertEquals ("UTF #3", 0x0391, UniCodeChars [2]);
+ Assertion.AssertEquals ("UTF #4", 0x002E, UniCodeChars [3]);
+ }
+
+ [Test]
#if NET_2_0
- [Category ("NotWorking")]
+ [Category ("NotWorking")]
#endif
- public void TestMaxCharCount()
- {
- UTF8Encoding UTF8enc = new UTF8Encoding ();
+ public void TestMaxCharCount()
+ {
+ UTF8Encoding UTF8enc = new UTF8Encoding ();
#if NET_2_0
- // hmm, where is this extra 1 coming from?
- Assertion.AssertEquals ("UTF #1", 51, UTF8enc.GetMaxCharCount(50));
+ // hmm, where is this extra 1 coming from?
+ Assertion.AssertEquals ("UTF #1", 51, UTF8enc.GetMaxCharCount(50));
#else
- Assertion.AssertEquals ("UTF #1", 50, UTF8enc.GetMaxCharCount(50));
+ Assertion.AssertEquals ("UTF #1", 50, UTF8enc.GetMaxCharCount(50));
#endif
- }
-
- [Test]
+ }
+
+ [Test]
#if NET_2_0
- [Category ("NotWorking")]
+ [Category ("NotWorking")]
#endif
- public void TestMaxByteCount()
- {
- UTF8Encoding UTF8enc = new UTF8Encoding ();
+ public void TestMaxByteCount()
+ {
+ UTF8Encoding UTF8enc = new UTF8Encoding ();
#if NET_2_0
- // maybe under .NET 2.0 insufficient surrogate pair is just not handled, and 3 is Preamble size.
- Assertion.AssertEquals ("UTF #1", 153, UTF8enc.GetMaxByteCount(50));
+ // maybe under .NET 2.0 insufficient surrogate pair is
+ // just not handled, and 3 is Preamble size.
+ Assertion.AssertEquals ("UTF #1", 153, UTF8enc.GetMaxByteCount(50));
#else
- Assertion.AssertEquals ("UTF #1", 200, UTF8enc.GetMaxByteCount(50));
+ Assertion.AssertEquals ("UTF #1", 200, UTF8enc.GetMaxByteCount(50));
#endif
- }
+ }
// regression for bug #59648
[Test]
byte[] data = new byte [] { 0xC0, 0xAF };
string s = u.GetString (data);
- AssertEquals (0, s.Length);
+ AssertEquals ("#A1", 0, s.Length);
data = new byte [] { 0x30, 0x31, 0xC0, 0xAF, 0x30, 0x32 };
s = u.GetString (data);
- AssertEquals (4, s.Length);
- AssertEquals (0x30, (int) s [0]);
- AssertEquals (0x31, (int) s [1]);
- AssertEquals (0x30, (int) s [2]);
- AssertEquals (0x32, (int) s [3]);
+ AssertEquals ("#B1", 4, s.Length);
+ AssertEquals ("#B2", 0x30, (int) s [0]);
+ AssertEquals ("#B3", 0x31, (int) s [1]);
+ AssertEquals ("#B4", 0x30, (int) s [2]);
+ AssertEquals ("#B5", 0x32, (int) s [3]);
}
// UTF8 decoding tests from http://www.cl.cam.ac.uk/~mgk25/
}
[Test]
-// MS Fx 1.1 accept this
+ // MS Fx 1.1 accept this
// [ExpectedException (typeof (DecoderException))]
public void T3_Malformed_3_LastContinuationMissing_337 ()
{
-//\r
-// UnicodeEncodingTest.cs - NUnit Test Cases for System.Text.UnicodeEncoding\r
-//\r
-// Author:\r
-// Patrick Kalkman kalkman@cistron.nl\r
-//\r
-// (C) 2003 Patrick Kalkman\r
-// \r
-using NUnit.Framework;\r
-using System;\r
-using System.Text;\r
-\r
-namespace MonoTests.System.Text\r
-{\r
- [TestFixture]\r
- public class UnicodeEncodingTest \r
- {\r
- [Test]\r
- public void TestEncodingGetBytes1()\r
- {\r
- //pi and sigma in unicode\r
- string Unicode = "\u03a0\u03a3";\r
- byte[] UniBytes;\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian\r
- UniBytes = UnicodeEnc.GetBytes (Unicode);\r
- \r
- Assertion.AssertEquals ("Uni #1", 0xA0, UniBytes [0]);\r
- Assertion.AssertEquals ("Uni #2", 0x03, UniBytes [1]);\r
- Assertion.AssertEquals ("Uni #3", 0xA3, UniBytes [2]);\r
- Assertion.AssertEquals ("Uni #4", 0x03, UniBytes [3]);\r
- }\r
- \r
- [Test]\r
- public void TestEncodingGetBytes2()\r
- {\r
- //pi and sigma in unicode\r
- string Unicode = "\u03a0\u03a3";\r
- byte[] UniBytes;\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian\r
- UniBytes = UnicodeEnc.GetBytes (Unicode);\r
- \r
- Assertion.AssertEquals ("Uni #1", 0x03, UniBytes [0]);\r
- Assertion.AssertEquals ("Uni #2", 0xA0, UniBytes [1]);\r
- Assertion.AssertEquals ("Uni #3", 0x03, UniBytes [2]);\r
- Assertion.AssertEquals ("Uni #4", 0xA3, UniBytes [3]);\r
- }\r
-\r
- [Test]\r
- public void TestEncodingGetBytes3()\r
- {\r
- //pi and sigma in unicode\r
- string Unicode = "\u03a0\u03a3";\r
- byte[] UniBytes = new byte [4];\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian \r
- int Cnt = UnicodeEnc.GetBytes (Unicode.ToCharArray(), 0, Unicode.Length, UniBytes, 0);\r
- \r
- Assertion.AssertEquals ("Uni #1", 4, Cnt);\r
- Assertion.AssertEquals ("Uni #2", 0xA0, UniBytes [0]);\r
- Assertion.AssertEquals ("Uni #3", 0x03, UniBytes [1]);\r
- Assertion.AssertEquals ("Uni #4", 0xA3, UniBytes [2]);\r
- Assertion.AssertEquals ("Uni #5", 0x03, UniBytes [3]);\r
- }\r
- \r
- [Test]\r
- public void TestEncodingDecodingGetBytes1()\r
- {\r
- //pi and sigma in unicode\r
- string Unicode = "\u03a0\u03a3";\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian \r
- //Encode the unicode string.\r
- byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);\r
- //Decode the bytes to a unicode char array.\r
- char[] UniChars = UnicodeEnc.GetChars (UniBytes);\r
- string Result = new string(UniChars);\r
- \r
- Assertion.AssertEquals ("Uni #1", Unicode, Result);\r
- }\r
-\r
- [Test]\r
- public void TestEncodingDecodingGetBytes2()\r
- {\r
- //pi and sigma in unicode\r
- string Unicode = "\u03a0\u03a3";\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian \r
- //Encode the unicode string.\r
- byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);\r
- //Decode the bytes to a unicode char array.\r
- char[] UniChars = UnicodeEnc.GetChars (UniBytes);\r
- string Result = new string(UniChars);\r
- \r
- Assertion.AssertEquals ("Uni #1", Unicode, Result);\r
- }\r
-\r
- [Test]\r
- public void TestEncodingGetCharCount ()\r
- {\r
- byte[] b = new byte[] {255, 254, 115, 0, 104, 0, 105, 0};\r
- UnicodeEncoding encoding = new UnicodeEncoding ();\r
-\r
- Assertion.AssertEquals ("GetCharCount #1", 3,\r
- encoding.GetCharCount (b, 2, b.Length - 2));\r
- }\r
-\r
- \r
- \r
- [Test]\r
- public void TestPreamble1()\r
- {\r
- //litle-endian with byte order mark.\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, true); \r
- byte[] PreAmble = UnicodeEnc.GetPreamble();\r
-\r
- Assertion.AssertEquals ("Uni #1", 0xFF, PreAmble [0]);\r
- Assertion.AssertEquals ("Uni #2", 0xFE, PreAmble [1]);\r
- }\r
-\r
- [Test]\r
- public void TestPreamble2()\r
- {\r
- //big-endian with byte order mark.\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); \r
- byte[] PreAmble = UnicodeEnc.GetPreamble();\r
-\r
- Assertion.AssertEquals ("Uni #1", 0xFE, PreAmble [0]);\r
- Assertion.AssertEquals ("Uni #2", 0xFF, PreAmble [1]);\r
- }\r
-\r
- [Test]\r
- public void TestPreamble3()\r
- {\r
- //little-endian without byte order mark.\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, false); \r
- byte[] PreAmble = UnicodeEnc.GetPreamble();\r
-\r
- Assertion.AssertEquals ("Uni #1", 0, PreAmble.Length);\r
- }\r
- \r
- [Test]\r
-#if NET_2_0\r
- [Category ("NotWorking")]\r
-#endif\r
- public void TestMaxCharCount()\r
- {\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding ();\r
-#if NET_2_0\r
- // where is this extra 1 coming from?\r
- Assertion.AssertEquals ("UTF #1", 25, UnicodeEnc.GetMaxCharCount(51));\r
-#else\r
- Assertion.AssertEquals ("UTF #1", 25, UnicodeEnc.GetMaxCharCount(50));\r
-#endif\r
- }\r
- \r
- [Test]\r
-#if NET_2_0\r
- [Category ("NotWorking")]\r
-#endif\r
- public void TestMaxByteCount()\r
- {\r
- UnicodeEncoding UnicodeEnc = new UnicodeEncoding ();\r
-#if NET_2_0\r
- // is this extra 2 BOM?\r
- Assertion.AssertEquals ("UTF #1", 102, UnicodeEnc.GetMaxByteCount(50));\r
-#else\r
- Assertion.AssertEquals ("UTF #1", 100, UnicodeEnc.GetMaxByteCount(50));\r
-#endif\r
- }\r
-\r
- [Test]\r
- public void ZeroLengthArrays ()\r
- {\r
- UnicodeEncoding encoding = new UnicodeEncoding ();\r
- encoding.GetCharCount (new byte [0]);\r
- encoding.GetChars (new byte [0]);\r
- encoding.GetCharCount (new byte [0], 0, 0);\r
- encoding.GetChars (new byte [0], 0, 0);\r
- encoding.GetChars (new byte [0], 0, 0, new char [0], 0);\r
- encoding.GetByteCount (new char [0]);\r
- encoding.GetBytes (new char [0]);\r
- encoding.GetByteCount (new char [0], 0, 0);\r
- encoding.GetBytes (new char [0], 0, 0);\r
- encoding.GetBytes (new char [0], 0, 0, new byte [0], 0);\r
- encoding.GetByteCount ("");\r
- encoding.GetBytes ("");\r
- }\r
-\r
- [Test]\r
- public void ByteOrderMark ()\r
- {\r
- string littleEndianString = "\ufeff\u0042\u004f\u004d";\r
- string bigEndianString = "\ufffe\u4200\u4f00\u4d00";\r
- byte [] littleEndianBytes = new byte [] {0xff, 0xfe, 0x42, 0x00, 0x4f, 0x00, 0x4d, 0x00};\r
- byte [] bigEndianBytes = new byte [] {0xfe, 0xff, 0x00, 0x42, 0x00, 0x4f, 0x00, 0x4d};\r
- UnicodeEncoding encoding;\r
- \r
- encoding = new UnicodeEncoding (false, true);\r
- Assertion.AssertEquals ("BOM #1", encoding.GetBytes (littleEndianString), littleEndianBytes);\r
- Assertion.AssertEquals ("BOM #2", encoding.GetBytes (bigEndianString), bigEndianBytes);\r
- Assertion.AssertEquals ("BOM #3", encoding.GetString (littleEndianBytes), littleEndianString);\r
- Assertion.AssertEquals ("BOM #4", encoding.GetString (bigEndianBytes), bigEndianString);\r
-\r
- encoding = new UnicodeEncoding (true, true);\r
- Assertion.AssertEquals ("BOM #5", encoding.GetBytes (littleEndianString), bigEndianBytes);\r
- Assertion.AssertEquals ("BOM #6", encoding.GetBytes (bigEndianString), littleEndianBytes);\r
- Assertion.AssertEquals ("BOM #7", encoding.GetString (littleEndianBytes), bigEndianString);\r
- Assertion.AssertEquals ("BOM #8", encoding.GetString (bigEndianBytes), littleEndianString);\r
- }\r
- }\r
-}\r
+//
+// UnicodeEncodingTest.cs - NUnit Test Cases for System.Text.UnicodeEncoding
+//
+// Author:
+// Patrick Kalkman kalkman@cistron.nl
+//
+// (C) 2003 Patrick Kalkman
+//
+using NUnit.Framework;
+using System;
+using System.Text;
+
+namespace MonoTests.System.Text
+{
+ [TestFixture]
+ public class UnicodeEncodingTest
+ {
+ [Test]
+ public void IsBrowserDisplay ()
+ {
+ UnicodeEncoding enc = new UnicodeEncoding ();
+ Assert.IsFalse (enc.IsBrowserDisplay);
+ }
+
+ [Test]
+ public void IsBrowserSave ()
+ {
+ UnicodeEncoding enc = new UnicodeEncoding ();
+ Assert.IsTrue (enc.IsBrowserSave);
+ }
+
+ [Test]
+ public void IsMailNewsDisplay ()
+ {
+ UnicodeEncoding enc = new UnicodeEncoding ();
+ Assert.IsFalse (enc.IsMailNewsDisplay);
+ }
+
+ [Test]
+ public void IsMailNewsSave ()
+ {
+ UnicodeEncoding enc = new UnicodeEncoding ();
+ Assert.IsFalse (enc.IsMailNewsSave);
+ }
+
+ [Test]
+ public void TestEncodingGetBytes1()
+ {
+ //pi and sigma in unicode
+ string Unicode = "\u03a0\u03a3";
+ byte[] UniBytes;
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian
+ UniBytes = UnicodeEnc.GetBytes (Unicode);
+
+ Assertion.AssertEquals ("Uni #1", 0xA0, UniBytes [0]);
+ Assertion.AssertEquals ("Uni #2", 0x03, UniBytes [1]);
+ Assertion.AssertEquals ("Uni #3", 0xA3, UniBytes [2]);
+ Assertion.AssertEquals ("Uni #4", 0x03, UniBytes [3]);
+ }
+
+ [Test]
+ public void TestEncodingGetBytes2()
+ {
+ //pi and sigma in unicode
+ string Unicode = "\u03a0\u03a3";
+ byte[] UniBytes;
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian
+ UniBytes = UnicodeEnc.GetBytes (Unicode);
+
+ Assertion.AssertEquals ("Uni #1", 0x03, UniBytes [0]);
+ Assertion.AssertEquals ("Uni #2", 0xA0, UniBytes [1]);
+ Assertion.AssertEquals ("Uni #3", 0x03, UniBytes [2]);
+ Assertion.AssertEquals ("Uni #4", 0xA3, UniBytes [3]);
+ }
+
+ [Test]
+ public void TestEncodingGetBytes3()
+ {
+ //pi and sigma in unicode
+ string Unicode = "\u03a0\u03a3";
+ byte[] UniBytes = new byte [4];
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian
+ int Cnt = UnicodeEnc.GetBytes (Unicode.ToCharArray(), 0, Unicode.Length, UniBytes, 0);
+
+ Assertion.AssertEquals ("Uni #1", 4, Cnt);
+ Assertion.AssertEquals ("Uni #2", 0xA0, UniBytes [0]);
+ Assertion.AssertEquals ("Uni #3", 0x03, UniBytes [1]);
+ Assertion.AssertEquals ("Uni #4", 0xA3, UniBytes [2]);
+ Assertion.AssertEquals ("Uni #5", 0x03, UniBytes [3]);
+ }
+
+ [Test]
+ public void TestEncodingDecodingGetBytes1()
+ {
+ //pi and sigma in unicode
+ string Unicode = "\u03a0\u03a3";
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian
+ //Encode the unicode string.
+ byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
+ //Decode the bytes to a unicode char array.
+ char[] UniChars = UnicodeEnc.GetChars (UniBytes);
+ string Result = new string(UniChars);
+
+ Assertion.AssertEquals ("Uni #1", Unicode, Result);
+ }
+
+ [Test]
+ public void TestEncodingDecodingGetBytes2()
+ {
+ //pi and sigma in unicode
+ string Unicode = "\u03a0\u03a3";
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian
+ //Encode the unicode string.
+ byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
+ //Decode the bytes to a unicode char array.
+ char[] UniChars = UnicodeEnc.GetChars (UniBytes);
+ string Result = new string(UniChars);
+
+ Assertion.AssertEquals ("Uni #1", Unicode, Result);
+ }
+
+ [Test]
+ public void TestEncodingGetCharCount ()
+ {
+ byte[] b = new byte[] {255, 254, 115, 0, 104, 0, 105, 0};
+ UnicodeEncoding encoding = new UnicodeEncoding ();
+
+ Assertion.AssertEquals ("GetCharCount #1", 3,
+ encoding.GetCharCount (b, 2, b.Length - 2));
+ }
+
+
+
+ [Test]
+ public void TestPreamble1()
+ {
+ //litle-endian with byte order mark.
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, true);
+ byte[] PreAmble = UnicodeEnc.GetPreamble();
+
+ Assertion.AssertEquals ("Uni #1", 0xFF, PreAmble [0]);
+ Assertion.AssertEquals ("Uni #2", 0xFE, PreAmble [1]);
+ }
+
+ [Test]
+ public void TestPreamble2()
+ {
+ //big-endian with byte order mark.
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true);
+ byte[] PreAmble = UnicodeEnc.GetPreamble();
+
+ Assertion.AssertEquals ("Uni #1", 0xFE, PreAmble [0]);
+ Assertion.AssertEquals ("Uni #2", 0xFF, PreAmble [1]);
+ }
+
+ [Test]
+ public void TestPreamble3()
+ {
+ //little-endian without byte order mark.
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, false);
+ byte[] PreAmble = UnicodeEnc.GetPreamble();
+
+ Assertion.AssertEquals ("Uni #1", 0, PreAmble.Length);
+ }
+
+ [Test]
+#if NET_2_0
+ [Category ("NotWorking")]
+#endif
+ public void TestMaxCharCount()
+ {
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding ();
+#if NET_2_0
+ // where is this extra 1 coming from?
+ Assertion.AssertEquals ("UTF #1", 25, UnicodeEnc.GetMaxCharCount(51));
+#else
+ Assertion.AssertEquals ("UTF #1", 25, UnicodeEnc.GetMaxCharCount(50));
+#endif
+ }
+
+ [Test]
+#if NET_2_0
+ [Category ("NotWorking")]
+#endif
+ public void TestMaxByteCount()
+ {
+ UnicodeEncoding UnicodeEnc = new UnicodeEncoding ();
+#if NET_2_0
+ // is this extra 2 BOM?
+ Assertion.AssertEquals ("UTF #1", 102, UnicodeEnc.GetMaxByteCount(50));
+#else
+ Assertion.AssertEquals ("UTF #1", 100, UnicodeEnc.GetMaxByteCount(50));
+#endif
+ }
+
+ [Test]
+ public void ZeroLengthArrays ()
+ {
+ UnicodeEncoding encoding = new UnicodeEncoding ();
+ encoding.GetCharCount (new byte [0]);
+ encoding.GetChars (new byte [0]);
+ encoding.GetCharCount (new byte [0], 0, 0);
+ encoding.GetChars (new byte [0], 0, 0);
+ encoding.GetChars (new byte [0], 0, 0, new char [0], 0);
+ encoding.GetByteCount (new char [0]);
+ encoding.GetBytes (new char [0]);
+ encoding.GetByteCount (new char [0], 0, 0);
+ encoding.GetBytes (new char [0], 0, 0);
+ encoding.GetBytes (new char [0], 0, 0, new byte [0], 0);
+ encoding.GetByteCount ("");
+ encoding.GetBytes ("");
+ }
+
+ [Test]
+ public void ByteOrderMark ()
+ {
+ string littleEndianString = "\ufeff\u0042\u004f\u004d";
+ string bigEndianString = "\ufffe\u4200\u4f00\u4d00";
+ byte [] littleEndianBytes = new byte [] {0xff, 0xfe, 0x42, 0x00, 0x4f, 0x00, 0x4d, 0x00};
+ byte [] bigEndianBytes = new byte [] {0xfe, 0xff, 0x00, 0x42, 0x00, 0x4f, 0x00, 0x4d};
+ UnicodeEncoding encoding;
+
+ encoding = new UnicodeEncoding (false, true);
+ Assertion.AssertEquals ("BOM #1", encoding.GetBytes (littleEndianString), littleEndianBytes);
+ Assertion.AssertEquals ("BOM #2", encoding.GetBytes (bigEndianString), bigEndianBytes);
+ Assertion.AssertEquals ("BOM #3", encoding.GetString (littleEndianBytes), littleEndianString);
+ Assertion.AssertEquals ("BOM #4", encoding.GetString (bigEndianBytes), bigEndianString);
+
+ encoding = new UnicodeEncoding (true, true);
+ Assertion.AssertEquals ("BOM #5", encoding.GetBytes (littleEndianString), bigEndianBytes);
+ Assertion.AssertEquals ("BOM #6", encoding.GetBytes (bigEndianString), littleEndianBytes);
+ Assertion.AssertEquals ("BOM #7", encoding.GetString (littleEndianBytes), bigEndianString);
+ Assertion.AssertEquals ("BOM #8", encoding.GetString (bigEndianBytes), littleEndianString);
+ }
+ }
+}