Skip to content
Snippets Groups Projects
Commit 933ea05c authored by Olivier Stasse's avatar Olivier Stasse Committed by olivier stasse
Browse files

[tests] Improve tests on value.cpp

parent 6441dda2
No related branches found
No related tags found
No related merge requests found
// Copyright 2011 Florent Lamiraux, Thomas Moulard. // Copyright 2011 Florent Lamiraux, Thomas Moulard.
// //
#include <dynamic-graph/exception-factory.h>
#include "dynamic-graph/value.h" #include "dynamic-graph/value.h"
#include <iostream> #include <iostream>
...@@ -11,21 +12,24 @@ ...@@ -11,21 +12,24 @@
using boost::test_tools::output_test_stream; using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_CASE(value_none) { namespace dg = dynamicgraph;
using dynamicgraph::command::Value;
Value value1(); BOOST_AUTO_TEST_CASE(value_none) {
using dg::command::Value;
Value value1;
Value value(value1);
{ {
output_test_stream output; output_test_stream output;
output << value1; output << value1;
BOOST_CHECK(output.is_equal("1")); BOOST_CHECK(output.is_equal("Type=unknown, value="));
} }
} }
BOOST_AUTO_TEST_CASE(value_bool) { BOOST_AUTO_TEST_CASE(value_bool) {
using dynamicgraph::command::Value; using dg::command::Value;
bool abool1(false); bool abool1(false);
Value value1(abool1); Value value1(abool1);
...@@ -44,8 +48,118 @@ BOOST_AUTO_TEST_CASE(value_bool) { ...@@ -44,8 +48,118 @@ BOOST_AUTO_TEST_CASE(value_bool) {
} }
} }
BOOST_AUTO_TEST_CASE(value_exceptions) {
using dg::command::Value;
Value value1;
dg::command::EitherType anet(value1);
output_test_stream output;
// Check if the exception is working when calling intValue
// while we are having a none.
bool res = false;
try {
int aInt(anet);
output << aInt;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling boolValue
// while we are having a none.
res = false;
try {
bool abool(anet);
output << abool;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling unsignedintValue
// while we are having a none.
res = false;
try {
unsigned int aint(anet);
output << aint;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling doubleValue
// while we are having a none.
res = false;
try {
double adouble(anet);
output << adouble;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling floatValue
// while we are having a none.
res = false;
try {
float afloat(anet);
output << afloat;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling stringValue
// while we are having a none.
res = false;
try {
std::string astring(anet);
output << astring;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling vectorValue
// while we are having a none.
res = false;
try {
dg::Vector avector;
avector = anet;
output << avector;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrixXdValue
// while we are having a none.
res = false;
try {
Eigen::MatrixXd amatrixXd;
amatrixXd = anet;
output << amatrixXd;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrix4dValue
// while we are having a none.
res = false;
try {
Eigen::Matrix4d amatrix4d;
amatrix4d = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
}
BOOST_AUTO_TEST_CASE(value_unsigned_int) { BOOST_AUTO_TEST_CASE(value_unsigned_int) {
using dynamicgraph::command::Value; using dg::command::Value;
unsigned int aint1(5); unsigned int aint1(5);
Value value1(aint1); Value value1(aint1);
...@@ -65,7 +179,7 @@ BOOST_AUTO_TEST_CASE(value_unsigned_int) { ...@@ -65,7 +179,7 @@ BOOST_AUTO_TEST_CASE(value_unsigned_int) {
} }
BOOST_AUTO_TEST_CASE(value_int) { BOOST_AUTO_TEST_CASE(value_int) {
using dynamicgraph::command::Value; using dg::command::Value;
int aint1(5); int aint1(5);
Value value1(aint1); Value value1(aint1);
...@@ -85,7 +199,7 @@ BOOST_AUTO_TEST_CASE(value_int) { ...@@ -85,7 +199,7 @@ BOOST_AUTO_TEST_CASE(value_int) {
} }
BOOST_AUTO_TEST_CASE(value_float) { BOOST_AUTO_TEST_CASE(value_float) {
using dynamicgraph::command::Value; using dg::command::Value;
float afloat1(0.5); float afloat1(0.5);
Value value1(afloat1); Value value1(afloat1);
...@@ -105,7 +219,7 @@ BOOST_AUTO_TEST_CASE(value_float) { ...@@ -105,7 +219,7 @@ BOOST_AUTO_TEST_CASE(value_float) {
} }
BOOST_AUTO_TEST_CASE(value_double) { BOOST_AUTO_TEST_CASE(value_double) {
using dynamicgraph::command::Value; using dg::command::Value;
double adouble1(0.5); double adouble1(0.5);
Value value1(adouble1); Value value1(adouble1);
...@@ -125,9 +239,9 @@ BOOST_AUTO_TEST_CASE(value_double) { ...@@ -125,9 +239,9 @@ BOOST_AUTO_TEST_CASE(value_double) {
} }
BOOST_AUTO_TEST_CASE(value_vector) { BOOST_AUTO_TEST_CASE(value_vector) {
using dynamicgraph::command::Value; using dg::command::Value;
dynamicgraph::Vector avector1; dg::Vector avector1;
avector1.resize(2); avector1.resize(2);
avector1[0]=0.5;avector1[1]=1.5; avector1[0]=0.5;avector1[1]=1.5;
Value value1(avector1); Value value1(avector1);
...@@ -147,7 +261,7 @@ BOOST_AUTO_TEST_CASE(value_vector) { ...@@ -147,7 +261,7 @@ BOOST_AUTO_TEST_CASE(value_vector) {
} }
BOOST_AUTO_TEST_CASE(value_string) { BOOST_AUTO_TEST_CASE(value_string) {
using dynamicgraph::command::Value; using dg::command::Value;
std::string str1("value #1"); std::string str1("value #1");
Value value1(str1); Value value1(str1);
...@@ -183,7 +297,7 @@ BOOST_AUTO_TEST_CASE(value_string) { ...@@ -183,7 +297,7 @@ BOOST_AUTO_TEST_CASE(value_string) {
} }
BOOST_AUTO_TEST_CASE(value_matrixXd) { BOOST_AUTO_TEST_CASE(value_matrixXd) {
using dynamicgraph::command::Value; using dg::command::Value;
Eigen::MatrixXd avector1; Eigen::MatrixXd avector1;
avector1.resize(2,2); avector1.resize(2,2);
...@@ -206,7 +320,7 @@ BOOST_AUTO_TEST_CASE(value_matrixXd) { ...@@ -206,7 +320,7 @@ BOOST_AUTO_TEST_CASE(value_matrixXd) {
} }
BOOST_AUTO_TEST_CASE(value_matrix4d) { BOOST_AUTO_TEST_CASE(value_matrix4d) {
using dynamicgraph::command::Value; using dg::command::Value;
Eigen::Matrix4d avector1; Eigen::Matrix4d avector1;
avector1.setZero(); avector1.setZero();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment