public void TestIndentity() { OneOfEach ooe = Fixtures.oneOfEach; Nesting n = new Nesting(); n.MyOoe = ooe; n.MyOoe.Integer16 = 16; n.MyOoe.Integer32 = 32; n.MyOoe.Integer64 = 64L; n.MyOoe.DoublePrecision = (Math.Sqrt(5) + 1) / 2; n.MyOoe.SomeCharacters = ":R (me going \"rrrr\")"; n.MyOoe.ZomgUnicode = "\u04c0\u216e\u039d\u0020\u041d\u03bf\u217f" + "\u043e\u0261\u0433\u0430\u03c1\u210e\u0020" + "\u0391\u0074\u0074\u03b1\u217d\u03ba\u01c3" + "\u203c"; n.MyBonk = Fixtures.nesting.MyBonk; var ooe2 = TMemoryBuffer.DeSerialize<OneOfEach>(TMemoryBuffer.Serialize(ooe)); Assert.AreEqual(ooe, ooe2); Assert.AreEqual(ooe.GetHashCode(), ooe2.GetHashCode()); var n2 = TMemoryBuffer.DeSerialize<Nesting>(TMemoryBuffer.Serialize(n)); Assert.AreEqual(n, n2); Assert.AreEqual(n.GetHashCode(), n2.GetHashCode()); HolyMoley hm = Fixtures.holyMoley; var hm2 = TMemoryBuffer.DeSerialize<HolyMoley>(TMemoryBuffer.Serialize(hm)); Assert.AreEqual(hm, hm2); Assert.AreEqual(hm.GetHashCode(), hm2.GetHashCode()); }
static Fixtures() { oneOfEach = new OneOfEach(); oneOfEach.ImTrue = true; oneOfEach.ImFalse = false; oneOfEach.ABite = (sbyte)0x16; oneOfEach.Integer16 = 27000; oneOfEach.Integer32 = 1 << 24; oneOfEach.Integer64 = (long)6000 * 1000 * 1000; oneOfEach.DoublePrecision = Math.PI; oneOfEach.SomeCharacters = "JSON THIS! \""; oneOfEach.ZomgUnicode = Encoding.UTF8.GetString(kUnicodeBytes); oneOfEach.Base64 = Encoding.UTF8.GetBytes("base64"); Bonk bonk = new Bonk(); bonk.Type = 31337; bonk.Message = "I am a bonk... xor!"; nesting = new Nesting(bonk, oneOfEach); holyMoley = new HolyMoley(); List<OneOfEach> big = new List<OneOfEach>(); big.Add(oneOfEach); big.Add(nesting.MyOoe); holyMoley.Big = big; holyMoley.Big[0].ABite = 0x22; holyMoley.Big[0].ABite = 0x23; holyMoley.Contain = new HashSet<List<string>>(); List<string> stage1 = new List<string>(2); stage1.Add("and a one"); stage1.Add("and a two"); holyMoley.Contain.Add(stage1); stage1 = new List<string>(3); stage1.Add("then a one, two"); stage1.Add("three!"); stage1.Add("FOUR!!"); holyMoley.Contain.Add(stage1); stage1 = new List<string>(0); holyMoley.Contain.Add(stage1); List<Bonk> stage2 = new List<Bonk>(); holyMoley.Bonks = new Dictionary<string, List<Bonk>>(); // one empty holyMoley.Bonks["zero"] = stage2; // one with two stage2 = new List<Bonk>(); Bonk b = new Bonk(); b.Type = 1; b.Message = "Wait."; stage2.Add(b); b = new Bonk(); b.Type = 2; b.Message = "What?"; stage2.Add(b); holyMoley.Bonks["two"] = stage2; // one with three stage2 = new List<Bonk>(); b = new Bonk(); b.Type = 3; b.Message = "quoth"; stage2.Add(b); b = new Bonk(); b.Type = 4; b.Message = "the raven"; stage2.Add(b); b = new Bonk(); b.Type = 5; b.Message = "nevermore"; stage2.Add(b); holyMoley.Bonks["three"] = stage2; // superhuge compact proto test struct compactProtoTestStruct = new CompactProtoTestStruct(); compactProtoTestStruct.ABinary = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; compactProtoTestStruct.AByte = 127; compactProtoTestStruct.AI16 = 32000; compactProtoTestStruct.AI32 = 100000000; compactProtoTestStruct.AI64 = 0xffffffffffL; compactProtoTestStruct.ADouble = 5.6789; compactProtoTestStruct.AString = "my string"; compactProtoTestStruct.TrueField = true; compactProtoTestStruct.FalseField = false; compactProtoTestStruct.EmptyStructField = new Empty(); compactProtoTestStruct.ByteList = new List<sbyte?> { -127, -1, 0, 1, 127 }; compactProtoTestStruct.I16List = new List<short?> { -1, 0, 1, 0x7fff }; compactProtoTestStruct.I32List = new List<int?> { -1, 0, 0xff, 0xffff, 0xffffff, 0x7fffffff }; compactProtoTestStruct.I64List = new List<long?> { -1L, 0L, 0xffL, 0xffffL, 0xffffffL, 0xffffffffL, 0xffffffffffL, 0xffffffffffffL, 0xffffffffffffffL, 0x7fffffffffffffffL }; compactProtoTestStruct.DoubleList = new List<double?> { 0.1, 0.2, 0.3 }; compactProtoTestStruct.StringList = new List<string> { "first", "second", "third" }; compactProtoTestStruct.BooleanList = new List<bool?> { true, true, true, false, false, false }; compactProtoTestStruct.StructList = new List<Empty> { new Empty(), new Empty() }; compactProtoTestStruct.ByteSet = new HashSet<sbyte?> { (sbyte)-127, (sbyte)-1, (sbyte)0, (sbyte)1, (sbyte)127 }; compactProtoTestStruct.I16Set = new HashSet<short?> { (short)-1, (short)0, (short)1, (short)0x7fff }; compactProtoTestStruct.I32Set = new HashSet<int?> { 1, 2, 3 }; compactProtoTestStruct.I64Set = new HashSet<long?> { -1L, 0L, 0xffL, 0xffffL, 0xffffffL, 0xffffffffL, 0xffffffffffL, 0xffffffffffffL, 0xffffffffffffffL, 0x7fffffffffffffffL }; compactProtoTestStruct.DoubleSet = new HashSet<double?> { 0.1, 0.2, 0.3 }; compactProtoTestStruct.StringSet = new HashSet<string> { "first", "second", "third" }; compactProtoTestStruct.BooleanSet = new HashSet<bool?> { true, false }; compactProtoTestStruct.StructSet = new HashSet<Empty> { new Empty() }; compactProtoTestStruct.ByteByteMap = new Dictionary<sbyte?, sbyte?> { { 1, 2 } }; compactProtoTestStruct.I16ByteMap = new Dictionary<short?, sbyte?> { { 1, 1 }, { -11, 1 }, { 0x7fff, 1 } }; compactProtoTestStruct.I32ByteMap = new Dictionary<int?, sbyte?> { {1, 1}, {-1, 1}, {0x7fffffff, 1} }; compactProtoTestStruct.I64ByteMap = new Dictionary<long?, sbyte?> { {0, 1}, {1, 1}, {-1, 1}, {0x7fffffffffffffffL, 1} }; compactProtoTestStruct.DoubleByteMap = new Dictionary<double?, sbyte?> { { -1.1, 1}, {1.1, 1} }; compactProtoTestStruct.StringByteMap = new Dictionary<string, sbyte?> { {"first", 1}, {"second", 2}, {"third", 3}, {"", 0}}; compactProtoTestStruct.BooleanByteMap = new Dictionary<bool?, sbyte?> { { true, 1 }, { false, 0 } }; compactProtoTestStruct.ByteI16Map = new Dictionary<sbyte?, short?> { { 1, 1 }, { 2, -1 }, { 3, 0x7fff } }; compactProtoTestStruct.ByteI32Map = new Dictionary<sbyte?, int?> { {1, 1}, {2, -1}, {3, 0x7fffffff} }; compactProtoTestStruct.ByteI64Map = new Dictionary<sbyte?, long?> { { 1, 1 }, { 2, -1 }, { 3, 0x7fffffffffffffffL } }; compactProtoTestStruct.ByteDoubleMap = new Dictionary<sbyte?, double?> { { 1, 0.1 }, { 2, -0.1 }, { 3, 1000000.1 } }; compactProtoTestStruct.ByteStringMap = new Dictionary<sbyte?, string> { { 1, "" }, { 2, "blah" }, { 3, "loooooooooooooong string" } }; compactProtoTestStruct.ByteBooleanMap = new Dictionary<sbyte?, bool?> { {1, true}, {2, false} }; compactProtoTestStruct.ListByteMap = new Dictionary<List<sbyte?>, sbyte?> { {new List<sbyte?> {1, 2, 3}, 1}, {new List<sbyte?> {0, 1}, 2 }, {new List<sbyte?>(), 0}}; compactProtoTestStruct.SetByteMap = new Dictionary<HashSet<sbyte?>, sbyte?> { { new HashSet<sbyte?> { 1, 2, 3 }, 1 }, { new HashSet<sbyte?> {0, 1}, 2}, { new HashSet<sbyte?>(), 0} }; compactProtoTestStruct.MapByteMap = new Dictionary<Dictionary<sbyte?, sbyte?>, sbyte?> { { new Dictionary<sbyte?, sbyte?> { { 1, 1 } }, 1 }, { new Dictionary<sbyte?, sbyte?> { { 2, 2 } }, 2 }, { new Dictionary<sbyte?, sbyte?>(), 0 } }; compactProtoTestStruct.ByteMapMap = new Dictionary<sbyte?, Dictionary<sbyte?, sbyte?>> { { 0, new Dictionary<sbyte?, sbyte?>() }, { 1, new Dictionary<sbyte?, sbyte?> { { 1, 1 } } }, { 2, new Dictionary<sbyte?, sbyte?> { { 1, 1 }, {2, 2} } } }; compactProtoTestStruct.ByteSetMap = new Dictionary<sbyte?, HashSet<sbyte?>> { {0, new HashSet<sbyte?>() }, {1, new HashSet<sbyte?> {1}}, {2, new HashSet<sbyte?> {1, 2}} }; compactProtoTestStruct.ByteListMap = new Dictionary<sbyte?, List<sbyte?>> { {0, new List<sbyte?>()}, {1, new List<sbyte?> { 1 }}, { 2, new List<sbyte?> {1, 2} } }; }