]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/program_options/test/required_test.cpp
1 // Copyright Sascha Ochsenknecht 2009.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt
4 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/program_options.hpp>
7 using namespace boost::program_options
;
14 #include "minitest.hpp"
17 void required_throw_test()
19 options_description opts
;
21 ("cfgfile,c", value
<string
>()->required(), "the configfile")
22 ("fritz,f", value
<string
>()->required(), "the output file")
28 // This test must throw exception
29 string cmdline
= "prg -f file.txt";
30 vector
< string
> tokens
= split_unix(cmdline
);
33 store(command_line_parser(tokens
).options(opts
).run(), vm
);
36 catch (required_option
& e
) {
37 BOOST_CHECK_EQUAL(e
.what(), string("the option '--cfgfile' is required but missing"));
44 // This test mustn't throw exception
45 string cmdline
= "prg -c config.txt";
46 vector
< string
> tokens
= split_unix(cmdline
);
49 store(command_line_parser(tokens
).options(opts
).run(), vm
);
52 catch (required_option
& e
) {
55 BOOST_CHECK(!throwed
);
61 void simple_required_test(const char* config_file
)
63 options_description opts
;
65 ("cfgfile,c", value
<string
>()->required(), "the configfile")
66 ("fritz,f", value
<string
>()->required(), "the output file")
72 // This test must throw exception
73 string cmdline
= "prg -f file.txt";
74 vector
< string
> tokens
= split_unix(cmdline
);
77 // options coming from different sources
78 store(command_line_parser(tokens
).options(opts
).run(), vm
);
79 store(parse_config_file
<char>(config_file
, opts
), vm
);
82 catch (required_option
& e
) {
85 BOOST_CHECK(!throwed
);
91 int main(int /*argc*/, char* av
[])
93 required_throw_test();
94 simple_required_test(av
[1]);