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 Traits.test unit tests */
26 //#include "Traits.test.hh"
27 //#include "Traits.test.ih"
31 #include "ParsedCommand.hh"
32 #include "Executor.hh"
34 #include "ScopedDirectory.hh"
36 #include "../Utils/auto_unit_test.hh"
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
43 enum TestEnum { Foo, Bar };
44 SENF_CONSOLE_REGISTER_ENUM( TestEnum, (Foo)(Bar) );
46 TestEnum test (TestEnum value) { return value; }
49 enum MemberEnum { MemberFoo, MemberBar };
50 static MemberEnum test (MemberEnum value) { return value; }
52 SENF_CONSOLE_REGISTER_ENUM_MEMBER( TestClass, MemberEnum, (MemberFoo)(MemberBar) );
54 bool boolTest(bool value) { return value; }
57 BOOST_AUTO_UNIT_TEST(boolTraits)
59 senf::console::Executor executor;
60 senf::console::CommandParser parser;
61 senf::console::ScopedDirectory<> dir;
62 senf::console::root().add("test", dir);
64 dir.add("test", &boolTest);
68 parser.parse("test/test true; test/test false",
69 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
70 BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" );
74 parser.parse("test/test enabled; test/test disabled",
75 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
76 BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" );
80 parser.parse("test/test yes; test/test no",
81 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
82 BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" );
86 parser.parse("test/test Y; test/test enA",
87 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
88 BOOST_CHECK_EQUAL( ss.str(), "true\n" "true\n" );
90 dir.add("test2", &boolTest).formatter( senf::console::formatEnabledDisabled );
93 parser.parse("test/test2 0; test/test2 -1",
94 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
95 BOOST_CHECK_EQUAL( ss.str(), "disabled\n" "enabled\n" );
98 BOOST_AUTO_UNIT_TEST(enumSupport)
100 senf::console::Executor executor;
101 senf::console::CommandParser parser;
102 senf::console::ScopedDirectory<> dir;
103 senf::console::root().add("test", dir);
105 dir.add("test",&test);
107 std::stringstream ss;
108 BOOST_CHECK_NO_THROW(
109 parser.parse("test/test Foo",
110 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
111 BOOST_CHECK_EQUAL( ss.str(), "Foo\n" );
114 BOOST_CHECK_NO_THROW(
115 parser.parse("test/test Bar",
116 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
117 BOOST_CHECK_EQUAL( ss.str(), "Bar\n" );
120 parser.parse("test/test (Foo Bar)",
121 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
122 senf::console::SyntaxErrorException );
125 parser.parse("test/test Baz",
126 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
127 senf::console::SyntaxErrorException );
129 dir.add("member", &TestClass::test);
132 BOOST_CHECK_NO_THROW(
133 parser.parse("test/member MemberFoo",
134 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
135 BOOST_CHECK_EQUAL( ss.str(), "MemberFoo\n" );
138 BOOST_CHECK_NO_THROW(
139 parser.parse("test/member MemberBar",
140 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
141 BOOST_CHECK_EQUAL( ss.str(), "MemberBar\n" );
145 ///////////////////////////////cc.e////////////////////////////////////////
152 // comment-column: 40
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"