X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ftest.c;h=d0d5329245a6ed398308a267b6c8c67127cb596a;hb=b1f4764b7718276d8ef176d5b3238718a782e839;hp=47db82c733a2e43aec483f3e5fe28d281a570e28;hpb=1d7f999b7d38db3308a0533a83fea23987fb0178;p=awesomized%2Flibmemcached diff --git a/tests/test.c b/tests/test.c index 47db82c7..d0d53292 100644 --- a/tests/test.c +++ b/tests/test.c @@ -14,19 +14,39 @@ #include "test.h" -long int timedif(struct timeval a, struct timeval b) +static long int timedif(struct timeval a, struct timeval b) { register int us, s; - us = a.tv_usec - b.tv_usec; + us = (int)(a.tv_usec - b.tv_usec); us /= 1000; - s = a.tv_sec - b.tv_sec; + s = (int)(a.tv_sec - b.tv_sec); s *= 1000; return s + us; } +static const char *test_strerror(test_return_t code) +{ + switch (code) { + case TEST_SUCCESS: + return "ok"; + case TEST_FAILURE: + return "failed"; + case TEST_MEMORY_ALLOCATION_FAILURE: + return "memory allocation"; + case TEST_SKIPPED: + return "skipped"; + case TEST_MAXIMUM_RETURN: + default: + fprintf(stderr, "Unknown return value\n"); + assert(0); + } + +} + int main(int argc, char *argv[]) { + test_return_t failed; unsigned int x; char *collection_to_run= NULL; char *wildcard= NULL; @@ -35,7 +55,6 @@ int main(int argc, char *argv[]) world_st world; collection_st *collection; collection_st *next; - uint8_t failed; void *world_ptr; memset(&world, 0, sizeof(world_st)); @@ -99,7 +118,6 @@ int main(int argc, char *argv[]) if (next->pre) { - memcached_return rc; rc= next->pre(memc); if (rc != MEMCACHED_SUCCESS) @@ -113,12 +131,9 @@ int main(int argc, char *argv[]) failed= run->function(memc); gettimeofday(&end_time, NULL); load_time= timedif(end_time, start_time); - if (failed) - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time / 1000, - load_time % 1000); - else - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); + + fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ %s ]\n", load_time / 1000, + load_time % 1000, test_strerror(failed)); if (next->post) (void)next->post(memc);