示例#1
0
        public void MultiByteUTF8()
        {
            Test2 t2 = new Test2 {
                B = "Toms Spezialitäten"
            },
                  clone = Serializer.DeepClone(t2);

            Assert.AreEqual(t2.B, clone.B);
        }
示例#2
0
        public void PerfTestEnumOnce()
        {
            Test4 t4 = new Test4 {
                D = TestEnum.D
            };

            Assert.IsTrue(Program.CheckBytes(t4, 0x20, 0x03));
            Assert.AreEqual(t4.D, Serializer.DeepClone(t4).D);
        }
示例#3
0
        public void Blob()
        {
            ItemWithBlob blob = new ItemWithBlob(), clone = Serializer.DeepClone(blob);

            Assert.IsTrue(Program.CheckBytes(blob, new byte[0]), "Empty serialization");
            Assert.IsTrue(Program.ArraysEqual(blob.Foo, clone.Foo), "Clone should be empty");

            blob.Foo = new byte[] { 0x01, 0x02, 0x03 };
            clone    = Serializer.DeepClone(blob);
            Assert.IsTrue(Program.ArraysEqual(blob.Foo, clone.Foo), "Clone should match");

            Assert.IsTrue(Program.CheckBytes(blob, 0x0A, 0x03, 0x01, 0x02, 0x03), "Stream should match");
        }
示例#4
0
        public void MultiByteUTF8KnownProblemLength()
        {   // 513 triggers buffer resize; specific problem case (i.e. bug)
            char mb = 'ä';

            Assert.AreEqual(2, Encoding.UTF8.GetByteCount(new char[] { mb }), "is multibyte");
            int   i  = 513;
            Test2 t2 = new Test2 {
                B = new string(mb, i)
            },
                  clone = Serializer.DeepClone(t2);

            Assert.AreEqual(i, t2.B.Length, "len");
            Assert.AreEqual(t2.B, clone.B, "Count: " + i.ToString());
        }
示例#5
0
        public void TestPartial()
        {
            PartialData orig = new PartialData {
                Name   = "abcdefghijklmnopqrstuvwxyz",
                Number = 1234,
                When   = new DateTime(2008, 1, 1),
                HowMuchNotSerialized = 123.456M
            }, clone = Serializer.DeepClone(orig);

            Assert.IsNotNull(orig, "original");
            Assert.IsNotNull(clone, "clone");
            Assert.AreEqual(orig.Name, clone.Name, "name");
            Assert.AreEqual(orig.Number, clone.Number, "number");
            Assert.AreEqual(orig.When, clone.When, "when");
            Assert.AreEqual(0.0M, clone.HowMuchNotSerialized, "how much");
        }
示例#6
0
        public void TestSubClass()
        {
            SubClassData orig = new SubClassData
            {
                Name   = "abcdefghijklmnopqrstuvwxyz",
                Number = 1234,
                When   = new DateTime(2008, 1, 1),
                HowMuchNotSerialized = 123.456M
            }, clone = (SubClassData)Serializer.DeepClone <PartialData>(orig);

            Assert.NotNull(orig);                           //, "original");
            Assert.NotNull(clone);                          //, "clone");
            Assert.Equal(orig.Name, clone.Name);            //, "name");
            Assert.Equal(orig.Number, clone.Number);        //, "number");
            Assert.Equal(orig.When, clone.When);            //, "when");
            Assert.Equal(0.0M, clone.HowMuchNotSerialized); //, "how much");
        }
示例#7
0
        public void MultiByteUTF8VariousLengths()
        {
            char mb = 'ä';

            Assert.AreEqual(2, Encoding.UTF8.GetByteCount(new char[] { mb }), "is multibyte");

            for (int i = 0; i < 1024; i++)
            {
                try
                {
                    Test2 t2 = new Test2 {
                        B = new string(mb, i)
                    },
                          clone = Serializer.DeepClone(t2);
                    Assert.AreEqual(i, t2.B.Length, "len");
                    Assert.AreEqual(t2.B, clone.B, "Count: " + i.ToString());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                    Assert.Fail(i.ToString() + ": " + ex.Message);
                }
            }
        }