a8e99af897cec2f0f7c9d121f4e4b2f28175a372
[senf.git] / Console / ObjectDirectory.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2008 
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 ObjectDirectory.test unit tests */
25
26 //#include "ObjectDirectory.test.hh"
27 //#include "ObjectDirectory.test.ih"
28
29 // Custom includes
30 #include <sstream>
31 #include "ObjectDirectory.hh"
32
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 namespace {
40     struct TestObject {
41         typedef TestObject Self;
42
43         senf::console::ObjectDirectory<Self> dir;
44         TestObject() : dir(this) {
45             dir.add("member", &Self::member);
46         }
47
48         void member(std::ostream & os, senf::console::CommandNode::Arguments const &) {
49             os << "member";
50         }
51     };
52 }
53
54 BOOST_AUTO_UNIT_TEST(objectDirectory)
55 {
56     {
57         TestObject ob;
58         senf::console::root().add("ob",ob.dir);
59         std::stringstream ss;
60         senf::console::ParseCommandInfo info;
61         senf::console::root()["ob"]("member")(ss, info.arguments());
62         BOOST_CHECK_EQUAL( ss.str(), "member" );
63     }
64     BOOST_CHECK_THROW( senf::console::root()["ob"], senf::console::UnknownNodeNameException );
65 }
66
67 ///////////////////////////////cc.e////////////////////////////////////////
68 #undef prefix_
69
70 \f
71 // Local Variables:
72 // mode: c++
73 // fill-column: 100
74 // comment-column: 40
75 // c-file-style: "senf"
76 // indent-tabs-mode: nil
77 // ispell-local-dictionary: "american"
78 // compile-command: "scons -u test"
79 // End: