]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/program_options/test/optional_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / program_options / test / optional_test.cpp
1 // Distributed under the Boost Software License, Version 1.0.
2 // (See accompanying file LICENSE_1_0.txt
3 // or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5 #include <boost/program_options.hpp>
6 namespace po = boost::program_options;
7
8 #include <boost/optional.hpp>
9
10 #include <string>
11
12 #include "minitest.hpp"
13
14 std::vector<std::string> sv(const char* array[], unsigned size)
15 {
16 std::vector<std::string> r;
17 for (unsigned i = 0; i < size; ++i)
18 r.push_back(array[i]);
19 return r;
20 }
21
22 void test_optional()
23 {
24 boost::optional<int> foo, bar, baz;
25
26 po::options_description desc;
27 desc.add_options()
28 ("foo,f", po::value(&foo), "")
29 ("bar,b", po::value(&bar), "")
30 ("baz,z", po::value(&baz), "")
31 ;
32
33 const char* cmdline1_[] = { "--foo=12", "--bar", "1"};
34 std::vector<std::string> cmdline1 = sv(cmdline1_,
35 sizeof(cmdline1_)/sizeof(const char*));
36 po::variables_map vm;
37 po::store(po::command_line_parser(cmdline1).options(desc).run(), vm);
38 po::notify(vm);
39
40 BOOST_REQUIRE(!!foo);
41 BOOST_CHECK(*foo == 12);
42
43 BOOST_REQUIRE(!!bar);
44 BOOST_CHECK(*bar == 1);
45
46 BOOST_CHECK(!baz);
47 }
48
49 int main(int, char*[])
50 {
51 test_optional();
52 return 0;
53 }