~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Util/testsuite/src/OptionSetTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// OptionSetTest.cpp
 
3
//
 
4
// $Id: //poco/1.2/Util/testsuite/src/OptionSetTest.cpp#2 $
 
5
//
 
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
7
// and Contributors.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person or organization
 
10
// obtaining a copy of the software and accompanying documentation covered by
 
11
// this license (the "Software") to use, reproduce, display, distribute,
 
12
// execute, and transmit the Software, and to prepare derivative works of the
 
13
// Software, and to permit third-parties to whom the Software is furnished to
 
14
// do so, all subject to the following:
 
15
// 
 
16
// The copyright notices in the Software and this entire statement, including
 
17
// the above license grant, this restriction and the following disclaimer,
 
18
// must be included in all copies of the Software, in whole or in part, and
 
19
// all derivative works of the Software, unless such copies or derivative
 
20
// works are solely in the form of machine-executable object code generated by
 
21
// a source language processor.
 
22
// 
 
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
29
// DEALINGS IN THE SOFTWARE.
 
30
//
 
31
 
 
32
 
 
33
#include "OptionSetTest.h"
 
34
#include "CppUnit/TestCaller.h"
 
35
#include "CppUnit/TestSuite.h"
 
36
#include "Poco/Util/OptionSet.h"
 
37
#include "Poco/Util/Option.h"
 
38
#include "Poco/Util/OptionException.h"
 
39
 
 
40
 
 
41
using Poco::Util::OptionSet;
 
42
using Poco::Util::Option;
 
43
 
 
44
 
 
45
OptionSetTest::OptionSetTest(const std::string& name): CppUnit::TestCase(name)
 
46
{
 
47
}
 
48
 
 
49
 
 
50
OptionSetTest::~OptionSetTest()
 
51
{
 
52
}
 
53
 
 
54
 
 
55
void OptionSetTest::testOptionSet()
 
56
{
 
57
        OptionSet set;
 
58
        set.addOption(
 
59
                Option("helper", "H", "start helper")
 
60
                        .required(false)
 
61
                        .repeatable(false));
 
62
        set.addOption(
 
63
                Option("help", "h", "print help text")
 
64
                        .required(false)
 
65
                        .repeatable(false));
 
66
        set.addOption(
 
67
                Option("include-dir", "I", "specify a search path for locating header files")
 
68
                        .required(false)
 
69
                        .repeatable(true)
 
70
                        .argument("path"));
 
71
        set.addOption(
 
72
                Option("library-dir", "L", "specify a search path for locating library files")
 
73
                        .required(false)
 
74
                        .repeatable(true)
 
75
                        .argument("path"));
 
76
        set.addOption(
 
77
                Option("insert", "it", "insert something")
 
78
                        .required(false)
 
79
                        .repeatable(true)
 
80
                        .argument("path"));
 
81
        set.addOption(
 
82
                Option("item", "", "insert something")
 
83
                        .required(false)
 
84
                        .repeatable(true)
 
85
                        .argument("path"));
 
86
        set.addOption(
 
87
                Option("include", "J", "specify a search path for locating header files")
 
88
                        .required(false)
 
89
                        .repeatable(true)
 
90
                        .argument("path"));
 
91
        
 
92
        assert (set.hasOption("include", false));
 
93
        assert (set.hasOption("I", true));
 
94
        assert (set.hasOption("Include", true));
 
95
        assert (set.hasOption("insert", false));
 
96
        assert (set.hasOption("it", true));
 
97
        assert (set.hasOption("Insert", false));
 
98
        assert (set.hasOption("item", false));
 
99
        assert (!set.hasOption("i", false));
 
100
        assert (!set.hasOption("in", false));
 
101
        
 
102
        assert (set.hasOption("help"));
 
103
        assert (set.hasOption("h", true));
 
104
        assert (set.hasOption("helper"));
 
105
        assert (set.hasOption("H", true));
 
106
        
 
107
        const Option& opt1 = set.getOption("include");
 
108
        assert (opt1.fullName() == "include");
 
109
 
 
110
        const Option& opt2 = set.getOption("item");
 
111
        assert (opt2.fullName() == "item");
 
112
 
 
113
        const Option& opt3 = set.getOption("I", true);
 
114
        assert (opt3.fullName() == "include-dir");
 
115
 
 
116
        const Option& opt4 = set.getOption("include-d");
 
117
        assert (opt4.fullName() == "include-dir");
 
118
 
 
119
        const Option& opt5 = set.getOption("help");
 
120
        assert (opt5.fullName() == "help");
 
121
 
 
122
        const Option& opt6 = set.getOption("helpe");
 
123
        assert (opt6.fullName() == "helper");
 
124
        
 
125
        try
 
126
        {
 
127
                set.getOption("in");
 
128
                fail("ambiguous - must throw");
 
129
        }
 
130
        catch (Poco::Util::AmbiguousOptionException&)
 
131
        {
 
132
        }
 
133
 
 
134
        try
 
135
        {
 
136
                set.getOption("he");
 
137
                fail("ambiguous - must throw");
 
138
        }
 
139
        catch (Poco::Util::AmbiguousOptionException&)
 
140
        {
 
141
        }
 
142
 
 
143
        try
 
144
        {
 
145
                set.getOption("i");
 
146
                fail("ambiguous - must throw");
 
147
        }
 
148
        catch (Poco::Util::AmbiguousOptionException&)
 
149
        {
 
150
        }
 
151
}
 
152
 
 
153
 
 
154
void OptionSetTest::setUp()
 
155
{
 
156
}
 
157
 
 
158
 
 
159
void OptionSetTest::tearDown()
 
160
{
 
161
}
 
162
 
 
163
 
 
164
CppUnit::Test* OptionSetTest::suite()
 
165
{
 
166
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OptionSetTest");
 
167
 
 
168
        CppUnit_addTest(pSuite, OptionSetTest, testOptionSet);
 
169
 
 
170
        return pSuite;
 
171
}