public void MultiByteUTF8VariousLengths() { char mb = 'ä'; Assert.AreEqual(2, Encoding.UTF8.GetByteCount(new char[] { mb }), "is multibyte"); for (int i = 0; i < 1024 * 8; #if DEBUG i += 100 #else i += 3 #endif ) { 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); } } }
public void MultiByteUTF8() { Test2 t2 = new Test2 { B = "Toms Spezialitäten" }, clone = Serializer.DeepClone(t2); Assert.AreEqual(t2.B, clone.B); }
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); }
public void StringSample() { Test2 t2 = new Test2 { B = "testing" }; Serializer.DeepClone(t2); // variant? //Assert.IsTrue(Program.CheckBytes(t2, 0x12, 0x0b, 0x10, 0x01, 0x52, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67)); }
public void EmbeddedMessageSample() { Test3 t3 = new Test3 { C = new Test1 { A = 150 } }; Serializer.DeepClone(t3); // variant? //Assert.IsTrue(Program.CheckBytes(t3, 0x1a, 0x07, 0x10, 0x01, 0x52, 0x03, 0x08, 0x96, 0x01)); }
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"); }
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()); }
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"); }