Пример #1
0
        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));
        }
Пример #2
0
        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");
        }
Пример #3
0
        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");
        }
Пример #4
0
        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());
        }
Пример #5
0
 private static void TestReadString(byte[] buffer, TextCodec codec)
 {
     TestReadStringNullTerminated(buffer, codec);
     TestReadStrings(buffer, codec);
 }