mirror of
https://github.com/json-c/json-c.git
synced 2026-03-25 07:59:07 +08:00
Add json_object_add_int functions
This commit is contained in:
@@ -25,6 +25,7 @@ TESTS+= test_compare.test
|
||||
TESTS+= test_set_value.test
|
||||
TESTS+= test_visit.test
|
||||
TESTS+= test_json_pointer.test
|
||||
TESTS+= test_int_add.test
|
||||
|
||||
check_PROGRAMS=
|
||||
check_PROGRAMS += $(TESTS:.test=)
|
||||
|
||||
41
tests/test_int_add.c
Normal file
41
tests/test_int_add.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
json_object *tmp = json_object_new_int(123);
|
||||
json_object_add_int(tmp, 123);
|
||||
assert(json_object_get_int(tmp) == 246);
|
||||
json_object_put(tmp);
|
||||
printf("INT ADD PASSED\n");
|
||||
tmp = json_object_new_int(INT32_MAX);
|
||||
json_object_add_int(tmp, 100);
|
||||
assert(json_object_get_int(tmp) == INT32_MAX);
|
||||
json_object_put(tmp);
|
||||
printf("INT ADD OVERFLOW PASSED\n");
|
||||
tmp = json_object_new_int(INT32_MIN);
|
||||
json_object_add_int(tmp, -100);
|
||||
assert(json_object_get_int(tmp) == INT32_MIN);
|
||||
json_object_put(tmp);
|
||||
printf("INT ADD UNDERFLOW PASSED\n");
|
||||
tmp = json_object_new_int64(321321321);
|
||||
json_object_add_int(tmp, 321321321);
|
||||
assert(json_object_get_int(tmp) == 642642642);
|
||||
json_object_put(tmp);
|
||||
printf("INT64 ADD PASSED\n");
|
||||
tmp = json_object_new_int64(INT64_MAX);
|
||||
json_object_add_int64(tmp, 100);
|
||||
assert(json_object_get_int64(tmp) == INT64_MAX);
|
||||
json_object_put(tmp);
|
||||
printf("INT64 ADD OVERFLOW PASSED\n");
|
||||
tmp = json_object_new_int64(INT64_MIN);
|
||||
json_object_add_int64(tmp, -100);
|
||||
assert(json_object_get_int64(tmp) == INT64_MIN);
|
||||
json_object_put(tmp);
|
||||
printf("INT64 ADD UNDERFLOW PASSED\n");
|
||||
|
||||
printf("PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
7
tests/test_int_add.expected
Normal file
7
tests/test_int_add.expected
Normal file
@@ -0,0 +1,7 @@
|
||||
INT ADD PASSED
|
||||
INT ADD OVERFLOW PASSED
|
||||
INT ADD UNDERFLOW PASSED
|
||||
INT64 ADD PASSED
|
||||
INT64 ADD OVERFLOW PASSED
|
||||
INT64 ADD UNDERFLOW PASSED
|
||||
PASSED
|
||||
1
tests/test_int_add.test
Symbolic link
1
tests/test_int_add.test
Symbolic link
@@ -0,0 +1 @@
|
||||
test_basic.test
|
||||
Reference in New Issue
Block a user