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 ParsedCommand.test unit tests */
26 //#include "ParsedCommand.test.hh"
27 //#include "ParsedCommand.test.ih"
31 #include "ParsedCommand.hh"
32 #include "Executor.hh"
34 #include "ScopedDirectory.hh"
36 #include <boost/test/auto_unit_test.hpp>
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
44 int cb1(int a, double b) { return int(a+b); }
45 double cb2() { return 1.2; }
47 std::string cb4(std::ostream & os) { os << "text\n"; return "value"; }
48 void cb5(std::ostream & os, int v) { os << "Value: " << v << "\n"; }
51 BOOST_AUTO_UNIT_TEST(parsedCommand)
53 senf::console::Executor executor;
54 senf::console::CommandParser parser;
55 senf::console::ScopedDirectory<> dir;
56 senf::console::root().add("test", dir);
61 parser.parse("test/cb1 2 3.2",
62 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
63 BOOST_CHECK_EQUAL( ss.str(), "5\n" );
69 parser.parse("test/cb2",
70 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
71 BOOST_CHECK_EQUAL( ss.str(), "1.2\n" );
77 parser.parse("test/cb3 234",
78 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
79 BOOST_CHECK_EQUAL( ss.str(), "" );
85 parser.parse("test/cb4",
86 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
87 BOOST_CHECK_EQUAL( ss.str(), "text\n" "value\n" );
93 parser.parse("test/cb5 1234",
94 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
95 BOOST_CHECK_EQUAL( ss.str(), "Value: 1234\n" );
102 parser.parse("test/cb1 2 3.2 foo",
103 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
104 senf::console::SyntaxErrorException );
107 parser.parse("test/cb1 2",
108 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
109 senf::console::SyntaxErrorException );
112 parser.parse("test/cb1 2 foo",
113 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
114 senf::console::SyntaxErrorException );
118 std::stringstream ss;
123 parser.parse("test/cb 111 222.4; test/cb 222; test/cb",
124 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
125 BOOST_CHECK_EQUAL( ss.str(), "333\n" "Value: 222\n" "1.2\n" );
133 senf::console::ScopedDirectory<Test> dir;
136 Test(std::string const & name) : dir(this), name_ (name) {
137 dir.add("name", &Test::name);
140 std::string name(std::string const & suffix) {
141 return name_ + suffix;
147 BOOST_AUTO_UNIT_TEST(memberParsedCommand)
149 senf::console::Executor executor;
150 senf::console::CommandParser parser;
151 senf::console::ScopedDirectory<> dir;
152 senf::console::root().add("test", dir);
156 dir.add("obj", obj.dir);
158 std::stringstream ss;
159 parser.parse("test/obj/name \": foo\"",
160 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
161 BOOST_CHECK_EQUAL( ss.str(), "bar: foo\n" );
165 ///////////////////////////////cc.e////////////////////////////////////////
172 // comment-column: 40
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"