X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fcurl_json_test.c;h=6c8640c2448bb75fc86b199cfee272f64c95599c;hp=255d14b8cbecee3ad1bef1ef4d20af55904e49d3;hb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;hpb=798339ec371ea2f38ef4f2090a9bb98b766da44b diff --git a/src/curl_json_test.c b/src/curl_json_test.c index 255d14b8..6c8640c2 100644 --- a/src/curl_json_test.c +++ b/src/curl_json_test.c @@ -47,13 +47,15 @@ static cj_t *test_setup(char *json, char *key_path) { db->curl = (void *)cj_avl_create(); cj_key_t *key = calloc(1, sizeof(*key)); - key->magic = CJ_KEY_MAGIC; key->path = strdup(key_path); key->type = strdup("MAGIC"); assert(cj_append_key(db, key) == 0); - db->state[0].tree = db->tree; + cj_tree_entry_t root = {0}; + root.type = TREE; + root.tree = db->tree; + db->state[0].entry = &root; cj_curl_callback(json, strlen(json), 1, db); #if HAVE_YAJL_V2 @@ -62,6 +64,8 @@ static cj_t *test_setup(char *json, char *key_path) { yajl_parse_complete(db->yajl); #endif + db->state[0].entry = NULL; + return db; } @@ -89,16 +93,39 @@ DEF_TEST(parse) { char *key_path; derive_t want; } cases[] = { + /* simple map */ {"{\"foo\":42,\"bar\":23}", "foo", 42}, {"{\"foo\":42,\"bar\":23}", "bar", 23}, + /* nested map */ {"{\"a\":{\"b\":{\"c\":123}}", "a/b/c", 123}, {"{\"x\":{\"y\":{\"z\":789}}", "x/*/z", 789}, - // {"[10,11,12,13]", "0", 10}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/0", 10}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/1", 11}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/2", 12}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/3", 13}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/4", 14}, + /* simple array */ + {"[10,11,12,13]", "0", 10}, + {"[10,11,12,13]", "1", 11}, + {"[10,11,12,13]", "2", 12}, + {"[10,11,12,13]", "3", 13}, + /* array index after non-numeric entry */ + {"[true,11]", "1", 11}, + {"[null,11]", "1", 11}, + {"[\"s\",11]", "1", 11}, + {"[{\"k\":\"v\"},11]", "1", 11}, + {"[[0,1,2],11]", "1", 11}, + /* nested array */ + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/0", 0}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/1", 1}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/2", 2}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/0", 3}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/1", 4}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/2", 5}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/0", 6}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/1", 7}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/2", 8}, + /* testcase from #2266 */ + {"{\"a\":[[10,11,12,13,14]]}", "a/0/0", 10}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/1", 11}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/2", 12}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/3", 13}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/4", 14}, }; for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { @@ -112,7 +139,7 @@ DEF_TEST(parse) { return 0; } -int main(int argc, char **argv) { +int main(void) { cj_submit = test_submit; RUN_TEST(parse);