Skip to content
Snippets Groups Projects
Commit c6a2bb87 authored by Zenker, Dr. Klaus (FWKE) - 126506's avatar Zenker, Dr. Klaus (FWKE) - 126506
Browse files

Fix test and use direct connection to the control system.

parent e019a35e
No related branches found
No related tags found
No related merge requests found
...@@ -42,17 +42,12 @@ struct testApp : public ChimeraTK::Application { ...@@ -42,17 +42,12 @@ struct testApp : public ChimeraTK::Application {
LoggingModule log{this, "LoggingModule", "LoggingModule test"}; LoggingModule log{this, "LoggingModule", "LoggingModule test"};
Logger logger{&log}; boost::shared_ptr<Logger> logger{new Logger(&log)};
ChimeraTK::ControlSystemModule cs; ChimeraTK::ControlSystemModule cs;
void defineConnections() override { void defineConnections() override {
cs("targetStream") >> log.targetStream; log.addSource(logger);
cs("logLevel") >> log.logLevel;
cs("logFile") >> log.logFile;
cs("tailLength") >> log.tailLength;
log.addSource(&logger);
log.findTag("CS").connectTo(cs); log.findTag("CS").connectTo(cs);
} }
...@@ -63,13 +58,12 @@ BOOST_AUTO_TEST_CASE(testLogMsg) { ...@@ -63,13 +58,12 @@ BOOST_AUTO_TEST_CASE(testLogMsg) {
testApp app; testApp app;
ChimeraTK::TestFacility tf; ChimeraTK::TestFacility tf;
tf.runApplication(); tf.runApplication();
auto tailLength = tf.getScalar<uint>("tailLength"); auto tailLength = tf.getScalar<uint>("maxTailLength");
tailLength = 1; tailLength = 1;
tailLength.write(); tailLength.write();
app.logger->sendMessage("test", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
app.logger.sendMessage("test", LogLevel::DEBUG); std::string ss = (std::string)tf.readScalar<std::string>("logTail");
tf.stepApplication();
std::string ss = (std::string)tf.readScalar<std::string>("LogTail");
BOOST_CHECK_EQUAL(ss.substr(ss.find("->") + 3), std::string("test\n")); BOOST_CHECK_EQUAL(ss.substr(ss.find("->") + 3), std::string("test\n"));
} }
...@@ -81,11 +75,10 @@ BOOST_AUTO_TEST_CASE(testLogfileFails) { ...@@ -81,11 +75,10 @@ BOOST_AUTO_TEST_CASE(testLogfileFails) {
tf.runApplication(); tf.runApplication();
logFile = std::string("/tmp/testLogging/test.log"); logFile = std::string("/tmp/testLogging/test.log");
logFile.write(); logFile.write();
tf.stepApplication();
// message not considered here but used to step through the application // message not considered here but used to step through the application
app.logger.sendMessage("test", LogLevel::DEBUG); app.logger->sendMessage("test", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
std::string ss = (std::string)tf.readScalar<std::string>("LogTail"); std::string ss = (std::string)tf.readScalar<std::string>("logTail");
std::vector<std::string> strs; std::vector<std::string> strs;
boost::split(strs, ss, boost::is_any_of("\n"), boost::token_compress_on); boost::split(strs, ss, boost::is_any_of("\n"), boost::token_compress_on);
BOOST_CHECK_EQUAL(strs.at(2).substr(strs.at(2).find("->") + 3), BOOST_CHECK_EQUAL(strs.at(2).substr(strs.at(2).find("->") + 3),
...@@ -102,9 +95,8 @@ BOOST_AUTO_TEST_CASE(testLogfile) { ...@@ -102,9 +95,8 @@ BOOST_AUTO_TEST_CASE(testLogfile) {
tf.runApplication(); tf.runApplication();
logFile = std::string("/tmp/testLogging/test.log"); logFile = std::string("/tmp/testLogging/test.log");
logFile.write(); logFile.write();
tf.stepApplication();
// message not considered here but used to step through the application // message not considered here but used to step through the application
app.logger.sendMessage("test", LogLevel::DEBUG); app.logger->sendMessage("test", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
std::fstream file; std::fstream file;
file.open("/tmp/testLogging/test.log"); file.open("/tmp/testLogging/test.log");
...@@ -124,19 +116,18 @@ BOOST_AUTO_TEST_CASE(testLogging) { ...@@ -124,19 +116,18 @@ BOOST_AUTO_TEST_CASE(testLogging) {
ChimeraTK::TestFacility tf; ChimeraTK::TestFacility tf;
auto logLevel = tf.getScalar<uint>("logLevel"); auto logLevel = tf.getScalar<uint>("logLevel");
auto tailLength = tf.getScalar<uint>("tailLength"); auto tailLength = tf.getScalar<uint>("maxTailLength");
tf.runApplication(); tf.runApplication();
logLevel = 0; logLevel = 0;
logLevel.write(); logLevel.write();
tailLength = 2; tailLength = 2;
tailLength.write(); tailLength.write();
app.logger->sendMessage("1st test message", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
app.logger.sendMessage("1st test message", LogLevel::DEBUG); app.logger->sendMessage("2nd test message", LogLevel::DEBUG);
tf.stepApplication();
app.logger.sendMessage("2nd test message", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
auto tail = tf.readScalar<std::string>("LogTail"); auto tail = tf.readScalar<std::string>("logTail");
std::vector<std::string> result; std::vector<std::string> result;
boost::algorithm::split(result, tail, boost::is_any_of("\n")); boost::algorithm::split(result, tail, boost::is_any_of("\n"));
// result length should be 3 not 2, because new line is used to split, which // result length should be 3 not 2, because new line is used to split, which
...@@ -146,9 +137,9 @@ BOOST_AUTO_TEST_CASE(testLogging) { ...@@ -146,9 +137,9 @@ BOOST_AUTO_TEST_CASE(testLogging) {
/**** Test log level ****/ /**** Test log level ****/
logLevel = 2; logLevel = 2;
logLevel.write(); logLevel.write();
app.logger.sendMessage("3rd test message", LogLevel::DEBUG); app.logger->sendMessage("3rd test message", LogLevel::DEBUG);
tf.stepApplication(); tf.stepApplication();
tail = tf.readScalar<std::string>("LogTail"); tail = tf.readScalar<std::string>("logTail");
boost::algorithm::split(result, tail, boost::is_any_of("\n")); boost::algorithm::split(result, tail, boost::is_any_of("\n"));
// should still be 3 because log level was too low! // should still be 3 because log level was too low!
BOOST_CHECK_EQUAL(result.size(), 3); BOOST_CHECK_EQUAL(result.size(), 3);
...@@ -156,16 +147,16 @@ BOOST_AUTO_TEST_CASE(testLogging) { ...@@ -156,16 +147,16 @@ BOOST_AUTO_TEST_CASE(testLogging) {
/**** Test tail length ****/ /**** Test tail length ****/
tailLength = 3; tailLength = 3;
tailLength.write(); tailLength.write();
// tf.stepApplication();
app.logger->sendMessage("4th test message", LogLevel::ERROR);
tf.stepApplication(); tf.stepApplication();
app.logger.sendMessage("4th test message", LogLevel::ERROR); tail = tf.readScalar<std::string>("logTail");
tf.stepApplication();
tail = tf.readScalar<std::string>("LogTail");
boost::algorithm::split(result, tail, boost::is_any_of("\n")); boost::algorithm::split(result, tail, boost::is_any_of("\n"));
BOOST_CHECK_EQUAL(result.size(), 4); BOOST_CHECK_EQUAL(result.size(), 4);
app.logger.sendMessage("5th test message", LogLevel::ERROR); app.logger->sendMessage("5th test message", LogLevel::ERROR);
tf.stepApplication(); tf.stepApplication();
tail = tf.readScalar<std::string>("LogTail"); tail = tf.readScalar<std::string>("logTail");
boost::algorithm::split(result, tail, boost::is_any_of("\n")); boost::algorithm::split(result, tail, boost::is_any_of("\n"));
// should still be 4 because tailLength is 3! // should still be 4 because tailLength is 3!
BOOST_CHECK_EQUAL(result.size(), 4); BOOST_CHECK_EQUAL(result.size(), 4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment