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 Variables unit tests */
31 //#include "Variables.test.hh"
32 //#include "Variables.test.ih"
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 void testParser(senf::console::ParseCommandInfo::TokensRange const &, int & value)
49 void testFormatter(int value, std::ostream & os)
50 { os << '[' << value << ']'; }
52 static bool changed_ (false);
53 void testCallback(int oldValue)
57 SENF_AUTO_UNIT_TEST(variables)
59 namespace fty = senf::console::factory;
61 senf::console::Executor executor;
62 senf::console::CommandParser parser;
63 senf::console::ScopedDirectory<> dir;
64 senf::console::root().add("test", dir);
69 dir.add("var", fty::Variable(var)
70 .doc("Current blorg limit")
71 .formatter(&testFormatter)
74 .onChange(&testCallback)
76 parser.parse("test/var; test/var 10; test/var",
77 boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
78 BOOST_CHECK_EQUAL( ss.str(), "[5]\n[0]\n" );
79 BOOST_CHECK( changed_ );
83 BOOST_CHECK_EQUAL(ss.str(),
86 " 2- var new_value:number\n"
88 "Current blorg limit\n");
90 senf::console::CommandNode & refvar (dir.add("refvar", fty::Variable(boost::ref(var))
91 .doc("Current blorg limit")
92 .formatter(&testFormatter)
97 senf::IGNORE( refvar );
99 dir.add("crefvar", fty::Variable(boost::cref(var))
100 .doc("Current blorg limit")
101 .formatter(&testFormatter)
110 senf::console::ScopedDirectory<Test2> dir;
112 Test2() : dir(this), var_(0)
113 { dir.add("var", senf::console::factory::Variable(boost::ref(var_))); }
121 SENF_AUTO_UNIT_TEST(memberVariables)
129 COMPILE_FAIL(constVariable)
131 senf::console::ScopedDirectory<> dir;
133 dir.add("var", boost::cref(var))
134 .parser(&testParser);
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
146 // comment-column: 40
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"