diff -r 000000000000 -r cbd63f7ba40f test/harness/testcaseio.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/harness/testcaseio.c Wed Jan 25 19:33:43 2012 +0000 @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include "testcaseparser.h" +#include "testcaseio.h" + +/* + * Read a testcase in from a file. + * On error, print a suitable message on stderr and return NULL. + * The returned testcase should be freed with testcase_free(). + */ +Testcase *testcase_parse_file(const char *filename) +{ + Testcase *testcase; + TestcaseParser *parser; + char *s; + const char *tag,*text; + boolean found_tag=FALSE; + parser=testcase_parser_new_from_file(filename); + if (!parser) + return NULL; + if (!*testcase_parser_get_flag(parser)) + { + fprintf(stderr,"%s: Not a valid testcase (flag)\n",filename); + testcase_parser_free(parser); + return NULL; + } + testcase=mem_new0(Testcase,1); + testcase->basename=path_get_basename(filename); + s=strrchr(testcase->basename,'.'); + if (s) + *s='\0'; + while(testcase_parser_get_next_tag(parser,&tag,&text)) + { + if (!testcase->input && !strcmp(tag,"INPUT")) + testcase->input=str_dup(text); + else if (!testcase->expected && !strcmp(tag,"EXPECTED")) + testcase->expected=str_dup(text); + else + { + fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag); + testcase_free(testcase); + testcase_parser_free(parser); + return NULL; + } + found_tag=TRUE; + } + if (!testcase_parser_at_eof(parser)) + { + if (found_tag) + fprintf(stderr,"%s: Not a valid testcase (garbage at end)\n", + filename); + else + fprintf(stderr,"%s: Not a valid testcase (no valid tags)\n", + filename); + testcase_free(testcase); + testcase_parser_free(parser); + return NULL; + } + testcase_parser_free(parser); + return testcase; +}