Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IOPSYS
json-editor
Commits
dd9ab7fb
Commit
dd9ab7fb
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
add test.json, make relative path
parent
47bf50f5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.c
+1
-1
1 addition, 1 deletion
api.c
test.json
+21
-0
21 additions, 0 deletions
test.json
test/api_test.c
+68
-25
68 additions, 25 deletions
test/api_test.c
with
90 additions
and
26 deletions
api.c
+
1
−
1
View file @
dd9ab7fb
...
...
@@ -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__
);
...
...
This diff is collapsed.
Click to expand it.
test.json
0 → 100644
+
21
−
0
View file @
dd9ab7fb
{
"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
}
]
}
}
This diff is collapsed.
Click to expand it.
test/api_test.c
+
68
−
25
View file @
dd9ab7fb
...
...
@@ -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
,
"array
1
"
,
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
,
"array
1
[-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
,
"array
123
"
,
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
,
"array
123
[-1].integer"
,
"1"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[0].string"
,
"test"
,
json_type_string
);
set_by_string
(
&
modify_obj
,
"array
123
[-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
,
"array
123
"
,
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
,
"{
\"
array
123
\"
: [{
\"
nested
\"
: {
\"
nested1
\"
: {
\"
integer
\"
: 1}}}]}"
,
json_type_object
);
set_by_string
(
&
modify_obj
,
"array
123
[5].nested.nested1.integer"
,
"1"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[-1].nested.nested1"
,
"{
\"
integer
\"
: 1}"
,
json_type_object
);
set_by_string
(
&
modify_obj
,
"array
123
[-1].nested"
,
"{
\"
nested1
\"
: {
\"
integer
\"
: 1}}"
,
json_type_object
);
set_by_string
(
&
modify_obj
,
"array
123
[-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
,
"array
123
"
,
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
,
"array
123
[0][0]"
,
"1"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[0][1]"
,
"2"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[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
,
"array
123
[1][-1]"
,
"5"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[1][-1]"
,
"6"
,
json_type_int
);
set_by_string
(
&
modify_obj
,
"array
123
[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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment