cover more testcases (starting several subsystems)

This commit is contained in:
Fischlurch 2009-01-03 01:11:21 +01:00
parent eac43b80d6
commit 762a108dff
2 changed files with 134 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/*
Exceptionhandlin(Test) - throwing and catching our exception type
ExceptionError(Test) - throwing and catching our exception type
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
@ -41,13 +41,11 @@ using std::cout;
namespace lumiera
{
namespace test
{
namespace lumiera {
namespace test {
/** local specific error-constant for use in the
* construcor of the nested SpecificError class.
* constructor of the nested SpecificError class.
*/
LUMIERA_ERROR_DEFINE(LIFE_AND_UNIVERSE, "and everything?");
LUMIERA_ERROR_DEFINE(DERIVED, "convoluted exception");
@ -98,7 +96,7 @@ namespace lumiera
void throwExternal(string _) { throw error::External(_); }
void throwRuntime (string _) { throw std::runtime_error(_); }
void throwExceptn (string ) { throw std::exception(); }
/** @test catching, repackaging and rethrowing of errors.
* This feature is important for passing exceptions transparently
@ -126,7 +124,7 @@ namespace lumiera
try { nestedThrower (msg); }
catch (Error& e)
{
cout << "2nd intermediate handler caught: " << e.what()
cout << "2nd intermediate handler caught: " << e.what()
<< "....will rethrow as error::Config\n";
throw error::Config (e);
}
@ -172,7 +170,7 @@ namespace lumiera
ASSERT (err2.rootCause() == err1.what());
ASSERT (err3.rootCause() == err1.what());
ASSERT (err4.rootCause() == err1.what());
ASSERT (err5.rootCause() == rerr.what());
ASSERT (err6.rootCause() == rerr.what());
}
@ -214,22 +212,22 @@ namespace lumiera
(this->*funky) (context);
}
catch (SpecificError& e) { cout << "caught: " << e.what() << "..the answer is: " << e.revealIt() << "\n"; }
catch (error::Logic& e) { cout << "caught error::Logic: " << e.what() << "\n"; }
catch (error::Invalid&e) { cout << "caught error::Invalid: " << e.what() << "\n"; }
catch (Error& e) { cout << "caught lumiera::Error: " << e.what() << "\n"; }
catch (runtime_error& e) { cout << "caught std::runtime_error: " << e.what() << "\n"; }
catch (SpecificError& e) { cout << "caught: " << e.what() << "..the answer is: " << e.revealIt() << "\n"; }
catch (error::Logic& e) { cout << "caught error::Logic: " << e.what() << "\n"; }
catch (error::Invalid&e) { cout << "caught error::Invalid: " << e.what() << "\n"; }
catch (Error& e) { cout << "caught lumiera::Error: " << e.what() << "\n"; }
catch (runtime_error& e) { cout << "caught std::runtime_error: " << e.what() << "\n"; }
catch (exception& e) { cout << "caught std::exception. (unspecific)" << "\n"; }
catch (...) { cout << "caught an unknown exception\n"; }
}
};
/** register this test class... */
LAUNCHER (ExceptionError_test, "function common");
/** register this test class... */
LAUNCHER (ExceptionError_test, "function common");
} // namespace test
} // namespace util

View file

