MDEV-18318 Unit tests for the Json_writer#4731
Open
varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
Open
MDEV-18318 Unit tests for the Json_writer#4731varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
Conversation
gkodinov
requested changes
Mar 4, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Please rebase to 10.11: this is enhanced test coverage and as such it should go to the earliest maintained version where the functionality was first pushed.
Please also make sure the commit message of your commit complies with CODING_STANDARDS.md.
Few testing ideas to increase coverage are listed below.
7717e5e to
cab7a58
Compare
cab7a58 to
1f21dc3
Compare
67a2427 to
6bce763
Compare
gkodinov
approved these changes
Mar 4, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
LGTM. Let's leave the rest of it for the final reviewer.
Please stand by for the final review.
e68f29a to
7afb4c5
Compare
Member
|
And notably correct the Windows compiling error |
be7c298 to
cb1cf0f
Compare
Add 104 TAP unit tests for the Json_writer class covering: - Invalid JSON detection (unnamed values in objects, named values in arrays, mismatched open/close) - Output verification for all value types (strings, integers, unsigned integers, booleans, null, doubles, sizes) - Edge cases: LLONG_MAX/MIN, ULLONG_MAX, special doubles (0.0, -0.0), Latin-1 and UTF-8 mb4 encoded strings, embedded NUL bytes in keys and values, duplicate key names - add_member(name, len) explicit key length - Single-line formatting helper including long-element fallback and embedded-NUL disable behavior - Nested structures (objects in objects, arrays of objects, mixed) - RAII wrappers (Json_writer_object, Json_writer_array) including ulonglong add overload preserving unsigned range - String_with_limit truncation behavior - Json_writer size limit enforcement with exact truncation count - add_size formatting (bytes, Kb, Mb) with boundary tests - Positive-path test for add(name, value, num_bytes) overload Also fix a missing my_writer NULL guard in Json_writer_object::add(const char*, const char*, size_t) which would crash when used with a NULL writer. Harden Single_line_formatting_helper against embedded NUL bytes: on_add_member() now rejects keys containing NUL, and on_add_str() disables single-line mode and flushes when a value contains NUL. Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
cb1cf0f to
86ed877
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add 104 TAP unit tests for the
Json_writerclass, plus two small production code fixes discovered during test development.Unit tests (
unittest/sql/my_json_writer-t.cc)LLONG_MAX/LLONG_MIN,ULLONG_MAX, special doubles (0.0,-0.0), Latin-1 and UTF-8 mb4 encoded strings, embedded NUL bytes in keys and values, duplicate key namesadd_member(name, len)explicit key length semanticsJson_writer_object,Json_writer_array) includingulonglongadd overload preserving unsigned rangeString_with_limittruncation behaviorJson_writersize limit enforcement with exact truncation countadd_sizeformatting (bytes, Kb, Mb) with boundary testsadd(name, value, num_bytes)overloadProduction code fixes
sql/my_json_writer.h: Fix missingmy_writerNULL guard inJson_writer_object::add(const char*, const char*, size_t)which would crash when used with a NULL writer (ignore mode).sql/my_json_writer.cc: HardenSingle_line_formatting_helperagainst embedded NUL bytes —on_add_member()now rejects keys containing NUL, andon_add_str()disables single-line mode and flushes when a value contains NUL.