diff options
author | Michael Jennings <mej@kainx.org> | 2002-05-22 04:18:45 +0000 |
---|---|---|
committer | Michael Jennings <mej@kainx.org> | 2002-05-22 04:18:45 +0000 |
commit | 99707b3d8b31cbc701a0e5d3f4bea13291192aa0 (patch) | |
tree | 54b064f032819e78299da9fcec82e6c3c12ac6e8 /test | |
parent | e75bbc9ae8dd4450128ee4324a36fc668f7d9467 (diff) | |
download | libast-99707b3d8b31cbc701a0e5d3f4bea13291192aa0.tar.gz |
Wed May 22 00:16:31 2002 Michael Jennings (mej)
Brought the performance tests up to date and cleaned up some memory
leaks in them.
SVN revision: 6266
Diffstat (limited to 'test')
-rw-r--r-- | test/perf.c | 423 | ||||
-rw-r--r-- | test/perf.h | 7 | ||||
-rw-r--r-- | test/test.c | 20 |
3 files changed, 354 insertions, 96 deletions
diff --git a/test/perf.c b/test/perf.c index 0f42182..e02d712 100644 --- a/test/perf.c +++ b/test/perf.c @@ -34,12 +34,16 @@ unsigned long tnum = 0; struct timeval time1, time2; double time_diff; long prof_counter; +size_t rep_cnt, rep_base; int perf_macros(void); int perf_strings(void); +int perf_options(void); int perf_obj(void); int perf_str(void); int perf_tok(void); +int perf_url(void); +int perf_list(void); int perf_macros(void) @@ -53,12 +57,22 @@ perf_macros(void) PERF_TEST(MEMSET(memset_test, '!', CONST_STRLEN(memset_test));); PERF_END(); + PERF_BEGIN("libc memset() function"); + PERF_TEST(memset(memset_test, '!', CONST_STRLEN(memset_test));); + PERF_END(); + PERF_BEGIN("SWAP() macro"); PERF_TEST(SWAP(sc1, sc2);); PERF_TEST(SWAP(si1, si2);); PERF_TEST(SWAP(sl1, sl2);); PERF_END(); + PERF_BEGIN("BINSWAP() macro"); + PERF_TEST(BINSWAP(sc1, sc2);); + PERF_TEST(BINSWAP(si1, si2);); + PERF_TEST(BINSWAP(sl1, sl2);); + PERF_END(); + PERF_BEGIN("BEG_STRCASECMP() macro"); PERF_TEST(BEG_STRCASECMP("this", "this is a test");); PERF_TEST(BEG_STRCASECMP("thx", "this is another test");); @@ -78,36 +92,24 @@ perf_strings(void) char **slist; PERF_BEGIN("left_str() function"); - PERF_TEST(s1 = left_str("bugger all", 3);); - PERF_TEST(s2 = left_str("testing 1-2-3", 7);); - PERF_TEST(s3 = left_str(NULL, 0);); - PERF_TEST(s4 = left_str("eat me", 0);); - FREE(s1); - FREE(s2); - FREE(s3); - FREE(s4); + PERF_TEST(s1 = left_str("bugger all", 3); FREE(s1);); + PERF_TEST(s2 = left_str("testing 1-2-3", 7); FREE(s2);); + PERF_TEST(s3 = left_str(NULL, 0); FREE(s3);); + PERF_TEST(s4 = left_str("eat me", 0); FREE(s4);); PERF_END(); PERF_BEGIN("mid_str() function"); - PERF_TEST(s1 = mid_str("pneumonoultramicroscopicsilicovolcanoconiosis", 8, 16);); - PERF_TEST(s2 = mid_str("abc", 7, 5);); - PERF_TEST(s3 = mid_str(NULL, 0, 0);); - PERF_TEST(s4 = mid_str("what the heck", -5, 42);); - FREE(s1); - FREE(s2); - FREE(s3); - FREE(s4); + PERF_TEST(s1 = mid_str("pneumonoultramicroscopicsilicovolcanoconiosis", 8, 16); FREE(s1);); + PERF_TEST(s2 = mid_str("abc", 7, 5); FREE(s2);); + PERF_TEST(s3 = mid_str(NULL, 0, 0); FREE(s3);); + PERF_TEST(s4 = mid_str("what the heck", -5, 42); FREE(s4);); PERF_END(); PERF_BEGIN("right_str() function"); - PERF_TEST(s1 = right_str("bugger all", 3);); - PERF_TEST(s2 = right_str("testing 1-2-3", 5);); - PERF_TEST(s3 = right_str(NULL, 0);); - PERF_TEST(s4 = right_str("eat me", 0);); - FREE(s1); - FREE(s2); - FREE(s3); - FREE(s4); + PERF_TEST(s1 = right_str("bugger all", 3); FREE(s1);); + PERF_TEST(s2 = right_str("testing 1-2-3", 5); FREE(s2);); + PERF_TEST(s3 = right_str(NULL, 0); FREE(s3);); + PERF_TEST(s4 = right_str("eat me", 0); FREE(s4);); PERF_END(); #ifdef HAVE_REGEX_H @@ -125,16 +127,11 @@ perf_strings(void) #endif PERF_BEGIN("split() function"); - PERF_TEST(slist = split(" ", "Splitting a string on spaces");); - free_array((void **) slist, 0); - PERF_TEST(slist = split(NULL, " a\t \ta a a a a a ");); - free_array((void **) slist, 0); - PERF_TEST(slist = split(NULL, " first \"just the second\" third \'fourth and \'\"fifth to\"gether last");); - free_array((void **) slist, 0); - PERF_TEST(slist = split(NULL, "\'don\\\'t\' try this at home \"\" ");); - free_array((void **) slist, 0); - PERF_TEST(slist = split(":", "A:B:C:D:::E");); - free_array((void **) slist, 0); + PERF_TEST(slist = split(" ", "Splitting a string on spaces"); free_array(slist, -1);); + PERF_TEST(slist = split(NULL, " a\t \ta a a a a a "); free_array(slist, -1);); + PERF_TEST(slist = split(NULL, " first \"just the second\" third \'fourth and \'\"fifth to\"gether last"); free_array(slist, -1);); + PERF_TEST(slist = split(NULL, "\'don\\\'t\' try this at home \"\" "); free_array(slist, -1);); + PERF_TEST(slist = split(":", "A:B:C:D:::E"); free_array(slist, -1);); PERF_END(); PERF_ENDED("string"); @@ -142,14 +139,86 @@ perf_strings(void) } int +perf_options(void) +{ + spif_uint32_t test_flag_var = 0; + char *file_var = NULL, **exec_list = NULL; + long num_var = 0, geom_var = 0; + char *argv1[] = { "test", "-abvf", "somefile", "-n1", "-g", "3", "-e", "help", "me", "rhonda", NULL }; + int argc1 = 10; + spifopt_t opts1[] = { + SPIFOPT_BOOL('a', "agony", "scream in agony", test_flag_var, 0x01), + SPIFOPT_BOOL('b', "bogus", "mark as bogus", test_flag_var, 0x02), + SPIFOPT_BOOL('c', "crap", "spew some random crap", test_flag_var, 0x04), + SPIFOPT_BOOL_LONG("dillhole", "are you a dillhole?", test_flag_var, 0x08), + SPIFOPT_ARGS('e', "exec", "what to exec", exec_list), + SPIFOPT_STR('f', "file", "set the filename", file_var), + SPIFOPT_INT('g', "geom", "geometry", geom_var), + SPIFOPT_INT('n', "num", "number", num_var), + SPIFOPT_BOOL_PP('v', "verbose", "be verbose", test_flag_var, 0x10) + }; + char *display = NULL, *name = NULL, *theme = NULL, **exec = NULL, **foo = NULL; + long color = 0; + spif_uint32_t options = 0; + static void handle_theme(char *val_ptr) {theme = STRDUP(val_ptr);} + char *argv2[] = { "test", "-rt", "mytheme", "--name", "This is a name", "--exec=ssh foo@bar.com", "--scrollbar", + "--buttonbar", "no", "--login=0", "-mvd", "foo:0", "--color", "4", "--foo", "blah", "-d", "eatme", NULL }; + int argc2 = 18; + spifopt_t opts2[] = { + SPIFOPT_STR_PP('d', "display", "X display to connect to", display), + SPIFOPT_ARGS_PP('e', "exec", "command to run", exec), + SPIFOPT_BOOL_PP('l', "login", "login shell", options, 0x01), + SPIFOPT_BOOL('m', "map-alert", "raise window on beep", options, 0x02), + SPIFOPT_STR('n', "name", "name", name), + SPIFOPT_BOOL('r', "reverse-video", "enable reverse video", options, 0x04), + SPIFOPT_ABST_PP('t', "theme", "theme to use", handle_theme), + SPIFOPT_BOOL_PP('v', "visual-bell", "enable visual bell", options, 0x08), + SPIFOPT_BOOL_LONG("scrollbar", "enable scrollbar", options, 0x10), + SPIFOPT_BOOL_LONG("buttonbar", "enable buttonbar", options, 0x20), + SPIFOPT_INT_LONG("color", "pick a color", color), + SPIFOPT_ARGS_LONG("foo", "foo", foo) + }; + + PERF_BEGIN("spifopt_parse() function"); + SPIFOPT_OPTLIST_SET(opts1); + SPIFOPT_NUMOPTS_SET(sizeof(opts1) / sizeof(spifopt_t)); + SPIFOPT_ALLOWBAD_SET(0); + PERF_TEST( + SPIFOPT_FLAGS_CLEAR(SPIFOPT_SETTING_POSTPARSE); + spifopt_parse(argc1, argv1); + spifopt_parse(argc1, argv1); + FREE(file_var); + free_array(exec_list, -1); + ); + + SPIFOPT_OPTLIST_SET(opts2); + SPIFOPT_NUMOPTS_SET(sizeof(opts2) / sizeof(spifopt_t)); + SPIFOPT_ALLOWBAD_SET(0); + PERF_TEST( + SPIFOPT_FLAGS_CLEAR(SPIFOPT_SETTING_POSTPARSE); + spifopt_parse(argc2, argv2); + spifopt_parse(argc2, argv2); + FREE(display); + FREE(name); + FREE(theme); + free_array(exec, -1); + free_array(foo, -1); + ); + + PERF_END(); + + PERF_ENDED("options"); + return 0; +} + +int perf_obj(void) { spif_obj_t testobj; spif_class_t cls; - PERF_BEGIN("spif_obj_create_delete"); - PERF_TEST(testobj = spif_obj_new();); - PERF_TEST(spif_obj_del(testobj);); + PERF_BEGIN("spif_obj create/delete"); + PERF_TEST(testobj = spif_obj_new(); spif_obj_del(testobj);); PERF_END(); testobj = spif_obj_new(); @@ -166,100 +235,134 @@ int perf_str(void) { spif_str_t teststr, test2str; - spif_class_t cls; signed char tmp[] = "this is a test"; signed char buff[4096] = "abcde"; signed char tmp2[] = "string #1\nstring #2"; spif_charptr_t foo; - PERF_BEGIN("spif_str_new_del"); - PERF_TEST(teststr = spif_str_new();); - PERF_TEST(spif_str_del(teststr);); + PERF_BEGIN("spif_str create/delete"); + PERF_TEST(teststr = spif_str_new(); spif_str_del(teststr);); PERF_END(); - teststr = spif_str_new(); - PERF_BEGIN("spif_obj_get_classname"); - PERF_TEST(cls = spif_obj_get_class(SPIF_OBJ(teststr));); - PERF_END(); - spif_str_del(teststr); - - PERF_BEGIN("spif_str_new_del_from_ptr"); - PERF_TEST(teststr = spif_str_new_from_ptr(tmp);); - PERF_TEST(spif_str_del(teststr);); + PERF_BEGIN("spif_str_new_from_ptr() function"); + PERF_TEST(teststr = spif_str_new_from_ptr(tmp); spif_str_del(teststr);); PERF_END(); - PERF_BEGIN("spif_str_new_del_from_buff"); - PERF_TEST(teststr = spif_str_new_from_buff(buff, sizeof(buff));); - PERF_TEST(spif_str_del(teststr);); + PERF_BEGIN("spif_str_new_from_buff() function"); + PERF_TEST(teststr = spif_str_new_from_buff(buff, sizeof(buff)); spif_str_del(teststr);); PERF_END(); - PERF_BEGIN("spif_str_dup"); - PERF_TEST(teststr = spif_str_new_from_ptr(tmp);); - PERF_TEST(test2str = spif_str_dup(teststr);); - PERF_TEST(spif_str_del(teststr);); - PERF_TEST(spif_str_del(test2str);); + PERF_BEGIN("spif_str_dup() function"); + PERF_TEST( + teststr = spif_str_new_from_ptr(tmp); + test2str = spif_str_dup(teststr); + spif_str_del(teststr); + spif_str_del(test2str); + ); PERF_END(); teststr = spif_str_new_from_ptr(tmp2); - PERF_BEGIN("spif_str_index"); + PERF_BEGIN("spif_str_index() function"); PERF_TEST(spif_str_index(teststr, '#');); PERF_END(); - PERF_BEGIN("spif_str_rindex"); + PERF_BEGIN("spif_str_rindex() function"); PERF_TEST(spif_str_rindex(teststr, '#');); PERF_END(); test2str = spif_str_new_from_ptr(SPIF_CAST(charptr) "ring"); - PERF_BEGIN("spif_str_find"); + PERF_BEGIN("spif_str_find() function"); PERF_TEST(spif_str_find(teststr, test2str);); PERF_END(); spif_str_del(test2str); - PERF_BEGIN("spif_str_find_from_ptr"); + PERF_BEGIN("spif_str_find_from_ptr() function"); PERF_TEST(spif_str_find_from_ptr(teststr, SPIF_CAST(charptr) "in");); PERF_END(); spif_str_del(teststr); teststr = spif_str_new_from_ptr(tmp); - PERF_BEGIN("spif_str_substr"); - PERF_TEST(test2str = spif_str_substr(teststr, 2, 5);); - PERF_TEST(spif_str_del(test2str);); - PERF_TEST(test2str = spif_str_substr(teststr, -4, 4);); - PERF_TEST(spif_str_del(test2str);); + PERF_BEGIN("spif_str_substr() function"); + PERF_TEST(test2str = spif_str_substr(teststr, 2, 5); spif_str_del(test2str);); + PERF_TEST(test2str = spif_str_substr(teststr, -4, 4); spif_str_del(test2str);); PERF_END(); spif_str_del(teststr); teststr = spif_str_new_from_ptr(tmp); - PERF_BEGIN("spif_str_substr_to_ptr"); - PERF_TEST(foo = spif_str_substr_to_ptr(teststr, 2, 5);); - FREE(foo); - PERF_TEST(foo = spif_str_substr_to_ptr(teststr, -4, 4);); - FREE(foo); + PERF_BEGIN("spif_str_substr_to_ptr() function"); + PERF_TEST(foo = spif_str_substr_to_ptr(teststr, 2, 5); FREE(foo);); + PERF_TEST(foo = spif_str_substr_to_ptr(teststr, -4, 4); FREE(foo);); PERF_END(); spif_str_del(teststr); teststr = spif_str_new_from_ptr(SPIF_CAST(charptr) "11001001"); - PERF_BEGIN("spif_str_to_num"); + PERF_BEGIN("spif_str_to_num() function"); PERF_TEST(spif_str_to_num(teststr, 10);); PERF_END(); spif_str_del(teststr); teststr = spif_str_new_from_ptr(SPIF_CAST(charptr) "3.1415"); - PERF_BEGIN("spif_str_to_float"); + PERF_BEGIN("spif_str_to_float() function"); PERF_TEST(spif_str_to_float(teststr);); PERF_END(); spif_str_del(teststr); - teststr = spif_str_new_from_ptr(SPIF_CAST(charptr) " \n \r\f \t testing 1 2 3 \v\r \n"); - PERF_BEGIN("spif_str_trim"); - PERF_TEST(spif_str_trim(teststr);); + teststr = spif_str_new_from_ptr("copy"); + test2str = spif_str_new_from_ptr("cat"); + PERF_BEGIN("spif_str_append() function"); + PERF_TEST(spif_str_append(teststr, test2str);); + PERF_END(); + spif_str_del(test2str); + spif_str_del(teststr); + + test2str = spif_str_new_from_ptr("Hello"); + PERF_BEGIN("spif_str_append_char() function"); + PERF_TEST(spif_str_append_char(test2str, '!');); + PERF_END(); + spif_str_del(test2str); + + teststr = spif_str_new_from_ptr("copy"); + PERF_BEGIN("spif_str_append_from_ptr() function"); + PERF_TEST(spif_str_append_from_ptr(teststr, "crime");); + PERF_END(); + spif_str_del(teststr); + + teststr = spif_str_new_from_ptr("abcdefg"); + PERF_BEGIN("spif_str_clear() function"); + PERF_TEST(spif_str_clear(teststr, SPIF_CAST_C(char) (rand() % 256));); PERF_END(); spif_str_del(teststr); + PERF_BEGIN("spif_str_trim() function"); + PERF_TEST( + teststr = spif_str_new_from_ptr(SPIF_CAST(charptr) " \n \r\f \t testing 1 2 3 \v\r \n"); + spif_str_trim(teststr); + spif_str_del(teststr); + ); + PERF_END(); + + PERF_BEGIN("spif_str_splice() function"); + PERF_TEST( + teststr = spif_str_new_from_ptr(tmp); + test2str = spif_str_new_from_ptr("lots of fun"); + spif_str_splice(teststr, 8, 6, test2str); + spif_str_del(test2str); + spif_str_del(teststr); + ); + PERF_END(); + + PERF_BEGIN("spif_str_splice_from_ptr() function"); + PERF_TEST( + teststr = spif_str_new_from_ptr(tmp); + spif_str_splice_from_ptr(teststr, 8, 0, "not "); + spif_str_del(teststr); + ); + PERF_END(); + teststr = spif_str_new_from_buff(buff, sizeof(buff)); - PERF_BEGIN("spif_str_reverse"); + PERF_BEGIN("spif_str_reverse() function"); PERF_TEST(spif_str_reverse(teststr);); PERF_END(); spif_str_del(teststr); @@ -271,17 +374,38 @@ perf_str(void) int perf_tok(void) { - spif_tok_t testtok, test2tok; - spif_class_t cls; + spif_tok_t testtok; + spif_str_t teststr; signed char tmp[] = "I \"can\'t\" feel my legs!"; signed char tmp2[] = ":::some:seedy:colon-delimited::data"; signed char tmp3[] = "\"this is one token\" and this \'over here\' is \"another one\""; signed char tmp4[] = "\"there shouldn't be\"\' any problems at\'\"\"\'\'\' \'\"all parsing this\""; - spif_charptr_t foo; - PERF_BEGIN("spif_tok_new_del_from_ptr"); - PERF_TEST(testtok = spif_tok_new_from_ptr(tmp);); - PERF_TEST(spif_tok_del(testtok);); + PERF_BEGIN("spif_tok_new_from_ptr() function"); + PERF_TEST(testtok = spif_tok_new_from_ptr(tmp); spif_tok_del(testtok);); + PERF_END(); + + PERF_BEGIN("spif_tok_eval() function"); + + testtok = spif_tok_new_from_ptr(tmp); + PERF_TEST(spif_tok_eval(testtok);); + spif_tok_del(testtok); + + testtok = spif_tok_new_from_ptr(tmp2); + teststr = spif_str_new_from_ptr(":"); + spif_tok_set_sep(testtok, teststr); + spif_str_del(teststr); + PERF_TEST(spif_tok_eval(testtok);); + spif_tok_del(testtok); + + testtok = spif_tok_new_from_ptr(tmp3); + PERF_TEST(spif_tok_eval(testtok);); + spif_tok_del(testtok); + + testtok = spif_tok_new_from_ptr(tmp4); + PERF_TEST(spif_tok_eval(testtok);); + spif_tok_del(testtok); + PERF_END(); PERF_ENDED("spif_tok_t"); @@ -289,14 +413,128 @@ perf_tok(void) } int +perf_url(void) +{ + spif_url_t testurl, testurl2, testurl3, testurl4; + spif_charptr_t tmp1 = "http://www.kainx.org/journal/?view=20020104"; + spif_charptr_t tmp2 = "mailto:foo@bar.com?Subject=Eat Me"; + spif_charptr_t tmp3 = "/path/to/some/file.jpg"; + spif_charptr_t tmp4 = "pop3://dummy:moo@pop.nowhere.com:110"; + + PERF_BEGIN("spif_url_new_from_ptr() function"); + PERF_TEST(testurl = spif_url_new_from_ptr(tmp1); spif_url_del(testurl);); + PERF_TEST(testurl2 = spif_url_new_from_ptr(tmp2); spif_url_del(testurl2);); + PERF_TEST(testurl3 = spif_url_new_from_ptr(tmp3); spif_url_del(testurl3);); + PERF_TEST(testurl4 = spif_url_new_from_ptr(tmp4); spif_url_del(testurl4);); + PERF_END(); + + PERF_ENDED("spif_url_t"); + return 0; +} + +int +perf_list(void) +{ + char buff[2] = "\0"; + unsigned short i; + spif_list_t testlist; + spif_str_t s, s2; + size_t idx, len; + + for (i = 0; i < 3; i++) { + if (i == 0) { + PERF_NOTICE("Testing list interface class, linked_list instance:"); + testlist = SPIF_LIST_NEW(linked_list); + } else if (i == 1) { + PERF_NOTICE("Testing list interface class, dlinked_list instance:"); + testlist = SPIF_LIST_NEW(dlinked_list); + } else if (i == 2) { + PERF_NOTICE("Testing list interface class, array instance:"); + testlist = SPIF_LIST_NEW(array); + } else if (i == 3) { + } + + PERF_BEGIN("SPIF_LIST_APPEND() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + PERF_TEST(SPIF_LIST_APPEND(testlist, spif_str_new_from_ptr(buff));); + PERF_END(); + + PERF_BEGIN("SPIF_LIST_PREPEND() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + PERF_TEST(SPIF_LIST_PREPEND(testlist, spif_str_new_from_ptr(buff));); + PERF_END(); + + s = spif_str_new(); + PERF_BEGIN("SPIF_LIST_CONTAINS() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + spif_str_init_from_ptr(s, buff); + PERF_TEST(SPIF_LIST_CONTAINS(testlist, s)); + spif_str_done(s); + PERF_END(); + spif_str_del(s); + + PERF_BEGIN("SPIF_LIST_COUNT() macro"); + PERF_TEST(SPIF_LIST_COUNT(testlist)); + PERF_END(); + + len = SPIF_LIST_COUNT(testlist); + PERF_BEGIN("SPIF_LIST_GET() macro"); + idx = SPIF_CAST_C(size_t) (rand() % len); + PERF_TEST(SPIF_LIST_GET(testlist, idx)); + PERF_END(); + + s = spif_str_new(); + PERF_BEGIN("SPIF_LIST_INDEX() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + spif_str_init_from_ptr(s, buff); + PERF_TEST(SPIF_LIST_INDEX(testlist, s)); + spif_str_done(s); + PERF_END(); + spif_str_del(s); + + PERF_BEGIN("SPIF_LIST_INSERT() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + PERF_TEST(SPIF_LIST_INSERT(testlist, spif_str_new_from_ptr(buff));); + PERF_END(); + + len = SPIF_LIST_COUNT(testlist); + PERF_BEGIN("SPIF_LIST_INSERT_AT() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + idx = rand() % len; + PERF_TEST(SPIF_LIST_INSERT_AT(testlist, spif_str_new_from_ptr(buff), idx);); + PERF_END(); + + s = spif_str_new(); + PERF_BEGIN("SPIF_LIST_REMOVE() macro"); + buff[0] = SPIF_CAST_C(char) (rand() % 256); + spif_str_init_from_ptr(s, buff); + PERF_TEST(s2 = SPIF_CAST(str) SPIF_LIST_REMOVE(testlist, s); if (!SPIF_STR_ISNULL(s2)) {spif_str_del(s2);}); + spif_str_done(s); + PERF_END(); + spif_str_del(s); + + PERF_BEGIN("SPIF_LIST_REMOVE_AT() macro"); + idx = rand() % SPIF_LIST_COUNT(testlist); + PERF_TEST(s2 = SPIF_CAST(str) SPIF_LIST_REMOVE_AT(testlist, idx); if (!SPIF_STR_ISNULL(s2)) {spif_str_del(s2);}); + PERF_END(); + + SPIF_SHOW(testlist, stderr); + SPIF_LIST_DEL(testlist); + } + + PERF_ENDED("list interface class"); + return 0; +} + +int main(int argc, char *argv[]) { int ret = 0; struct timeval t1, t2; + spifopt_t options[] = { + }; - USE_VAR(argc); - USE_VAR(argv); - + DEBUG_LEVEL = 5; gettimeofday(&t1, NULL); @@ -306,6 +544,9 @@ main(int argc, char *argv[]) if ((ret = perf_strings()) != 0) { return ret; } + if ((ret = perf_options()) != 0) { + return ret; + } if ((ret = perf_obj()) != 0) { return ret; } @@ -315,6 +556,14 @@ main(int argc, char *argv[]) if ((ret = perf_tok()) != 0) { return ret; } + if ((ret = perf_url()) != 0) { + return ret; + } + if ((ret = perf_list()) != 0) { + return ret; + } + MALLOC_DUMP(); + return 0; gettimeofday(&t2, NULL); diff --git a/test/perf.h b/test/perf.h index beb1703..91c6919 100644 --- a/test/perf.h +++ b/test/perf.h @@ -24,20 +24,16 @@ #ifndef _LIBAST_PERF_H_ # define _LIBAST_PERF_H_ +# define PERF_ITERATIONS 100000 # define TDIFF(t1, t2) (((t2).tv_sec + ((double) (t2).tv_usec / 1000000.0)) \ - ((t1).tv_sec + ((double) (t1).tv_usec / 1000000.0))) - -# define PERF_ITERATIONS 100000 - # define PERF_BEGIN(s) do { \ tnum = 0; \ printf("Profiling " s "..."); \ fflush(stdout); \ gettimeofday(&time1, NULL); \ for (prof_counter = 0; prof_counter < PERF_ITERATIONS; prof_counter++) { - # define PERF_TEST(x) do { tnum++; x ; } while (0) - # define PERF_END() } \ gettimeofday(&time2, NULL); \ time_diff = TDIFF(time1, time2); \ @@ -45,5 +41,6 @@ tnum, time_diff, time_diff / tnum); \ } while (0) # define PERF_ENDED(s) printf(s " profiling done.\n\n"); return 0; +# define PERF_NOTICE(s) printf("%s\n", s) #endif diff --git a/test/test.c b/test/test.c index 73875e4..0e325a3 100644 --- a/test/test.c +++ b/test/test.c @@ -67,6 +67,18 @@ test_macros(void) TEST_FAIL_IF(sl2 != 0x98765432); TEST_PASS(); + TEST_BEGIN("BINSWAP() macro"); + BINSWAP(sc1, sc2); + BINSWAP(si1, si2); + BINSWAP(sl1, sl2); + TEST_FAIL_IF(sc1 != 'X'); + TEST_FAIL_IF(sc2 != 'K'); + TEST_FAIL_IF(si1 != 472); + TEST_FAIL_IF(si2 != 8786345); + TEST_FAIL_IF(sl1 != 0x98765432); + TEST_FAIL_IF(sl2 != 0xffeeddff); + TEST_PASS(); + TEST_BEGIN("BEG_STRCASECMP() macro"); TEST_FAIL_IF(!BEG_STRCASECMP("this", "this is a test")); TEST_FAIL_IF(!BEG_STRCASECMP("thx", "this is another test")); @@ -895,12 +907,12 @@ test_list(void) TEST_BEGIN("SPIF_LIST_REMOVE() macro"); s = spif_str_new_from_ptr("MOO"); - s2 = SPIF_LIST_REMOVE(testlist, s); + s2 = SPIF_CAST(str) SPIF_LIST_REMOVE(testlist, s); TEST_FAIL_IF(SPIF_OBJ_ISNULL(s2)); spif_str_del(s2); spif_str_done(s); spif_str_init_from_ptr(s, "GRIN"); - s2 = SPIF_LIST_REMOVE(testlist, s); + s2 = SPIF_CAST(str) SPIF_LIST_REMOVE(testlist, s); TEST_FAIL_IF(SPIF_OBJ_ISNULL(s2)); spif_str_del(s2); spif_str_del(s); @@ -923,9 +935,9 @@ test_list(void) TEST_PASS(); TEST_BEGIN("SPIF_LIST_REMOVE_AT() macro"); - s2 = SPIF_LIST_REMOVE_AT(testlist, 6); + s2 = SPIF_CAST(str) SPIF_LIST_REMOVE_AT(testlist, 6); spif_str_del(s2); - s2 = SPIF_LIST_REMOVE_AT(testlist, 3); + s2 = SPIF_CAST(str) SPIF_LIST_REMOVE_AT(testlist, 3); spif_str_del(s2); s = spif_str_new_from_ptr("0"); |