From 680c646011ec55dd4c639a5b61d8c42a10272ae2 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 24 Jul 2009 16:05:18 +0000 Subject: More extensive testing, and documentation in the header files. --- server/src/queryparser.cc | 72 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'server/src/queryparser.cc') 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 + +static char xml[] = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" +; + +static char badxml[] = + "\n" + "\n" + "\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*/ -- cgit v1.2.3