Adds tests to avoid json_object_set_* memory leaks (fixed in 39c2d51).

This commit is contained in:
Krzysztof Gabis 2019-11-12 09:01:03 +01:00
parent 39c2d51c52
commit 2be6991d84

13
tests.c
View File

@ -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);
@ -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);
@ -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;