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 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 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 } 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; }