private void Compare(string prefix, string start, byte[] end) { byte[] bytes = unix.GetBytes(start); Assert.AreEqual(end.Length, bytes.Length, prefix + ": byte length"); for (int i = 0; i < global::System.Math.Min(bytes.Length, end.Length); ++i) { Assert.AreEqual(end [i], bytes [i], prefix + ": byte " + i); } int cc = unix.GetCharCount(end, 0, end.Length); Assert.AreEqual(start.Length, cc, prefix + ": char count"); char[] chars = new char [cc]; int r = unix.GetChars(end, 0, end.Length, chars, 0); Assert.AreEqual(start.Length, r, prefix + ": chars length"); for (int i = 0; i < global::System.Math.Min(r, start.Length); ++i) { Assert.AreEqual(start [i], chars [i], prefix + ": char " + i); } }
public void TestDecodingGetChars1() { UnixEncoding unixEnc = new UnixEncoding(); // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>." // see (RFC 2044) byte[] unixBytes = new byte [] { 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E }; char[] UniCodeChars = unixEnc.GetChars(unixBytes); Assert.AreEqual(0x0041, UniCodeChars [0], "UTF #1"); Assert.AreEqual(0x2262, UniCodeChars [1], "UTF #2"); Assert.AreEqual(0x0391, UniCodeChars [2], "UTF #3"); Assert.AreEqual(0x002E, UniCodeChars [3], "UTF #4"); }
public void TestEmptyString() { byte[] data = new byte [] {}; Encoding enc = new UnixEncoding(); string s = enc.GetString(data); Assert.AreEqual(s, "", "#1"); char[] chars = enc.GetChars(data); Assert.AreEqual(chars.Length, 0, "#2"); byte[] b1 = enc.GetBytes(""); Assert.AreEqual(b1.Length, 0, "#3"); byte[] b2 = enc.GetBytes(new char[] {}); Assert.AreEqual(b2.Length, 0, "#3"); }