From 95ef4134d3f65237b7adfb66e5e7aa10fcfa1fa3 Mon Sep 17 00:00:00 2001 From: Mark Hansen Date: Mon, 23 Sep 2024 14:51:15 -0700 Subject: [PATCH] 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 --- .../com/google/protobuf/CodedOutputStreamTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 9e6529696a..2e87a10a59 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/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); + } } }