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 STLSupport unit tests */
31 //#include "STLSupport.test.hh"
32 //#include "STLSupport.test.ih"
35 #include <boost/assign/list_of.hpp>
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 template <class Container>
49 static int test(Container const & data)
52 for (typename Container::const_iterator i (data.begin()), i_end (data.end());
59 std::pair<std::string, int> mapTest(std::map<std::string,int> const & data)
63 for (std::map<std::string,int>::const_iterator i (data.begin()), i_end (data.end());
68 return std::make_pair(keys,sum);
73 SENF_AUTO_UNIT_TEST(vectorSupport)
75 namespace fty = senf::console::factory;
77 senf::console::Executor executor;
78 senf::console::CommandParser parser;
79 senf::console::ScopedDirectory<> dir;
80 senf::console::root().add("test", dir);
82 std::vector<int> defv (boost::assign::list_of(7)(2).to_container(defv));
83 dir.add("test", fty::Command(&Summer<std::vector<int> >::test)
84 .arg("data", "test data", senf::console::kw::default_value = defv)
89 parser.parse("test/test; test/test (); test/test 5; test/test (13); test/test (4 5 8)",
90 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
91 BOOST_CHECK_EQUAL( ss.str(), "9\n" "0\n" "5\n" "13\n" "17\n" );
95 parser.parse("help test/test",
96 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
100 " test [data:vector<int>]\n"
104 " default: (7 2)\n" );
107 SENF_AUTO_UNIT_TEST(listSupport)
109 namespace fty = senf::console::factory;
111 senf::console::Executor executor;
112 senf::console::CommandParser parser;
113 senf::console::ScopedDirectory<> dir;
114 senf::console::root().add("test", dir);
116 std::list<int> defv (boost::assign::list_of(7)(2).to_container(defv));
117 dir.add("test", fty::Command(&Summer<std::list<int> >::test)
118 .arg("data", "test data", senf::console::kw::default_value = defv)
120 std::stringstream ss;
123 parser.parse("test/test; test/test (); test/test 5; test/test (13); test/test (4 5 8)",
124 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
125 BOOST_CHECK_EQUAL( ss.str(), "9\n" "0\n" "5\n" "13\n" "17\n" );
129 parser.parse("help test/test",
130 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
134 " test [data:list<int>]\n"
138 " default: (7 2)\n" );
141 SENF_AUTO_UNIT_TEST(setSupport)
143 namespace fty = senf::console::factory;
145 senf::console::Executor executor;
146 senf::console::CommandParser parser;
147 senf::console::ScopedDirectory<> dir;
148 senf::console::root().add("test", dir);
150 std::set<int> defv (boost::assign::list_of(7)(2).to_container(defv));
151 dir.add("test", fty::Command(&Summer<std::set<int> >::test)
152 .arg("data", "test data", senf::console::kw::default_value = defv)
154 std::stringstream ss;
157 parser.parse("test/test; test/test (); test/test 5; test/test (13); test/test (4 5 8)",
158 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
159 BOOST_CHECK_EQUAL( ss.str(), "9\n" "0\n" "5\n" "13\n" "17\n" );
163 parser.parse("help test/test",
164 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
168 " test [data:set<int>]\n"
172 " default: (2 7)\n" );
175 SENF_AUTO_UNIT_TEST(mapSupport)
177 namespace fty = senf::console::factory;
179 senf::console::Executor executor;
180 senf::console::CommandParser parser;
181 senf::console::ScopedDirectory<> dir;
182 senf::console::root().add("test", dir);
184 std::map<std::string, int> defv (
185 boost::assign::map_list_of("foo bar",7)("bar",2).to_container(defv));
186 dir.add("test", fty::Command(&mapTest)
187 .arg("data", "test data", senf::console::kw::default_value = defv)
189 std::stringstream ss;
192 parser.parse("test/test; test/test (); "
193 "test/test (vier=4 fuenf = 5 acht=8 )",
194 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
195 BOOST_CHECK_EQUAL( ss.str(), "(\"barfoo bar\" 9)\n" "(\"\" 0)\n" "(achtfuenfvier 17)\n" ); //
199 parser.parse("help test/test",
200 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
204 " test [data:map<string,int>]\n"
208 " default: (bar=2 \"foo bar\"=7)\n" );
211 //-/////////////////////////////////////////////////////////////////////////////////////////////////
218 // comment-column: 40
219 // c-file-style: "senf"
220 // indent-tabs-mode: nil
221 // ispell-local-dictionary: "american"
222 // compile-command: "scons -u test"