diff options
author | Lloyd Hilaiel <lloyd@hilaiel.com> | 2011-04-21 09:36:26 -0600 |
---|---|---|
committer | Lloyd Hilaiel <lloyd@hilaiel.com> | 2011-04-21 13:55:45 -0600 |
commit | 0858bb341280956947df1cfae33eb5ac6ecfe6f7 (patch) | |
tree | 2f61e004f7a892f00f6f34d38a8a194618400b59 /test | |
parent | 6aefdaab38d81f33c46e33353c5a156884ea022d (diff) | |
download | yajl-0858bb341280956947df1cfae33eb5ac6ecfe6f7.tar.gz |
rework programmatic configuration of yajl. both generator and parser now have a yajl_XXX_config() function that accepts varargs so that configuration is simple, and new config options can be added in the future that preserve backwards binary compatibility. closes #23.
Diffstat (limited to 'test')
-rw-r--r-- | test/cases/ac_difficult_json_c_test_case_with_comments.json (renamed from test/cases/difficult_json_c_test_case_with_comments.json) | 0 | ||||
-rw-r--r-- | test/cases/ac_difficult_json_c_test_case_with_comments.json.gold (renamed from test/cases/difficult_json_c_test_case_with_comments.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ac_simple_with_comments.json (renamed from test/cases/dc_simple_with_comments.json) | 0 | ||||
-rw-r--r-- | test/cases/ac_simple_with_comments.json.gold | 9 | ||||
-rw-r--r-- | test/cases/ag_false_then_garbage.json (renamed from test/cases/false_then_garbage.json) | 0 | ||||
-rw-r--r-- | test/cases/ag_false_then_garbage.json.gold (renamed from test/cases/false_then_garbage.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ag_null_then_garbage.json (renamed from test/cases/null_then_garbage.json) | 0 | ||||
-rw-r--r-- | test/cases/ag_null_then_garbage.json.gold (renamed from test/cases/null_then_garbage.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ag_true_then_garbage.json (renamed from test/cases/true_then_garbage.json) | 0 | ||||
-rw-r--r-- | test/cases/ag_true_then_garbage.json.gold (renamed from test/cases/true_then_garbage.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ap_array_open.json (renamed from test/cases/array_open.json) | 0 | ||||
-rw-r--r-- | test/cases/ap_array_open.json.gold (renamed from test/cases/array_open.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ap_eof_str.json (renamed from test/cases/eof_str.json) | 0 | ||||
-rw-r--r-- | test/cases/ap_eof_str.json.gold (renamed from test/cases/eof_str.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ap_map_open.json (renamed from test/cases/map_open.json) | 0 | ||||
-rw-r--r-- | test/cases/ap_map_open.json.gold (renamed from test/cases/map_open.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/ap_partial_ok.json (renamed from test/cases/partial_ok.json) | 0 | ||||
-rw-r--r-- | test/cases/ap_partial_ok.json.gold (renamed from test/cases/partial_ok.json.gold) | 0 | ||||
-rw-r--r-- | test/cases/dc_simple_with_comments.json.gold | 5 | ||||
-rw-r--r-- | test/cases/multiple.json.gold | 1 | ||||
-rw-r--r-- | test/cases/simple_with_comments.json.gold | 6 | ||||
-rwxr-xr-x | test/run_tests.sh | 43 | ||||
-rw-r--r-- | test/yajl_test.c | 25 |
23 files changed, 47 insertions, 42 deletions
diff --git a/test/cases/difficult_json_c_test_case_with_comments.json b/test/cases/ac_difficult_json_c_test_case_with_comments.json index 2463c71..2463c71 100644 --- a/test/cases/difficult_json_c_test_case_with_comments.json +++ b/test/cases/ac_difficult_json_c_test_case_with_comments.json diff --git a/test/cases/difficult_json_c_test_case_with_comments.json.gold b/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold index c3adc11..c3adc11 100644 --- a/test/cases/difficult_json_c_test_case_with_comments.json.gold +++ b/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold diff --git a/test/cases/dc_simple_with_comments.json b/test/cases/ac_simple_with_comments.json index 3b79bba..3b79bba 100644 --- a/test/cases/dc_simple_with_comments.json +++ b/test/cases/ac_simple_with_comments.json diff --git a/test/cases/ac_simple_with_comments.json.gold b/test/cases/ac_simple_with_comments.json.gold new file mode 100644 index 0000000..80fcad2 --- /dev/null +++ b/test/cases/ac_simple_with_comments.json.gold @@ -0,0 +1,9 @@ +map open '{' +key: 'this' +string: 'is' +key: 'really' +string: 'simple' +key: 'json' +string: 'right?' +map close '}' +memory leaks: 0 diff --git a/test/cases/false_then_garbage.json b/test/cases/ag_false_then_garbage.json index 78f4e96..78f4e96 100644 --- a/test/cases/false_then_garbage.json +++ b/test/cases/ag_false_then_garbage.json diff --git a/test/cases/false_then_garbage.json.gold b/test/cases/ag_false_then_garbage.json.gold index e55fa1f..e55fa1f 100644 --- a/test/cases/false_then_garbage.json.gold +++ b/test/cases/ag_false_then_garbage.json.gold diff --git a/test/cases/null_then_garbage.json b/test/cases/ag_null_then_garbage.json index 7b65b35..7b65b35 100644 --- a/test/cases/null_then_garbage.json +++ b/test/cases/ag_null_then_garbage.json diff --git a/test/cases/null_then_garbage.json.gold b/test/cases/ag_null_then_garbage.json.gold index 94ad0fa..94ad0fa 100644 --- a/test/cases/null_then_garbage.json.gold +++ b/test/cases/ag_null_then_garbage.json.gold diff --git a/test/cases/true_then_garbage.json b/test/cases/ag_true_then_garbage.json index 9151612..9151612 100644 --- a/test/cases/true_then_garbage.json +++ b/test/cases/ag_true_then_garbage.json diff --git a/test/cases/true_then_garbage.json.gold b/test/cases/ag_true_then_garbage.json.gold index 0858bf7..0858bf7 100644 --- a/test/cases/true_then_garbage.json.gold +++ b/test/cases/ag_true_then_garbage.json.gold diff --git a/test/cases/array_open.json b/test/cases/ap_array_open.json index 558ed37..558ed37 100644 --- a/test/cases/array_open.json +++ b/test/cases/ap_array_open.json diff --git a/test/cases/array_open.json.gold b/test/cases/ap_array_open.json.gold index 478b6b9..478b6b9 100644 --- a/test/cases/array_open.json.gold +++ b/test/cases/ap_array_open.json.gold diff --git a/test/cases/eof_str.json b/test/cases/ap_eof_str.json index 6a21793..6a21793 100644 --- a/test/cases/eof_str.json +++ b/test/cases/ap_eof_str.json diff --git a/test/cases/eof_str.json.gold b/test/cases/ap_eof_str.json.gold index 736730b..736730b 100644 --- a/test/cases/eof_str.json.gold +++ b/test/cases/ap_eof_str.json.gold diff --git a/test/cases/map_open.json b/test/cases/ap_map_open.json index 98232c6..98232c6 100644 --- a/test/cases/map_open.json +++ b/test/cases/ap_map_open.json diff --git a/test/cases/map_open.json.gold b/test/cases/ap_map_open.json.gold index ab1f33d..ab1f33d 100644 --- a/test/cases/map_open.json.gold +++ b/test/cases/ap_map_open.json.gold diff --git a/test/cases/partial_ok.json b/test/cases/ap_partial_ok.json index 2fbd027..2fbd027 100644 --- a/test/cases/partial_ok.json +++ b/test/cases/ap_partial_ok.json diff --git a/test/cases/partial_ok.json.gold b/test/cases/ap_partial_ok.json.gold index 9f754c7..9f754c7 100644 --- a/test/cases/partial_ok.json.gold +++ b/test/cases/ap_partial_ok.json.gold diff --git a/test/cases/dc_simple_with_comments.json.gold b/test/cases/dc_simple_with_comments.json.gold deleted file mode 100644 index d222e9b..0000000 --- a/test/cases/dc_simple_with_comments.json.gold +++ /dev/null @@ -1,5 +0,0 @@ -map open '{' -key: 'this' -string: 'is' -lexical error: probable comment found in input text, comments are not enabled. -memory leaks: 0 diff --git a/test/cases/multiple.json.gold b/test/cases/multiple.json.gold index c687717..0f6f3df 100644 --- a/test/cases/multiple.json.gold +++ b/test/cases/multiple.json.gold @@ -1,3 +1,4 @@ map open '{' map close '}' +parse error: trailing garbage memory leaks: 0 diff --git a/test/cases/simple_with_comments.json.gold b/test/cases/simple_with_comments.json.gold index 80fcad2..d222e9b 100644 --- a/test/cases/simple_with_comments.json.gold +++ b/test/cases/simple_with_comments.json.gold @@ -1,9 +1,5 @@ map open '{' key: 'this' string: 'is' -key: 'really' -string: 'simple' -key: 'json' -string: 'right?' -map close '}' +lexical error: probable comment found in input text, comments are not enabled. memory leaks: 0 diff --git a/test/run_tests.sh b/test/run_tests.sh index 9a7d0fc..0d75ed3 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -28,47 +28,54 @@ fi ${ECHO} "using test binary: $testBin" +testBinShort=`basename $testBin` + testsSucceeded=0 testsTotal=0 for file in cases/*.json ; do - allowComments="-c" - forbidGarbage="" + allowComments="" + allowGarbage="" allowMultiple="" - noPartials="" + allowPartials="" # if the filename starts with dc_, we disallow comments for this test case $(basename $file) in - dc_*) - allowComments="" + ac_*) + allowComments="-c " ;; - fg_*) - forbidGarbage="-g" + ag_*) + allowGarbage="-g " ;; am_*) - allowMultiple="-m"; + allowMultiple="-m "; ;; - np_*) - noPartials="-p"; + ap_*) + allowPartials="-p "; ;; esac - ${ECHO} -n " test case: '$file': " + fileShort=`basename $file` + testName=`echo $fileShort | sed -e 's/\.json$//'` + + ${ECHO} -n " test ($testName): " iter=1 - success="success" + success="SUCCESS" - ${ECHO} "$testBin $noPartials $allowComments $forbidGarbage $allowMultiple -b $iter < $file > ${file}.test " + ${ECHO} -n "$testBinShort $allowPartials$allowComments$allowGarbage$allowMultiple-b $iter < $fileShort > ${fileShort}.test : " # parse with a read buffer size ranging from 1-31 to stress stream parsing - while [ $iter -lt 32 ] && [ $success = "success" ] ; do - $testBin $noPartials $allowComments $forbidGarbage $allowMultiple -b $iter < $file > ${file}.test 2>&1 - diff ${DIFF_FLAGS} ${file}.gold ${file}.test + while [ $iter -lt 32 ] && [ $success = "SUCCESS" ] ; do + $testBin $allowPartials $allowComments $allowGarbage $allowMultiple -b $iter < $file > ${file}.test 2>&1 + diff ${DIFF_FLAGS} ${file}.gold ${file}.test > ${file}.out if [ $? -eq 0 ] ; then if [ $iter -eq 31 ] ; then : $(( testsSucceeded += 1)) ; fi - else + else success="FAILURE" iter=32 + ${ECHO} + cat ${file}.out fi : $(( iter += 1 )) - rm ${file}.test + rm ${file}.test ${file}.out done ${ECHO} $success diff --git a/test/yajl_test.c b/test/yajl_test.c index 1b07f8b..7d507f8 100644 --- a/test/yajl_test.c +++ b/test/yajl_test.c @@ -156,10 +156,10 @@ static void usage(const char * progname) "to stdout\n" " -b set the read buffer size\n" " -c allow comments\n" - " -g forbid *g*arbage after valid JSON text\n" + " -g allow *g*arbage after valid JSON text\n" " -m allows the parser to consume multiple JSON values\n" " from a single string separated by whitespace\n" - " -p partial JSON documents should be considered invalid\n", + " -p partial JSON documents should not cause errors\n", progname); exit(1); } @@ -173,9 +173,8 @@ main(int argc, char ** argv) size_t bufSize = BUF_SIZE; yajl_status stat; size_t rd; - yajl_parser_config cfg = { 0, 1 }; int i, j; - int multiple = 0 ,trailing = 0, partial = 0; + /* memory allocation debugging: allocate a structure which collects * statistics */ yajlTestMemoryContext memCtx = { 0,0 }; @@ -191,10 +190,13 @@ main(int argc, char ** argv) allocFuncs.ctx = (void *) &memCtx; + /* allocate the parser */ + hand = yajl_alloc(&callbacks, &allocFuncs, NULL); + /* check arguments. We expect exactly one! */ for (i=1;i<argc;i++) { if (!strcmp("-c", argv[i])) { - cfg.allowComments = 1; + yajl_config(hand, yajl_allow_comments, 1); } else if (!strcmp("-b", argv[i])) { if (++i >= argc) usage(argv[0]); @@ -212,11 +214,11 @@ main(int argc, char ** argv) bufSize); } } else if (!strcmp("-g", argv[i])) { - trailing = 1; + yajl_config(hand, yajl_allow_trailing_garbage, 1); } else if (!strcmp("-m", argv[i])) { - multiple = 1; partial = 1; + yajl_config(hand, yajl_allow_multiple_values, 1); } else if (!strcmp("-p", argv[i])) { - partial = 1; + yajl_config(hand, yajl_allow_partial_values, 1); } else { fprintf(stderr, "invalid command line option: '%s'\n", argv[i]); @@ -230,17 +232,12 @@ main(int argc, char ** argv) fprintf(stderr, "failed to allocate read buffer of %zu bytes, exiting.", bufSize); + yajl_free(hand); exit(2); } fileName = argv[argc-1]; - /* ok. open file. let's read and parse */ - hand = yajl_alloc(&callbacks, &cfg, &allocFuncs, NULL); - if (trailing) yajl_forbid_trailing_garbage(hand); - if (multiple) yajl_allow_multiple_values(hand); - if (partial) yajl_forbid_partial_values(hand); - for (;;) { rd = fread((void *) fileData, 1, bufSize, stdin); |