-/* $Id: testlib.c,v 1.28 2005-11-09 12:01:09 adam Exp $
+/* $Id: testlib.c,v 1.29 2005-12-15 13:28:32 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
{
const char *srcdir = getenv("srcdir");
if (!srcdir || ! *srcdir)
- srcdir=".";
+ srcdir = ".";
return srcdir;
}
sprintf(cfg, "%.200s/%.50s", srcdir, cfgname);
zs = zebra_start(cfg);
- if (!zs)
- {
- printf("zebra_start failed, probably because missing config file \n"
- "check %s\n", cfg);
- exit(9);
- }
+ TL_ASSERT2(zs, "zebra_start_failed. Missing config file?");
return zs;
}
zebra_result(zh, &i, &addinfo);
yaz_log(log_level, "Error %d %s", i, addinfo);
printf(" Error %d %s\n", i, addinfo);
- exit(1);
+ TL_ASSERT(i == 0);
}
if (recs)
{
parser = yaz_pqf_create();
rpn = yaz_pqf_parse(parser, odr, query);
yaz_pqf_destroy(parser);
- if (!rpn) {
- yaz_log(log_level, "PQF Parse failed\n");
- printf("Error: Parse failed \n%s\n", query);
- exit(1);
- }
+ TL_ASSERT2(rpn, "Parse of pqf failed");
rc = zebra_search_RPN(zh, odr, rpn, setname, &hits);
if (experror)
{
"expected", rc);
printf("Error: search returned %d (OK), but error was expected\n"
"%s\n", rc, query);
- exit(1);
+ TL_ASSERT(rc == ZEBRA_FAIL);
}
code = zebra_errCode(zh);
if (code != experror)
printf("Error: search returned error code %d, but error %d was "
"expected\n%s\n",
code, experror, query);
- exit(1);
+ TL_ASSERT(code == experror);
}
}
else
-/* $Id: testlib.h,v 1.16 2005-09-13 11:51:07 adam Exp $
+/* $Id: testlib.h,v 1.17 2005-12-15 13:28:32 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
* if filter given by name does not exist, exit nicely but warn in log
*/
void check_filter(ZebraService zs, const char *name);
+
+#define TL_ASSERT(x) if (!(x)) { yaz_log(YLOG_FATAL, "%s:%d TL_ASSERT(%s) failed", __FILE__, __LINE__, #x); exit(1); }
+#define TL_ASSERT2(x,m) if (!(x)) { yaz_log(YLOG_WARN, "%s", m); yaz_log(YLOG_FATAL, "%s:%d TL_ASSERT(%s) failed", __FILE__, __LINE__, #x); exit(1); }