SDFM_CONROL_TEAST_EFC/EFC_PlatformC28xTest/AsyncRunnerTest.cpp
2024-10-11 09:35:38 +03:00

93 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* \file AsyncRunnerTest.cpp
* \project EFC_PlatformC28x_Test
*
* \date 21 мая 2024 г.
* \author leonid
*/
#include "AsyncRunnerTest.hh"
void umlib::tests::AsyncRunnerTest::OnceCallTask::reset() {
counter = 0;
}
void umlib::tests::AsyncRunnerTest::OnceCallTask::do_task() {
++counter;
}
umlib::tests::AsyncRunnerTest::AsyncRunnerTest( umlib::tests::AsyncRunnerInterface & async_runner ) : runner(async_runner) {}
void umlib::tests::AsyncRunnerTest::run( TestResult & result ) {
test_once_call_on_zero(result);
test_once_call_on_one(result);
test_ran_after_run(result);
test_cancel(result);
}
void umlib::tests::AsyncRunnerTest::test_once_call_on_zero( TestResult & result ) {
OnceCallTask once_call_task;
once_call_task.reset();
runner.run_after( &once_call_task, 0 );
for( volatile int i = 0; i < 1; i++ );
result.assert_true( once_call_task.counter == 1, "AsyncRunner call task once with 0");
}
void umlib::tests::AsyncRunnerTest::test_once_call_on_one(
TestResult & result ) {
OnceCallTask once_call_task;
once_call_task.reset();
runner.run_after( &once_call_task, 1 );
for( volatile int i = 0; i < 2; i++ );
result.assert_true( once_call_task.counter == 1, "AsyncRunner call task once with 1");
}
void umlib::tests::AsyncRunnerTest::test_ran_after_run(
TestResult & result ) {
OnceCallTask once_call_task;
once_call_task.reset();
runner.run_after( &once_call_task, 1 );
for( volatile int i = 0; i < 64; i++ );
result.assert_true( runner.is_ran(), "AsyncRunner ran after run");
}
void umlib::tests::AsyncRunnerTest::test_cancel( TestResult & result ) {
OnceCallTask once_call_task;
once_call_task.reset();
runner.run_after( &once_call_task, 200 );
runner.cancel();
for( volatile int i = 0; i < 200; i++ );
result.assert_false( runner.is_ran(), "AsyncRunner not ran after cancel");
result.assert_true( once_call_task.counter == 0, "AsyncRunner not call task after cancel");
}