Ejemplo n.º 1
0
 @Test
 public void lastValueWinsForRepeatedValueOfNonrepeatedField() throws Exception {
   // tag 1 / type 0: 456
   // tag 1 / type 0: 789
   ByteString data = ByteString.decodeHex("08c803089506");
   OneField oneField = OneField.ADAPTER.decode(data.toByteArray());
   assertThat(new OneField.Builder().opt_int32(789).build()).isEqualTo(oneField);
 }
Ejemplo n.º 2
0
 @Ignore("TODO(jwilson)")
 @Test
 public void typeMismatchHonorsWireDeclaredType() throws Exception {
   // tag 1 / 3-byte length-delimited string: 0x109506
   // (0x109506 is a well-formed proto message that sets tag 2 to 456).
   ByteString data = ByteString.decodeHex("0a03109506");
   OneField oneField = OneField.ADAPTER.decode(data.toByteArray());
   assertThat(oneField).isEqualTo(new OneField.Builder().opt_int32(3).build());
 }
Ejemplo n.º 3
0
 @Test
 public void unknownTagIgnored() throws Exception {
   // tag 1 / type 0: 456
   // tag 2 / type 0: 789
   ByteString data = ByteString.decodeHex("08c803109506");
   OneField oneField = OneField.ADAPTER.decode(data.toByteArray());
   OneField expected = new OneField.Builder().opt_int32(456).build();
   assertThat(oneField).isNotEqualTo(expected);
   assertThat(oneField.withoutUnknownFields()).isEqualTo(expected);
 }
Ejemplo n.º 4
0
 @Test
 public void unknownTypeThrowsIOException() throws Exception {
   // tag 1 / type 0: 456
   // tag 2 / type 7: 789
   ByteString data = ByteString.decodeHex("08c803179506");
   try {
     OneField.ADAPTER.decode(data.toByteArray());
     fail();
   } catch (ProtocolException expected) {
     assertThat(expected).hasMessage("Unexpected field encoding: 7");
   }
 }
Ejemplo n.º 5
0
 @Ignore("we no longer enforce this constraint")
 @Test
 public void repeatedUnknownValueWithDifferentTypesThrowsIOException() throws Exception {
   // tag 2 / 3-byte length-delimited string: 0x109506
   // tag 2 / type 0: 456
   ByteString data = ByteString.decodeHex("120300000010c803");
   try {
     OneField.ADAPTER.decode(data.toByteArray());
     fail();
   } catch (ProtocolException expected) {
     assertThat(expected)
         .hasMessage("Wire type VARINT differs from previous type LENGTH_DELIMITED for tag 2");
   }
 }