PageRenderTime 213ms CodeModel.GetById 101ms app.highlight 4ms RepoModel.GetById 107ms app.codeStats 0ms

/src/test/params_test.c

http://ftk.googlecode.com/
C | 36 lines | 28 code | 8 blank | 0 comment | 4 complexity | 98918dad77eee865716695cf94450483 MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_params.h"
 3
 4int main(int argc, char* argv[])
 5{
 6	int i = 0;
 7	int nr = 100;
 8	char key[FTK_KEY_LEN+1];
 9	char value[FTK_VALUE_LEN+1];
10	FtkParams* thiz = NULL;
11	ftk_set_allocator(ftk_allocator_default_create());
12	
13	thiz = ftk_params_create(nr, nr);
14
15	for(i = 0; i < nr; i++)
16	{
17		snprintf(key, FTK_KEY_LEN, "key%d", i);
18		snprintf(value, FTK_VALUE_LEN, "2*($i%d+%d)-($i%d+%d))", i, i, i, i);
19		assert(ftk_params_set_param(thiz, key, value) == RET_OK);
20
21		snprintf(key, FTK_KEY_LEN, "i%d", i);
22		snprintf(value, FTK_VALUE_LEN, "%d", i);
23		assert(ftk_params_set_var(thiz, key, value) == RET_OK);
24		
25		snprintf(key, FTK_KEY_LEN, "key%d", i);
26
27		assert(ftk_params_eval_int(thiz, key, 0) == 2 * i);
28		ftk_logd("[%d] %d\n", i, ftk_params_eval_int(thiz, key, 0));
29		ftk_logd("[%d] %s\n", i, ftk_params_eval_string(thiz, key));
30	}
31
32	ftk_params_dump(thiz);
33	ftk_params_destroy(thiz);
34
35	return 0;
36}