diff options
author | deva <deva> | 2009-07-24 16:05:18 +0000 |
---|---|---|
committer | deva <deva> | 2009-07-24 16:05:18 +0000 |
commit | 680c646011ec55dd4c639a5b61d8c42a10272ae2 (patch) | |
tree | 171aea7bbd680a1dc7cf80bc5cdabc55c82a7618 /server/src/queryparser.cc | |
parent | 408c7c5b36e1058a76741a22876593ee8c042dd4 (diff) |
More extensive testing, and documentation in the header files.
Diffstat (limited to 'server/src/queryparser.cc')
-rw-r--r-- | server/src/queryparser.cc | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/server/src/queryparser.cc b/server/src/queryparser.cc index 2b0dbdc..602ba80 100644 --- a/server/src/queryparser.cc +++ b/server/src/queryparser.cc @@ -76,12 +76,50 @@ void QueryParser::parseError(char *buf, size_t len, std::string error, int linen if(fwrite(buf, len, 1, stderr) != len) {} fprintf(stderr, "]\n"); fflush(stderr); + + char *slineno; + if(asprintf(&slineno, " at line %d\n", lineno) != -1) { + throw Exception(error + slineno); + free(slineno); + } + } #ifdef TEST_QUERYPARSER -#include "queryhandlerpentominos.h" -#include "tcpsocket.h" +#include <string.h> + +static char xml[] = + "<?xml version='1.0' encoding='UTF-8'?>\n" + "<results>\n" + " <result class=\"testclass\" timestamp=\"1234567890\">\n" + " <group name=\"testgroup\">\n" + " <value name=\"testvalue\" value=\"42\"/>\n" + " <value name=\"anothertestvalue\" value=\"42\"/>\n" + " </group>\n" + " <group name=\"anothertestgroup\">\n" + " <value name=\"testvalue\" value=\"42\"/>\n" + " <value name=\"anothertestvalue\" value=\"42\"/>\n" + " </group>\n" + " </result>\n" + " <result class=\"anothertestclass\" timestamp=\"1234567890\">\n" + " <group name=\"testgroup\">\n" + " <value name=\"testvalue\" value=\"42\"/>\n" + " <value name=\"anothertestvalue\" value=\"42\"/>\n" + " </group>\n" + " <group name=\"anothertestgroup\">\n" + " <value name=\"testvalue\" value=\"42\"/>\n" + " <value name=\"anothertestvalue\" value=\"42\"/>\n" + " </group>\n" + " </result>\n" + "</results>\n" +; + +static char badxml[] = + "<?xml version='1.0' encoding='UTF-8'?>\n" + "<results>\n" + "</sulrets>\n" +; static std::string loadresultstring(QueryResult &res, std::string group = "") { @@ -105,20 +143,26 @@ static std::string loadresultstring(QueryResult &res, std::string group = "") int main() { - TCPSocket s; - s.connect("localhost", 11108); - - QueryHandlerPentominos qh(&s, "2003791613"); - - Query q1; - q1.attributes["device_id"] = "lensmeter"; - q1.attributes["device_type"] = "lensmeter"; + // Parse something + { + QueryParser parser; + parser.parse(xml, strlen(xml)); + printf("%s\n", loadresultstring(parser.result).c_str()); + } - QueryResult res = qh.exec(q1); - - printf("%s\n", loadresultstring(res).c_str()); + // Parse something, and fail! + try { + QueryParser parser; + parser.parse(badxml, strlen(badxml)); + printf("%s\n", loadresultstring(parser.result).c_str()); + } catch(Exception &e) { + printf("ERROR: %s\n", e.what()); + goto weitergehen; + } + return 1; + weitergehen: return 0; } -#endif +#endif/*TEST_QUERYPARSER*/ |