File: test_commandline_options.cpp

package info (click to toggle)
libwibble 0.1.9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 500 kB
  • ctags: 1,183
  • sloc: cpp: 5,760; sh: 113; makefile: 71
file content (81 lines) | stat: -rw-r--r-- 2,020 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
#include <wibble/config.h>
#include <wibble/commandline/options.h>
#include <wibble/tests/tut-wibble.h>

namespace tut {

struct commandline_options_shar {
};
TESTGRP( commandline_options );

using namespace std;
using namespace wibble::commandline;

// Happy trick to get access to protected methods we need to use for the tests
template<typename T>
class Public : public T
{
public:
	Public(const std::string& name)
		: T(name) {}
	Public(const std::string& name,
			char shortName,
			const std::string& longName,
			const std::string& usage = std::string(),
			const std::string& description = std::string())
		: T(name, shortName, longName, usage, description) {}

	virtual ArgList::iterator parse(ArgList& a, ArgList::iterator begin) { return T::parse(a, begin); }
	virtual bool parse(const std::string& str) { return T::parse(str); }
};

// Test BoolOption
template<> template<>
void to::test<1>()
{
	Public<BoolOption> opt("test");

	ensure_equals(opt.name(), string("test"));
	ensure_equals(opt.boolValue(), false);
	ensure_equals(opt.stringValue(), string("false"));

	ensure_equals(opt.parse(string()), false);
	ensure_equals(opt.boolValue(), true);
	ensure_equals(opt.stringValue(), string("true"));
}

// Test IntOption
template<> template<>
void to::test<2>()
{
	Public<IntOption> opt("test");

	ensure_equals(opt.name(), string("test"));
	ensure_equals(opt.boolValue(), false);
	ensure_equals(opt.intValue(), 0);
	ensure_equals(opt.stringValue(), string("0"));

	ensure_equals(opt.parse("42"), true);
	ensure_equals(opt.boolValue(), true);
	ensure_equals(opt.intValue(), 42);
	ensure_equals(opt.stringValue(), string("42"));
}

// Test StringOption
template<> template<>
void to::test<3>()
{
	Public<StringOption> opt("test");

	ensure_equals(opt.name(), string("test"));
	ensure_equals(opt.boolValue(), false);
	ensure_equals(opt.stringValue(), string());

	ensure_equals(opt.parse("-a"), true);
	ensure_equals(opt.boolValue(), true);
	ensure_equals(opt.stringValue(), "-a");
}

}

// vim:set ts=4 sw=4: