From e0e9fccea09461cf9b48c5c843830b7c3dc54d47 Mon Sep 17 00:00:00 2001 From: Richard Giliam Date: Wed, 31 Jul 2024 16:54:53 -0700 Subject: [PATCH] Adjust test name, and add zero length blob reading test for text --- test/test_ion_binary.cpp | 2 +- test/test_ion_text.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test_ion_binary.cpp b/test/test_ion_binary.cpp index a9b2ec3..558b0d6 100644 --- a/test/test_ion_binary.cpp +++ b/test/test_ion_binary.cpp @@ -635,7 +635,7 @@ TEST(IonBinaryBlob, CanFullyReadBlobUsingPartialReads) { // Simple test to ensure that if we supply a buffer size of 0 to ion_reader_read_lob_bytes, we don't assert. If the user // is reading values via the LOB size, and does not specifically handle 0-lengthed LOBs the reader shouldn't fail. -TEST(IonBinaryBlob, CanReadZeroLengthBlobWithLobLength) { +TEST(IonBinaryBlob, CanReadZeroLength) { hREADER reader; ION_TYPE type; const char *buffer = "\xE0\x01\x00\xEA\xA0"; diff --git a/test/test_ion_text.cpp b/test/test_ion_text.cpp index ad470b4..8836107 100644 --- a/test/test_ion_text.cpp +++ b/test/test_ion_text.cpp @@ -657,6 +657,25 @@ TEST(IonTextBlob, CanReadBlob) { tid_BLOB, 23, "This is a BLOB of text."); } +TEST(IonTextBlob, CanReadZeroLength) { + hREADER reader; + ION_TYPE type; + const char *buffer = "{{}}"; + char bytes[1]; // Shouldn't write any.. + + SIZE lob_size, bytes_read; + ION_ASSERT_OK(ion_reader_open_buffer(&reader, (BYTE*)buffer, 4, NULL)); + + ION_ASSERT_OK(ion_reader_next(reader, &type)); + ASSERT_EQ(tid_BLOB, type); + ION_ASSERT_OK(ion_reader_get_lob_size(reader, &lob_size)); + ASSERT_EQ(0, lob_size); + ION_ASSERT_OK(ion_reader_read_lob_bytes(reader, (BYTE*)bytes, lob_size, &bytes_read)); + ASSERT_EQ(0, bytes_read); + + ION_ASSERT_OK(ion_reader_close(reader)); +} + void test_text_list(const char *ion_text) { ION_TYPE expected_tid = tid_LIST;