File: test.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (46 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
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
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */

#include <r_util.h>

ut64 num_callback(RNum *num, const char *str, int *ok) {
	if (!strcmp(str, "foo")) {
		*ok=1;
		return 11;
	}
	*ok = 0;
	return 0;
}

int test_num(RNum *num, const char *str, ut64 okvalue) {
	ut64 ret;
	printf("        %"PFMT64d" == ", okvalue);
 	ret = r_num_math(num, str);
	printf("%"PFMT64d"  \t; %s", ret, str);
	if (ret == okvalue) printf("\r ok\n");
	else printf("\rFAIL\n");
}

int main() {
	struct r_num_t num;
	num.callback = num_callback;
	num.userptr = NULL;

#if 1
	test_num(&num, "33", 33);
	test_num(&num, "0x24", 36);
	test_num(&num, "44o", 0x24);
	test_num(&num, "foo", 11);
	test_num(&num, "1+2", 3);
	test_num(&num, "3+3*2", 12);
	test_num(&num, "3+(3*2)", 9);
	test_num(&num, "(3*2)+3", 9);
	test_num(&num, "(3*2)+(3*2)", 12);
	test_num(&num, "3+(3*2+(4*2))", 17);
	test_num(&num, "8/2+(9*2)+(4*2)+(23+(43-18))", 78);
	test_num(&num, "8+(9*2)", 26);
	test_num(&num, "8/2+(9*2)", 22);
#endif
	test_num(&num, "(9*2)+(4*2)", 26);

	return 0;
}