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

[tests] Improve coverage of signal-ptr.

parent a955e307
No related branches found
No related tags found
No related merge requests found
...@@ -88,20 +88,16 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) { ...@@ -88,20 +88,16 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) {
try { try {
// Signal<double, int> * r = // Signal<double, int> * r =
sigNotPlug.getPtr(); sigNotPlug.getPtr();
} } catch (const ExceptionSignal &aea) {
catch(const ExceptionSignal &aea) res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
{
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
} }
BOOST_CHECK(res); BOOST_CHECK(res);
/// Testing const getPtr() interface: no plug case /// Testing const getPtr() interface: no plug case
try { try {
cstSigNotPlug.getPtr(); cstSigNotPlug.getPtr();
} } catch (const ExceptionSignal &aea) {
catch(const ExceptionSignal &aea) res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
{
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
} }
BOOST_CHECK(res); BOOST_CHECK(res);
...@@ -112,35 +108,34 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) { ...@@ -112,35 +108,34 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) {
sigNotPlug.display(output); sigNotPlug.display(output);
cstSigNotPlug.display(output); cstSigNotPlug.display(output);
/// Testing getAbsatractPtr() interface: no plug /// Testing getAbsatractPtr() interface: no plug
res=false; res = false;
try { try {
sigNotPlug.getAbstractPtr(); sigNotPlug.getAbstractPtr();
} } catch (const ExceptionSignal &aea) {
catch(const ExceptionSignal &aea) res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
{
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
} }
BOOST_CHECK(res); BOOST_CHECK(res);
/// Testing const getAbstractPtr() interface: no plug case /// Testing const getAbstractPtr() interface: no plug case
try { try {
cstSigNotPlug.getAbstractPtr(); cstSigNotPlug.getAbstractPtr();
} } catch (const ExceptionSignal &aea) {
catch(const ExceptionSignal &aea) res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
{
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
} }
BOOST_CHECK(res); BOOST_CHECK(res);
try { sigNotPlug.checkCompatibility(); } try {
catch(...) { } sigNotPlug.checkCompatibility();
} catch (...) {
}
BOOST_CHECK(res); BOOST_CHECK(res);
} }
BOOST_AUTO_TEST_CASE(normal_test) { BOOST_AUTO_TEST_CASE(normal_test) {
Signal<double, int> sig("sig"); Signal<double, int> sig("sig");
Signal<int, int> sigint("sig");
Signal<std::string, int> sigstr("sig_str");
SignalPtr<double, int> sigPtrA(NULL, "sigPtrA"), sigPtrB(NULL, "sigPtrB"); SignalPtr<double, int> sigPtrA(NULL, "sigPtrA"), sigPtrB(NULL, "sigPtrB");
SignalPtr<double, int> sigPtrAbstract(NULL, "sigPtrAbstract"); SignalPtr<double, int> sigPtrAbstract(NULL, "sigPtrAbstract");
DummyClass<double> pro3("pro3"); DummyClass<double> pro3("pro3");
...@@ -156,32 +151,68 @@ BOOST_AUTO_TEST_CASE(normal_test) { ...@@ -156,32 +151,68 @@ BOOST_AUTO_TEST_CASE(normal_test) {
e.getExceptionName(); e.getExceptionName();
} }
BOOST_CHECK(true); BOOST_CHECK(true);
sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2)); sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
/// Plugging signal. /// Plugging signal.
SignalBase<int> &sigRef = sig; SignalBase<int> &sigRef = sig, sigBase("sigBase");
SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB, SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB,
&sigPtrAbstractRef = sigPtrAbstract; &sigPtrAbstractRef = sigPtrAbstract;
sigPtrARef.plug(0); sigPtrARef.plug(0);
sigPtrARef.plug(&sigRef); sigPtrARef.plug(&sigRef);
sigPtrBRef.plug(&sigPtrARef); sigPtrBRef.plug(&sigPtrARef);
/// Try to plug an incompatible signal.
/// leave
bool res = false;
try {
sigPtrARef.plug(&sigstr);
} catch (const ExceptionSignal &aes) {
res = (aes.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Plug the signal. /// Plug the signal.
sigPtrAbstractRef.plug(&sigRef); sigPtrAbstractRef.plug(&sigRef);
sigPtrA.getPtr(); sigPtrA.getPtr();
BOOST_CHECK(true); BOOST_CHECK(true);
try { sigPtrARef.checkCompatibility(); } try {
catch(...) { } sigPtrARef.checkCompatibility();
} catch (const ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (const std::exception &e) {
std::cout << "Standard Exception:" << e.what() << std::endl;
} catch (...) {
std::cout << "Anything else: " << std::endl;
}
sigPtrA.needUpdate(5); sigPtrA.needUpdate(5);
// BOOST_CHECK(res); BOOST_CHECK(true);
int ltime = sigPtrA.getTime(); int ltime = sigPtrA.getTime();
sigPtrA.getPluged(); sigPtrA.getPluged();
sigPtrA(ltime); sigPtrA(ltime);
BOOST_CHECK(true);
sigPtrB.getPtr(); sigPtrB.getPtr();
sigPtrAbstract.getAbstractPtr(); /// Test sigPtrAbstract with a normal plug.
res = false;
try {
sigPtrAbstract.getAbstractPtr();
} catch (ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
std::cout << "Code: " << aes.getCode() << std::endl;
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (...) {
std::cout << "Anything else with sigPtrAbstract.getAbstractPtr()"
<< std::endl;
}
BOOST_CHECK(true);
/// Test the case where the plug ref is zero.
sigPtrAbstractRef.plug(0);
BOOST_CHECK(true);
assert(sigRef.isPlugged() != true); assert(sigRef.isPlugged() != true);
SignalBase<int> *t = sigRef.getPluged(); SignalBase<int> *t = sigRef.getPluged();
...@@ -204,12 +235,12 @@ BOOST_AUTO_TEST_CASE(normal_test) { ...@@ -204,12 +235,12 @@ BOOST_AUTO_TEST_CASE(normal_test) {
sigPtrA.setReferenceNonConstant(tab_D, NULL); sigPtrA.setReferenceNonConstant(tab_D, NULL);
sigPtrA.access(5); sigPtrA.access(5);
sigPtrA.display(output); sigPtrA.display(output);
// getreference // getreference
sigPtrA.operator=(1.2); sigPtrA.operator=(1.2);
// getconstant // getconstant
sigPtrA.displayDependencies(output); sigPtrA.displayDependencies(output);
cout << t << std::endl; cout << t << std::endl;
cout << "Sig = "; cout << "Sig = ";
sigRef.get(cout); sigRef.get(cout);
......
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