Skip to content

Commit

Permalink
Adds tests to avoid json_object_set_* memory leaks (fixed in 39c2d51).
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabis committed Nov 12, 2019
1 parent 39c2d51 commit 2be6991
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void test_suite_8(void); /* Test serialization */
void test_suite_9(void); /* Test serialization (pretty) */
void test_suite_10(void); /* Testing for memory leaks */
void test_suite_11(void); /* Additional things that require testing */
void test_memory_leaks(void);

void print_commits_info(const char *username, const char *repo);
void persistence_example(void);
Expand Down Expand Up @@ -84,6 +85,7 @@ int main() {
test_suite_9();
test_suite_10();
test_suite_11();
test_memory_leaks();

printf("Tests failed: %d\n", tests_failed);
printf("Tests passed: %d\n", tests_passed);
Expand Down Expand Up @@ -561,6 +563,17 @@ void test_suite_11() {
TEST(STREQ(array_with_escaped_slashes, serialized));
}

void test_memory_leaks() {
malloc_count = 0;

TEST(json_object_set_string(NULL, "lorem", "ipsum") == JSONFailure);
TEST(json_object_set_number(NULL, "lorem", 42) == JSONFailure);
TEST(json_object_set_boolean(NULL, "lorem", 0) == JSONFailure);
TEST(json_object_set_null(NULL, "lorem") == JSONFailure);

TEST(malloc_count == 0);
}

void print_commits_info(const char *username, const char *repo) {
JSON_Value *root_value;
JSON_Array *commits;
Expand Down

0 comments on commit 2be6991

Please sign in to comment.