コード例 #1
0
        public void TestLite()
        {
            // Since lite messages are a subset of regular messages, we can mostly
            // assume that the functionality of lite messages is already thoroughly
            // tested by the regular tests.  All this test really verifies is that
            // a proto with optimize_for = LITE_RUNTIME compiles correctly when
            // linked only against the lite library.  That is all tested at compile
            // time, leaving not much to do in this method.  Let's just do some random
            // stuff to make sure the lite message is actually here and usable.

            TestAllTypesLite message =
                TestAllTypesLite.CreateBuilder()
                .SetOptionalInt32(123)
                .AddRepeatedString("hello")
                .SetOptionalNestedMessage(
                    TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7))
                .Build();

            ByteString data = message.ToByteString();

            TestAllTypesLite message2 = TestAllTypesLite.ParseFrom(data);

            Assert.AreEqual(123, message2.OptionalInt32);
            Assert.AreEqual(1, message2.RepeatedStringCount);
            Assert.AreEqual("hello", message2.RepeatedStringList[0]);
            Assert.AreEqual(7, message2.OptionalNestedMessage.Bb);
        }