summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/Makefile.am11
-rw-r--r--server/src/configurationparser.cc62
2 files changed, 72 insertions, 1 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index d797bc6..3bc3069 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -106,6 +106,7 @@ EXTRA_DIST = \
################
TESTFILES = \
+ test_configurationparser \
test_exception \
test_templateheaderparser \
test_macroheaderparser \
@@ -128,7 +129,7 @@ TESTFILES = \
TESTLOGS = `for F in ${TESTFILES}; do echo $$F.log; done`
BASICFILES = exception.cc log.cc debug.cc configuration.cc utf8.cc
-BASICFLAGS = -I.. -DHAVE_CONFIG_H
+BASICFLAGS = -I.. -DHAVE_CONFIG_H $(CONFIG_CXXFLAGS) $(CONFIG_LIBS)
PARSERFILES = saxparser.cc
PARSERFLAGS = -lexpat
@@ -142,6 +143,14 @@ test: $(TESTFILES)
test_clean:
rm -f $(TESTFILES) $(TESTLOGS)
+TEST_CONFIGURATIONPARSER_FILES = \
+ configurationparser.cc \
+ configuration.cc \
+ exception.cc \
+ log.cc
+test_configurationparser: $(TEST_CONFIGURATIONPARSER_FILES)
+ @../../tools/test $(TEST_CONFIGURATIONPARSER_FILES) $(BASICFLAGS)
+
TEST_EXCEPTION_FILES = \
exception.cc \
log.cc
diff --git a/server/src/configurationparser.cc b/server/src/configurationparser.cc
index 1c89655..a3e7532 100644
--- a/server/src/configurationparser.cc
+++ b/server/src/configurationparser.cc
@@ -128,3 +128,65 @@ void ConfigurationParser::reload()
} catch( ... ) {
}
}
+
+#ifdef TEST_CONFIGURATIONPARSER
+
+#define CONFFILE "/tmp/configurationparser.conf"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <memory.h>
+
+static char conf[] =
+"a = 1;\n"
+"b = \"hello\";\n"
+"c = true;\n"
+;
+
+static char confbad[] =
+"a = 1;\n"
+"b = \"hello\"\n"
+"c = true;\n"
+;
+
+int main()
+{
+ FILE *fp = fopen(CONFFILE, "w");
+ if(!fp) {
+ printf("Could not write to %s\n", CONFFILE);
+ return 1;
+ }
+ fprintf(fp, conf);
+ fclose(fp);
+ try {
+ ConfigurationParser parser(CONFFILE);
+ } catch(Exception &e) {
+ printf("%s\n", e.what());
+ return 1;
+ }
+
+ fp = fopen(CONFFILE, "w");
+ if(!fp) {
+ printf("Could not write to %s\n", CONFFILE);
+ return 1;
+ }
+ fprintf(fp, confbad);
+ fclose(fp);
+ try {
+ ConfigurationParser parser(CONFFILE);
+ } catch(Exception &e) {
+ printf("%s\n", e.what());
+ goto on;
+ }
+ return 1;
+ on:
+
+ unlink(CONFFILE);
+
+ return 0;
+}
+
+#endif/*TEST_CONFIGURATIONPARSER*/