summaryrefslogtreecommitdiff
path: root/server/src/macroheaderparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/macroheaderparser.cc')
-rw-r--r--server/src/macroheaderparser.cc106
1 files changed, 105 insertions, 1 deletions
diff --git a/server/src/macroheaderparser.cc b/server/src/macroheaderparser.cc
index def80c3..6193e94 100644
--- a/server/src/macroheaderparser.cc
+++ b/server/src/macroheaderparser.cc
@@ -135,10 +135,114 @@ void MacroHeaderParser::parseError(char *buf, size_t len, std::string error, int
throw Exception(error + slineno);
free(slineno);
}
-
}
Macro *MacroHeaderParser::getMacro()
{
return m;
}
+
+#ifdef TEST_MACROHEADERPARSER
+
+#define XMLFILE "/tmp/test_macroheaderparser.xml"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <memory.h>
+
+static char xml[] =
+"<?xml version='1.0' encoding='UTF-8'?>\n"
+"<macro name=\"testmacro\" version=\"1.0\">\n"
+" <sometag/>\n"
+" <someothertag/>\n"
+"</macro>"
+;
+
+static char xml_nonmacro[] =
+"<?xml version='1.0' encoding='UTF-8'?>\n"
+"<dims name=\"testmacro\" version=\"1.0\">\n"
+" <sometag/>\n"
+" <someothertag/>\n"
+"</dims>"
+;
+
+static char xml_fail[] =
+"<?xml version='1.0' encoding='UTF-8'?>\n"
+"<macro name\"testmacro\" version=\"1.0\">\n"
+" <sometag/>\n"
+" <someothertag/>\n"
+"</macro>"
+;
+
+int main()
+{
+ FILE *fp = fopen(XMLFILE, "w");
+ if(!fp) {
+ printf("Could not write to %s\n", XMLFILE);
+ return 1;
+ }
+ fprintf(fp, xml);
+ fclose(fp);
+
+ {
+ // Test parsing of correct macro xml data.
+ MacroHeaderParser parser(XMLFILE);
+ try {
+ parser.parse();
+ } catch(Exception &e) {
+ printf("Failed to parse: %s\n", e.what());
+ return 1;
+ }
+ }
+
+ fp = fopen(XMLFILE, "w");
+ if(!fp) {
+ printf("Could not write to %s\n", XMLFILE);
+ return 1;
+ }
+ fprintf(fp, xml_nonmacro);
+ fclose(fp);
+
+ // Test parsing of correct xml data, but not macro (should throw an exception).
+ {
+ MacroHeaderParser parser(XMLFILE);
+ try {
+ parser.parse();
+ } catch(Exception &e) {
+ printf("Failed to parse: %s\n", e.what());
+ goto onandon;
+ }
+ return 1;
+ }
+ onandon:
+
+ fp = fopen(XMLFILE, "w");
+ if(!fp) {
+ printf("Could not write to %s\n", XMLFILE);
+ return 1;
+ }
+ fprintf(fp, xml_fail);
+ fclose(fp);
+
+ // Test parsing of invalid xml data (should throw an exception).
+ {
+ MacroHeaderParser parser(XMLFILE);
+ try {
+ parser.parse();
+ } catch(Exception &e) {
+ printf("Failed to parse: %s\n", e.what());
+ goto yetonandon;
+ }
+ return 1;
+ }
+ yetonandon:
+
+ unlink(XMLFILE);
+
+ return 0;
+}
+
+#endif/*TEST_MACROHEADERPARSER*/