Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitri Naumov
ogs
Commits
f7e9f2da
Commit
f7e9f2da
authored
9 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for ConfigTree
parent
896f553b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/ConfigTree.h
+0
-4
0 additions, 4 deletions
BaseLib/ConfigTree.h
Tests/BaseLib/TestConfigTree.cpp
+76
-2
76 additions, 2 deletions
Tests/BaseLib/TestConfigTree.cpp
with
76 additions
and
6 deletions
BaseLib/ConfigTree.h
+
0
−
4
View file @
f7e9f2da
...
@@ -353,8 +353,6 @@ public:
...
@@ -353,8 +353,6 @@ public:
* The return value is suitable to be used with range-base for-loops.
* The return value is suitable to be used with range-base for-loops.
*
*
* \pre \c param must not have been read before from this ConfigTree.
* \pre \c param must not have been read before from this ConfigTree.
*
* \todo write tests
*/
*/
Range
<
ParameterIterator
>
Range
<
ParameterIterator
>
getConfParamList
(
std
::
string
const
&
param
)
const
;
getConfParamList
(
std
::
string
const
&
param
)
const
;
...
@@ -382,8 +380,6 @@ public:
...
@@ -382,8 +380,6 @@ public:
* \return the requested attribute
* \return the requested attribute
*
*
* \pre \c param must not have been read before from this ConfigTree.
* \pre \c param must not have been read before from this ConfigTree.
*
* \todo write tests
*/
*/
template
<
typename
T
>
boost
::
optional
<
T
>
template
<
typename
T
>
boost
::
optional
<
T
>
getConfAttributeOptional
(
std
::
string
const
&
attr
)
const
;
getConfAttributeOptional
(
std
::
string
const
&
attr
)
const
;
...
...
This diff is collapsed.
Click to expand it.
Tests/BaseLib/TestConfigTree.cpp
+
76
−
2
View file @
f7e9f2da
...
@@ -129,7 +129,8 @@ TEST(BaseLibConfigTree, Get)
...
@@ -129,7 +129,8 @@ TEST(BaseLibConfigTree, Get)
" <ignored2/>"
" <ignored2/>"
"</sub>"
"</sub>"
"<x>Y</x>"
"<x>Y</x>"
"<z attr=
\"
0.5
\"
>32.0</z>"
;
"<z attr=
\"
0.5
\"
optattr=
\"
false
\"
>32.0</z>"
;
auto
const
ptree
=
readXml
(
xml
);
auto
const
ptree
=
readXml
(
xml
);
Callbacks
cbs
;
Callbacks
cbs
;
...
@@ -220,12 +221,19 @@ TEST(BaseLibConfigTree, Get)
...
@@ -220,12 +221,19 @@ TEST(BaseLibConfigTree, Get)
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_EQ
(
0.5
,
z
.
getConfAttribute
<
double
>
(
"attr"
));
EXPECT_EQ
(
0.5
,
z
.
getConfAttribute
<
double
>
(
"attr"
));
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
RUN_SAFE
(
z
.
getConfAttribute
<
double
>
(
"attr"
));
// getting attr twice
RUN_SAFE
(
z
.
getConfAttribute
<
double
>
(
"attr"
));
// getting attr
ibute
twice
EXPECT_ERR_WARN
(
cbs
,
true
,
false
);
EXPECT_ERR_WARN
(
cbs
,
true
,
false
);
RUN_SAFE
(
z
.
getConfAttribute
<
double
>
(
"not_an_attr"
));
// nonexistent attribute
RUN_SAFE
(
z
.
getConfAttribute
<
double
>
(
"not_an_attr"
));
// nonexistent attribute
EXPECT_ERR_WARN
(
cbs
,
true
,
false
);
EXPECT_ERR_WARN
(
cbs
,
true
,
false
);
EXPECT_EQ
(
32.0
,
z
.
getValue
<
double
>
());
EXPECT_EQ
(
32.0
,
z
.
getValue
<
double
>
());
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
auto
const
opt
=
z
.
getConfAttributeOptional
<
bool
>
(
"optattr"
);
EXPECT_TRUE
(
!!
opt
);
EXPECT_FALSE
(
*
opt
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
//RUN_SAFE(z.getConfAttributeOptional<bool>("optattr")); // getting attribute twice
//EXPECT_ERR_WARN(cbs, true, false);
EXPECT_FALSE
(
z
.
getConfAttributeOptional
<
bool
>
(
"also_not_an_attr"
));
// nonexisting attribute
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
}
}
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
}
// ConfigTree destroyed here
}
// ConfigTree destroyed here
...
@@ -328,6 +336,13 @@ TEST(BaseLibConfigTree, GetSubtreeList)
...
@@ -328,6 +336,13 @@ TEST(BaseLibConfigTree, GetSubtreeList)
{
{
auto
const
conf
=
makeConfigTree
(
ptree
,
cbs
);
auto
const
conf
=
makeConfigTree
(
ptree
,
cbs
);
for
(
auto
p
:
conf
.
getConfSubtreeList
(
"nonexistent_list"
))
{
(
void
)
p
;
FAIL
()
<<
"Expected empty list"
;
}
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
int
i
=
0
;
int
i
=
0
;
for
(
auto
ct
:
conf
.
getConfSubtreeList
(
"val"
))
for
(
auto
ct
:
conf
.
getConfSubtreeList
(
"val"
))
{
{
...
@@ -339,6 +354,58 @@ TEST(BaseLibConfigTree, GetSubtreeList)
...
@@ -339,6 +354,58 @@ TEST(BaseLibConfigTree, GetSubtreeList)
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
}
}
TEST
(
BaseLibConfigTree
,
GetParamList
)
{
const
char
xml
[]
=
"<int>0</int>"
"<int>1</int>"
"<int>2</int>"
"<int2 a=
\"
b
\"
>3</int2>"
"<int3>4<error/></int3>"
;
auto
const
ptree
=
readXml
(
xml
);
Callbacks
cbs
;
{
auto
const
conf
=
makeConfigTree
(
ptree
,
cbs
);
for
(
auto
p
:
conf
.
getConfParamList
(
"nonexistent_list"
))
{
(
void
)
p
;
FAIL
()
<<
"Expected empty list"
;
}
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
int
i
=
0
;
for
(
auto
p
:
conf
.
getConfParamList
(
"int"
))
{
EXPECT_EQ
(
i
,
p
.
getValue
<
int
>
());
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
++
i
;
}
for
(
auto
p
:
conf
.
getConfParamList
(
"int2"
))
{
EXPECT_EQ
(
i
,
p
.
getValue
<
int
>
());
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
++
i
;
}
EXPECT_ERR_WARN
(
cbs
,
false
,
true
);
// attribute "a" not read
{
auto
range
=
conf
.
getConfParamList
(
"int3"
);
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
RUN_SAFE
(
*
range
.
begin
());
// Error because of child tag, raises exception, thus
// a temporary ConfigTree gets destroyed producing a warning.
EXPECT_ERR_WARN
(
cbs
,
true
,
true
);
}
// range destroyed here
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
}
// ConfigTree destroyed here
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
}
TEST
(
BaseLibConfigTree
,
GetValueList
)
TEST
(
BaseLibConfigTree
,
GetValueList
)
{
{
...
@@ -352,6 +419,13 @@ TEST(BaseLibConfigTree, GetValueList)
...
@@ -352,6 +419,13 @@ TEST(BaseLibConfigTree, GetValueList)
{
{
auto
const
conf
=
makeConfigTree
(
ptree
,
cbs
);
auto
const
conf
=
makeConfigTree
(
ptree
,
cbs
);
for
(
auto
p
:
conf
.
getConfParamList
<
int
>
(
"nonexistent_list"
))
{
(
void
)
p
;
FAIL
()
<<
"Expected empty list"
;
}
EXPECT_ERR_WARN
(
cbs
,
false
,
false
);
int
n
=
0
;
int
n
=
0
;
for
(
auto
i
:
conf
.
getConfParamList
<
int
>
(
"int"
))
for
(
auto
i
:
conf
.
getConfParamList
<
int
>
(
"int"
))
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment