PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/lookup_table_test.c

http://ftk.googlecode.com/
C | 34 lines | 26 code | 8 blank | 0 comment | 3 complexity | 7a2deb17d71ffd798729aeabccaf87db MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_lookup_table.h"
 3#include "ftk_allocator_default.h"
 4
 5int compare(const void* obj1, const void* obj2)
 6{
 7	return strncmp(obj1, obj2, strlen(obj2));
 8}
 9
10int main(int argc, char* argv[])
11{
12	const char* start = NULL;
13	char value[FTK_VALUE_LEN + 1] = {0};
14	FtkLookupTable* thiz = NULL;
15	
16	ftk_set_allocator((ftk_allocator_default_create()));
17	if(argc != 3)
18	{
19		ftk_logd("usage: %s file key\n", argv[0]);
20
21		return 0;
22	}
23
24	thiz = ftk_lookup_table_create(argv[1], 0, compare);
25
26	assert(ftk_lookup_table_load(thiz) == RET_OK);
27
28	start = ftk_lookup_table_lookup(thiz, argv[2]);
29	strncpy(value, start, FTK_VALUE_LEN);
30	ftk_logd("%s=%s\n", argv[2], value);
31	ftk_lookup_table_destroy(thiz);
32
33	return 0;
34}