diff options
| author | chenzizhan <[email protected]> | 2023-08-02 13:50:44 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-08-02 13:50:44 +0800 |
| commit | d9046d02306bd1c821a0b717a49f9406c989468a (patch) | |
| tree | f16c73b98138ae6da2d04fa008d90d56232d8c69 /test/test_exporter_json.cpp | |
| parent | 6d5d6ed2d1ae63be9ded93ce6c211d562d0e1f97 (diff) | |
my build json
Diffstat (limited to 'test/test_exporter_json.cpp')
| -rw-r--r-- | test/test_exporter_json.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index 7757c5c..7c46f3e 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -398,6 +398,49 @@ TEST(export_test, skip_empty_metrics_given_cube_deleted) { cJSON_Delete(root_arr); } +extern "C" { +extern int add_object_to_json_array_start(char *buf, int buf_len); +extern int add_object_to_json_array_end(char **buf, int buf_len, int start); +extern int add_object_to_json_array(char **buf, int *buf_len, int start, const char *str); +} + +TEST(export_unit_test, test_add_json_length_is_on_margin_4096) +{ + int buf_len = 4096; // the initial buffer max len is 4096 + char *buf = (char *)malloc(buf_len); + char str[4096 + 1]; + memset(str, 'a', 4096); + str[4096] = '\0'; + + int used_len = add_object_to_json_array_start(buf, buf_len); + used_len = add_object_to_json_array(&buf, &buf_len, used_len, str); + used_len = add_object_to_json_array_end(&buf, buf_len, used_len); + + EXPECT_EQ(used_len, 4096 + 3); + std::string target = "[" + std::string(str) + "]"; + EXPECT_STREQ(buf, target.c_str()); + + free(buf); +} + +TEST(export_unit_test, test_add_json_length_is_on_margin_4095) +{ + int buf_len = 4096; // the initial buffer max len is 4096 + char *buf = (char *)malloc(buf_len); + char str[4096]; + memset(str, 'a', 4095); + str[4095] = '\0'; + + int used_len = add_object_to_json_array_start(buf, buf_len); + used_len = add_object_to_json_array(&buf, &buf_len, used_len, str); + used_len = add_object_to_json_array_end(&buf, buf_len, used_len); + + std::string target = "[" + std::string(str) + "]"; + EXPECT_STREQ(buf, target.c_str()); + + free(buf); +} + void init_hll_standard_oper() { g_hll_standard = ST_hyperloglog_new(12); |
