Skip to content

Commit c24bc64

Browse files
[tests] Improve overall coverage to check the behavior and clean the code.
1 parent 5daf1d3 commit c24bc64

File tree

5 files changed

+96
-10
lines changed

5 files changed

+96
-10
lines changed

tests/exceptions.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
using boost::test_tools::output_test_stream;
1616
using namespace dynamicgraph;
1717

18+
BOOST_AUTO_TEST_CASE(exception_abstract_param) {
19+
20+
/// Test param from Exception
21+
/// Default constructor
22+
ExceptionAbstract::Param aParamSimple;
23+
/// Advanced constructor
24+
ExceptionAbstract::Param aParam(60, "function_test", "my_file");
25+
aParamSimple.initCopy(aParam);
26+
}
27+
1828
BOOST_AUTO_TEST_CASE(exception_abstract) {
29+
30+
/// Test exception abstract with a simple message
1931
std::string msg_aea("Test exception abstract");
2032
ExceptionAbstract aEA(10, msg_aea);
2133

@@ -27,9 +39,22 @@ BOOST_AUTO_TEST_CASE(exception_abstract) {
2739
output << aEA;
2840
BOOST_CHECK(
2941
output.is_equal("AbstractError [#10]: Test exception abstract\n"));
42+
}
3043

31-
std::string msg_aet("Test exception abstract");
32-
ExceptionTraces aET(ExceptionTraces::GENERIC, msg_aet);
44+
BOOST_AUTO_TEST_CASE(exception_traces) {
3345

46+
std::string msg_aet("Test exception traces simple");
47+
ExceptionTraces aET(ExceptionTraces::GENERIC, msg_aet);
48+
output_test_stream output;
3449
output << aET;
50+
BOOST_CHECK(
51+
output.is_equal("TracesError [#300]: Test exception traces simple\n"));
52+
53+
/// Test exception traces with a format.
54+
int a = 2, b = 3;
55+
std::string msg_aet2("Test exception traces ");
56+
ExceptionTraces aET2(ExceptionTraces::GENERIC, msg_aet2, "(%d,%d)", a, b);
57+
output << aET2;
58+
BOOST_CHECK(
59+
output.is_equal("TracesError [#300]: Test exception traces (2,3)\n"));
3560
}

tests/signal-all.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,55 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
144144
iss.str("1");
145145
defaultCR.cast(iss);
146146

147+
bool res = false;
147148
try {
148149
std::istringstream iss_fail;
149150
iss.str("test");
150151
defaultCR.cast(iss_fail);
151152
} catch (ExceptionSignal &e) {
152153
// Take int, not string
154+
res = true;
155+
}
156+
BOOST_CHECK(res);
157+
158+
/// Test cast register with Vector
159+
output_test_stream output;
160+
dynamicgraph::Vector avec;
161+
DefaultCastRegisterer<dynamicgraph::Vector> defaultVR;
162+
avec.resize(4);
163+
avec[0] = 1.0;
164+
avec[1] = 2.0;
165+
avec[2] = 3.0;
166+
avec[3] = 4.0;
167+
res = true;
168+
try {
169+
defaultVR.trace(avec, output);
170+
} catch (ExceptionSignal &e) {
171+
/// Exception in case of wrong cast.
172+
/// This should not happen.
173+
res = false;
153174
}
175+
BOOST_CHECK(res);
176+
177+
/// Test cast register with Matrix
178+
dynamicgraph::Matrix amatrix;
179+
DefaultCastRegisterer<dynamicgraph::Matrix> defaultMR;
180+
amatrix.resize(2, 2);
181+
amatrix(0, 0) = 0.0;
182+
amatrix(0, 1) = 1.0;
183+
amatrix(1, 0) = 2.0;
184+
amatrix(1, 1) = 3.0;
185+
res = true;
186+
try {
187+
defaultMR.trace(amatrix, output);
188+
} catch (ExceptionSignal &e) {
189+
/// Exception in case of wrong cast.
190+
/// This should happen
191+
res = false;
192+
}
193+
BOOST_CHECK(res);
194+
195+
std::istringstream aiss("test");
196+
DefaultCastRegisterer<std::string> defaultSR;
197+
boost::any aTest = defaultSR.cast(aiss);
154198
}

