private static void TestEncodeEqualsDecode(TextCodec encoder, string text) { MemoryStream wstream = new MemoryStream(); encoder.WriteString(wstream, text); MemoryStream rstream = new MemoryStream(wstream.ToArray()); string text2 = encoder.ReadString(rstream, false); UnitTest.Test(text.Equals(text2)); }
private static void TestReadStrings(byte[] buffer, TextCodec codec) { IEnumerable <string> result = null; using (MemoryStream stream = new MemoryStream(buffer)) { result = codec.ReadStrings(stream); } UnitTest.Test(result.Count() == 2); UnitTest.Test(result.ElementAt(0) == "A"); UnitTest.Test(result.ElementAt(1) == "B"); }
private static void TestReadStringNullTerminated(byte[] buffer, TextCodec codec) { string result0 = null; string result1 = null; using (MemoryStream stream = new MemoryStream(buffer)) { result0 = codec.ReadString(stream, false); result1 = codec.ReadString(stream, false); } UnitTest.Test(result0 == "A"); UnitTest.Test(result1 == "B"); }
public int CodecTypeByCodec(TextCodec encoder) { int index = 0; foreach (Type t in CodecClasses) { if (!Object.ReferenceEquals(t, null) && t.Equals(encoder.GetType())) { return(index); } index++; } throw new Exception("CodecTypeByCodec failed: " + encoder.GetType().ToString()); }
private static void TestReadString(byte[] buffer, TextCodec codec) { TestReadStringNullTerminated(buffer, codec); TestReadStrings(buffer, codec); }