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 ProgramOptions unit tests */
31 //#include "ProgramOptions.test.hh"
32 //#include "ProgramOptions.test.ih"
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 void fun1(std::string p)
54 SENF_AUTO_UNIT_TEST(programOptions)
56 namespace fty = senf::console::factory;
58 senf::console::ScopedDirectory<> root;
59 senf::console::root().add("root", root);
61 root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
62 root.add("fun2", fty::Command(&fun2));
63 root.add("name-with-dashes", fty::Directory()).add("fun-2", fty::Command(&fun2));
66 char const * argv[] = { "", "--dir1-fun1=foo","--fun2" };
67 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
69 SENF_CHECK_NO_THROW( opts.parse() );
70 BOOST_CHECK_EQUAL( val1, "foo" );
71 BOOST_CHECK_EQUAL( val2, true );
75 char const * argv[] = { "", "--d-f=foo","--fun" };
76 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
81 SENF_CHECK_NO_THROW( opts.parse() );
82 BOOST_CHECK_EQUAL( val1, "foo" );
83 BOOST_CHECK_EQUAL( val2, true );
87 char const * argv[] = { "", "--name-w-fun" };
88 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
93 SENF_CHECK_NO_THROW( opts.parse() );
94 BOOST_CHECK_EQUAL( val1, "" );
95 BOOST_CHECK_EQUAL( val2, true );
99 char const * argv[] = { "", "-ab" };
100 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
102 .alias('a', "--dir1-fun1=baz")
103 .alias('b', "--fun2");
108 SENF_CHECK_NO_THROW( opts.parse() );
109 BOOST_CHECK_EQUAL( val1, "baz" );
110 BOOST_CHECK_EQUAL( val2, true );
114 char const * argv[] = { "", "-badoo" };
115 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
117 .alias('a', "--dir1-fun1", true)
118 .alias('b', "--fun2");
123 SENF_CHECK_NO_THROW( opts.parse() );
124 BOOST_CHECK_EQUAL( val1, "doo" );
125 BOOST_CHECK_EQUAL( val2, true );
129 char const * argv[] = { "", "-a","dii","-b" };
130 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
132 .alias('a', "--dir1-fun1", true)
133 .alias('b', "--fun2");
138 SENF_CHECK_NO_THROW( opts.parse() );
139 BOOST_CHECK_EQUAL( val1, "dii" );
140 BOOST_CHECK_EQUAL( val2, true );
144 //-/////////////////////////////////////////////////////////////////////////////////////////////////
151 // comment-column: 40
152 // c-file-style: "senf"
153 // indent-tabs-mode: nil
154 // ispell-local-dictionary: "american"
155 // compile-command: "scons -u test"