Commit c2a1f9b5 authored by csharptest's avatar csharptest Committed by rogerk

Unit testing of Packed/Unpacked parsing in Lite

parent 6da3170a
......@@ -178,6 +178,23 @@ message TestPackedTypesLite {
repeated ForeignEnumLite packed_enum = 103 [packed = true];
}
message TestUnpackedTypesLite {
repeated int32 unpacked_int32 = 90;
repeated int64 unpacked_int64 = 91;
repeated uint32 unpacked_uint32 = 92;
repeated uint64 unpacked_uint64 = 93;
repeated sint32 unpacked_sint32 = 94;
repeated sint64 unpacked_sint64 = 95;
repeated fixed32 unpacked_fixed32 = 96;
repeated fixed64 unpacked_fixed64 = 97;
repeated sfixed32 unpacked_sfixed32 = 98;
repeated sfixed64 unpacked_sfixed64 = 99;
repeated float unpacked_float = 100;
repeated double unpacked_double = 101;
repeated bool unpacked_bool = 102;
repeated ForeignEnumLite unpacked_enum = 103;
}
message TestAllExtensionsLite {
extensions 1 to max;
}
......@@ -305,6 +322,27 @@ extend TestPackedExtensionsLite {
repeated ForeignEnumLite packed_enum_extension_lite = 103 [packed = true];
}
message TestUnpackedExtensionsLite {
extensions 1 to max;
}
extend TestUnpackedExtensionsLite {
repeated int32 unpacked_int32_extension_lite = 90;
repeated int64 unpacked_int64_extension_lite = 91;
repeated uint32 unpacked_uint32_extension_lite = 92;
repeated uint64 unpacked_uint64_extension_lite = 93;
repeated sint32 unpacked_sint32_extension_lite = 94;
repeated sint64 unpacked_sint64_extension_lite = 95;
repeated fixed32 unpacked_fixed32_extension_lite = 96;
repeated fixed64 unpacked_fixed64_extension_lite = 97;
repeated sfixed32 unpacked_sfixed32_extension_lite = 98;
repeated sfixed64 unpacked_sfixed64_extension_lite = 99;
repeated float unpacked_float_extension_lite = 100;
repeated double unpacked_double_extension_lite = 101;
repeated bool unpacked_bool_extension_lite = 102;
repeated ForeignEnumLite unpacked_enum_extension_lite = 103;
}
message TestNestedExtensionLite {
extend TestAllExtensionsLite {
optional int32 nested_extension = 12345;
......
......@@ -258,48 +258,42 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedUint64ExtensionLite, 0));
}
[Test]
public void ExtensionWriterTestPacked()
private TestPackedExtensionsLite BuildPackedExtensions()
{
TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.CreateBuilder()
.AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
.AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
.AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u);
.AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
.AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
.AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
.AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
.AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u);
TestPackedExtensionsLite msg = builder.Build();
return msg;
}
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestLiteProtoFile.RegisterAllExtensions(registry);
TestPackedExtensionsLite.Builder copyBuilder =
TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
TestPackedExtensionsLite copy = copyBuilder.Build();
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
private void AssertPackedExtensions(TestPackedExtensionsLite copy)
{
Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, 0));
Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 0));
Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 0));
......@@ -328,5 +322,56 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 1));
Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 1));
}
[Test]
public void ExtensionWriterTestPacked()
{
TestPackedExtensionsLite msg = BuildPackedExtensions();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestLiteProtoFile.RegisterAllExtensions(registry);
TestPackedExtensionsLite.Builder copyBuilder =
TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
TestPackedExtensionsLite copy = copyBuilder.Build();
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
AssertPackedExtensions(copy);
}
[Test]
public void TestUnpackedAndPackedExtensions()
{
TestPackedExtensionsLite original = BuildPackedExtensions();
AssertPackedExtensions(original);
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestLiteProtoFile.RegisterAllExtensions(registry);
TestUnpackedExtensionsLite unpacked = TestUnpackedExtensionsLite.ParseFrom(original.ToByteArray(), registry);
TestPackedExtensionsLite packed = TestPackedExtensionsLite.ParseFrom(unpacked.ToByteArray(), registry);
Assert.AreEqual(original, packed);
Assert.AreEqual(original.ToByteArray(), packed.ToByteArray());
AssertPackedExtensions(packed);
}
[Test]
public void TestUnpackedFromPackedInput()
{
byte[] packedData = BuildPackedExtensions().ToByteArray();
TestUnpackedTypesLite unpacked = TestUnpackedTypesLite.ParseFrom(packedData);
TestPackedTypesLite packed = TestPackedTypesLite.ParseFrom(unpacked.ToByteArray());
Assert.AreEqual(packedData, packed.ToByteArray());
unpacked = TestUnpackedTypesLite.ParseFrom(packed.ToByteArray());
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestLiteProtoFile.RegisterAllExtensions(registry);
AssertPackedExtensions(TestPackedExtensionsLite.ParseFrom(unpacked.ToByteArray(), registry));
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment