public void TestIBuilderLiteWeakMergeFromByteStringExtensions()
        {
            TestAllExtensionsLite copy,
                                  msg = TestAllExtensionsLite.CreateBuilder()
                                        .SetExtension(UnittestLite.OptionalStringExtensionLite,
                                                      "Should be merged.").Build();

            copy = TestAllExtensionsLite.DefaultInstance;
            Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());

            copy =
                (TestAllExtensionsLite)
                ((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), ExtensionRegistry.Empty).WeakBuild();
            Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            copy =
                (TestAllExtensionsLite)
                ((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), registry).WeakBuild();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
            Assert.AreEqual("Should be merged.", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
        }
Exemple #2
0
        public void ExtensionWriterTestMessages()
        {
            TestAllExtensionsLite.Builder b = TestAllExtensionsLite.CreateBuilder().SetExtension(
                UnittestLite.OptionalForeignMessageExtensionLite,
                ForeignMessageLite.CreateBuilder().SetC(123).Build());
            TestAllExtensionsLite copy, msg = b.Build();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
Exemple #3
0
        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();

            UnittestLite.RegisterAllExtensions(registry);
            AssertPackedExtensions(TestPackedExtensionsLite.ParseFrom(unpacked.ToByteArray(), registry));
        }
Exemple #4
0
        public void ExtensionWriterTestPacked()
        {
            TestPackedExtensionsLite msg = BuildPackedExtensions();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            TestPackedExtensionsLite.Builder copyBuilder =
                TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
            TestPackedExtensionsLite copy = copyBuilder.Build();

            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());

            AssertPackedExtensions(copy);
        }
Exemple #5
0
        public void TestUnpackedAndPackedExtensions()
        {
            TestPackedExtensionsLite original = BuildPackedExtensions();

            AssertPackedExtensions(original);

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);
            UnittestExtrasLite.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);
        }
Exemple #6
0
        public void ExtensionWriterTestSetExtensionLists()
        {
            TestAllExtensionsLite msg, copy;

            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .SetExtension(UnittestLite.RepeatedBoolExtensionLite, new[] { true, false })
                                                    .SetExtension(UnittestLite.RepeatedCordExtensionLite, new[] { "123", "456" })
                                                    .SetExtension(UnittestLite.RepeatedForeignEnumExtensionLite,
                                                                  new[] { ForeignEnumLite.FOREIGN_LITE_BAZ, ForeignEnumLite.FOREIGN_LITE_FOO })
            ;

            msg = builder.Build();
            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());

            Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_FOO,
                            copy.GetExtension(UnittestLite.RepeatedForeignEnumExtensionLite, 1));
        }
        public void TestBuilderLiteMergeFromStreamExtensions()
        {
            TestAllExtensionsLite copy,
                                  msg = TestAllExtensionsLite.CreateBuilder()
                                        .SetExtension(UnittestLite.OptionalStringExtensionLite,
                                                      "Should be merged.").Build();

            copy = TestAllExtensionsLite.DefaultInstance;
            Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());

            Stream s = new MemoryStream();

            msg.WriteTo(s);
            s.Position = 0;

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            copy = copy.ToBuilder().MergeFrom(s, registry).Build();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
            Assert.AreEqual("Should be merged.", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
        }
