public void TestRoundTripNegativeEnums()
        {
            NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder()
                                      .SetValue(NegativeEnum.MinusOne)         //11
                                      .AddValues(NegativeEnum.Zero)            //2
                                      .AddValues(NegativeEnum.MinusOne)        //11
                                      .AddValues(NegativeEnum.FiveBelow)       //11
                                                                               //2
                                      .AddPackedValues(NegativeEnum.Zero)      //1
                                      .AddPackedValues(NegativeEnum.MinusOne)  //10
                                      .AddPackedValues(NegativeEnum.FiveBelow) //10
                                      .Build();

            Assert.AreEqual(58, msg.SerializedSize);

            byte[]            bytes  = new byte[58];
            CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);

            msg.WriteTo(output);
            Assert.AreEqual(0, output.SpaceLeft);

            NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes);

            Assert.AreEqual(msg, copy);
        }
        public void TestRoundTripNegativeEnums()
        {
            NegativeEnumMessage msg = new NegativeEnumMessage
            {
                Value = NegativeEnum.MinusOne,
                Values = { NegativeEnum.NEGATIVE_ENUM_ZERO, NegativeEnum.MinusOne, NegativeEnum.FiveBelow },
                PackedValues = { NegativeEnum.NEGATIVE_ENUM_ZERO, NegativeEnum.MinusOne, NegativeEnum.FiveBelow }
            };

            Assert.AreEqual(58, msg.CalculateSize());

            byte[] bytes = new byte[58];
            CodedOutputStream output = new CodedOutputStream(bytes);

            msg.WriteTo(output);
            Assert.AreEqual(0, output.SpaceLeft);

            NegativeEnumMessage copy = NegativeEnumMessage.Parser.ParseFrom(bytes);
            Assert.AreEqual(msg, copy);
        }
示例#3
0
        public void TestRoundTripNegativeEnums()
        {
            NegativeEnumMessage msg = new NegativeEnumMessage
            {
                Value = NegativeEnum.MinusOne,
                Values = { NegativeEnum.NEGATIVE_ENUM_ZERO, NegativeEnum.MinusOne, NegativeEnum.FiveBelow },
                PackedValues = { NegativeEnum.NEGATIVE_ENUM_ZERO, NegativeEnum.MinusOne, NegativeEnum.FiveBelow }
            };

            Assert.AreEqual(58, msg.CalculateSize());

            byte[] bytes = new byte[58];
            CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);

            msg.WriteTo(output);
            Assert.AreEqual(0, output.SpaceLeft);

            NegativeEnumMessage copy = NegativeEnumMessage.Parser.ParseFrom(bytes);
            Assert.AreEqual(msg, copy);
        }