* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: test.h,v 1.1 2006-01-27 17:30:44 adam Exp $
+ * $Id: test.h,v 1.2 2006-01-27 18:58:57 adam Exp $
*/
#ifndef YAZ_TEST_H
#include <yaz/yconfig.h>
#include <stdio.h>
-#define YAZ_CHECK_INIT(thename) \
-static char *yaz_unit_test_name = #thename;
-static FILE *yaz_unit_file = 0; \
-static int yaz_unit_test_number = 0; \
+#define YAZ_TEST_TYPE_OK 1
+#define YAZ_TEST_TYPE_FAIL 2
-#define YAZ_CHECK(as) \
-yaz_unit_test_number++; \
-if (!yaz_unit_file) yaz_unit_file = stderr; \
-if (!as) { \
- fprintf(yaz_unit_file, "%s:%d test failed: %s\n", __FILE__, __LINE__, #as); \
+#define YAZ_CHECK(as) { \
+ if (as) { \
+ yaz_check_print1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, #as); \
+ } else { \
+ yaz_check_print1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, #as); \
+ } \
}
+#define YAZ_CHECK_INIT(argc, argv) yaz_check_init1(&argc, &argv)
+
+YAZ_BEGIN_CDECL
+YAZ_EXPORT void yaz_check_init1(int *argc, char ***argv);
+YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line,
+ const char *expr);
+YAZ_END_CDECL
+
+
#endif
/*
* Local variables:
## This file is part of the YAZ toolkit.
## Copyright (C) 1994-2005, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.26 2006-01-27 17:31:37 adam Exp $
+## $Id: Makefile.am,v 1.27 2006-01-27 18:58:58 adam Exp $
YAZ_VERSION_INFO=2:0:0
cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c \
cqlstrer.c querytowrbuf.c \
eventl.c seshigh.c statserv.c requestq.c tcpdchk.c \
- eventl.h service.c service.h session.h \
+ eventl.h service.c service.h session.h test.c \
xmlquery.c
libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO)
--- /dev/null
+/*
+ * Copyright (C) 1995-2005, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: test.c,v 1.1 2006-01-27 18:58:58 adam Exp $
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <yaz/test.h>
+
+static FILE *test_fout;
+static int test_number = 0;
+static int test_verbose = 0;
+
+void yaz_check_init1(int *argc_p, char ***argv_p)
+{
+ int i = 0;
+ int argc = *argc_p;
+ char **argv = *argv_p;
+
+ test_fout = 0;
+ for (i = 1; i<argc; i++)
+ {
+ if (strlen(argv[i]) >= 7 && !memcmp(argv[i], "--test-", 7))
+ {
+ const char *suf = argv[i]+7;
+ if (i < argc-1 && !strcmp(suf, "file"))
+ {
+ i++;
+ if (test_fout)
+ fclose(test_fout);
+ test_fout = fopen(argv[i], "w");
+ continue;
+ }
+ else if (i < argc-1 && !strcmp(suf, "verbose"))
+ {
+ i++;
+ test_verbose = atoi(argv[i]);
+ continue;
+ }
+ else if (!strcmp(suf, "help"))
+ {
+ fprintf(stderr,
+ "--test-help help\n"
+ "--test-verbose level verbose; 0=quiet; 1=normal; 2=more\n"
+ "--test-file fname output to fname\n");
+ exit(0);
+ }
+ else
+ {
+ fprintf(stderr, "Unrecognized option for YAZ test: %s\n",
+ argv[i]);
+ fprintf(stderr, "Use --test-help for more info\n");
+ exit(1);
+ }
+
+ }
+ break;
+ }
+ /* remove --test- options from argc, argv so that they disappear */
+ (*argv_p)[i-1] = **argv_p; /* program name */
+ --i;
+ *argc_p -= i;
+ *argv_p += i;
+ if (!test_fout)
+ test_fout = stdout;
+}
+
+void yaz_check_print1(int type, const char *file, int line, const char *expr)
+{
+ const char *msg = "unknown";
+
+ test_number++;
+ switch(type)
+ {
+ case YAZ_TEST_TYPE_FAIL:
+ msg = "failed";
+ if (test_verbose < 1)
+ return;
+ break;
+ case YAZ_TEST_TYPE_OK:
+ msg = "OK";
+ if (test_verbose < 2)
+ return;
+ break;
+ }
+ fprintf(test_fout, "%s:%d %s: %s\n", file, line, msg, expr);
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstxmlquery.c,v 1.1 2006-01-27 17:33:15 adam Exp $
+ * $Id: tstxmlquery.c,v 1.2 2006-01-27 18:58:58 adam Exp $
*/
#include <stdlib.h>
int main (int argc, char **argv)
{
+ YAZ_CHECK_INIT(argc, argv);
+
pqf2xml_text("@attr 1=4 computer");
exit(0);