Exemple #8
0
        public void ExtensionWriterTest()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .SetExtension(UnittestLite.DefaultBoolExtensionLite, true)
                                                    .SetExtension(UnittestLite.DefaultBytesExtensionLite, ByteString.CopyFromUtf8("123"))
                                                    .SetExtension(UnittestLite.DefaultCordExtensionLite, "123")
                                                    .SetExtension(UnittestLite.DefaultDoubleExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultFixed32ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.DefaultFixed64ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.DefaultFloatExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
                                                    .SetExtension(UnittestLite.DefaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
                                                    .SetExtension(UnittestLite.DefaultInt32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultInt64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultNestedEnumExtensionLite,
                                                                  TestAllTypesLite.Types.NestedEnum.FOO)
                                                    .SetExtension(UnittestLite.DefaultSfixed32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultSfixed64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultSint32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultSint64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.DefaultStringExtensionLite, "123")
                                                    .SetExtension(UnittestLite.DefaultStringPieceExtensionLite, "123")
                                                    .SetExtension(UnittestLite.DefaultUint32ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.DefaultUint64ExtensionLite, 123u)
                                                    //Optional
                                                    .SetExtension(UnittestLite.OptionalBoolExtensionLite, true)
                                                    .SetExtension(UnittestLite.OptionalBytesExtensionLite, ByteString.CopyFromUtf8("123"))
                                                    .SetExtension(UnittestLite.OptionalCordExtensionLite, "123")
                                                    .SetExtension(UnittestLite.OptionalDoubleExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalFixed32ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.OptionalFixed64ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.OptionalFloatExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
                                                    .SetExtension(UnittestLite.OptionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
                                                    .SetExtension(UnittestLite.OptionalInt32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalInt64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalNestedEnumExtensionLite,
                                                                  TestAllTypesLite.Types.NestedEnum.FOO)
                                                    .SetExtension(UnittestLite.OptionalSfixed32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalSfixed64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalSint32ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalSint64ExtensionLite, 123)
                                                    .SetExtension(UnittestLite.OptionalStringExtensionLite, "123")
                                                    .SetExtension(UnittestLite.OptionalStringPieceExtensionLite, "123")
                                                    .SetExtension(UnittestLite.OptionalUint32ExtensionLite, 123u)
                                                    .SetExtension(UnittestLite.OptionalUint64ExtensionLite, 123u)
                                                    //Repeated
                                                    .AddExtension(UnittestLite.RepeatedBoolExtensionLite, true)
                                                    .AddExtension(UnittestLite.RepeatedBytesExtensionLite, ByteString.CopyFromUtf8("123"))
                                                    .AddExtension(UnittestLite.RepeatedCordExtensionLite, "123")
                                                    .AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedFixed32ExtensionLite, 123u)
                                                    .AddExtension(UnittestLite.RepeatedFixed64ExtensionLite, 123u)
                                                    .AddExtension(UnittestLite.RepeatedFloatExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
                                                    .AddExtension(UnittestLite.RepeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
                                                    .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedInt64ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedNestedEnumExtensionLite,
                                                                  TestAllTypesLite.Types.NestedEnum.FOO)
                                                    .AddExtension(UnittestLite.RepeatedSfixed32ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedSfixed64ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedSint32ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedSint64ExtensionLite, 123)
                                                    .AddExtension(UnittestLite.RepeatedStringExtensionLite, "123")
                                                    .AddExtension(UnittestLite.RepeatedStringPieceExtensionLite, "123")
                                                    .AddExtension(UnittestLite.RepeatedUint32ExtensionLite, 123u)
                                                    .AddExtension(UnittestLite.RepeatedUint64ExtensionLite, 123u)
            ;
            TestAllExtensionsLite msg = builder.Build();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestLite.RegisterAllExtensions(registry);

            TestAllExtensionsLite.Builder copyBuilder =
                TestAllExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
            TestAllExtensionsLite copy = copyBuilder.Build();

            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());

            Assert.AreEqual(true, copy.GetExtension(UnittestLite.DefaultBoolExtensionLite));
            Assert.AreEqual(ByteString.CopyFromUtf8("123"),
                            copy.GetExtension(UnittestLite.DefaultBytesExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultCordExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultDoubleExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultFixed32ExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultFixed64ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultFloatExtensionLite));
            Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
                            copy.GetExtension(UnittestLite.DefaultForeignEnumExtensionLite));
            Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
                            copy.GetExtension(UnittestLite.DefaultImportEnumExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultInt32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultInt64ExtensionLite));
            Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
                            copy.GetExtension(UnittestLite.DefaultNestedEnumExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSfixed32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSfixed64ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSint32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSint64ExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultStringExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultStringPieceExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultUint32ExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultUint64ExtensionLite));

            Assert.AreEqual(true, copy.GetExtension(UnittestLite.OptionalBoolExtensionLite));
            Assert.AreEqual(ByteString.CopyFromUtf8("123"),
                            copy.GetExtension(UnittestLite.OptionalBytesExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalCordExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalDoubleExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalFixed32ExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalFixed64ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalFloatExtensionLite));
            Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
                            copy.GetExtension(UnittestLite.OptionalForeignEnumExtensionLite));
            Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
                            copy.GetExtension(UnittestLite.OptionalImportEnumExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalInt64ExtensionLite));
            Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
                            copy.GetExtension(UnittestLite.OptionalNestedEnumExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSfixed32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSfixed64ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSint32ExtensionLite));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSint64ExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalStringPieceExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalUint32ExtensionLite));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalUint64ExtensionLite));

            Assert.AreEqual(true, copy.GetExtension(UnittestLite.RepeatedBoolExtensionLite, 0));
            Assert.AreEqual(ByteString.CopyFromUtf8("123"),
                            copy.GetExtension(UnittestLite.RepeatedBytesExtensionLite, 0));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedCordExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedDoubleExtensionLite, 0));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedFixed32ExtensionLite, 0));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedFixed64ExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedFloatExtensionLite, 0));
            Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
                            copy.GetExtension(UnittestLite.RepeatedForeignEnumExtensionLite, 0));
            Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
                            copy.GetExtension(UnittestLite.RepeatedImportEnumExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedInt64ExtensionLite, 0));
            Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
                            copy.GetExtension(UnittestLite.RepeatedNestedEnumExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSfixed32ExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSfixed64ExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSint32ExtensionLite, 0));
            Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSint64ExtensionLite, 0));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedStringExtensionLite, 0));
            Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedStringPieceExtensionLite, 0));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedUint32ExtensionLite, 0));
            Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedUint64ExtensionLite, 0));
        }