Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph
Commits
c24bc649
Commit
c24bc649
authored
Jan 17, 2020
by
Olivier Stasse
Browse files
[tests] Improve overall coverage to check the behavior and clean the code.
parent
5daf1d39
Changes
5
Hide whitespace changes
Inline
Side-by-side
tests/exceptions.cpp
View file @
c24bc649
...
...
@@ -15,7 +15,19 @@
using
boost
::
test_tools
::
output_test_stream
;
using
namespace
dynamicgraph
;
BOOST_AUTO_TEST_CASE
(
exception_abstract_param
)
{
/// Test param from Exception
/// Default constructor
ExceptionAbstract
::
Param
aParamSimple
;
/// Advanced constructor
ExceptionAbstract
::
Param
aParam
(
60
,
"function_test"
,
"my_file"
);
aParamSimple
.
initCopy
(
aParam
);
}
BOOST_AUTO_TEST_CASE
(
exception_abstract
)
{
/// Test exception abstract with a simple message
std
::
string
msg_aea
(
"Test exception abstract"
);
ExceptionAbstract
aEA
(
10
,
msg_aea
);
...
...
@@ -27,9 +39,22 @@ BOOST_AUTO_TEST_CASE(exception_abstract) {
output
<<
aEA
;
BOOST_CHECK
(
output
.
is_equal
(
"AbstractError [#10]: Test exception abstract
\n
"
));
}
std
::
string
msg_aet
(
"Test exception abstract"
);
ExceptionTraces
aET
(
ExceptionTraces
::
GENERIC
,
msg_aet
);
BOOST_AUTO_TEST_CASE
(
exception_traces
)
{
std
::
string
msg_aet
(
"Test exception traces simple"
);
ExceptionTraces
aET
(
ExceptionTraces
::
GENERIC
,
msg_aet
);
output_test_stream
output
;
output
<<
aET
;
BOOST_CHECK
(
output
.
is_equal
(
"TracesError [#300]: Test exception traces simple
\n
"
));
/// Test exception traces with a format.
int
a
=
2
,
b
=
3
;
std
::
string
msg_aet2
(
"Test exception traces "
);
ExceptionTraces
aET2
(
ExceptionTraces
::
GENERIC
,
msg_aet2
,
"(%d,%d)"
,
a
,
b
);
output
<<
aET2
;
BOOST_CHECK
(
output
.
is_equal
(
"TracesError [#300]: Test exception traces (2,3)
\n
"
));
}
tests/signal-all.cpp
View file @
c24bc649
...
...
@@ -144,11 +144,55 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
iss
.
str
(
"1"
);
defaultCR
.
cast
(
iss
);
bool
res
=
false
;
try
{
std
::
istringstream
iss_fail
;
iss
.
str
(
"test"
);
defaultCR
.
cast
(
iss_fail
);
}
catch
(
ExceptionSignal
&
e
)
{
// Take int, not string
res
=
true
;
}
BOOST_CHECK
(
res
);
/// Test cast register with Vector
output_test_stream
output
;
dynamicgraph
::
Vector
avec
;
DefaultCastRegisterer
<
dynamicgraph
::
Vector
>
defaultVR
;
avec
.
resize
(
4
);
avec
[
0
]
=
1.0
;
avec
[
1
]
=
2.0
;
avec
[
2
]
=
3.0
;
avec
[
3
]
=
4.0
;
res
=
true
;
try
{
defaultVR
.
trace
(
avec
,
output
);
}
catch
(
ExceptionSignal
&
e
)
{
/// Exception in case of wrong cast.
/// This should not happen.
res
=
false
;
}
BOOST_CHECK
(
res
);
/// Test cast register with Matrix
dynamicgraph
::
Matrix
amatrix
;
DefaultCastRegisterer
<
dynamicgraph
::
Matrix
>
defaultMR
;
amatrix
.
resize
(
2
,
2
);
amatrix
(
0
,
0
)
=
0.0
;
amatrix
(
0
,
1
)
=
1.0
;
amatrix
(
1
,
0
)
=
2.0
;
amatrix
(
1
,
1
)
=
3.0
;
res
=
true
;
try
{
defaultMR
.
trace
(
amatrix
,
output
);
}
catch
(
ExceptionSignal
&
e
)
{
/// Exception in case of wrong cast.
/// This should happen
res
=
false
;
}
BOOST_CHECK
(
res
);
std
::
istringstream
aiss
(
"test"
);
DefaultCastRegisterer
<
std
::
string
>
defaultSR
;
boost
::
any
aTest
=
defaultSR
.
cast
(
aiss
);
}
tests/signal-cast-registerer.cpp
View file @
c24bc649
...
...
@@ -214,6 +214,13 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
}
catch
(
ExceptionSignal
&
e
)
{
std
::
cout
<<
"Test passed : ss[-1] !=
\"
)
\"
"
;
}
try
{
output_test_stream
output
;
myVectorSignal
.
trace
(
output
);
}
catch
(
ExceptionSignal
&
e
)
{
std
::
cout
<<
"Test passed : ss[-1] !=
\"
)
\"
"
;
}
}
BOOST_AUTO_TEST_CASE
(
custom_matrix_registerer
)
{
...
...
tests/signal-ptr.cpp
View file @
c24bc649
...
...
@@ -155,6 +155,7 @@ BOOST_AUTO_TEST_CASE(normal_test) {
BOOST_CHECK
(
true
);
sigPtrA
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro3
,
_1
,
_2
));
sigPtrA
.
recompute
(
3
);
/// Plugging signal.
SignalBase
<
int
>
&
sigRef
=
sig
,
sigBase
(
"sigBase"
);
...
...
@@ -261,6 +262,9 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
Signal
<
std
::
string
,
int
>
outSig
(
"output"
);
SignalPtr
<
std
::
string
,
int
>
inSig
(
NULL
,
"input"
);
Signal
<
dynamicgraph
::
Vector
,
int
>
outSigVec
(
"outputVec"
);
SignalPtr
<
dynamicgraph
::
Vector
,
int
>
inSigVec
(
NULL
,
"inputVec"
);
std
::
string
str
(
"two words"
);
outSig
.
setConstant
(
str
);
inSig
.
plug
(
&
outSig
);
...
...
@@ -270,6 +274,20 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
std
::
string
res
(
os1
.
str
());
BOOST_CHECK
(
res
==
str
);
dynamicgraph
::
Vector
aVec
;
aVec
.
resize
(
5
);
aVec
(
0
)
=
1.0
;
aVec
(
1
)
=
2.0
;
aVec
(
2
)
=
3.0
;
aVec
(
3
)
=
4.0
;
aVec
(
4
)
=
5.0
;
outSigVec
.
setConstant
(
aVec
);
inSigVec
.
plug
(
&
outSigVec
);
inSigVec
.
recompute
(
1
);
output_test_stream
output
;
inSigVec
.
get
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"1
\n
2
\n
3
\n
4
\n
5
\n
"
));
Signal
<
std
::
string
,
int
>
s
(
"signal"
);
std
::
ostringstream
os2
;
s
.
setConstant
(
str
);
...
...
tests/value.cpp
View file @
c24bc649
...
...
@@ -64,7 +64,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
bool
res
=
false
;
try
{
int
aInt
(
anet
);
output
<<
aInt
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
output
<<
aea
.
getExceptionName
();
output2
<<
aea
.
what
();
...
...
@@ -79,7 +78,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
res
=
false
;
try
{
bool
abool
(
anet
);
output
<<
abool
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -90,7 +88,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
res
=
false
;
try
{
unsigned
int
aint
(
anet
);
output
<<
aint
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -101,7 +98,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
res
=
false
;
try
{
double
adouble
(
anet
);
output
<<
adouble
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -112,7 +108,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
res
=
false
;
try
{
float
afloat
(
anet
);
output
<<
afloat
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -123,7 +118,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
res
=
false
;
try
{
std
::
string
astring
(
anet
);
output
<<
astring
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -135,7 +129,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
try
{
dg
::
Vector
avector
;
avector
=
anet
;
output
<<
avector
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
@@ -147,7 +140,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
try
{
Eigen
::
MatrixXd
amatrixXd
;
amatrixXd
=
anet
;
output
<<
amatrixXd
;
}
catch
(
const
dg
::
ExceptionAbstract
&
aea
)
{
res
=
(
aea
.
getCode
()
==
dg
::
ExceptionAbstract
::
TOOLS
);
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment