From 2f1772e6ceae5de8a838b9811822a21acc49a80b Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Wed, 29 Nov 2006 12:48:59 +0000 Subject: [PATCH] Removed the nfa tests as well. Now passes make check. --- test/Makefile.am | 5 +- test/nfatest1.c | 441 ---------------------------------------------------- test/nfaxmltest1.c | 333 --------------------------------------- 3 files changed, 1 insertion(+), 778 deletions(-) delete mode 100644 test/nfatest1.c delete mode 100644 test/nfaxmltest1.c diff --git a/test/Makefile.am b/test/Makefile.am index 0c39c8d..1d6395c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,10 +1,9 @@ ## Copyright (C) 1994-2006, Index Data ApS ## All rights reserved. -## $Id: Makefile.am,v 1.26 2006-08-28 12:34:42 adam Exp $ +## $Id: Makefile.am,v 1.27 2006-11-29 12:48:59 heikki Exp $ check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \ - nfatest1 nfaxmltest1 \ tst_filepath tst_record_conv tst_retrieval tst_tpath check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh tstmarccol.sh @@ -56,8 +55,6 @@ tstsoap2_SOURCES = tstsoap2.c tstlogthread_SOURCES = tstlogthread.c tstxmlquery_SOURCES = tstxmlquery.c tstpquery_SOURCES = tstpquery.c -nfatest1_SOURCES = nfatest1.c -nfaxmltest1_SOURCES = nfaxmltest1.c tst_filepath_SOURCES = tst_filepath.c tst_record_conv_SOURCES = tst_record_conv.c tst_retrieval_SOURCES = tst_retrieval.c diff --git a/test/nfatest1.c b/test/nfatest1.c deleted file mode 100644 index 9ca0cb9..0000000 --- a/test/nfatest1.c +++ /dev/null @@ -1,441 +0,0 @@ -/* Copyright (C) 2006, Index Data ApS - * See the file LICENSE for details. - * - * $Id: nfatest1.c,v 1.8 2006-10-09 14:22:44 heikki Exp $ - * - */ - - -#include -#include -#include -#include -#include - - -char *printfunc(void *result) { - static char buf[200]; - sprintf(buf, "\"%s\"", (char*) result); - return buf; -} - -char *printfunc2(void *result) { - static char buf[200]; - sprintf(buf,"(%p)", result); - return buf; -} - -void test_match(yaz_nfa *n, - yaz_nfa_char *buf, size_t buflen, - int expcode, char *expstr) { - yaz_nfa_char *c = buf; - yaz_nfa_char *cp1, *cp2; - void *resptr = 0; - int i, bi; - size_t buflen2 = buflen; - i = yaz_nfa_match(n,&c, &buflen2,&resptr); - if (yaz_test_get_verbosity()>3) - printf("\n'%s' returned %d. Moved c by %ld, and resulted in '%s'\n", - expstr, i, (long)(c-buf),(char*)resptr); - YAZ_CHECK_EQ(buflen-buflen2, c-buf); - YAZ_CHECK_EQ(i, expcode); - if (i==0) - YAZ_CHECK_EQ(strcmp(expstr,(char*)resptr), 0); - i = 0; - bi = 0; - while((bi!=2) && (yaz_test_get_verbosity()>3)){ - bi = yaz_nfa_get_backref(n, i,&cp1,&cp2); - if (bi==0 && ( cp1 || cp2 ) ) { - printf(" got backref %d of %ld chars (%p to %p): '", - i, (long)(cp2-cp1+1), cp1, cp2); - while (cp2-cp1 >= 0 ) - printf("%c", *cp1++); - printf("'\n"); - } - i++; - } -} - -void construction_test(void) { - yaz_nfa* n= yaz_nfa_init(); - yaz_nfa_char *cp, *cp1, *cp2; - yaz_nfa_state *s, *s0, *s1, *s2, *s3, *s4, *s5; - int i; - yaz_nfa_char seq1[]={'p', 'r', 'e', 'f', 'i', 'x', 0}; - yaz_nfa_char seq2[]={'p', 'r', 'e', 'l', 'i', 'm', 0}; - yaz_nfa_char tst1[]={'c', 0}; - yaz_nfa_char tst2[]={'c', 'k', 0}; - yaz_nfa_char tst3[]={'c', 'x', 0}; - yaz_nfa_char tst4[]={'z', 'k', 0}; - yaz_nfa_char tst5[]={'y', 'k', 'l', 'k', 'k', 'l', 'k', 'd', 0}; - yaz_nfa_char tst6[]={'x', 'z', 'k', 'a', 'b', 0}; - void *p; - size_t sz; - - YAZ_CHECK(n); - - s = yaz_nfa_get_first(n); - YAZ_CHECK(!s); - - s0 = yaz_nfa_add_state(n); - - s = yaz_nfa_get_first(n); - YAZ_CHECK(s); - s = yaz_nfa_get_next(n, s); - YAZ_CHECK(!s); - - s1 = yaz_nfa_add_state(n); - i = yaz_nfa_set_result(n, s1, "first"); - YAZ_CHECK_EQ(i, 0); - - i = yaz_nfa_set_result(n, s1, "DUPLICATE"); - YAZ_CHECK_EQ(i, YAZ_NFA_ALREADY); - - p = yaz_nfa_get_result(n, s1); - YAZ_CHECK(p); - YAZ_CHECK( strcmp((char*)p, "first")==0 ); - - i = yaz_nfa_set_result(n, s1, 0); - YAZ_CHECK_EQ(i, 0); - p = yaz_nfa_get_result(n, s1); - YAZ_CHECK(!p); - i = yaz_nfa_set_result(n, s1, "first"); - YAZ_CHECK_EQ(i, 0); - - s2 = yaz_nfa_add_state(n); - s3 = yaz_nfa_add_state(n); - yaz_nfa_set_result(n, s3, "a-k, x-z"); - - s = yaz_nfa_get_first(n); - YAZ_CHECK(s); - s = yaz_nfa_get_next(n, s); - YAZ_CHECK(s); - - - yaz_nfa_add_transition(n, s0, s1, 'a', 'k'); - yaz_nfa_add_transition(n, s1, s1, 'k', 'k'); - yaz_nfa_add_transition(n, s0, s2, 'p', 'p'); - yaz_nfa_add_transition(n, s1, s3, 'x', 'z'); - - s = yaz_nfa_add_range(n, 0, 'k', 's' ); - yaz_nfa_set_result(n, s, "K-S"); - - s4 = yaz_nfa_add_range(n, s2, 'l', 'r' ); - s5 = yaz_nfa_add_range(n, s2, 'l', 'r' ); - YAZ_CHECK((s4==s5)); - s = yaz_nfa_add_range(n, 0, 'c', 'c' ); - - s = yaz_nfa_add_range(n, 0, 'z', 'z' ); - yaz_nfa_add_empty_transition(n, s, s); - yaz_nfa_set_result(n, s, "loop"); - - s = yaz_nfa_add_range(n, 0, 'y', 'y' ); - yaz_nfa_set_backref_point(n, s, 1, 1); - s1 = yaz_nfa_add_state(n); - yaz_nfa_add_empty_transition(n, s, s1); - s = s1; - yaz_nfa_add_transition(n, s, s, 'k', 'l'); - s = yaz_nfa_add_range(n, s, 'd', 'd' ); - yaz_nfa_set_result(n, s, "y k+ d"); - yaz_nfa_set_backref_point(n, s, 1, 0); - - s = yaz_nfa_add_sequence(n, 0, seq1,6 ); - yaz_nfa_set_result(n, s, "PREFIX"); - s = yaz_nfa_add_sequence(n, 0, seq2,6 ); - yaz_nfa_set_result(n, s, "PRELIM"); - - s = yaz_nfa_add_range(n, 0, 'x', 'x' ); - i=yaz_nfa_set_backref_point(n, s, 2, 0); - YAZ_CHECK_EQ(i,YAZ_NFA_NOSTART); - i=yaz_nfa_set_backref_point(n, s, 2, 1); - YAZ_CHECK_EQ(i,YAZ_NFA_SUCCESS); - i=yaz_nfa_set_backref_point(n, s, 2, 1); - YAZ_CHECK_EQ(i,YAZ_NFA_ALREADY); - s1 = yaz_nfa_add_sequence(n, s, tst4,2); - yaz_nfa_set_backref_point(n, s1, 2, 0); - yaz_nfa_set_result(n, s1, "xzk"); - - /* check return codes before doing any matches */ - i = yaz_nfa_get_backref(n, 0, &cp1, &cp2 ); - YAZ_CHECK_EQ(i, YAZ_NFA_NOMATCH); - i = yaz_nfa_get_backref(n, 3, &cp1, &cp2 ); - YAZ_CHECK_EQ(i, YAZ_NFA_NOSUCHBACKREF ); - i = yaz_nfa_get_backref(n, 1, &cp1, &cp2 ); - YAZ_CHECK_EQ(i, YAZ_NFA_NOMATCH ); - - - if (yaz_test_get_verbosity()>3) - yaz_nfa_dump(0, n, printfunc); - - test_match(n, seq2, 3, YAZ_NFA_OVERRUN, "K-S"); - test_match(n, seq2, 6, YAZ_NFA_SUCCESS, "PRELIM"); - test_match(n, tst1, 3, YAZ_NFA_SUCCESS, "first"); - test_match(n, tst2, 3, YAZ_NFA_SUCCESS, "first"); - test_match(n, tst3, 3, YAZ_NFA_SUCCESS, "a-k, x-z"); - test_match(n, tst4, 9, YAZ_NFA_LOOP, "loop"); - test_match(n, tst5, 9, YAZ_NFA_SUCCESS, "y k+ d"); - - cp = tst6; /* xzkab */ - sz = 8; - i = yaz_nfa_match(n, &cp, &sz, &p); - YAZ_CHECK_EQ(i, YAZ_NFA_SUCCESS); - i = yaz_nfa_get_backref(n, 2, &cp1, &cp2 ); - YAZ_CHECK_EQ(i, 0); - YAZ_CHECK_EQ(cp2-cp1+1,2); - YAZ_CHECK_EQ(*cp1, 'z' ); - YAZ_CHECK_EQ(*cp2, 'k' ); - if (yaz_test_get_verbosity()>3) - printf("backref from %p '%c' to %p '%c' is %ld long. sz is now %ld\n", - cp1, *cp1, cp2, *cp2, (long)(cp2-cp1+1), (long)sz ); - - yaz_nfa_destroy(n); -} - -void converter_test(void) { - yaz_nfa* n= yaz_nfa_init(); - yaz_nfa_converter *c1, *c2, *c3; - yaz_nfa_char str1[]={'a','b','c'}; - yaz_nfa_char seq1[]={'A','B','C'}; - yaz_nfa_char seq2[]={'k','m','n','m','x','P','Q','X',0}; - yaz_nfa_char outbuf[1024]; - yaz_nfa_char *outp, *cp, *cp1, *cp2; - yaz_nfa_state *s, *s2; - void *vp; - int i; - size_t sz; - - c1=yaz_nfa_create_string_converter(n,str1,3); - - for(i=0;i<1024;i++) - outbuf[i]=10000+i; - outp=outbuf; - sz=1; - i=yaz_nfa_run_converters(n, c1, &outp, &sz); - YAZ_CHECK_EQ(i,4); /* overrun */ - YAZ_CHECK_EQ(outbuf[0],'a'); - YAZ_CHECK_EQ(outbuf[1],10000+1); - - for(i=0;i<1024;i++) - outbuf[i]=10000+i; - outp=outbuf; - sz=3; - i=yaz_nfa_run_converters(n, c1, &outp, &sz); - YAZ_CHECK_EQ(i,0); - YAZ_CHECK_EQ(outbuf[0],'a'); - YAZ_CHECK_EQ(outbuf[1],'b'); - YAZ_CHECK_EQ(outbuf[2],'c'); - YAZ_CHECK_EQ(outbuf[3],10000+3); - YAZ_CHECK_EQ(sz,0); - - c2=yaz_nfa_create_string_converter(n,str1,2); - yaz_nfa_append_converter(n,c1,c2); - - for(i=0;i<1024;i++) - outbuf[i]=10000+i; - outp=outbuf; - sz=10; - i=yaz_nfa_run_converters(n, c1, &outp, &sz); - YAZ_CHECK_EQ(i,0); - YAZ_CHECK_EQ(outbuf[0],'a'); - YAZ_CHECK_EQ(outbuf[1],'b'); - YAZ_CHECK_EQ(outbuf[2],'c'); - YAZ_CHECK_EQ(outbuf[3],'a'); - YAZ_CHECK_EQ(outbuf[4],'b'); - YAZ_CHECK_EQ(outbuf[5],10000+5); - YAZ_CHECK_EQ(sz,5); - - /* ABC -> abcab */ - (void) yaz_nfa_add_state(n);/* start state */ - s=yaz_nfa_add_state(n); - yaz_nfa_add_empty_transition(n,0,s); - yaz_nfa_set_backref_point(n,s,1,1); - s=yaz_nfa_add_sequence(n, s, seq1,3 ); - yaz_nfa_set_result(n,s,c1); - yaz_nfa_set_backref_point(n,s,1,0); - - /* ([k-o][m-n]*)x -> \1 */ - s=yaz_nfa_add_state(n); - yaz_nfa_add_empty_transition(n,0,s); - yaz_nfa_set_backref_point(n,s,2,1); - s2=yaz_nfa_add_state(n); - yaz_nfa_add_transition(n,s,s2,'k','o'); - yaz_nfa_add_transition(n,s2,s2,'m','n'); - s=yaz_nfa_add_state(n); - yaz_nfa_add_transition(n,s2,s,'x','x'); - yaz_nfa_set_backref_point(n,s,2,0); - - c1=yaz_nfa_create_backref_converter(n,2); - yaz_nfa_set_result(n,s,c1); - - if (yaz_test_get_verbosity()>3) - yaz_nfa_dump(0,n, printfunc2); - - cp=seq2; - sz=18; - i=yaz_nfa_match(n,&cp,&sz,&vp); - c2=vp; - YAZ_CHECK_EQ(i,YAZ_NFA_SUCCESS); - i=yaz_nfa_get_backref(n, 2, &cp1, &cp2 ); - if (yaz_test_get_verbosity()>3) - printf("backref from %p '%c' to %p '%c' is %ld long. sz is now %ld\n", - cp1, *cp1, cp2, *cp2, (long)(cp2-cp1+1), (long)sz ); - YAZ_CHECK_EQ(i,0); - /*YAZ_CHECK_EQ((int)c1,(int)c2);*/ /* got our pointer back from nfa */ - YAZ_CHECK(c1==c2); /* got our pointer back from nfa */ - for(i=0;i<1024;i++) - outbuf[i]=10000+i; - outp=outbuf; - sz=11; - i=yaz_nfa_run_converters(n, c2, &outp, &sz); - YAZ_CHECK_EQ(i,0); - YAZ_CHECK_EQ(outbuf[0],'k'); - YAZ_CHECK_EQ(outbuf[1],'m'); - YAZ_CHECK_EQ(outbuf[2],'n'); - YAZ_CHECK_EQ(outbuf[3],'m'); - YAZ_CHECK_EQ(outbuf[4],'x'); - YAZ_CHECK_EQ(outbuf[5],10000+5); - YAZ_CHECK_EQ(sz,11-5); - - c3=yaz_nfa_create_range_converter(n,2, 'a', 'A' ); - for(i=0;i<1024;i++) - outbuf[i]=10000+i; - outp=outbuf; - sz=11; - i=yaz_nfa_run_converters(n, c3, &outp, &sz); - YAZ_CHECK_EQ(i,0); - YAZ_CHECK_EQ(outbuf[0],'K'); - YAZ_CHECK_EQ(outbuf[1],'M'); - YAZ_CHECK_EQ(outbuf[2],'N'); - YAZ_CHECK_EQ(outbuf[3],'M'); - YAZ_CHECK_EQ(outbuf[4],'X'); - YAZ_CHECK_EQ(outbuf[5],10000+5); - YAZ_CHECK_EQ(sz,11-5); - - yaz_nfa_destroy(n); -} - -yaz_nfa_char *makebuff(NMEM nmem, char *in) { - yaz_nfa_char *buff = nmem_malloc(nmem, strlen(in)*sizeof(yaz_nfa_char)); - yaz_nfa_char *op=buff; - while ( (*op++ = *in++) ) - ; - return buff; -} - -void dumpbuff(char *msg, yaz_nfa_char *start, yaz_nfa_char *end) { - if (yaz_test_get_verbosity()>3) { - printf("%s\"",msg); - while (start!=end) - printf("%c",*start++); - printf("\"\n"); - } -} - -void chkbuff( yaz_nfa_char *start, yaz_nfa_char *end, char *exp) { - char *orig_exp=exp; - while (start!=end) - if ( *start++ != *exp++ ) { - if (yaz_test_get_verbosity()>3) { - start--; - exp--; - printf ("chkbuff: unexpected conversion '%c' != '%c' \n" - "\"%s\"\n", *start, *exp, orig_exp ); - } - YAZ_CHECK(!"conversion differs! "); - return; - } - -} - -void high_level_test(void) { - NMEM nmem=nmem_create(); - yaz_nfa_char from1[] = {'f','o','o','b','a','r'}; - yaz_nfa_char to1[] = {'f','u','b','a','r'}; - yaz_nfa_char tospace[] = {' '}; - yaz_nfa_char todot[] = {'.'}; - char *fromtext = - "It was a Dark and Rainy Night, when alpha and beta " - "fixme - FIND better names ?? !! ## - " - "went out to fix the foobar " - "that was all foo."; - char *expected = - "IT WAS A DARK AND RAINY NIGHT. WHEN ALPHA AND b " - "to-be-fixed-later . FIND BETTER NAMES .. .. .. . " - "WENT OUT TO (fix) THE fubar " - "THAT WAS ALL FOO."; - yaz_nfa_char *from3 = makebuff(nmem,fromtext); - yaz_nfa_char *to3 = nmem_malloc(nmem, 1024*sizeof(yaz_nfa_char)); - yaz_nfa_char *fromp=from3; - yaz_nfa_char *top=to3; - size_t insize=strlen(fromtext); - size_t outsize=1024; - size_t prev_insize=0; - - yaz_nfa *n = yaz_nfa_init(); - int i; - i = yaz_nfa_add_string_rule(n, from1, 6, to1, 5); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_string_rule(n, from1, 6, to1, 5); - YAZ_CHECK_EQ(i,YAZ_NFA_ALREADY); - i = yaz_nfa_add_ascii_string_rule(n,"beta","b"); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_ascii_string_rule(n,"fixme","to-be-fixed-later"); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_ascii_string_rule(n,"fix","(fix)"); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_char_range_rule(n, 'a','z','A'); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_char_string_rule(n, 0,' ', tospace,1); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_char_string_rule(n, '!','/', todot,1); - YAZ_CHECK_EQ(i,0); - i = yaz_nfa_add_char_string_rule(n, ':','?', todot,1); - YAZ_CHECK_EQ(i,0); - if (yaz_test_get_verbosity()>3) - yaz_nfa_dump(0,n, printfunc2); - - YAZ_CHECK_EQ( *from3, 'I' ); /* just to be sure my copy func works */ - for (i=0;i<100;i++) - to3[i]=10000+i; - i=yaz_nfa_convert_slice(n, &fromp, &insize, &top, &outsize); - YAZ_CHECK_EQ(i,YAZ_NFA_SUCCESS); - YAZ_CHECK_EQ(*to3,'I'); - YAZ_CHECK_EQ(insize, strlen(fromtext)-1); - YAZ_CHECK_EQ(outsize, 1024-1); - - while ( (i==YAZ_NFA_SUCCESS) && (insize > 0) && (prev_insize!=insize) ) { - prev_insize=insize; /* detect dead loops if something goes wrong */ - i=yaz_nfa_convert_slice(n, &fromp, &insize, &top, &outsize); - } - YAZ_CHECK_EQ(i,YAZ_NFA_SUCCESS); - YAZ_CHECK_EQ(insize,0); - YAZ_CHECK(prev_insize != insize); /* the loop would have been endless */ - - dumpbuff("Original text: ",from3, fromp); - dumpbuff("Converted text: ",to3, top); - - chkbuff(to3, top, expected); - - yaz_nfa_destroy(n); - nmem_destroy(nmem); -} - -int main(int argc, char **argv) -{ - YAZ_CHECK_INIT(argc, argv); - nmem_init (); - construction_test(); - converter_test(); - high_level_test(); - nmem_exit (); - YAZ_CHECK_TERM; -} - - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/test/nfaxmltest1.c b/test/nfaxmltest1.c deleted file mode 100644 index cf87fc4..0000000 --- a/test/nfaxmltest1.c +++ /dev/null @@ -1,333 +0,0 @@ -/* Copyright (C) 2006, Index Data ApS - * See the file LICENSE for details. - * - * $Id: nfaxmltest1.c,v 1.9 2006-10-09 14:22:44 heikki Exp $ - * - */ - - -#include -#include -#include -#include -#include -#include - -#if YAZ_HAVE_XML2 -#include - - -/** \brief Test parsing of a minimal, valid xml string */ -void test1(void) { - char *xmlstr = " " - " " - " foo " - " bar " - "" - ""; - yaz_nfa *nfa = yaz_nfa_parse_xml_memory(xmlstr,"test1"); - YAZ_CHECK(nfa); - yaz_nfa_destroy(nfa); -} - - -/** \brief Test parsing of a minimal, invalid xml string */ -void test2(void) { - yaz_nfa *nfa; - char *xmlstr = " " - " " - " foo " - " bar " - ""; - /* missing "" */ - yaz_log(YLOG_LOG,"Parsing bad xml, expecting errors:"); - nfa = yaz_nfa_parse_xml_memory(xmlstr,"test2"); - YAZ_CHECK(!nfa); - nfa = yaz_nfa_parse_xml_memory(0,"test2-null"); - YAZ_CHECK(!nfa); -} - -/** \brief Test parsing a few minimal xml files */ -void test3(void) { - char *goodfilenames[] = { - "nfaxml-simple.xml", - "nfaxml-main.xml", /* x-includes nfaxml-include */ - 0}; - char *badfilenames[] = { - "nfaxml-missing.xml", /* file not there at all */ - "nfaxml-badinclude.xml", /* bad xinclude in it */ - 0}; - yaz_nfa *nfa; - char **f = goodfilenames; - do { - yaz_log(YLOG_LOG,"Parsing (good) xml file '%s'", *f); - nfa=yaz_nfa_parse_xml_file(*f); - YAZ_CHECK_TODO(nfa); /* fails on make distcheck, can't find the files*/ - } while (*++f); - - f = badfilenames; - do { - yaz_log(YLOG_LOG,"Parsing bad xml file '%s'. Expecting errors", *f); - nfa = yaz_nfa_parse_xml_file(*f); - YAZ_CHECK(!nfa); - } while (*++f); -} - -/** \brief Test parsing of a few minimal xml strings, with logical errors */ -void test4(void) { - yaz_nfa *nfa; - char *xmls[] = { - /*a*/" ", - /*b*/" ", - /*c*/" ", - /*d*/"" - "MissingTo" - "", - /*e*/"" - "DuplicateFrom" - "Another Fromstring" - "", - /*f*/"" - "MissingFrom" - "", - /*g*/"" - "DuplicateTo" - "AnotherTo" - "", - /*h*/"" - "GoodUTF:æøå" - "", - /*i*/"" - "BadUtf8:Ø" - "", - /*j*/"" - "" - "ConflictingRules" - "IdenticalStrings" - "" - "" - "ConflictingRules" - "IdenticalStrings" - "" - "", - /*k*/"", /* empty string! */ - /*l*/"" - "" - "A-Z" - "a-x" - "" - "", - 0 }; - char **xmlp=xmls; - char label[]= { 'a', 0 }; - while ( *xmlp ) { - yaz_log(YLOG_LOG,"test4-%s: Parsing bad xml, expecting errors:", - label); - nfa = yaz_nfa_parse_xml_memory(*xmlp,label); - YAZ_CHECK(!nfa); - xmlp++; - label[0]++; - } -} /* test4 */ - -static void test5(void) { - struct conv_test { - char *name; - int expresult; - char *xml; - char *from; - char *to; - }; - struct conv_test tests[]= { - { "test5-1", YAZ_NFA_SUCCESS, - "" - "" - "foo" - "bar" - "" - "", - "this is a foo test ofoofo fo foofoo fofoofooofoooo ", - "this is a bar test obarfo fo barbar fobarbarobaroo " - }, - { "test5-2", YAZ_NFA_SUCCESS, - "" - "" - "ooooo" - "five " - "" - "" - "oooo" - "four " - "" - "" - "ooo" - "three " - "" - "" - "oo" - "two " - "" - "", - "oo-oooo-", - "two -four -" - }, - { "test5-4", YAZ_NFA_SUCCESS, 0, /* same xml */ - "oo-oooo-ooooooo-", - "two -four -five two -" - }, - { "test5-3", YAZ_NFA_OVERRUN, 0, /* could match further oo's */ - "oo-oooo-ooooooo", - "two -four -five " - }, - { "test5-4 (lowercase)", YAZ_NFA_SUCCESS, - "" - "" - "A-Z" - "a-z" - "" - "", - "LowerCase TEST with A-Z and a-z", - "lowercase test with a-z and a-z" - }, - { "test5-5 (lowercase entities)", YAZ_NFA_SUCCESS, - "" - "" - "A-Z" - "a-z" - "" - "", - "LowerCase TEST with A-Z and a-z (and ) A; )", - "lowercase test with a-z and a-z (and ) a; )" - }, - { "test5-6 (danish lowercase)", YAZ_NFA_SUCCESS, - "" - "" - "A-Z" - "a-z" - "" - "" - "À-Ö" - "à-ö" - "" - "" - "Ø-ß" - "ø-ÿ" - "" - "" - "Å" - "å" - "" - "" - "Dänish" - "DÄNISH" - "" - "", - "LowerCase TEST with Dänish Å !? åæø ÅÆØ XYZ", - "lowercase test with DÄNISH å !? åæø åæø xyz" - }, - {0,0,0,0} - }; - char *xml=0; -#define MAXBUF 2048 - yaz_nfa *nfa; - yaz_nfa_char frombuf[MAXBUF]; - yaz_nfa_char tobuf[MAXBUF]; - char charbuf[MAXBUF]; - struct conv_test *thistest=tests; - char *cp; - yaz_nfa_char *ycp; - size_t incharsleft; - size_t outcharsleft; - size_t prev_incharsleft; - int rc; - yaz_nfa_char *fromp; - yaz_nfa_char *top; - while (thistest->name) { - yaz_log(YLOG_DEBUG,"Starting test %s",thistest->name); - if (thistest->xml) - xml=thistest->xml; - nfa = yaz_nfa_parse_xml_memory(xml, thistest->name); - YAZ_CHECK(nfa); - if (nfa) { - if ( yaz_test_get_verbosity() > 3) { - yaz_nfa_dump(0,nfa,yaz_nfa_dump_converter); - } - ycp=frombuf; - cp=thistest->from; - while ( (*ycp++ = (unsigned char)*cp++) ) - ; /* strcpy, but expand to yaz_nfa_chars */ - incharsleft = strlen(thistest->from); - prev_incharsleft = 0; - outcharsleft = MAXBUF-1; - fromp = frombuf; - top = tobuf; - rc = YAZ_NFA_SUCCESS; - while ( (rc == YAZ_NFA_SUCCESS) && (incharsleft>0) && - (prev_incharsleft != incharsleft ) ) /* prevent loops */ - { - prev_incharsleft=incharsleft; - rc=yaz_nfa_convert_slice(nfa, &fromp, &incharsleft, - &top, &outcharsleft); - } - YAZ_CHECK_EQ(rc, thistest->expresult); - if ( (rc == thistest->expresult) && - (rc == YAZ_NFA_SUCCESS)) { - YAZ_CHECK_EQ(incharsleft, 0); - YAZ_CHECK( prev_incharsleft != incharsleft ); - } - ycp=tobuf; - cp=charbuf; - while (ycp != top ) - *cp++ = *ycp++; - *cp=0; - if ( yaz_test_get_verbosity() > 2) { - printf("%s from: '%s' \n",thistest->name, thistest->from); - printf("%s result: '%s' \n",thistest->name, charbuf); - printf("%s expect: '%s' \n",thistest->name, thistest->to); - } - YAZ_CHECK( 0==strcmp(thistest->to,charbuf) ); - yaz_nfa_destroy(nfa); - } - thistest++; - } - -} /* test5 */ - - -/* More things to test: - * - * - Empty strings in to/from - * - ranges, length mismatches, etc - */ - -int main(int argc, char **argv) -{ - YAZ_CHECK_INIT(argc, argv); - YAZ_CHECK_LOG(); - nmem_init (); - - test1(); - test2(); - test3(); - test4(); - test5(); - - nmem_exit (); - YAZ_CHECK_TERM; -} - -#else -int main(int argc, char **argv) { - YAZ_CHECK_INIT(argc, argv); - YAZ_CHECK_TERM; -} - -#endif - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ -- 1.7.10.4