[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Confuse-devel] [PATCH 1/3] tests: add failing test for include() when p
From: |
Carlo Marcelo Arenas Belon |
Subject: |
[Confuse-devel] [PATCH 1/3] tests: add failing test for include() when parsing a buffer |
Date: |
Thu, 1 Jan 2009 17:24:24 -0800 |
Add a test case that parses a buffer to include a.conf (also used by the
suite_dup test case).
Signed-off-by: Carlo Marcelo Arenas Belon <address@hidden>
---
tests/Makefile.am | 2 +-
tests/include.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletions(-)
create mode 100644 tests/include.c
Carlo
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5774c35..c874716 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
TESTS = suite_single suite_dup suite_func suite_list \
suite_validate list_plus_syntax section_title_dupes \
- single_title_sections quote_before_print
+ single_title_sections quote_before_print include
check_PROGRAMS=$(TESTS)
LDADD=-L../src ../src/libconfuse.la $(LTLIBINTL)
diff --git a/tests/include.c b/tests/include.c
new file mode 100644
index 0000000..968842d
--- /dev/null
+++ b/tests/include.c
@@ -0,0 +1,34 @@
+/* Test cfg_include when called from a buffer
+ */
+
+#include <string.h>
+#include "check_confuse.h"
+
+/* reuse suite_dup.c profile so that a.conf could be used for testing */
+cfg_opt_t sec_opts[] = {
+ CFG_INT("a", 1, CFGF_NONE),
+ CFG_INT("b", 2, CFGF_NONE),
+ CFG_END()
+};
+
+cfg_opt_t opts[] = {
+ CFG_SEC("sec", sec_opts, CFGF_MULTI | CFGF_TITLE),
+ CFG_FUNC("include", &cfg_include),
+ CFG_END()
+};
+
+int
+main(void)
+{
+ char *buf = "include (\"a.conf\")\n";
+ cfg_t *cfg = cfg_init(opts, CFGF_NONE);
+ fail_unless(cfg);
+ fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);
+ fail_unless(cfg_size(cfg, "sec") == 1);
+ fail_unless(cfg_getint(cfg, "sec|a") == 5);
+ fail_unless(cfg_getint(cfg, "sec|b") == 2);
+ cfg_free(cfg);
+
+ return 0;
+}
+