Commit 933ea05c authored by Olivier Stasse's avatar Olivier Stasse Committed by olivier stasse

[tests] Improve tests on value.cpp

parent 6441dda2
// Copyright 2011 Florent Lamiraux, Thomas Moulard.
//
#include <dynamic-graph/exception-factory.h>
#include "dynamic-graph/value.h"
#include <iostream>
......@@ -11,21 +12,24 @@
using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_CASE(value_none) {
using dynamicgraph::command::Value;
namespace dg = dynamicgraph;
Value value1();
BOOST_AUTO_TEST_CASE(value_none) {
using dg::command::Value;
Value value1;
Value value(value1);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("1"));
BOOST_CHECK(output.is_equal("Type=unknown, value="));
}
}
BOOST_AUTO_TEST_CASE(value_bool) {
using dynamicgraph::command::Value;
using dg::command::Value;
bool abool1(false);
Value value1(abool1);
......@@ -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) {
using dynamicgraph::command::Value;
using dg::command::Value;
unsigned int aint1(5);
Value value1(aint1);
......@@ -65,7 +179,7 @@ BOOST_AUTO_TEST_CASE(value_unsigned_int) {
}
BOOST_AUTO_TEST_CASE(value_int) {
using dynamicgraph::command::Value;
using dg::command::Value;
int aint1(5);
Value value1(aint1);
......@@ -85,7 +199,7 @@ BOOST_AUTO_TEST_CASE(value_int) {
}
BOOST_AUTO_TEST_CASE(value_float) {
using dynamicgraph::command::Value;
using dg::command::Value;
float afloat1(0.5);
Value value1(afloat1);
......@@ -105,7 +219,7 @@ BOOST_AUTO_TEST_CASE(value_float) {
}
BOOST_AUTO_TEST_CASE(value_double) {
using dynamicgraph::command::Value;
using dg::command::Value;
double adouble1(0.5);
Value value1(adouble1);
......@@ -125,9 +239,9 @@ BOOST_AUTO_TEST_CASE(value_double) {
}
BOOST_AUTO_TEST_CASE(value_vector) {
using dynamicgraph::command::Value;
using dg::command::Value;
dynamicgraph::Vector avector1;
dg::Vector avector1;
avector1.resize(2);
avector1[0]=0.5;avector1[1]=1.5;
Value value1(avector1);
......@@ -147,7 +261,7 @@ BOOST_AUTO_TEST_CASE(value_vector) {
}
BOOST_AUTO_TEST_CASE(value_string) {
using dynamicgraph::command::Value;
using dg::command::Value;
std::string str1("value #1");
Value value1(str1);
......@@ -183,7 +297,7 @@ BOOST_AUTO_TEST_CASE(value_string) {
}
BOOST_AUTO_TEST_CASE(value_matrixXd) {
using dynamicgraph::command::Value;
using dg::command::Value;
Eigen::MatrixXd avector1;
avector1.resize(2,2);
......@@ -206,7 +320,7 @@ BOOST_AUTO_TEST_CASE(value_matrixXd) {
}
BOOST_AUTO_TEST_CASE(value_matrix4d) {
using dynamicgraph::command::Value;
using dg::command::Value;
Eigen::Matrix4d avector1;
avector1.setZero();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment