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 ScopedDirectory.test unit tests */
26 //#include "ScopedDirectory.test.hh"
27 //#include "ScopedDirectory.test.ih"
31 #include "ScopedDirectory.hh"
32 #include <boost/iterator/transform_iterator.hpp>
34 #include "../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
42 typedef TestObject Self;
44 senf::console::ScopedDirectory<Self> dir;
45 TestObject() : dir(this) {
46 dir.add("member", &Self::member);
49 void member(std::ostream & os, senf::console::ParseCommandInfo const &) {
55 BOOST_AUTO_UNIT_TEST(scopedDirectory)
59 senf::console::root().add("ob",ob.dir);
61 senf::console::ParseCommandInfo info;
62 senf::console::root()["ob"]("member")(ss, info);
63 BOOST_CHECK_EQUAL( ss.str(), "member" );
65 BOOST_CHECK_THROW( senf::console::root()["ob"], senf::console::UnknownNodeNameException );
69 void callback(std::ostream & os, senf::console::ParseCommandInfo const &) {
74 BOOST_AUTO_UNIT_TEST(scopedDirectoryVoid)
77 senf::console::ScopedDirectory<> dir;
78 senf::console::root().add("dir", dir);
79 dir.add("cb", &callback);
81 senf::console::ParseCommandInfo info;
82 senf::console::root()["dir"]("cb")(ss, info);
83 BOOST_CHECK_EQUAL( ss.str(), "cb" );
85 BOOST_CHECK_THROW( senf::console::root()["dir"],
86 senf::console::UnknownNodeNameException );
92 typedef T result_type;
93 template <class U> result_type operator()(U const & u) const { return u.first; }
97 BOOST_AUTO_UNIT_TEST(scopedDirectoryBase)
100 senf::console::ScopedDirectory<> dir;
101 senf::console::root().add("dir", dir);
103 dir.add("cb", &callback);
104 BOOST_CHECK( &dir["foo"] == &dir.get("foo") );
105 BOOST_CHECK( &dir("cb") == &dir.get("cb") );
107 char const * const children[] = { "cb", "foo" };
108 BOOST_CHECK_EQUAL_COLLECTIONS(
109 boost::make_transform_iterator(dir.children().begin(),
110 select1st<std::string const &>()),
111 boost::make_transform_iterator(dir.children().end(),
112 select1st<std::string const &>()),
114 children+sizeof(children)/sizeof(children[0]) );
117 std::stringstream ss;
119 BOOST_CHECK_EQUAL( ss.str(), "dir\n" );
123 ///////////////////////////////cc.e////////////////////////////////////////
130 // comment-column: 40
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"