4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Config.test unit tests */
26 //#include "Config.test.hh"
27 //#include "Config.test.ih"
32 #include "ScopedDirectory.hh"
33 #include "ParsedCommand.hh"
34 #include <boost/filesystem/operations.hpp>
36 #include "../Utils/auto_unit_test.hh"
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
47 void fun1(int v) { var1 = v; }
48 void fun2() { var2 = true; }
53 TempFile(std::string const & name) : name_ (name), file_ (name_.c_str()) {}
54 ~TempFile() { file_.close(); boost::filesystem::remove(name_); }
56 template <class T> TempFile & operator<<(T const & v) { file_ << v; return *this; }
57 enum Closer { close }; void operator<<(Closer) { file_.close(); }
58 std::string const & name() { return name_; }
68 BOOST_AUTO_UNIT_TEST(configFile)
70 TempFile cfgf ("test.cfg");
71 cfgf << "dir1/fun1 10;\n"
74 senf::console::ScopedDirectory<> dir1;
75 senf::console::root().add("dir1", dir1);
76 dir1.add("fun1",&fun1);
80 senf::console::ConfigFile cfg (cfgf.name());
81 SENF_CHECK_NO_THROW( cfg.parse() )
82 BOOST_CHECK_EQUAL( var1, 10 );
86 BOOST_AUTO_UNIT_TEST(configFileRestrict)
88 TempFile cfgf ("test.cfg");
89 cfgf << "dir1/fun1 10;\n"
93 senf::console::ScopedDirectory<> dir1;
94 senf::console::root().add("dir1", dir1);
95 dir1.add("fun1",&fun1);
100 senf::console::ConfigFile cfg (cfgf.name());
101 SENF_CHECK_NO_THROW( cfg.parse(dir1.node()) );
102 BOOST_CHECK_EQUAL( var1, 10 );
103 BOOST_CHECK_EQUAL( var2, false );
105 senf::console::ScopedDirectory<> dir2;
106 senf::console::root().add("dir2", dir2);
107 dir2.add("fun2",&fun2);
111 SENF_CHECK_NO_THROW( cfg.parse() );
112 BOOST_CHECK_EQUAL( var1, 0 );
113 BOOST_CHECK_EQUAL( var2, true );
117 BOOST_AUTO_UNIT_TEST(configFileSkipGroup)
119 TempFile cfgf ("test.cfg");
120 cfgf << "dir1/fun1 10;\n"
121 << "dir2 { dir3 { fun2; } fun1 5; }"
124 senf::console::ScopedDirectory<> dir1;
125 senf::console::root().add("dir1", dir1);
126 dir1.add("fun1",&fun1);
128 senf::console::ScopedDirectory<> dir2;
129 senf::console::root().add("dir2", dir2);
131 dir2.mkdir("dir3").add("fun2", &fun2);
132 dir2.add("fun1", &fun1);
137 senf::console::ConfigFile cfg (cfgf.name());
138 SENF_CHECK_NO_THROW( cfg.parse(dir1.node()) );
139 BOOST_CHECK_EQUAL( var1, 10 );
140 BOOST_CHECK_EQUAL( var2, false );
144 SENF_CHECK_NO_THROW( cfg.parse(dir2["dir3"]) );
145 BOOST_CHECK_EQUAL( var1, 0 );
146 BOOST_CHECK_EQUAL( var2, true );
150 SENF_CHECK_NO_THROW( cfg.parse() );
151 BOOST_CHECK_EQUAL( var1, 5 );
152 BOOST_CHECK_EQUAL( var2, false );
156 ///////////////////////////////cc.e////////////////////////////////////////
163 // comment-column: 40
164 // c-file-style: "senf"
165 // indent-tabs-mode: nil
166 // ispell-local-dictionary: "american"
167 // compile-command: "scons -u test"