예제 #1
0
        public void TestAllTypesDefaultedRoundTrip()
        {
            TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;

            Assert.IsTrue(msg.IsInitialized);
            TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();

            TestUtil.AssertBytesEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #2
0
        public void TestIBuilderLiteWeakClear()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.DefaultInstance;

            copy = msg.ToBuilder().SetOptionalString("Should be removed.").Build();
            Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());

            copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakClear().WeakBuild();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #3
0
        public void TestBuilderLiteMergeFromCodedInputStream()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
                                         .SetOptionalString("Should be merged.").Build();

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

            copy = copy.ToBuilder().MergeFrom(CodedInputStream.CreateInstance(new MemoryStream(msg.ToByteArray()))).Build();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #4
0
        public void TestIBuilderLiteWeakMergeFromByteString()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
                                         .SetOptionalString("Should be merged.").Build();

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

            copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString()).WeakBuild();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #5
0
        public void TestBuilderLiteMergeDelimitedFrom()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
                                         .SetOptionalString("Should be merged.").Build();

            copy = TestAllTypesLite.DefaultInstance;
            Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
            Stream s = new MemoryStream();

            msg.WriteDelimitedTo(s);
            s.Position = 0;
            copy       = copy.ToBuilder().MergeDelimitedFrom(s).Build();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #6
0
        public void TestMergeFromCodedInputStream()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
                                         .SetOptionalUint32(uint.MaxValue).Build();

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

            using (MemoryStream ms = new MemoryStream(msg.ToByteArray())) {
                CodedInputStream ci = CodedInputStream.CreateInstance(ms);
                copy = copy.ToBuilder().MergeFrom(ci).Build();
            }

            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #7
0
        public void TestGeneratedBuilderLiteAddRange()
        {
            TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
                                         .SetOptionalUint32(123)
                                         .AddRepeatedInt32(1)
                                         .AddRepeatedInt32(2)
                                         .AddRepeatedInt32(3)
                                         .Build();

            copy = msg.DefaultInstanceForType.ToBuilder().MergeFrom(msg).Build();
            Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #8
0
        public void TestAllTypesModifiedRoundTrip()
        {
            TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;

            msg.ToBuilder()
            .SetOptionalBool(true)
            .SetOptionalCord("Hi")
            .SetOptionalDouble(1.123)
            .SetOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO)
            .SetOptionalForeignMessage(ForeignMessageLite.CreateBuilder().SetC('c').Build())
            .SetOptionalGroup(TestAllTypesLite.Types.OptionalGroup.CreateBuilder().SetA('a').Build())
            .SetOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
            .SetOptionalInt32(32)
            .SetOptionalInt64(64)
            .SetOptionalNestedEnum(TestAllTypesLite.Types.NestedEnum.FOO)
            .SetOptionalString("SetOptionalString")
            .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('a').Build())
            .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('A').Build())
            ;
            TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();

            TestUtil.AssertBytesEqual(msg.ToByteArray(), copy.ToByteArray());
        }
예제 #9
0
        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);
        }