all unit tests: replaced BOOST_AUTO_UNIT_TEST with new SENF_AUTO_UNIT_TEST macro
[senf.git] / senf / Utils / Console / ProgramOptions.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 ProgramOptions unit tests */
25
26 //#include "ProgramOptions.test.hh"
27 //#include "ProgramOptions.test.ih"
28
29 // Custom includes
30 #include "Console.hh"
31
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 namespace {
39     std::string val1;
40     bool val2 (false);
41
42     void fun1(std::string p)
43     { val1 = p; }
44
45     void fun2()
46     { val2 = true; }
47 }
48
49 SENF_AUTO_UNIT_TEST(programOptions)
50 {
51     senf::console::ScopedDirectory<> root;
52     senf::console::root().add("root", root);
53
54     root.mkdir("dir1").add("fun1", &fun1);
55     root.add("fun2", &fun2);
56     root.mkdir("name-with-dashes").add("fun-2", &fun2);
57
58     {
59         char const * argv[] = { "", "--dir1-fun1=foo","--fun2" };
60         senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
61
62         SENF_CHECK_NO_THROW( opts.parse() );
63         BOOST_CHECK_EQUAL( val1, "foo" );
64         BOOST_CHECK_EQUAL( val2, true );
65     }
66
67     {
68         char const * argv[] = { "", "--d-f=foo","--fun" };
69         senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
70
71         val1 = "";
72         val2 = false;
73
74         SENF_CHECK_NO_THROW( opts.parse() );
75         BOOST_CHECK_EQUAL( val1, "foo" );
76         BOOST_CHECK_EQUAL( val2, true );
77     }
78
79     {
80         char const * argv[] = { "", "--name-w-fun" };
81         senf::console::ProgramOptions opts (sizeof(argv)/sizeof(argv[0]), argv, root);
82
83         val1 = "";
84         val2 = false;
85
86         SENF_CHECK_NO_THROW( opts.parse() );
87         BOOST_CHECK_EQUAL( val1, "" );
88         BOOST_CHECK_EQUAL( val2, true );
89     }
90     
91     {
92         char const * argv[] = { "", "-ab" };
93         senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
94         opts
95             .alias('a', "--dir1-fun1=baz")
96             .alias('b', "--fun2");
97
98         val1 = "";
99         val2 = false;
100
101         SENF_CHECK_NO_THROW( opts.parse() );
102         BOOST_CHECK_EQUAL( val1, "baz" );
103         BOOST_CHECK_EQUAL( val2, true );
104     }
105
106     {
107         char const * argv[] = { "", "-badoo" };
108         senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
109         opts
110             .alias('a', "--dir1-fun1", true)
111             .alias('b', "--fun2");
112
113         val1 = "";
114         val2 = false;
115
116         SENF_CHECK_NO_THROW( opts.parse() );
117         BOOST_CHECK_EQUAL( val1, "doo" );
118         BOOST_CHECK_EQUAL( val2, true );
119     }
120
121     {
122         char const * argv[] = { "", "-a","dii","-b" };
123         senf::console::ProgramOptions opts(sizeof(argv)/sizeof(argv[0]), argv, root);
124         opts
125             .alias('a', "--dir1-fun1", true)
126             .alias('b', "--fun2");
127
128         val1 = "";
129         val2 = false;
130
131         SENF_CHECK_NO_THROW( opts.parse() );
132         BOOST_CHECK_EQUAL( val1, "dii" );
133         BOOST_CHECK_EQUAL( val2, true );
134     }
135 }
136
137 ///////////////////////////////cc.e////////////////////////////////////////
138 #undef prefix_
139
140 \f
141 // Local Variables:
142 // mode: c++
143 // fill-column: 100
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"
149 // End: