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
a3e2e20e
Commit
a3e2e20e
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
prepare nested array cmocka test
parent
83329806
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/api_test.c
+30
-1
30 additions, 1 deletion
test/api_test.c
with
30 additions
and
1 deletion
test/api_test.c
+
30
−
1
View file @
a3e2e20e
...
@@ -290,7 +290,7 @@ static void test_json_add_array_nested_object(void **state)
...
@@ -290,7 +290,7 @@ static void test_json_add_array_nested_object(void **state)
json_object_object_add
(
file_obj
,
"array"
,
arr
);
json_object_object_add
(
file_obj
,
"array"
,
arr
);
set_by_string
(
NULL
,
&
modify_obj
,
"{
\"
array
\"
: [{
\"
nested
\"
: {
\"
nested1
\"
: {
\"
integer
\"
: 1}}}]}"
,
json_type_object
);
set_by_string
(
NULL
,
&
modify_obj
,
"{
\"
array
\"
: [{
\"
nested
\"
: {
\"
nested1
\"
: {
\"
integer
\"
: 1}}}]}"
,
json_type_object
);
set_by_string
(
"array[
-1
].nested.nested1.integer"
,
&
modify_obj
,
"1"
,
json_type_int
);
set_by_string
(
"array[
5
].nested.nested1.integer"
,
&
modify_obj
,
"1"
,
json_type_int
);
set_by_string
(
"array[-1].nested.nested1"
,
&
modify_obj
,
"{
\"
integer
\"
: 1}"
,
json_type_object
);
set_by_string
(
"array[-1].nested.nested1"
,
&
modify_obj
,
"{
\"
integer
\"
: 1}"
,
json_type_object
);
set_by_string
(
"array[-1].nested"
,
&
modify_obj
,
"{
\"
nested1
\"
: {
\"
integer
\"
: 1}}"
,
json_type_object
);
set_by_string
(
"array[-1].nested"
,
&
modify_obj
,
"{
\"
nested1
\"
: {
\"
integer
\"
: 1}}"
,
json_type_object
);
set_by_string
(
"array[-1]"
,
&
modify_obj
,
"{
\"
nested
\"
: {
\"
nested1
\"
: {
\"
integer
\"
: 1}}}"
,
json_type_object
);
set_by_string
(
"array[-1]"
,
&
modify_obj
,
"{
\"
nested
\"
: {
\"
nested1
\"
: {
\"
integer
\"
: 1}}}"
,
json_type_object
);
...
@@ -301,6 +301,34 @@ static void test_json_add_array_nested_object(void **state)
...
@@ -301,6 +301,34 @@ static void test_json_add_array_nested_object(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
}
static
void
test_json_add_array_nested_array
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
arr
=
json_object_new_array
();
struct
json_object
*
nested_arr
=
json_object_new_array
();
struct
json_object
*
nested1_arr
=
json_object_new_array
();
json_object_array_add
(
nested_arr
,
json_object_new_int
(
1
));
json_object_array_add
(
nested_arr
,
json_object_new_int
(
2
));
json_object_array_add
(
nested_arr
,
json_object_new_int
(
3
));
json_object_array_add
(
nested1_arr
,
json_object_new_int
(
5
));
json_object_array_add
(
nested1_arr
,
json_object_new_int
(
6
));
json_object_array_add
(
nested1_arr
,
json_object_new_int
(
7
));
json_object_array_add
(
arr
,
nested_arr
);
json_object_array_add
(
arr
,
nested1_arr
);
json_object_object_add
(
file_obj
,
"array"
,
arr
);
set_by_string
(
"array[0][0]"
,
&
modify_obj
,
"1"
,
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
));
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
int
setup
(
void
**
state
)
{
static
int
setup
(
void
**
state
)
{
file_obj
=
path_to_obj
(
"/home/jakob/git/json-editor-api/test.json"
);
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"
);
modify_obj
=
path_to_obj
(
"/home/jakob/git/json-editor-api/test.json"
);
...
@@ -329,6 +357,7 @@ int main(void) {
...
@@ -329,6 +357,7 @@ int main(void) {
cmocka_unit_test_setup_teardown
(
test_json_add_array_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_nested_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_nested_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_nested_array
,
setup
,
teardown
),
};
};
return
cmocka_run_group_tests
(
tests
,
NULL
,
NULL
);
return
cmocka_run_group_tests
(
tests
,
NULL
,
NULL
);
...
...
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