tests/signal-cast-registerer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
214214
} catch (ExceptionSignal &e) {
215215
std::cout << "Test passed : ss[-1] != \")\"";
216216
}
217+
218+
try {
219+
output_test_stream output;
220+
myVectorSignal.trace(output);
221+
} catch (ExceptionSignal &e) {
222+
std::cout << "Test passed : ss[-1] != \")\"";
223+
}
217224
}
218225

219226
BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {

tests/signal-ptr.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ BOOST_AUTO_TEST_CASE(normal_test) {
155155
BOOST_CHECK(true);
156156

157157
sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
158+
sigPtrA.recompute(3);
158159

159160
/// Plugging signal.
160161
SignalBase<int> &sigRef = sig, sigBase("sigBase");
@@ -261,6 +262,9 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
261262
Signal<std::string, int> outSig("output");
262263
SignalPtr<std::string, int> inSig(NULL, "input");
263264

265+
Signal<dynamicgraph::Vector, int> outSigVec("outputVec");
266+
SignalPtr<dynamicgraph::Vector, int> inSigVec(NULL, "inputVec");
267+
264268
std::string str("two words");
265269
outSig.setConstant(str);
266270
inSig.plug(&outSig);
@@ -270,6 +274,20 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
270274
std::string res(os1.str());
271275
BOOST_CHECK(res == str);
272276

277+
dynamicgraph::Vector aVec;
278+
aVec.resize(5);
279+
aVec(0) = 1.0;
280+
aVec(1) = 2.0;
281+
aVec(2) = 3.0;
282+
aVec(3) = 4.0;
283+
aVec(4) = 5.0;
284+
outSigVec.setConstant(aVec);
285+
inSigVec.plug(&outSigVec);
286+
inSigVec.recompute(1);
287+
output_test_stream output;
288+
inSigVec.get(output);
289+
BOOST_CHECK(output.is_equal("1\n2\n3\n4\n5\n"));
290+
273291
Signal<std::string, int> s("signal");
274292
std::ostringstream os2;
275293
s.setConstant(str);

tests/value.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
6464
bool res = false;
6565
try {
6666
int aInt(anet);
67-
output << aInt;
6867
} catch (const dg::ExceptionAbstract &aea) {
6968
output << aea.getExceptionName();
7069
output2 << aea.what();
@@ -79,7 +78,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
7978
res = false;
8079
try {
8180
bool abool(anet);
82-
output << abool;
8381
} catch (const dg::ExceptionAbstract &aea) {
8482
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
8583
}
@@ -90,7 +88,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
9088
res = false;
9189
try {
9290
unsigned int aint(anet);
93-
output << aint;
9491
} catch (const dg::ExceptionAbstract &aea) {
9592
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
9693
}
@@ -101,7 +98,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
10198
res = false;
10299
try {
103100
double adouble(anet);
104-
output << adouble;
105101
} catch (const dg::ExceptionAbstract &aea) {
106102
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
107103
}
@@ -112,7 +108,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
112108
res = false;
113109
try {
114110
float afloat(anet);
115-
output << afloat;
116111
} catch (const dg::ExceptionAbstract &aea) {
117112
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
118113
}
@@ -123,7 +118,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
123118
res = false;
124119
try {
125120
std::string astring(anet);
126-
output << astring;
127121
} catch (const dg::ExceptionAbstract &aea) {
128122
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
129123
}
@@ -135,7 +129,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
135129
try {
136130
dg::Vector avector;
137131
avector = anet;
138-
output << avector;
139132
} catch (const dg::ExceptionAbstract &aea) {
140133
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
141134
}
@@ -147,7 +140,6 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
147140
try {
148141
Eigen::MatrixXd amatrixXd;
149142
amatrixXd = anet;
150-
output << amatrixXd;
151143
} catch (const dg::ExceptionAbstract &aea) {
152144
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
153145
}

0 commit comments

Comments
 (0)