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 ProgramOptions unit tests */
26 //#include "ProgramOptions.test.hh"
27 //#include "ProgramOptions.test.ih"
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 void fun1(std::string p)
49 SENF_AUTO_UNIT_TEST(programOptions)
51 namespace fty = senf::console::factory;
53 senf::console::ScopedDirectory<> root;
54 senf::console::root().add("root", root);
56 root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
57 root.add("fun2", fty::Command(&fun2));
58 root.add("name-with-dashes", fty::Directory()).add("fun-2", fty::Command(&fun2));
61 char const * argv[] = { "", "--dir1-fun1=foo","--fun2" };
62 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
64 SENF_CHECK_NO_THROW( opts.parse() );
65 BOOST_CHECK_EQUAL( val1, "foo" );
66 BOOST_CHECK_EQUAL( val2, true );
70 char const * argv[] = { "", "--d-f=foo","--fun" };
71 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
76 SENF_CHECK_NO_THROW( opts.parse() );
77 BOOST_CHECK_EQUAL( val1, "foo" );
78 BOOST_CHECK_EQUAL( val2, true );
82 char const * argv[] = { "", "--name-w-fun" };
83 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
88 SENF_CHECK_NO_THROW( opts.parse() );
89 BOOST_CHECK_EQUAL( val1, "" );
90 BOOST_CHECK_EQUAL( val2, true );
94 char const * argv[] = { "", "-ab" };
95 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
97 .alias('a', "--dir1-fun1=baz")
98 .alias('b', "--fun2");
103 SENF_CHECK_NO_THROW( opts.parse() );
104 BOOST_CHECK_EQUAL( val1, "baz" );
105 BOOST_CHECK_EQUAL( val2, true );
109 char const * argv[] = { "", "-badoo" };
110 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
112 .alias('a', "--dir1-fun1", true)
113 .alias('b', "--fun2");
118 SENF_CHECK_NO_THROW( opts.parse() );
119 BOOST_CHECK_EQUAL( val1, "doo" );
120 BOOST_CHECK_EQUAL( val2, true );
124 char const * argv[] = { "", "-a","dii","-b" };
125 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
127 .alias('a', "--dir1-fun1", true)
128 .alias('b', "--fun2");
133 SENF_CHECK_NO_THROW( opts.parse() );
134 BOOST_CHECK_EQUAL( val1, "dii" );
135 BOOST_CHECK_EQUAL( val2, true );
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"