I started using CATCH yesterday, and one of my problems is, that I need to test code running with Qt.
Some part of this code is only running and passing correctly if the eventloop is also running.
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
TEST_CASE( "LibProcessSink", "[ProcessSink]" ) {
QVariant id = 1;
ProcessSink test_path_invalid(" ",id);
REQUIRE(test_path_invalid.start()==false);
ProcessSink path_valid("C:\\windows\\system32\\cmd.exe /c dir",id);
REQUIRE(path_valid.start()==true);
path_valid.waitForFinished();
REQUIRE(path_valid.getResult().isEmpty() == false);
}
void startCatch()
{
// this works, but is CATCH set up correctly that way? (no commandline args is clear)
Catch::Session session;
session.run();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
/*Catch::Session().run(argc, argv);// well, that one isn't going to run during eventloop execution, test results not valid*/
QTimer timer;
timer.setSingleShot(true);
// I probably could also use a lambda here, to hand over the commandline parameters
QObject::connect(&timer,&QTimer::timeout,startCatch);
timer.start(1000);//*/
return a.exec();
}
This works for now, but its just a first shot at the problem, is there a better way?
While I found a solution for this, one of my concerns currently is how to test asynchrone code (f.e. Qt SIGNAL/SLOT, boost::asio).
Especially if I need to wait for certain events/signals, what would be the best way to this with catch?