+ return 1;
+ }
+ return 0;
+}
+
+static int strcmp_prefix(const char *s, const char *p)
+{
+ size_t l = strlen(p);
+ if (strlen(s) >= l && !memcmp(s, p, l))
+ return 1;
+ return 0;
+}
+
+static void init_delay(struct delay *delayp)
+{
+ delayp->d1 = delayp->d2 = 0.0;
+}
+
+static int parse_delay(struct delay *delayp, const char *value)
+{
+ if (sscanf(value, "%lf:%lf", &delayp->d1, &delayp->d2) == 2)
+ ;
+ else if (sscanf(value, "%lf", &delayp->d1) == 1)
+ delayp->d2 = 0.0;
+ else
+ return -1;
+ 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)
+ {
+ if (delayp->d2 > d)
+ d += (rand()) * (delayp->d2 - d) / RAND_MAX;
+ ztest_sleep(d);
+ }
+}
+
+static void addterms(ODR odr, Z_FacetField *facet_field) {
+ int index;
+ int freq = 100;
+ const char *key = "key";
+ for (index = 0; index < facet_field->num_terms; index++) {
+ Z_Term *term = term_create(odr, key);
+ Z_FacetTerm *facet_term = facet_term_create(odr, term, freq);
+ freq = freq - 10 ;
+ facet_field_term_set(odr, facet_field, facet_term, index);
+ //yaz_log(YLOG_DEBUG, "Facet term %d %d", term->u.characterString, *facet_term->count);
+ }
+}
+Z_OtherInformation *build_facet_response(ODR odr, Z_FacetList *facet_list) {
+ int index;
+ Z_OtherInformation *oi = odr_malloc(odr, sizeof(*oi));
+ Z_OtherInformationUnit *oiu = odr_malloc(odr, sizeof(*oiu));
+ Z_FacetList *new_list = facet_list_create(odr, facet_list->num);
+
+ for (index = 0; index < facet_list->num; index++) {
+ new_list->elements[index] = facet_field_create(odr, facet_list->elements[index]->attributes, 3);
+ addterms(odr, new_list->elements[index]);
+ }
+ oi->num_elements = 1;
+ oi->list = odr_malloc(odr, oi->num_elements * sizeof(*oi->list));
+ oiu->category = 0;
+ oiu->which = Z_OtherInfo_externallyDefinedInfo;
+ oiu->information.externallyDefinedInfo = odr_malloc(odr, sizeof(*oiu->information.externallyDefinedInfo));
+ oiu->information.externallyDefinedInfo->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_facet_1);
+ oiu->information.externallyDefinedInfo->which = Z_External_userFacets;
+ oiu->information.externallyDefinedInfo->u.facetList = new_list;
+ oi->list[0] = oiu;
+ return oi;
+}
+
+int ztest_search(void *handle, bend_search_rr *rr)
+{
+ struct session_handle *sh = (struct session_handle*) handle;
+ struct result_set *new_set;
+ const char *db, *db_sep;
+
+ if (rr->num_bases != 1)
+ {
+ rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
+ return 0;
+ }
+
+ db = rr->basenames[0];
+
+ /* Allow Default, db.* and Slow */
+ if (strcmp_prefix(db, "Default"))
+ ; /* Default is OK in our test */
+ else if (strcmp_prefix(db, "db"))
+ ; /* db.* is OK in our test */
+ else if (check_slow(rr->basenames[0], rr->association))
+ {