]>
Commit | Line | Data |
---|---|---|
8954859e | 1 | #define BOOST_TEST_DYN_LINK |
2 | #define BOOST_TEST_NO_MAIN | |
3 | #ifdef HAVE_CONFIG_H | |
4 | #include "config.h" | |
5 | #endif | |
6 | #include <stdlib.h> | |
7 | #include <unistd.h> | |
8 | #include <boost/test/unit_test.hpp> | |
9 | #include "arguments.hh" | |
10 | #include "namespaces.hh" | |
11 | ||
12 | BOOST_AUTO_TEST_SUITE(test_arguments_cc) | |
13 | ||
14 | BOOST_AUTO_TEST_CASE(test_file_parse) { | |
15 | char path[]="/tmp/pdns-test-conf.XXXXXX"; | |
16 | int fd=mkstemp(path); | |
17 | if(fd < 0) | |
18 | BOOST_FAIL("Unable to generate a temporary file"); | |
19 | ||
20 | string config= | |
21 | R"(launch=launch=1234 | |
22 | test=123\ | |
23 | 456 | |
24 | test2=here # and here it stops | |
25 | fail=no | |
26 | success=on | |
27 | really=yes)"; | |
28 | ||
29 | int len=write(fd, config.c_str(), config.size()); | |
30 | ||
31 | BOOST_CHECK_EQUAL(len, config.size()); | |
32 | if(!len) | |
33 | return; | |
34 | close(fd); | |
35 | ||
36 | try { | |
37 | ArgvMap arg; | |
38 | for(auto& a : {"launch", "test", "test2", "fail", "success", "really"} ) | |
39 | arg.set(a,a); | |
40 | arg.set("default", "default")="no"; | |
41 | arg.file(path); | |
42 | unlink(path); | |
43 | ||
44 | BOOST_CHECK_EQUAL(arg["launch"], "launch=1234"); | |
45 | BOOST_CHECK_EQUAL(arg["test"], "123456"); | |
46 | BOOST_CHECK_EQUAL(arg.asNum("test"), 123456); | |
47 | BOOST_CHECK_EQUAL(arg["test2"], "here"); | |
48 | BOOST_CHECK_EQUAL(arg.mustDo("fail"), false); | |
49 | BOOST_CHECK_EQUAL(arg.mustDo("success"), true); | |
50 | BOOST_CHECK_EQUAL(arg.mustDo("really"), true); | |
51 | BOOST_CHECK_EQUAL(arg["default"], "no"); | |
52 | ||
53 | } | |
54 | catch(PDNSException& e) { | |
55 | unlink(path); | |
56 | cerr<<"Exception: "<<e.reason<<endl; | |
57 | BOOST_FAIL("Exception: "+e.reason); | |
58 | } | |
59 | }; | |
60 | ||
61 | BOOST_AUTO_TEST_SUITE_END(); |