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 unit tests */
26 //#include "ScopedDirectory.test.hh"
27 //#include "ScopedDirectory.test.ih"
32 #include <boost/iterator/transform_iterator.hpp>
34 #include <senf/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", senf::console::factory::Command(&Self::member, this));
49 void member(std::ostream & os, senf::console::ParseCommandInfo const &) {
55 SENF_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 SENF_AUTO_UNIT_TEST(scopedDirectoryVoid)
76 namespace fty = senf::console::factory;
79 senf::console::ScopedDirectory<> dir;
80 senf::console::root().add("dir", dir);
81 dir.add("cb", fty::Command(&callback));
83 senf::console::ParseCommandInfo info;
84 senf::console::root()["dir"]("cb")(ss, info);
85 BOOST_CHECK_EQUAL( ss.str(), "cb" );
87 BOOST_CHECK_THROW( senf::console::root()["dir"],
88 senf::console::UnknownNodeNameException );
94 typedef T result_type;
95 template <class U> result_type operator()(U const & u) const { return u.first; }
99 SENF_AUTO_UNIT_TEST(scopedDirectoryBase)
101 namespace fty = senf::console::factory;
104 senf::console::ScopedDirectory<> dir;
105 senf::console::root().add("dir", dir);
106 dir.add("foo",fty::Directory());
107 dir.add("cb", fty::Command(&callback));
108 BOOST_CHECK( &dir["foo"] == &dir.get("foo") );
109 BOOST_CHECK( &dir("cb") == &dir.get("cb") );
110 BOOST_CHECK_EQUAL(dir.name(), "dir");
112 char const * const children[] = { "cb", "foo" };
113 BOOST_CHECK_EQUAL_COLLECTIONS(
114 boost::make_transform_iterator(dir.children().begin(),
115 select1st<std::string const &>()),
116 boost::make_transform_iterator(dir.children().end(),
117 select1st<std::string const &>()),
119 children+sizeof(children)/sizeof(children[0]) );
122 std::stringstream ss;
124 BOOST_CHECK_EQUAL( ss.str(), "dir\n" );
128 ///////////////////////////////cc.e////////////////////////////////////////
135 // comment-column: 40
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"