Skip to content
Snippets Groups Projects
Commit dd9ab7fb authored by Jakob Olsson's avatar Jakob Olsson
Browse files

add test.json, make relative path

parent 47bf50f5
No related branches found
No related tags found
No related merge requests found
......@@ -399,7 +399,7 @@ struct json_object *get(struct json_object *src, char *fmt)
int main()
{
struct json_object *obj = path_to_obj("/home/jakob/git/json-editor/test.json");
struct json_object *obj = path_to_obj("test.json");
struct json_object *ptr;
printf("%s %d\n", __func__, __LINE__);
......
{
"test":"success",
"nested": {
"api":"test2"
},
"integer": 1,
"array": [[1,2,3], [4,5,6]],
"complex_nested": {
"dummy": {},
"array": [
{
"test":"1",
"test2":2
},
{
"test": "3",
"test2": 4
}
]
}
}
......@@ -13,7 +13,7 @@ static void test_cfg_parse_success(void **state)
{
(void) state; /* unused */
struct json_object *file = path_to_obj("/home/jakob/git/json-editor-api/test.json");
struct json_object *file = path_to_obj("test.json");
struct json_object *obj = json_object_new_object();
struct json_object *tot = json_object_new_object();
......@@ -35,15 +35,58 @@ static void test_cfg_parse_fail(void **state)
if (obj)
json_object_put(obj);
}
/*
{
"test":"success",
"nested": {
"api":"test2"
},
"integer": 1,
"array": [[1, 2, 3],[3, 4, 5]],
"complex_nested": {
"dummy": {},
"array": [
{
"test":"1",
"test2":2
},
{
"test": "3",
"test2": 4
}
]
}
}
*/
static void test_build_from_scratch(void **state)
{
(void) state; /* unused */
struct json_object *file = path_to_obj("/home/jakob/git/json-editor-api/test.json");
struct json_object *file = path_to_obj("test.json");
struct json_object *jobj = NULL;
set_by_string(&jobj, NULL, "{ \"test\":\"success\", \"nested\": { \"api\":\"test2\"} }", json_type_object);
set_by_string(&jobj, NULL,
"{\
\"test\":\"success\",\
\"nested\": { \
\"api\":\"test2\"\
},\
\"integer\": 1,\
\"array\": [[1, 2, 3],[4, 5, 6]],\
\"complex_nested\": {\
\"dummy\": {},\
\"array\": [\
{\
\"test\":\"1\",\
\"test2\":2\
},\
{\
\"test\": \"3\",\
\"test2\": 4\
}\
]\
}\
}", json_type_object);
printf("file_obj=%s\n", json_object_get_string(file));
printf("modify_obj=%s\n", json_object_get_string(jobj));
......@@ -237,11 +280,11 @@ static void test_json_add_array_int(void **state)
struct json_object *obj = json_object_new_object();
json_object_array_add(arr, json_object_new_int(1));
json_object_object_add(file_obj, "array", arr);
json_object_object_add(file_obj, "array1", arr);
json_object_object_add(obj, "array", json_object_get(arr));
json_object_object_add(file_obj, "inner", obj);
set_by_string(&modify_obj, "array[-1]", "1", json_type_int);
set_by_string(&modify_obj, "array1[-1]", "1", json_type_int);
set_by_string(&modify_obj, "inner.array[-1]", "1", json_type_int);
printf("file_obj=%s\n", json_object_get_string(file_obj));
......@@ -263,11 +306,11 @@ static void test_json_add_array_object(void **state)
json_object_array_add(arr, obj);
json_object_array_add(arr, json_object_get(obj)); // array will now hold two references to the same object (will double free otherwise)
json_object_object_add(file_obj, "array", arr);
json_object_object_add(file_obj, "array123", arr);
set_by_string(&modify_obj, "array[-1].integer", "1", json_type_int);
set_by_string(&modify_obj, "array[0].string", "test", json_type_string);
set_by_string(&modify_obj, "array[-1]", "{\"integer\": 1, \"string\":\"test\"}", json_type_object);
set_by_string(&modify_obj, "array123[-1].integer", "1", json_type_int);
set_by_string(&modify_obj, "array123[0].string", "test", json_type_string);
set_by_string(&modify_obj, "array123[-1]", "{\"integer\": 1, \"string\":\"test\"}", json_type_object);
printf("file_obj=%s\n", json_object_get_string(file_obj));
printf("modify_obj=%s\n", json_object_get_string(modify_obj));
......@@ -292,13 +335,13 @@ static void test_json_add_array_nested_object(void **state)
json_object_array_add(arr, json_object_get(obj));
json_object_array_add(arr, json_object_get(obj));
json_object_array_add(arr, json_object_get(obj));
json_object_object_add(file_obj, "array", arr);
json_object_object_add(file_obj, "array123", arr);
set_by_string(&modify_obj, NULL, "{\"array\": [{\"nested\": {\"nested1\": {\"integer\": 1}}}]}", json_type_object);
set_by_string(&modify_obj, "array[5].nested.nested1.integer", "1", json_type_int);
set_by_string(&modify_obj, "array[-1].nested.nested1", "{\"integer\": 1}", json_type_object);
set_by_string(&modify_obj, "array[-1].nested", "{\"nested1\": {\"integer\": 1}}", json_type_object);
set_by_string(&modify_obj, "array[-1]", "{\"nested\": {\"nested1\": {\"integer\": 1}}}", json_type_object);
set_by_string(&modify_obj, NULL, "{\"array123\": [{\"nested\": {\"nested1\": {\"integer\": 1}}}]}", json_type_object);
set_by_string(&modify_obj, "array123[5].nested.nested1.integer", "1", json_type_int);
set_by_string(&modify_obj, "array123[-1].nested.nested1", "{\"integer\": 1}", json_type_object);
set_by_string(&modify_obj, "array123[-1].nested", "{\"nested1\": {\"integer\": 1}}", json_type_object);
set_by_string(&modify_obj, "array123[-1]", "{\"nested\": {\"nested1\": {\"integer\": 1}}}", json_type_object);
printf("file_obj=%s\n", json_object_get_string(file_obj));
printf("modify_obj=%s\n", json_object_get_string(modify_obj));
......@@ -324,16 +367,16 @@ static void test_json_add_array_nested_array(void **state)
json_object_array_add(arr, nested_arr);
json_object_array_add(arr, nested1_arr);
json_object_object_add(file_obj, "array", arr);
json_object_object_add(file_obj, "array123", arr);
//set_by_string("array[0][0].test", &modify_obj, "1", json_type_int);
set_by_string(&modify_obj, "array[0][0]", "1", json_type_int);
set_by_string(&modify_obj, "array[0][1]", "2", json_type_int);
set_by_string(&modify_obj, "array[0][2]", "3", json_type_int);
set_by_string(&modify_obj, "array123[0][0]", "1", json_type_int);
set_by_string(&modify_obj, "array123[0][1]", "2", json_type_int);
set_by_string(&modify_obj, "array123[0][2]", "3", json_type_int);
set_by_string(&modify_obj, "array[1][-1]", "5", json_type_int);
set_by_string(&modify_obj, "array[1][-1]", "6", json_type_int);
set_by_string(&modify_obj, "array[1][-1]", "7", json_type_int);
set_by_string(&modify_obj, "array123[1][-1]", "5", json_type_int);
set_by_string(&modify_obj, "array123[1][-1]", "6", json_type_int);
set_by_string(&modify_obj, "array123[1][-1]", "7", json_type_int);
printf("file_obj=%s\n", json_object_get_string(file_obj));
printf("modify_obj=%s\n", json_object_get_string(modify_obj));
......@@ -344,8 +387,8 @@ static void test_json_add_array_nested_array(void **state)
}
static int setup (void** state) {
file_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json");
modify_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json");
file_obj = path_to_obj("test.json");
modify_obj = path_to_obj("test.json");
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment