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 unit tests */
26 //#include "Config.test.hh"
27 //#include "Config.test.ih"
31 #include <boost/filesystem/operations.hpp>
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
43 void fun1(std::string p)
52 TempFile(std::string const & name) : name_ (name), file_ (name_.c_str()) {}
53 ~TempFile() { file_.close(); boost::filesystem::remove(name_); }
55 template <class T> TempFile & operator<<(T const & v) { file_ << v; return *this; }
56 enum Closer { close }; void operator<<(Closer) { file_.close(); }
57 std::string const & name() { return name_; }
66 SENF_AUTO_UNIT_TEST(configBundle_empty)
68 TempFile cfg ("test.cfg");
69 cfg << TempFile::close;
71 senf::console::ScopedDirectory<> root;
72 root.add("fun2", senf::console::factory::Command(&fun2));
74 senf::console::ConfigBundle bundle(root);
75 bundle.add( senf::console::FileConfig(cfg.name()));
77 SENF_CHECK_NO_THROW( bundle.parse() );
80 SENF_AUTO_UNIT_TEST(configBundle)
82 namespace fty = senf::console::factory;
84 senf::console::ScopedDirectory<> root;
85 senf::console::root().add("root", root);
87 senf::console::ScopedDirectory<> chroot;
88 senf::console::root().add("chroot", chroot);
90 root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
91 root.add("fun2", fty::Command(&fun2));
92 chroot.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
93 chroot.add("fun2", fty::Command(&fun2));
95 TempFile cfg ("test.cfg");
96 cfg << "dir1/fun1 foo; fun2;" << TempFile::close;
98 char const * argv[] = { "", "--dir1-fun1=bar" };
100 senf::console::ConfigBundle bundle(root);
101 bundle.add( senf::console::FileConfig(cfg.name()) );
102 bundle.add( senf::console::OptionsConfig(sizeof(argv)/sizeof(argv[0]), argv) );
104 SENF_CHECK_NO_THROW( bundle.parse() );
105 BOOST_CHECK_EQUAL( val1, "bar" );
106 BOOST_CHECK_EQUAL( val2, true );
108 bundle.chroot( chroot);
109 SENF_CHECK_NO_THROW( bundle.parse() );
110 BOOST_CHECK_EQUAL( val1, "bar" );
111 BOOST_CHECK_EQUAL( val2, true );
114 ///////////////////////////////cc.e////////////////////////////////////////
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"