Skip to content

Commit

Permalink
added two test cases for executor order of execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wilmans committed Jan 1, 2025
1 parent b1f6c77 commit 805756d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion application/CobaltFusionTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(CobaltFusionTest)

add_executable(${PROJECT_NAME} CobaltFusionTest.cpp)
add_executable(${PROJECT_NAME} CobaltFusionTest.cpp TestExecutor.cpp TestGuiExecutor.cpp)

target_link_libraries(${PROJECT_NAME}
PRIVATE
Expand Down
54 changes: 54 additions & 0 deletions application/CobaltFusionTest/TestGuiExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <boost/test/unit_test_gui.hpp>
#include "CobaltFusion/GuiExecutor.h"

using namespace std::chrono_literals;

namespace fusion {

BOOST_AUTO_TEST_SUITE(TestExecutor)
Expand Down Expand Up @@ -55,6 +57,58 @@ BOOST_AUTO_TEST_CASE(TestGuiExecutor)
testThread.join();
}

void TestGuiExecutionOrderImpl(GuiExecutor& executor)
{
enum class mark
{
unset,
scheduled_call,
immediate
};

mark task_mark = mark::unset;

auto scheduled_call = executor.CallAfter(5min, [&] { task_mark = mark::scheduled_call; });
executor.Call([&] { task_mark = mark::immediate; });
scheduled_call.Cancel();
BOOST_CHECK(task_mark == mark::immediate);
}

BOOST_AUTO_TEST_CASE(TestGuiExecutionOrder)
{
GuiExecutor executor;
std::thread testThread([&executor]() { TestGuiExecutionOrderImpl(executor); });

bool elapsed = false;
executor.CallAfter(1s, [&executor, &elapsed]() { elapsed = true; });

GuiWaitFor([&executor, &elapsed]() { return elapsed; });

testThread.join();
}

void TestActiveExecutorOrderImpl(ActiveExecutor& executor)
{
enum class mark
{
unset,
scheduled_call,
immediate
};

mark task_mark = mark::unset;

auto scheduled_call = executor.CallAfter(5min, [&] { task_mark = mark::scheduled_call; });
executor.Call([&] { task_mark = mark::immediate; });
scheduled_call.Cancel();
BOOST_CHECK(task_mark == mark::immediate);
}

BOOST_AUTO_TEST_CASE(TestActiveExecutionOrder)
{
ActiveExecutor executor;
TestActiveExecutorOrderImpl(executor);
}
BOOST_AUTO_TEST_SUITE_END()

} // namespace fusion

0 comments on commit 805756d

Please sign in to comment.