Browse Source

update pointer test case

tags/json-c-0.14-20200419
dota17 5 years ago
parent
commit
48ae9e8874
2 changed files with 30 additions and 0 deletions
  1. +27
    -0
      tests/test_json_pointer.c
  2. +3
    -0
      tests/test_json_pointer.expected

+ 27
- 0
tests/test_json_pointer.c View File

@@ -146,6 +146,8 @@ static void test_recursion_get()
assert(json_object_is_type(jo2, json_type_string)); assert(json_object_is_type(jo2, json_type_string));
assert(0 == strcmp("1", json_object_get_string(jo2))); assert(0 == strcmp("1", json_object_get_string(jo2)));


assert(0 == json_pointer_getf(jo1, &jo2, "%s", "\0"));

printf("PASSED - GET - RECURSION TEST\n"); printf("PASSED - GET - RECURSION TEST\n");


json_object_put(jo1); json_object_put(jo1);
@@ -176,8 +178,14 @@ static void test_wrong_inputs_get()
assert(0 != json_pointer_get(NULL, NULL, NULL)); assert(0 != json_pointer_get(NULL, NULL, NULL));
assert(errno == EINVAL); assert(errno == EINVAL);
errno = 0; errno = 0;
assert(0 != json_pointer_getf(NULL, NULL, NULL));
assert(errno == EINVAL);
errno = 0;
assert(0 != json_pointer_get(jo1, NULL, NULL)); assert(0 != json_pointer_get(jo1, NULL, NULL));
assert(errno == EINVAL); assert(errno == EINVAL);
errno = 0;
assert(0 != json_pointer_getf(jo1, NULL, NULL));
assert(errno == EINVAL);
printf("PASSED - GET - NULL INPUTS\n"); printf("PASSED - GET - NULL INPUTS\n");


/* Test invalid indexes for array */ /* Test invalid indexes for array */
@@ -185,6 +193,9 @@ static void test_wrong_inputs_get()
assert(0 != json_pointer_get(jo1, "/foo/a", NULL)); assert(0 != json_pointer_get(jo1, "/foo/a", NULL));
assert(errno == EINVAL); assert(errno == EINVAL);
errno = 0; errno = 0;
assert(0 != json_pointer_get(jo1, "/foo/01", NULL));
assert(errno == EINVAL);
errno = 0;
assert(0 != json_pointer_getf(jo1, NULL, "/%s/a", "foo")); assert(0 != json_pointer_getf(jo1, NULL, "/%s/a", "foo"));
assert(errno == EINVAL); assert(errno == EINVAL);
errno = 0; errno = 0;
@@ -258,10 +269,24 @@ static void test_wrong_inputs_set()
printf("PASSED - SET - LOADED TEST JSON\n"); printf("PASSED - SET - LOADED TEST JSON\n");
printf("%s\n", json_object_get_string(jo1)); printf("%s\n", json_object_get_string(jo1));


assert(0 != json_pointer_set(NULL, NULL, NULL));
assert(0 != json_pointer_setf(NULL, NULL, NULL));
assert(0 != json_pointer_set(&jo1, NULL, NULL));
assert(0 != json_pointer_setf(&jo1, NULL, NULL));
printf("PASSED - SET - failed with NULL params for input json & path\n");

assert(0 != json_pointer_set(&jo1, "foo/bar", (jo2 = json_object_new_string("cod")))); assert(0 != json_pointer_set(&jo1, "foo/bar", (jo2 = json_object_new_string("cod"))));
printf("PASSED - SET - failed 'cod' with path 'foo/bar'\n"); printf("PASSED - SET - failed 'cod' with path 'foo/bar'\n");
json_object_put(jo2); json_object_put(jo2);


assert(0 != json_pointer_setf(&jo1, (jo2 = json_object_new_string("cod")), "%s", "foo/bar"));
printf("PASSED - SET - failed 'cod' with path 'foo/bar'\n");
json_object_put(jo2);

assert(0 != json_pointer_set(&jo1, "0", (jo2 = json_object_new_string("cod"))));
printf("PASSED - SET - failed with invalid array index'\n");
json_object_put(jo2);

jo2 = json_object_new_string("whatever"); jo2 = json_object_new_string("whatever");
assert(0 != json_pointer_set(&jo1, "/fud/gaw", jo2)); assert(0 != json_pointer_set(&jo1, "/fud/gaw", jo2));
assert(0 == json_pointer_set(&jo1, "/fud", json_object_new_object())); assert(0 == json_pointer_set(&jo1, "/fud", json_object_new_object()));
@@ -276,6 +301,8 @@ static void test_wrong_inputs_set()
json_object_put(jo2); json_object_put(jo2);
printf("PASSED - SET - failed to set index to non-array\n"); printf("PASSED - SET - failed to set index to non-array\n");


assert(0 == json_pointer_setf(&jo1, json_object_new_string("cod"), "%s", "\0"));

json_object_put(jo1); json_object_put(jo1);
} }




+ 3
- 0
tests/test_json_pointer.expected View File

@@ -32,5 +32,8 @@ PASSED - SET - Final JSON is: { "foo": [ "bar", "cod" ], "": 9, "a\/b": 1, "c%d"
10 10
PASSED - SET - LOADED TEST JSON PASSED - SET - LOADED TEST JSON
{ "foo": [ "bar", "baz" ], "": 0, "a\/b": 1, "c%d": 2, "e^f": 3, "g|h": 4, "i\\j": 5, "k\"l": 6, " ": 7, "m~n": 8 } { "foo": [ "bar", "baz" ], "": 0, "a\/b": 1, "c%d": 2, "e^f": 3, "g|h": 4, "i\\j": 5, "k\"l": 6, " ": 7, "m~n": 8 }
PASSED - SET - failed with NULL params for input json & path
PASSED - SET - failed 'cod' with path 'foo/bar' PASSED - SET - failed 'cod' with path 'foo/bar'
PASSED - SET - failed 'cod' with path 'foo/bar'
PASSED - SET - failed with invalid array index'
PASSED - SET - failed to set index to non-array PASSED - SET - failed to set index to non-array

Loading…
Cancel
Save