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
c870d756
Commit
c870d756
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
add failure verification tests
parent
f38670f0
No related branches found
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
+75
-0
75 additions, 0 deletions
test/api_test.c
with
75 additions
and
0 deletions
test/api_test.c
+
75
−
0
View file @
c870d756
...
@@ -540,6 +540,77 @@ static void test_json_write_to_file(void **state)
...
@@ -540,6 +540,77 @@ static void test_json_write_to_file(void **state)
json_object_put
(
obj
);
json_object_put
(
obj
);
}
}
static
void
test_json_set_object_invalid_format
(
void
**
state
)
{
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
struct
json_object
*
obj
=
json_object_new_object
();
json_object_object_add
(
obj
,
"test2"
,
json_object_new_string
(
"success"
));
json_object_object_add
(
e
->
file_obj
,
"string"
,
obj
);
json_object_set_by_string
(
&
e
->
modify_obj
,
"string"
,
"{
\"
test2
\"
:
\"
success
\"
"
,
json_type_object
);
printf
(
"e->file_obj=%s
\n
"
,
json_object_get_string
(
e
->
file_obj
));
printf
(
"e->modify_obj=%s
\n
"
,
json_object_get_string
(
e
->
modify_obj
));
assert_non_null
(
e
->
file_obj
);
assert_non_null
(
e
->
modify_obj
);
assert_int_not_equal
(
1
,
json_object_equal
(
e
->
modify_obj
,
e
->
file_obj
));
}
static
void
test_json_set_array_invalid_format
(
void
**
state
)
{
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
struct
json_object
*
arr
=
json_object_new_array
();
json_object_array_add
(
arr
,
json_object_new_int
(
1
));
json_object_array_add
(
arr
,
json_object_new_int
(
2
));
json_object_array_add
(
arr
,
json_object_new_int
(
3
));
json_object_object_add
(
e
->
file_obj
,
"ints"
,
arr
);
json_object_set_by_string
(
&
e
->
modify_obj
,
"ints"
,
"[ 1, 2 3 ]"
,
json_type_array
);
printf
(
"e->file_obj=%s
\n
"
,
json_object_get_string
(
e
->
file_obj
));
printf
(
"e->modify_obj=%s
\n
"
,
json_object_get_string
(
e
->
modify_obj
));
assert_non_null
(
e
->
file_obj
);
assert_non_null
(
e
->
modify_obj
);
assert_int_not_equal
(
1
,
json_object_equal
(
e
->
modify_obj
,
e
->
file_obj
));
}
static
void
test_json_set_wrong_type_string_to_int
(
void
**
state
)
{
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
json_object_object_add
(
e
->
file_obj
,
"string"
,
json_object_new_string
(
"abc"
));
json_object_set_by_string
(
&
e
->
modify_obj
,
"string"
,
"abc"
,
json_type_int
);
printf
(
"e->file_obj=%s
\n
"
,
json_object_get_string
(
e
->
file_obj
));
printf
(
"e->modify_obj=%s
\n
"
,
json_object_get_string
(
e
->
modify_obj
));
assert_non_null
(
e
->
file_obj
);
assert_non_null
(
e
->
modify_obj
);
assert_int_not_equal
(
1
,
json_object_equal
(
e
->
modify_obj
,
e
->
file_obj
));
}
static
void
test_json_set_wrong_type_int_to_string
(
void
**
state
)
{
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
json_object_object_add
(
e
->
file_obj
,
"string"
,
json_object_new_int
(
1
));
json_object_set_by_string
(
&
e
->
modify_obj
,
"string"
,
"1"
,
json_type_string
);
printf
(
"e->file_obj=%s
\n
"
,
json_object_get_string
(
e
->
file_obj
));
printf
(
"e->modify_obj=%s
\n
"
,
json_object_get_string
(
e
->
modify_obj
));
assert_non_null
(
e
->
modify_obj
);
assert_int_not_equal
(
1
,
json_object_equal
(
e
->
modify_obj
,
e
->
file_obj
));
}
static
int
setup
(
void
**
state
)
{
static
int
setup
(
void
**
state
)
{
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
struct
test_env
*
e
=
(
struct
test_env
*
)
*
state
;
...
@@ -600,6 +671,10 @@ int main(void) {
...
@@ -600,6 +671,10 @@ int main(void) {
cmocka_unit_test_setup_teardown
(
test_json_get_array_nested_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_array_nested_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_object_array_nested_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_object_array_nested_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_write_to_file
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_write_to_file
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_object_invalid_format
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array_invalid_format
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_wrong_type_string_to_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_wrong_type_int_to_string
,
setup
,
teardown
),
};
};
return
cmocka_run_group_tests
(
tests
,
group_setup
,
group_teardown
);
return
cmocka_run_group_tests
(
tests
,
group_setup
,
group_teardown
);
...
...
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