Commit 428aaa76 authored by Samuel Debionne's avatar Samuel Debionne

Add a CmdThread test with a command throwing a Lima Exception

parent fd7933dc
Pipeline #32172 passed with stages
in 35 minutes and 7 seconds
......@@ -26,3 +26,16 @@ if (NOT WIN32)
endif()
limatools_run_camera_tests("${test_src}" ${NAME})
add_executable(test_cmdthread
test_cmdthread.cpp
)
target_link_libraries(test_cmdthread
limacore
)
add_test(NAME test_cmdthread
COMMAND test_cmdthread
)
#include <iostream>
#include <lima/Exceptions.h>
#include <lima/ThreadUtils.h>
using namespace lima;
struct CommandThread : public CmdThread
{
enum {Ready = MaxThreadStatus};
enum Cmd {Hello = MaxThreadCmd, Throw};
~CommandThread()
{
abort();
}
protected:
void init() override
{
setStatus(Ready);
}
void execCmd(int cmd) override
{
switch(cmd)
{
case Cmd::Hello:
std::cout << "Hello" << std::endl;
break;
case Cmd::Throw:
LIMA_COM_EXC(Error, "Something bad happend");
}
}
};
int main(int /*argc*/, char */*argv*/[])
{
try {
CommandThread thread;
thread.start();
thread.waitStatus(CommandThread::Ready);
std::cout << "Sending Hello command" << std::endl;
thread.sendCmd(CommandThread::Hello);
std::cout << "Sending Throw command" << std::endl;
thread.sendCmd(CommandThread::Throw);
} catch (Exception e) {
std::cerr << "LIMA Exception: " << e << std::endl;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment