From aaae37afba8f3695bafff934dd259553c4aed974 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Tue, 26 Jan 2010 21:19:48 +0200 Subject: [PATCH 1/4] doc/Makefile.am: Don't remove changes.rst in clean --- doc/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile.am b/doc/Makefile.am index 1a3f560..d620775 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -16,4 +16,4 @@ uninstall-local: clean-local: rm -rf _build - rm -f ext/refcounting.pyc changes.rst + rm -f ext/refcounting.pyc From d8ea2f8c4b16d52d16d089de384b890c2201311f Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 28 Jan 2010 20:57:52 +0200 Subject: [PATCH 2/4] run-tests.sh: Print the test name correctly when VERBOSE=1 --- test/scripts/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/run-tests.sh b/test/scripts/run-tests.sh index 2559766..5d140ff 100644 --- a/test/scripts/run-tests.sh +++ b/test/scripts/run-tests.sh @@ -29,7 +29,7 @@ for test_path in $suite_srcdir/*; do rm -rf $test_log mkdir -p $test_log if [ $VERBOSE -eq 1 ]; then - echo -n "$name... " + echo -n "$test_name... " fi if run_test; then From ab2e56768571dbe555d6bd56d31af07771f1e3a9 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 28 Jan 2010 20:58:25 +0200 Subject: [PATCH 3/4] test/suites/api: Fail when a test fails The valgrind fix a while back apparently made the test system not notice normal failures in suites/api. --- test/suites/api/run | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/suites/api/run b/test/suites/api/run index 02e92b0..8688e0f 100755 --- a/test/suites/api/run +++ b/test/suites/api/run @@ -17,7 +17,8 @@ run_test() { else $test_runner $suite_builddir/${test_name%.c} \ >$test_log/stdout \ - 2>$test_log/stderr + 2>$test_log/stderr \ + || return 1 valgrind_check $test_log/stderr || return 1 fi } From f5662a82cd8fc4d5f43123ed81e5d4b7d5e34bb4 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 28 Jan 2010 21:04:21 +0200 Subject: [PATCH 4/4] test/suites/api/test_object.c: Enhance tests for iterators --- test/suites/api/test_object.c | 72 +++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c index 7e9ada8..849dac0 100644 --- a/test/suites/api/test_object.c +++ b/test/suites/api/test_object.c @@ -205,10 +205,68 @@ static void test_set_nocheck() json_decref(object); } +static void test_iterators() +{ + json_t *object, *foo, *bar, *baz; + void *iter; + + if(json_object_iter(NULL)) + fail("able to iterate over NULL"); + + if(json_object_iter_next(NULL, NULL)) + fail("able to increment an iterator on a NULL object"); + + object = json_object(); + foo = json_string("foo"); + bar = json_string("bar"); + baz = json_string("baz"); + if(!object || !foo || !bar || !bar) + fail("unable to create values"); + + if(json_object_iter_next(object, NULL)) + fail("able to increment a NULL iterator"); + + if(json_object_set(object, "a", foo) || + json_object_set(object, "b", bar) || + json_object_set(object, "c", baz)) + fail("unable to populate object"); + + iter = json_object_iter(object); + if(!iter) + fail("unable to get iterator"); + if(strcmp(json_object_iter_key(iter), "a")) + fail("iterating failed: wrong key"); + if(json_object_iter_value(iter) != foo) + fail("iterating failed: wrong value"); + + iter = json_object_iter_next(object, iter); + if(!iter) + fail("unable to increment iterator"); + if(strcmp(json_object_iter_key(iter), "b")) + fail("iterating failed: wrong key"); + if(json_object_iter_value(iter) != bar) + fail("iterating failed: wrong value"); + + iter = json_object_iter_next(object, iter); + if(!iter) + fail("unable to increment iterator"); + if(strcmp(json_object_iter_key(iter), "c")) + fail("iterating failed: wrong key"); + if(json_object_iter_value(iter) != baz) + fail("iterating failed: wrong value"); + + if(json_object_iter_next(object, iter) != NULL) + fail("able to iterate over the end"); + + json_decref(object); + json_decref(foo); + json_decref(bar); + json_decref(baz); +} + static void test_misc() { json_t *object, *string, *other_string, *value; - void *iter; object = json_object(); string = json_string("test"); @@ -231,17 +289,6 @@ static void test_misc() if(!json_object_set(object, "a", NULL)) fail("able to set NULL value"); - iter = json_object_iter(object); - if(!iter) - fail("unable to get iterator"); - - if(strcmp(json_object_iter_key(iter), "a")) - fail("iterating failed: wrong key"); - if(json_object_iter_value(iter) != string) - fail("iterating failed: wrong value"); - if(json_object_iter_next(object, iter) != NULL) - fail("able to iterate over the end"); - /* invalid UTF-8 in key */ if(!json_object_set(object, "a\xefz", string)) fail("able to set invalid unicode key"); @@ -332,6 +379,7 @@ int main() test_update(); test_circular(); test_set_nocheck(); + test_iterators(); return 0; }