File: ParameterSection_test.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (201 lines) | stat: -rw-r--r-- 5,860 bytes parent folder | download | duplicates (4)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>

///////////////////////////

#include <BALL/FORMAT/parameterSection.h>
#include <BALL/FORMAT/parameters.h>

///////////////////////////

START_TEST(Parameters)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;

Parameters param(BALL_TEST_DATA_PATH(ParameterSection_test.ini));
param.init();

{
ParameterSection* ps = 0;
CHECK(ParameterSection::ParameterSection())
	ps = new ParameterSection;
	TEST_NOT_EQUAL(ps, 0)
RESULT


CHECK(ParameterSection::~ParameterSection())
	delete ps;
RESULT
}

CHECK(ParameterSection::clear())
	ParameterSection ps;
	ps.extractSection(param, "Section2");
	ps.clear();
	ParameterSection ps_new;
	// assumes that operator == () is correct.
	bool result = (ps == ps_new);
	TEST_EQUAL(result, true);
RESULT

CHECK(ParameterSection::getSectionName() const)
	ParameterSection ps;
	TEST_EQUAL(ps.getSectionName(), "")
RESULT

CHECK(ParameterSection::extractSection(Parameters& parameters, const String& section_name))
	ParameterSection ps;
  bool result;
	CAPTURE_OUTPUT_LEVEL(2000)
		result = ps.extractSection(param, "Section1");
	COMPARE_OUTPUT("ParameterSection::extractSection: error reading section Section1 of file " BALL_TEST_DATA_PATH(ParameterSection_test.ini) ":\nWrong number of fields in the format line: 0. FORMAT:\n")
	TEST_EQUAL(result, false)
	TEST_EQUAL(ps.getSectionName(), "Section1")

	result = ps.extractSection(param, "Section2");
	TEST_EQUAL(result, true)
	TEST_EQUAL(ps.getSectionName(), "Section2")

	result = ps.extractSection(param, "Section3");
	TEST_EQUAL(result, true)
	TEST_EQUAL(ps.getSectionName(), "Section3")

	result = ps.extractSection(param, "Section4");
	TEST_EQUAL(result, false)
	TEST_EQUAL(ps.getSectionName(), "Section4")

	result = ps.extractSection(param, "Section5");
	TEST_EQUAL(result, false)
	TEST_EQUAL(ps.getSectionName(), "Section5")

  CAPTURE_OUTPUT_LEVEL(2000)
		result = ps.extractSection(param, "Section6");
	COMPARE_OUTPUT("ParameterSectionFile data/ParameterSection_test.ini has no Section Section6.\nParameterSectionFile data/ParameterSection_test.ini has no Section .\n")
	TEST_EQUAL(result, false)
	TEST_EQUAL(ps.getSectionName(), "Section6")

	CAPTURE_OUTPUT_LEVEL(2000)
		result = ps.extractSection(param, "");
	COMPARE_OUTPUT("ParameterSectionFile data/ParameterSection_test.ini has no Section .\n")
	TEST_EQUAL(result, false)
	TEST_EQUAL(ps.getSectionName(), "")
RESULT

ParameterSection ps;
ps.extractSection(param, "Section2");


CHECK(ParameterSection::getValue(const String& key, const String& variable) const )
	TEST_EQUAL(ps.getValue("A", "val"), "B")
	TEST_EQUAL(ps.getValue("C", "val"), "C")
	TEST_EQUAL(ps.getValue("D", "val"), "E")
	TEST_EQUAL(ps.getValue("F", "val"), "G")
	TEST_EQUAL(ps.getValue("J", "val"), " K")
	TEST_EQUAL(ps.getValue(" L", "val"), " M")
	TEST_EQUAL(ps.getValue("N", "val"), "O")
	TEST_EQUAL(ps.getValue("X", "val"), ParameterSection::UNDEFINED)
RESULT


CHECK(ParameterSection::has(const String& key, const String& variable) const )
	ParameterSection ps;
	ps.extractSection(param, "Section2");

	TEST_EQUAL(ps.has("A", "val"), true)
	TEST_EQUAL(ps.has(" L", "val"), true)
	TEST_EQUAL(ps.has("N", "val"), true)
	TEST_EQUAL(ps.has("X", "val"), false)
	TEST_EQUAL(ps.has("N", "X"), false)
RESULT


CHECK(ParameterSection::has(const String& key) const )
	TEST_EQUAL(ps.has("A"), true)
	TEST_EQUAL(ps.has(" L"), true)
	TEST_EQUAL(ps.has("X"), false)
RESULT


CHECK(ParameterSection::hasVariable(const String& variable) const )
	TEST_EQUAL(ps.hasVariable("val"), true)
	TEST_EQUAL(ps.hasVariable("x"), false)
RESULT


CHECK(ParameterSection::getColumnIndex(const String& variable) const )
	TEST_EQUAL(ps.getColumnIndex("val"), 0)
	TEST_EQUAL(ps.getColumnIndex("X"), INVALID_Position)
RESULT


CHECK(ParameterSection::getNumberOfVariables() const )
	TEST_EQUAL(ps.getNumberOfVariables(), 1)
RESULT


CHECK(ParameterSection::getNumberOfKeys() const )
	TEST_EQUAL(ps.getNumberOfKeys(), 7)
RESULT


CHECK(ParameterSection::getValue(Position key_index, Position variable_index) const )
	TEST_EQUAL(ps.getValue(2, 0), "E")
	TEST_EQUAL(ps.getValue(2, 1), ParameterSection::UNDEFINED)
	TEST_EQUAL(ps.getValue(20, 1), ParameterSection::UNDEFINED)
	TEST_EQUAL(ps.getValue(20, 60000), ParameterSection::UNDEFINED)
RESULT


CHECK(ParameterSection::getKey(Position key_index) const )
	TEST_EQUAL(ps.getKey(2), "D")
RESULT


CHECK(ParameterSection::isValid() const )
	TEST_EQUAL(ps.isValid(), true)
RESULT


CHECK(bool ParameterSection::operator == (const ParameterSection& parameter_section))
	// there's no practical way to test that stuff...
	ParameterSection ps2(ps);
	bool result = (ps2 == ps);
	TEST_EQUAL(result, true)
	result = (ps == ps2);
	TEST_EQUAL(result, true)
	ParameterSection ps1;
	result = (ps == ps1);
	TEST_EQUAL(result, false)
RESULT


CHECK(const ParameterSection& ParameterSection::operator = (const ParameterSection& parameter_section))
	ParameterSection ps2;
	ps2 = ps;

	TEST_EQUAL(ps2.getValue("A", "val"), "B")
	TEST_EQUAL(ps2.getValue("C", "val"), "C")
	TEST_EQUAL(ps2.getValue("D", "val"), "E")
	TEST_EQUAL(ps2.getValue("F", "val"), "G")
	TEST_EQUAL(ps2.getValue("J", "val"), " K")
	TEST_EQUAL(ps2.getValue(" L", "val"), " M")
	TEST_EQUAL(ps2.getValue("N", "val"), "O")
	TEST_EQUAL(ps2.getValue("X", "val"), ParameterSection::UNDEFINED)

	TEST_EQUAL(ps2.getValue(2, 0), "E")
	TEST_EQUAL(ps2.getValue(2, 1), ParameterSection::UNDEFINED)
	TEST_EQUAL(ps2.getValue(20, 1), ParameterSection::UNDEFINED)
	TEST_EQUAL(ps2.getValue(20, 60000), ParameterSection::UNDEFINED)
RESULT


/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST