X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Fnfaxmltest1.c;h=754be3b209e0ccdef1a4e037a7ee13fad4bfbe4e;hp=b6cf6d5b17d37ce83b8b6177b5554708d5e8ac2a;hb=fd3a0b7302ceed6425c05b6537cb654201cb1494;hpb=5ed3b6561d90d13f64be7f9ae8beaf4a0b3f8e32
diff --git a/test/nfaxmltest1.c b/test/nfaxmltest1.c
index b6cf6d5..754be3b 100644
--- a/test/nfaxmltest1.c
+++ b/test/nfaxmltest1.c
@@ -1,7 +1,7 @@
/* Copyright (C) 2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: nfaxmltest1.c,v 1.6 2006-07-07 13:39:05 heikki Exp $
+ * $Id: nfaxmltest1.c,v 1.7 2006-07-14 13:06:38 heikki Exp $
*
*/
@@ -25,8 +25,9 @@ void test1() {
" bar "
""
"";
- yaz_nfa *nfa = yaz_nfa_parse_xml_memory(xmlstr);
- YAZ_CHECK_TODO(nfa);
+ yaz_nfa *nfa = yaz_nfa_parse_xml_memory(xmlstr,"test1");
+ YAZ_CHECK(nfa);
+ yaz_nfa_destroy(nfa);
}
@@ -40,7 +41,9 @@ void test2() {
"";
/* missing "" */
yaz_log(YLOG_LOG,"Parsing bad xml, expecting errors:");
- nfa = yaz_nfa_parse_xml_memory(xmlstr);
+ nfa = yaz_nfa_parse_xml_memory(xmlstr,"test2");
+ YAZ_CHECK(!nfa);
+ nfa = yaz_nfa_parse_xml_memory(0,"test2-null");
YAZ_CHECK(!nfa);
}
@@ -59,7 +62,7 @@ void test3() {
do {
yaz_log(YLOG_LOG,"Parsing (good) xml file '%s'", *f);
nfa=yaz_nfa_parse_xml_file(*f);
- YAZ_CHECK_TODO(nfa);
+ YAZ_CHECK_TODO(nfa); /* fails on make distcheck, can't find the files*/
} while (*++f);
f = badfilenames;
@@ -70,6 +73,232 @@ void test3() {
} while (*++f);
}
+/** \brief Test parsing of a few minimal xml strings, with logical errors */
+void test4() {
+ 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() {
+ struct conv_test {
+ unsigned char *name;
+ int expresult;
+ unsigned char *xml;
+ unsigned char *from;
+ unsigned 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];
+ unsigned char charbuf[MAXBUF];
+ struct conv_test *thistest=tests;
+ unsigned 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++ = *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)
{
@@ -80,6 +309,8 @@ int main(int argc, char **argv)
test1();
test2();
test3();
+ test4();
+ test5();
nmem_exit ();
YAZ_CHECK_TERM;