summaryrefslogtreecommitdiff
path: root/server/src/configurationparser.cc
diff options
context:
space:
mode:
authordeva <deva>2009-07-30 12:56:38 +0000
committerdeva <deva>2009-07-30 12:56:38 +0000
commit1569827e40b9a622c818b806b3a19ab12ff04eb4 (patch)
tree188780ac10abeb4dbde58fa1d9935c0ce2dc2714 /server/src/configurationparser.cc
parent567f9e493f353ae2a607a62df38d176367040717 (diff)
More unit tests...
Diffstat (limited to 'server/src/configurationparser.cc')
-rw-r--r--server/src/configurationparser.cc62
1 files changed, 62 insertions, 0 deletions
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*/