4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Config unit tests */
31 //#include "Config.test.hh"
32 //#include "Config.test.ih"
36 #include <boost/filesystem/operations.hpp>
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 void fun1(std::string p)
57 TempFile(std::string const & name) : name_ (name), file_ (name_.c_str()) {}
58 ~TempFile() { file_.close(); boost::filesystem::remove(name_); }
60 template <class T> TempFile & operator<<(T const & v) { file_ << v; return *this; }
61 enum Closer { close }; void operator<<(Closer) { file_.close(); }
62 std::string const & name() { return name_; }
71 SENF_AUTO_UNIT_TEST(configBundle_empty)
73 TempFile cfg ("test.cfg");
74 cfg << TempFile::close;
76 senf::console::ScopedDirectory<> root;
77 root.add("fun2", senf::console::factory::Command(&fun2));
79 senf::console::ConfigBundle bundle(root);
80 bundle.add( senf::console::FileConfig(cfg.name()));
82 SENF_CHECK_NO_THROW( bundle.parse() );
85 SENF_AUTO_UNIT_TEST(configBundle)
87 namespace fty = senf::console::factory;
89 senf::console::ScopedDirectory<> root;
90 senf::console::root().add("root", root);
92 senf::console::ScopedDirectory<> chroot;
93 senf::console::root().add("chroot", chroot);
95 root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
96 root.add("fun2", fty::Command(&fun2));
97 chroot.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
98 chroot.add("fun2", fty::Command(&fun2));
100 TempFile cfg ("test.cfg");
101 cfg << "dir1/fun1 foo; fun2;" << TempFile::close;
103 char const * argv[] = { "", "--dir1-fun1=bar" };
105 senf::console::ConfigBundle bundle(root);
106 bundle.add( senf::console::FileConfig(cfg.name()) );
107 bundle.add( senf::console::OptionsConfig(sizeof(argv)/sizeof(argv[0]), argv) );
109 SENF_CHECK_NO_THROW( bundle.parse() );
110 BOOST_CHECK_EQUAL( val1, "bar" );
111 BOOST_CHECK_EQUAL( val2, true );
113 bundle.chroot( chroot);
114 SENF_CHECK_NO_THROW( bundle.parse() );
115 BOOST_CHECK_EQUAL( val1, "bar" );
116 BOOST_CHECK_EQUAL( val2, true );
119 //-/////////////////////////////////////////////////////////////////////////////////////////////////
126 // comment-column: 40
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"