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 ScopedDirectory unit tests */
31 //#include "ScopedDirectory.test.hh"
32 //#include "ScopedDirectory.test.ih"
37 #include <boost/iterator/transform_iterator.hpp>
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 typedef TestObject Self;
49 senf::console::ScopedDirectory<Self> dir;
50 TestObject() : dir(this) {
51 dir.add("member", senf::console::factory::Command(&Self::member, this));
54 void member(std::ostream & os, senf::console::ParseCommandInfo const &) {
60 SENF_AUTO_UNIT_TEST(scopedDirectory)
64 senf::console::root().add("ob",ob.dir);
66 senf::console::ParseCommandInfo info;
67 senf::console::root()["ob"]("member")(ss, info);
68 BOOST_CHECK_EQUAL( ss.str(), "member" );
70 BOOST_CHECK_THROW( senf::console::root()["ob"], senf::console::UnknownNodeNameException );
74 void callback(std::ostream & os, senf::console::ParseCommandInfo const &) {
79 SENF_AUTO_UNIT_TEST(scopedDirectoryVoid)
81 namespace fty = senf::console::factory;
84 senf::console::ScopedDirectory<> dir;
85 senf::console::root().add("dir", dir);
86 dir.add("cb", fty::Command(&callback));
88 senf::console::ParseCommandInfo info;
89 senf::console::root()["dir"]("cb")(ss, info);
90 BOOST_CHECK_EQUAL( ss.str(), "cb" );
92 BOOST_CHECK_THROW( senf::console::root()["dir"],
93 senf::console::UnknownNodeNameException );
99 typedef T result_type;
100 template <class U> result_type operator()(U const & u) const { return u.first; }
104 SENF_AUTO_UNIT_TEST(scopedDirectoryBase)
106 namespace fty = senf::console::factory;
109 senf::console::ScopedDirectory<> dir;
110 senf::console::root().add("dir", dir);
111 dir.add("foo",fty::Directory());
112 dir.add("cb", fty::Command(&callback));
113 BOOST_CHECK( &dir["foo"] == &dir.get("foo") );
114 BOOST_CHECK( &dir("cb") == &dir.get("cb") );
115 BOOST_CHECK_EQUAL(dir.name(), "dir");
117 char const * const children[] = { "cb", "foo" };
118 BOOST_CHECK_EQUAL_COLLECTIONS(
119 boost::make_transform_iterator(dir.children().begin(),
120 select1st<std::string const &>()),
121 boost::make_transform_iterator(dir.children().end(),
122 select1st<std::string const &>()),
124 children+sizeof(children)/sizeof(children[0]) );
127 std::stringstream ss;
129 BOOST_CHECK_EQUAL( ss.str(), "dir\n" );
133 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 // comment-column: 40
141 // c-file-style: "senf"
142 // indent-tabs-mode: nil
143 // ispell-local-dictionary: "american"
144 // compile-command: "scons -u test"