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 ///////////////////////////////cc.p////////////////////////////////////////
42 void fun1(std::string p)
49 BOOST_AUTO_UNIT_TEST(programOptions)
51 senf::console::ScopedDirectory<> root;
52 senf::console::root().add("root", root);
54 root.mkdir("dir1").add("fun1", &fun1);
55 root.add("fun2", &fun2);
56 root.mkdir("name-with-dashes").add("fun-2", &fun2);
59 char const * argv[] = { "", "--dir1-fun1=foo","--fun2" };
60 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
62 SENF_CHECK_NO_THROW( opts.parse() );
63 BOOST_CHECK_EQUAL( val1, "foo" );
64 BOOST_CHECK_EQUAL( val2, true );
68 char const * argv[] = { "", "--d-f=foo","--fun" };
69 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
74 SENF_CHECK_NO_THROW( opts.parse() );
75 BOOST_CHECK_EQUAL( val1, "foo" );
76 BOOST_CHECK_EQUAL( val2, true );
80 char const * argv[] = { "", "--name-w-fun" };
81 senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
86 SENF_CHECK_NO_THROW( opts.parse() );
87 BOOST_CHECK_EQUAL( val1, "" );
88 BOOST_CHECK_EQUAL( val2, true );
92 char const * argv[] = { "", "-ab" };
93 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
95 .alias('a', "--dir1-fun1=baz")
96 .alias('b', "--fun2");
101 SENF_CHECK_NO_THROW( opts.parse() );
102 BOOST_CHECK_EQUAL( val1, "baz" );
103 BOOST_CHECK_EQUAL( val2, true );
107 char const * argv[] = { "", "-badoo" };
108 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
110 .alias('a', "--dir1-fun1", true)
111 .alias('b', "--fun2");
116 SENF_CHECK_NO_THROW( opts.parse() );
117 BOOST_CHECK_EQUAL( val1, "doo" );
118 BOOST_CHECK_EQUAL( val2, true );
122 char const * argv[] = { "", "-a","dii","-b" };
123 senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
125 .alias('a', "--dir1-fun1", true)
126 .alias('b', "--fun2");
131 SENF_CHECK_NO_THROW( opts.parse() );
132 BOOST_CHECK_EQUAL( val1, "dii" );
133 BOOST_CHECK_EQUAL( val2, true );
137 ///////////////////////////////cc.e////////////////////////////////////////
144 // comment-column: 40
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"