diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-28 12:04:09 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-28 12:04:09 -0700 |
commit | fab83ed0ade087a4a55648fb09c0c9cc95295a3f (patch) | |
tree | 8096651c122293ba1c176085a014549c4a48f840 /tests/runner.py | |
parent | ed88bc7051a61e05c6e85e792d56513826722d2e (diff) | |
parent | f1e8583e475e32e47aa1fd7d42388b144604477b (diff) |
Merge pull request #651 from larsxschneider/json_parser
Fix -O1 warning and use proper pointers for Jansson library.
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/runner.py b/tests/runner.py index 5780b910..71acb4da 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -5324,13 +5324,29 @@ int main(int argc, char **argv) { json_error_t error; json_t *root = json_loadb(jsonString, strlen(jsonString), 0, &error); - if(!root || !json_is_object(root)) + if(!root) { + printf("Node `root` is `null`."); return 0; + } + + if(!json_is_object(root)) { + printf("Node `root` is no object."); + return 0; + } + printf("%s\\n", json_string_value(json_object_get(root, "key"))); json_t *array = json_object_get(root, "array"); - if(!array || !json_is_array(array)) + if(!array) { + printf("Node `array` is `null`."); + return 0; + } + + if(!json_is_array(array)) { + printf("Node `array` is no array."); return 0; + } + for(size_t i=0; i<json_array_size(array); ++i) { json_t *arrayNode = json_array_get(array, i); @@ -5349,11 +5365,17 @@ int main(int argc, char **argv) { if(!numberNode || !json_is_number(numberNode) || !floatNode || !json_is_real(floatNode)) return 0; - + printf("%i\\n", json_integer_value(numberNode)); printf("%.2f\\n", json_number_value(numberNode)); printf("%.2f\\n", json_real_value(floatNode)); + json_t *invalidNode = json_object_get(dict, "invalidNode"); + if(invalidNode) + return 0; + + printf("%i\\n", json_number_value(invalidNode)); + json_decref(root); if(!json_is_object(root)) @@ -5362,7 +5384,7 @@ int main(int argc, char **argv) { return 0; } ''' - self.do_run(src, 'value\narray_item1\narray_item2\narray_item3\n3\n3.00\n2.20\njansson!') + self.do_run(src, 'value\narray_item1\narray_item2\narray_item3\n3\n3.00\n2.20\nJansson: Node with ID `0` not found. Context has `10` nodes.\n0\nJansson: No JSON context.\njansson!') ### 'Medium' tests |