Utils/Console: Parse char arguments as integers
[senf.git] / senf / Utils / Console / Utility.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Utility.test unit tests */
25
26 //#include "Utility.test.hh"
27 //#include "Utility.test.ih"
28
29 // Custom includes
30 #include "Utility.hh"
31 #include "Traits.hh"
32 #include "ParsedCommand.hh"
33 #include "Executor.hh"
34 #include "Parse.hh"
35 #include "ScopedDirectory.hh"
36
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
39
40 #define prefix_
41 ///////////////////////////////cc.p////////////////////////////////////////
42
43 namespace {
44
45     enum TestEnum { Foo=1, Bar=2, FooBar=4 };
46     SENF_CONSOLE_REGISTER_ENUM( TestEnum, (Foo)(Bar)(FooBar) );
47
48     senf::console::FlagCollection<TestEnum> collectionTest(
49         senf::console::FlagCollection<TestEnum> flags) { return flags; }
50
51 }
52
53 BOOST_AUTO_UNIT_TEST(flagCollection)
54 {
55     senf::console::Executor executor;
56     senf::console::CommandParser parser;
57     senf::console::ScopedDirectory<> dir;
58     senf::console::root().add("test", dir);
59     std::stringstream ss;
60
61     dir.add("test",&collectionTest);
62     
63     ss.str("");
64     SENF_CHECK_NO_THROW(
65         parser.parse("test/test foo",
66                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
67     BOOST_CHECK_EQUAL( ss.str(), "Foo\n" );
68
69     ss.str("");
70     SENF_CHECK_NO_THROW(
71         parser.parse("test/test (foo bar)",
72                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
73     BOOST_CHECK_EQUAL( ss.str(), "(Foo Bar)\n" );
74
75     ss.str("");
76     SENF_CHECK_NO_THROW(
77         parser.parse("test/test ()",
78                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
79     BOOST_CHECK_EQUAL( ss.str(), "()\n" );
80 }
81
82 ///////////////////////////////cc.e////////////////////////////////////////
83 #undef prefix_
84
85 \f
86 // Local Variables:
87 // mode: c++
88 // fill-column: 100
89 // comment-column: 40
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // End: