Add tests that CodedOutputStream.spaceLeft isn't negative after overflow.

For writing fixed32 and fixed64.

Not all encoders pass this test yet.

PiperOrigin-RevId: 677948616
pull/18446/head
Mark Hansen 6 months ago committed by Copybara-Service
parent 0e75d92cce
commit 95ef4134d3
  1. 12
      java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java

@ -294,6 +294,12 @@ public class CodedOutputStreamTest {
for (int i = 0; i < 4; i++) {
Coder coder = outputType.newCoder(i);
assertThrows(OutOfSpaceException.class, () -> coder.stream().writeFixed32NoTag(1));
// These OutputTypes are not behaving correctly yet.
if (outputType != OutputType.ARRAY
&& outputType != OutputType.NIO_HEAP
&& outputType != OutputType.NIO_HEAP_WITH_INITIAL_OFFSET) {
assertThat(coder.stream().spaceLeft()).isEqualTo(i);
}
}
}
@ -305,6 +311,12 @@ public class CodedOutputStreamTest {
for (int i = 0; i < 8; i++) {
Coder coder = outputType.newCoder(i);
assertThrows(OutOfSpaceException.class, () -> coder.stream().writeFixed64NoTag(1));
// These OutputTypes are not behaving correctly yet.
if (outputType != OutputType.ARRAY
&& outputType != OutputType.NIO_HEAP
&& outputType != OutputType.NIO_HEAP_WITH_INITIAL_OFFSET) {
assertThat(coder.stream().spaceLeft()).isEqualTo(i);
}
}
}

Loading…
Cancel
Save