Skip to content

test(cpp): cover the decoder batch and exact-read contracts - #1135

Merged
ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:colin/cpp-decoder-contract-tests
Nov 20, 2026
Merged

ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:colin/cpp-decoder-contract-tests

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

Summary

encoding/decoder.h is the contract layer every codec derives from, but its base-class helpers had 60.9% line coverage because each concrete decoder overrides most entry points and the defaults are only used by a few codecs.

cpp/test/encoding/decoder_contract_test.cc adds a fake Decoder that implements only the abstract interface, so the shared helpers run directly:

  • default read_batch_int32/int64/float/double: capacity limits, exhaustion, and read-error propagation
  • default skip_int32/int64/float/double: clamping at end, zero/absent skips, and error propagation
  • read_exact_* / skip_exact_*: exact counts, the batch-then-single fallback, insufficient data, invalid arguments, and corrupt batch counts (E_TSFILE_CORRUPTED)
  • default block hooks (peek_next_block_range_int64, skip_peeked_block_int64), destroy(), owns_resources() and reset() reuse

Coverage of decoder.h: 60.9% -> 87.2% lines, 30/30 functions. The remaining lines are the float/double exact wrappers and template lines that gcov attributes to the calling translation units.

Test plan

  • ./mvnw -B clean verify -P with-java,with-python -Denable.lzma2=ON (Java, C++, Python; 1866 C++ tests passed)
  • ./mvnw -B clean verify -P with-cpp -Denable.asan=ON -Dbuild.type=RelWithDebInfo -Denable.lzma2=ON (1867 tests, 0 failed; macOS run used the Xcode 26.6 toolchain with ASAN_OPTIONS=detect_container_overflow=0 for the uninstrumented ANTLR runtime)
  • ./mvnw spotless:check -P with-java,with-python

Add a fake Decoder that implements only the abstract interface so the
base-class helpers can be exercised directly: default read_batch_* and
skip_* behaviour (capacity limits, exhaustion, error propagation),
read_exact_*/skip_exact_* (exact counts, insufficient data, invalid
arguments, corrupt batch counts), the default block hooks, and
destroy/owns_resources.

decoder.h: 60.9% -> 87.2% line coverage, 30/30 functions.
@ColinLeeo
ColinLeeo merged commit 5a51125 into apache:develop Nov 20, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant