How To Use
 All Modules Pages
C++ sample: Testcase with oBLOCKING, oSYNC, _ContinueExecution
TTB_TEST_FUNC(BlockingWait)
{
SomeSimulatedObject a("SimObjectA");
// Use waitable sync events
a._SetOption(TTB::Option::oSYNC, "CalculateSomething");
// Hold execution on the 3rd call
a._SetOption(TTB::Option::oBLOCKING, "CalculateSomething",
TTB::OptionType::AFTER_N_CALLS_ACTIVE_ONCE, 3);
TTB_INFO("\nCalling CalculateSomething asynchronously 5 times, block on 3rd call");
TTB_INIT_SYNC(3);
// call asynchronous to stay reactive (one of the calls will block)
std::thread t([&]()
{
int result;
a.CalculateSomething(17, result);
a.CalculateSomething(18, result);
a.CalculateSomething(19, result);
a.CalculateSomething(20, result);
a.CalculateSomething(21, result);
});
TTB_WAIT_SYNC();
TTB_EXP("CalculateSomething in_val=17 out_val=34 (SimObjectA)");
TTB_EXP("CalculateSomething in_val=18 out_val=36 (SimObjectA)");
TTB_EXP("CalculateSomething-Start in_val=19 (SimObjectA)");
// Now the 3rd call to CalculateSomething is blocked.
// In a more realistic test scenario we could check internal conditions of
// our SUT or provoke some interrupt by calling other interface methods
// while CalculateSomething is called.
// Here we simply decide that the currently waiting call shall return
// an error and the following calls shall succeed.
a._SetOption(TTB::Option::oERROR, "CalculateSomething", TTB::OptionType::ACTIVE_ONCE);
TTB_INFO("\nNow continuing the interrupted call to CalculateSomething with error and proceed the call sequence");
TTB_INIT_SYNC(3);
a._ContinueExecution("CalculateSomething");
TTB_WAIT_SYNC();
TTB_EXP("CalculateSomething-Stop out_val=-99 return error (SimObjectA)");
TTB_EXP("CalculateSomething in_val=20 out_val=40 (SimObjectA)");
TTB_EXP("CalculateSomething in_val=21 out_val=42 (SimObjectA)");
t.join(); // cleanup thread
}