X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=ztest%2Fztest.c;h=6cc2bffefd4ea49a27fb4586ff94497e2ad0d155;hb=5cf76d0f27403990896771b870e833605a7f87f6;hp=6d806b273d194dc076990414a1d008ec285ea85f;hpb=f3027244f210c7014b46dc564e868bbdf10560e2;p=yaz-moved-to-github.git diff --git a/ztest/ztest.c b/ztest/ztest.c index 6d806b2..6cc2bff 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -11,9 +11,19 @@ #include #include #include + +#if HAVE_SYS_TIME_H +#include +#endif #if HAVE_UNISTD_H #include #endif +#if HAVE_SYS_SELECT_H +#include +#endif +#ifdef WIN32 +#include +#endif #include #include @@ -123,12 +133,16 @@ static Odr_int get_term_hit(Z_RPNStructure *s) */ static Odr_int get_hit_count(Z_Query *q) { - Odr_int h = -1; if (q->which == Z_Query_type_1 || q->which == Z_Query_type_101) + { + Odr_int h = -1; h = get_term_hit(q->u.type_1->RPNStructure); - if (h == -1) - h = rand() % 24; - return h; + if (h == -1) + h = rand() % 24; + return h; + } + else + return 24; } /** \brief checks if it's a dummy Slow database @@ -188,18 +202,27 @@ static int parse_delay(struct delay *delayp, const char *value) return 0; } +static void ztest_sleep(double d) +{ +#ifdef WIN32 + Sleep( (DWORD) (d * 1000)); +#else + struct timeval tv; + tv.tv_sec = floor(d); + tv.tv_usec = (d - floor(d)) * 1000000; + select(0, 0, 0, 0, &tv); +#endif +} + static void do_delay(const struct delay *delayp) { double d = delayp->d1; if (d > 0.0) { - struct timeval tv; if (delayp->d2 > d) d += (rand()) * (delayp->d2 - d) / RAND_MAX; - tv.tv_sec = floor(d); - tv.tv_usec = (d - floor(d)) * 1000000; - select(0, 0, 0, 0, &tv); + ztest_sleep(d); } } @@ -268,7 +291,7 @@ int ztest_search(void *handle, bend_search_rr *rr) const char *name = names[i]; const char *value = values[i]; if (!strcmp(name, "seed")) - srandom(atoi(value)); + srand(atoi(value)); else if (!strcmp(name, "search-delay")) parse_delay(&new_set->search_delay, value); else if (!strcmp(name, "present-delay"))