PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/config_test.c

http://ftk.googlecode.com/
C | 39 lines | 30 code | 9 blank | 0 comment | 13 complexity | 8e6af2ca398b77796d8802ab394c5fba MD5 | raw file
 1#include "ftk_globals.h"
 2#include "ftk_config.h"
 3#include "ftk_allocator_default.h"
 4
 5const char* args[] = {"./config_test", "--disable-statusbar", "--enable-cursor", "--theme=abc", "--data-dir=/data", "--test-data-dir=/testdata", NULL};
 6const char* xml="<statusbar enable=\"0\" />\n<cursor enable=\"1\" />\n <theme name=\"abc\" /><data_dir value=\"/data\" /> <test_data_dir value=\"/testdata\" />";
 7
 8int main(int argc, char* argv[])
 9{
10	FtkConfig* thiz = NULL;
11	ftk_set_allocator(ftk_allocator_default_create());
12
13	thiz = ftk_config_create();
14	assert(ftk_config_init(thiz, (sizeof(args)/sizeof(args[0]))-1, (char **)args) == RET_OK);
15
16	assert(strcmp(ftk_config_get_theme(thiz), "abc") == 0);
17	assert(strcmp(ftk_config_get_data_dir(thiz), "/data") == 0);
18	assert(strcmp(ftk_config_get_test_data_dir(thiz), "/testdata") == 0);
19	assert(ftk_config_get_enable_cursor(thiz));
20	assert(!ftk_config_get_enable_status_bar(thiz));
21
22	assert(ftk_config_set_theme(thiz, "") == RET_OK);
23	assert(ftk_config_set_data_dir(thiz, "") == RET_OK);
24	assert(ftk_config_set_test_data_dir(thiz, "") == RET_OK);
25	assert(ftk_config_set_enable_cursor(thiz, 0) == RET_OK);
26	assert(ftk_config_set_enable_status_bar(thiz, 0) == RET_OK);
27	assert(ftk_config_parse(thiz, xml, strlen(xml)) == RET_OK);
28	
29	assert(strcmp(ftk_config_get_theme(thiz), "abc") == 0);
30	assert(strcmp(ftk_config_get_data_dir(thiz), "/data") == 0);
31	assert(strcmp(ftk_config_get_test_data_dir(thiz), "/testdata") == 0);
32	assert(ftk_config_get_enable_cursor(thiz));
33	assert(!ftk_config_get_enable_status_bar(thiz));
34
35	ftk_config_destroy(thiz);
36
37	return 0;
38}
39