예제 #1
0
        [TestMethod] public void Simple_TermString_singleChar()
        {
            var formatter = TerminateStringFormatter.create("-");

            void check1(string data)
            {
                var bytes = formatter.serialize(data);
                var dec   = formatter.deserialize(bytes);

                Assert.AreEqual(dec, data);
            }

            void checkMany(params string[] data)
            {
                var mem = new MemoryStream();

                foreach (var s in data)
                {
                    mem.Write(s, formatter);
                }
                mem.Seek(0, SeekOrigin.Begin);
                foreach (var s in data)
                {
                    var dec = mem.Read(formatter);
                    Assert.AreEqual(s, dec);
                }
            }

            check1("a");
            check1("abra kadabra");
            check1(new string('a', 300));
            checkMany("a", "abrakadabra", new string('a', 300), "tooMany", "toofar");
        }
예제 #2
0
        [TestMethod] public void Simple_TermString_multichar_tailcut()
        {
            var formatter  = TerminateStringFormatter.create("<EOF>");
            var tailcutter = formatter.inner;

            void check1(string data)
            {
                var bytes = tailcutter.serialize(data);
                var dec   = formatter.deserialize(bytes);

                Assert.AreEqual(dec, data);
            }

            void checkMany(params string[] data)
            {
                var mem = new MemoryStream();

                foreach (var s in data.Take(data.Length - 1))
                {
                    mem.Write(s, formatter);
                }
                mem.Write(data.Last(), tailcutter);
                mem.Seek(0, SeekOrigin.Begin);
                foreach (var s in data)
                {
                    var dec = mem.Read(formatter);
                    Assert.AreEqual(s, dec);
                }
            }

            check1("a");
            check1("abra kadabra");
            check1(new string('a', 300));
            checkMany("a", "abrakadabra", new string('a', 300), "tooMany", "toofar");
        }
예제 #3
0
        [TestMethod] public void Simple_TermString_multichar_unseek()
        {
            var formatter = TerminateStringFormatter.create("<EOF>");

            void check1(string data)
            {
                var ms = new MemoryStream();

                formatter.Serialize(data, ms);
                ms.Seek(0, SeekOrigin.Begin);
                var dec = formatter.Deserialize(new unseekingStream(ms));

                Assert.AreEqual(dec, data);
            }

            void checkMany(params string[] data)
            {
                Stream mem = new MemoryStream();

                foreach (var s in data)
                {
                    mem.Write(s, formatter);
                }
                mem.Seek(0, SeekOrigin.Begin);
                mem = new unseekingStream(mem);
                foreach (var s in data)
                {
                    var dec = mem.Read(formatter);
                    Assert.AreEqual(s, dec);
                }
            }

            check1("a");
            check1("abra kadabra");
            check1(new string('a', 300));
            checkMany("a", "abrakadabra", new string('a', 300), "tooMany", "toofar");
        }