@ -38,7 +38,6 @@
using std::cout;
using std::tr1::bind;
using std::tr1::placeholders::_1;
using util::isnil;
using test::Test;
using lib::Sync;
@ -64,6 +63,10 @@ namespace lumiera {
util::Cmdline dummyArgs ("");
lumiera::Option dummyOpt (dummyArgs);
/** marker for simulated failure exceptions */
LUMIERA_ERROR_DEFINE( TEST, "simulated failure.");
/**
@ -82,8 +85,8 @@ namespace lumiera {
Literal id_;
Literal spec_;
bool isUp_;
bool didRun_;
volatile bool isUp_;
volatile bool didRun_;
volatile bool termRequest_;
int running_duration_;
@ -113,8 +116,11 @@ namespace lumiera {
isUp_ = true;
}
else
if ("fail"==startSpec) //----starting incorrectly reports success
return true;
else
if ("throw"==startSpec) //---starting flounders
throw error::Fatal("simulated failure to start the subsystem");
throw error::Fatal("simulated failure to start the subsystem", LUMIERA_ERROR_TEST);
return isUp_;
}
@ -150,16 +156,17 @@ namespace lumiera {
Lock wait_blocking (this, &MockSys::tick);
}
Error problemIndicator("simulated Problem killing a subsystem");
Error problemIndicator("simulated Problem killing a subsystem",LUMIERA_ERROR_TEST);
lumiera_error(); // reset error state....
// Note: in real life this actually
// would be an catched exception!
Lock guard (this);
isUp_ = false;
termination ("true"==runSpec? 0 : &problemIndicator);
}
{
Lock guard (this);
isUp_ = false;
termination ("true"==runSpec? 0 : &problemIndicator);
} }
bool
@ -228,6 +235,10 @@ namespace lumiera {
run (Arg)
{
singleSubsys_complete_cycle();
singleSubsys_start_failure();
singleSubsys_emegency_exit();
dependentSubsys_complete_cycle();
}
@ -246,6 +257,99 @@ namespace lumiera {
ASSERT (!unit.isRunning());
ASSERT (unit.didRun());
}
void
singleSubsys_start_failure()
{
MockSys unit1 ("U1", "start(false), run(false).");
MockSys unit2 ("U2", "start(throw), run(false).");
MockSys unit3 ("U3", "start(fail), run(false)."); // simulates incorrect behaviour
MockSys unit4 ("U4", "start(true), run(false).");
SubsystemRunner runner(dummyOpt);
runner.maybeRun (unit1);
runner.maybeRun (unit4);
try
{
runner.maybeRun (unit2);
NOTREACHED;
}
catch (lumiera::Error&)
{
ASSERT (lumiera_error() == LUMIERA_ERROR_TEST);
}
try
{
runner.maybeRun (unit3);
NOTREACHED;
}
catch (lumiera::Error&)
{
ASSERT (lumiera_error() == error::LUMIERA_ERROR_LOGIC); // incorrect behaviour trapped
}
bool emergency = runner.wait();
ASSERT (emergency); // emergency state from unit4 got propagated
ASSERT (!unit1.isRunning());
ASSERT (!unit2.isRunning());
ASSERT (!unit3.isRunning());
ASSERT (!unit4.isRunning());
ASSERT (!unit1.didRun());
ASSERT (!unit2.didRun());
ASSERT (!unit3.didRun());
ASSERT (!unit4.didRun());
}
void
singleSubsys_emegency_exit()
{
MockSys unit ("one", "start(true), run(fail).");
SubsystemRunner runner(dummyOpt);
runner.maybeRun (unit);
bool emergency = runner.wait();
ASSERT (emergency); // emergency state got propagated
ASSERT (!unit.isRunning());
ASSERT (unit.didRun());
}
void
dependentSubsys_complete_cycle()
{
MockSys unit1 ("U1", "start(true), run(true).");
MockSys unit2 ("U2", "start(true), run(true).");
MockSys unit3 ("U3", "start(true), run(true).");
MockSys unit4 ("U4", "start(true), run(true).");
unit2.depends (unit1);
unit4.depends (unit3);
unit4.depends (unit1);
unit3.depends (unit2);
SubsystemRunner runner(dummyOpt);
runner.maybeRun (unit4);
ASSERT (unit1.isRunning());
ASSERT (unit2.isRunning());
ASSERT (unit3.isRunning());
ASSERT (unit4.isRunning());
bool emergency = runner.wait();
ASSERT (!emergency);
ASSERT (!unit1.isRunning());
ASSERT (!unit2.isRunning());
ASSERT (!unit3.isRunning());
ASSERT (!unit4.isRunning());
ASSERT (unit1.didRun());
ASSERT (unit2.didRun());
ASSERT (unit3.didRun());
ASSERT (unit4.didRun());
}
};