File: test_int_add.c

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (47 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#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_int_inc(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_int_inc(tmp, 100);
	assert(json_object_get_int(tmp) == INT32_MAX);
	assert(json_object_get_int64(tmp) == (int64_t)INT32_MAX + 100L);
	json_object_put(tmp);
	printf("INT ADD OVERFLOW PASSED\n");
	tmp = json_object_new_int(INT32_MIN);
	json_object_int_inc(tmp, -100);
	assert(json_object_get_int(tmp) == INT32_MIN);
	assert(json_object_get_int64(tmp) == (int64_t)INT32_MIN - 100L);
	json_object_put(tmp);
	printf("INT ADD UNDERFLOW PASSED\n");
	tmp = json_object_new_int64(321321321);
	json_object_int_inc(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_int_inc(tmp, 100);
	assert(json_object_get_int64(tmp) == INT64_MAX);
	json_object_int_inc(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_int_inc(tmp, -100);
	assert(json_object_get_int64(tmp) == INT64_MIN);
	json_object_int_inc(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;
}