File: options_description_test.cpp

package info (click to toggle)
boost 1.32.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 93,952 kB
  • ctags: 128,458
  • sloc: cpp: 492,477; xml: 52,125; python: 13,519; ansic: 13,013; sh: 1,773; yacc: 853; makefile: 526; perl: 418; lex: 110; csh: 6
file content (98 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright Vladimir Prus 2002-2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)


#include <boost/program_options/options_description.hpp>
using namespace boost::program_options;

#include <boost/function.hpp>
using namespace boost;

#define BOOST_INCLUDE_MAIN  // for testing, include rather than link
#include <boost/test/test_tools.hpp>

#include <utility>
using namespace std;

/*  This is very wierd test case -- it tests trivial things. After writing it,
    I think that XP folks must be somehow wrong.
*/
void test_option_description_construction()
{
    option_description d1("a", new untyped_value(), "desc1");
    BOOST_TEST(d1.long_name() == "a");
    BOOST_TEST(d1.description() == "desc1");
    BOOST_TEST(d1.semantic()->name() == "arg");

    // It is not possible to compare boost::function
    #if 0
    function<string, string> f1;
    BOOST_TEST(&option_description("x", "y", "z").
               validator(f1).validator() ==
               &f1);
    function<void, string> f2;
    BOOST_TEST(&option_description("x", "y", "z").
               notify(f2).notify() ==
               &f2);
    #endif

    option_description d4("foo,f", new untyped_value(), "desc1");
    BOOST_CHECK(d4.long_name() == "foo");
    BOOST_CHECK(d4.short_name() == "f");
}

void test_options_description()
{
    options_description desc;

    shared_ptr<option_description> d1(
        new option_description("first,f", new untyped_value(), ""));
    desc.add(d1);
    BOOST_TEST(desc.count("first") == 1);
    BOOST_TEST(desc.count("-f") == 1);
    BOOST_TEST(desc.keys().size() == 2);
    BOOST_TEST(desc.keys().count("first") == 1);
    BOOST_TEST(desc.keys().count("-f") == 1);

    desc.add_options()
        ("second,s", new untyped_value())
        ("third,t", new untyped_value())
        ;
    BOOST_TEST(desc.count("second") == 1);
    BOOST_TEST(desc.count("-s") == 1);

    desc.add_options()
        (",x", new untyped_value)
        ;
    BOOST_TEST(desc.primary_keys().size() == 4);
    BOOST_TEST(desc.primary_keys().count("first") == 1);
    BOOST_TEST(desc.primary_keys().count("second") == 1);
    BOOST_TEST(desc.primary_keys().count("third") == 1);
    BOOST_TEST(desc.primary_keys().count("-x") == 1);
}

void test_approximation()
{
    options_description desc;
    desc.add_options()
    ("foo", new untyped_value())
    ("fee", new untyped_value())
    ("baz", new untyped_value());

    BOOST_TEST(desc.count_approx("f") == 2);
    BOOST_TEST(desc.count_approx("foo") == 1);
    set<string> a = desc.approximations("f");
    BOOST_TEST(a.size() == 2);
    BOOST_TEST(*a.begin() == "fee");
    BOOST_TEST(*(++a.begin()) == "foo");
}

int test_main(int, char* [])
{
    test_option_description_construction();
    test_options_description();
    test_approximation();
    return 0;
}