public void TestMissingExtensionsLite() { const int optionalInt32 = 12345678; TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); builder.SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, optionalInt32); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.1); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.2); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.3); TestAllExtensionsLite msg = builder.Build(); Assert.IsTrue(msg.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); Assert.AreEqual(3, msg.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); byte[] bits = msg.ToByteArray(); TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits); Assert.IsFalse(copy.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); Assert.AreEqual(0, copy.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); Assert.AreNotEqual(msg, copy); //The lite runtime removes all unknown fields and extensions byte[] copybits = copy.ToByteArray(); Assert.AreEqual(0, copybits.Length); }
public void ExtensionWriterTestMessages() { TestAllExtensionsLite.Builder b = TestAllExtensionsLite.CreateBuilder().SetExtension( UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite, ForeignMessageLite.CreateBuilder().SetC(123).Build()); TestAllExtensionsLite copy, msg = b.Build(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); UnitTestLiteProtoFile.RegisterAllExtensions(registry); copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry); Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); }
public void TestMissingFieldsLite() { TestAllTypesLite msg = TestAllTypesLite.CreateBuilder() .SetOptionalInt32(123) .SetOptionalString("123") .Build(); byte[] bits = msg.ToByteArray(); TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits); Assert.AreNotEqual(msg, copy); //The lite runtime removes all unknown fields and extensions byte[] copybits = copy.ToByteArray(); Assert.AreEqual(0, copybits.Length); }
public void ExtensionWriterTestSetExtensionLists() { TestAllExtensionsLite msg, copy; TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() .SetExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, new[] { true, false }) .SetExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, new[] { "123", "456" }) .SetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, new[] { ForeignEnumLite.FOREIGN_LITE_BAZ, ForeignEnumLite.FOREIGN_LITE_FOO }) ; msg = builder.Build(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); UnitTestLiteProtoFile.RegisterAllExtensions(registry); copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry); Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_FOO, copy.GetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, 1)); }