6 #include "testcaseparser.h"
7 #include "testcaseio.h"
10 * Read a testcase in from a file.
11 * On error, print a suitable message on stderr and return NULL.
12 * The returned testcase should be freed with testcase_free().
14 Testcase *testcase_parse_file(const char *filename)
17 TestcaseParser *parser;
19 const char *tag,*text;
20 gboolean found_tag=FALSE;
21 parser=testcase_parser_new_from_file(filename);
24 if (!*testcase_parser_get_flag(parser))
26 fprintf(stderr,"%s: Not a valid testcase (flag)\n",filename);
27 testcase_parser_free(parser);
30 testcase=g_new0(Testcase,1);
31 testcase->basename=g_path_get_basename(filename);
32 s=strrchr(testcase->basename,'.');
35 while(testcase_parser_get_next_tag(parser,&tag,&text))
37 if (!testcase->input && !strcmp(tag,"INPUT"))
38 testcase->input=g_strdup(text);
39 else if (!testcase->expected && !strcmp(tag,"EXPECTED"))
40 testcase->expected=g_strdup(text);
41 else if (!testcase->encoding && !strcmp(tag,"ENCODING"))
42 testcase->encoding=g_strchomp(g_strdup(text));
45 fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag);
46 testcase_free(testcase);
47 testcase_parser_free(parser);
52 if (!testcase_parser_at_eof(parser))
55 fprintf(stderr,"%s: Not a valid testcase (garbage at end)\n",
58 fprintf(stderr,"%s: Not a valid testcase (no valid tags)\n",
60 testcase_free(testcase);
61 testcase_parser_free(parser);
64 testcase_parser_free(parser);