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
e144f13d
Commit
e144f13d
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
add getter tests
parent
1f024b17
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
+158
-26
158 additions, 26 deletions
test/api_test.c
with
158 additions
and
26 deletions
test/api_test.c
+
158
−
26
View file @
e144f13d
...
...
@@ -95,7 +95,7 @@ static void test_build_from_scratch(void **state)
assert_int_equal
(
1
,
json_object_equal
(
file
,
jobj
));
}
static
void
test_json_
add
_object
(
void
**
state
)
static
void
test_json_
set
_object
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -112,7 +112,7 @@ static void test_json_add_object(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_array
(
void
**
state
)
static
void
test_json_
set
_array
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -132,7 +132,7 @@ static void test_json_add_array(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_multi_types
(
void
**
state
)
static
void
test_json_
set
_multi_types
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -164,7 +164,7 @@ static void test_json_add_multi_types(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_multi_obj
(
void
**
state
)
static
void
test_json_
set
_multi_obj
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -193,7 +193,7 @@ static void test_json_add_multi_obj(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_string
(
void
**
state
)
static
void
test_json_
set
_string
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -210,7 +210,7 @@ static void test_json_add_string(void **state)
}
static
void
test_json_overwrite_string
(
void
**
state
)
static
void
test_json_
set_
overwrite_string
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -238,7 +238,7 @@ static void test_json_overwrite_string(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_int
(
void
**
state
)
static
void
test_json_
set
_int
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -254,7 +254,7 @@ static void test_json_add_int(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_int_nested
(
void
**
state
)
static
void
test_json_
set
_int_nested
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -273,7 +273,7 @@ static void test_json_add_int_nested(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_array_int
(
void
**
state
)
static
void
test_json_
set
_array_int
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -295,7 +295,7 @@ static void test_json_add_array_int(void **state)
}
static
void
test_json_
add
_array_object
(
void
**
state
)
static
void
test_json_
set
_array_object
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -319,7 +319,7 @@ static void test_json_add_array_object(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_array_nested_object
(
void
**
state
)
static
void
test_json_
set
_array_nested_object
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -350,7 +350,7 @@ static void test_json_add_array_nested_object(void **state)
assert_int_equal
(
1
,
json_object_equal
(
modify_obj
,
file_obj
));
}
static
void
test_json_
add
_array_nested_array
(
void
**
state
)
static
void
test_json_
set
_array_nested_array
(
void
**
state
)
{
(
void
)
state
;
...
...
@@ -399,23 +399,155 @@ static int teardown (void** state) {
return
0
;
}
static
void
test_json_get_int
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"integer"
,
&
tmp
);
obj
=
get
(
file_obj
,
"integer"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_string
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"test"
,
&
tmp
);
obj
=
get
(
file_obj
,
"test"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_array
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"simple_array"
,
&
tmp
);
obj
=
get
(
file_obj
,
"simple_array"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_object
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"nested"
,
&
tmp
);
obj
=
get
(
file_obj
,
"nested"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_nested_object
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"nested"
,
&
tmp
);
json_object_object_get_ex
(
tmp
,
"api"
,
&
tmp
);
obj
=
get
(
file_obj
,
"nested.api"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_array_int
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"simple_array"
,
&
tmp
);
tmp
=
json_object_array_get_idx
(
tmp
,
1
);
obj
=
get
(
file_obj
,
"simple_array[1]"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_array_nested_int
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"array"
,
&
tmp
);
tmp
=
json_object_array_get_idx
(
tmp
,
1
);
tmp
=
json_object_array_get_idx
(
tmp
,
2
);
obj
=
get
(
file_obj
,
"array[1][-1]"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
static
void
test_json_get_object_array_nested_int
(
void
**
state
)
{
(
void
)
state
;
struct
json_object
*
tmp
,
*
obj
;
json_object_object_get_ex
(
file_obj
,
"complex_nested"
,
&
tmp
);
json_object_object_get_ex
(
tmp
,
"array"
,
&
tmp
);
tmp
=
json_object_array_get_idx
(
tmp
,
1
);
json_object_object_get_ex
(
tmp
,
"test2"
,
&
tmp
);
obj
=
get
(
file_obj
,
"complex_nested.array[1].test2"
);
printf
(
"obj=%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"tmp=%s
\n
"
,
json_object_get_string
(
tmp
));
assert_int_equal
(
1
,
json_object_equal
(
tmp
,
obj
));
}
int
main
(
void
)
{
const
struct
CMUnitTest
tests
[]
=
{
cmocka_unit_test
(
test_cfg_parse_success
),
cmocka_unit_test
(
test_cfg_parse_fail
),
//
cmocka_unit_test(test_cfg_parse_success),
//
cmocka_unit_test(test_cfg_parse_fail),
cmocka_unit_test
(
test_build_from_scratch
),
cmocka_unit_test_setup_teardown
(
test_json_add_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_int_nested
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_string
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_multi_types
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_multi_obj
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_overwrite_string
,
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_nested_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_add_array_nested_array
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_int_nested
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_string
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_multi_types
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_multi_obj
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_overwrite_string
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array_nested_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_set_array_nested_array
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_int
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_string
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_array
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_nested_object
,
setup
,
teardown
),
cmocka_unit_test_setup_teardown
(
test_json_get_array_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
),
};
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