Add Tests

This commit is contained in:
2020-06-10 10:16:28 +02:00
parent e7d247ca42
commit 709df81110
9 changed files with 335 additions and 1 deletions
+69
View File
@@ -0,0 +1,69 @@
#include "Test.h"
#include "Metronome.h"
#include <Logging.h>
#include <chrono>
#include <ctime>
#include <sstream>
#include <string>
#include <unistd.h>
namespace Timer {
namespace Test {
int g_callbacks = 0;
void Callback()
{
auto now = std::chrono::system_clock::now();
auto in_time_t = std::chrono::system_clock::to_time_t(now);
std::stringstream ss;
char time[10];
if (0 < strftime(time, sizeof(time), "%X", std::localtime(&in_time_t)))
ss << time << " ";
ss << "Callback Triggered" << std::endl;
++g_callbacks;
Logging::Log(Logging::Severity::Info, ss.str());
}
bool TestMetronome()
{
std::stringstream ss;
ss << "----------------------------------" << std::endl;
ss << "| TestMetronome |" << std::endl;
ss << "----------------------------------" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
auto callback = std::bind(&Callback);
int iterations = 3;
int waitTime = 2;
Metronome metronome(Metronome::Quantity::Seconds, waitTime);
metronome.Connect(callback);
auto now = std::chrono::system_clock::now();
auto in_time_t = std::chrono::system_clock::to_time_t(now);
ss.str("");
char time[10];
if (0 < strftime(time, sizeof(time), "%X", std::localtime(&in_time_t)))
ss << time << " ";
ss << "Start Metronome" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
sleep((iterations * waitTime) + 1);
ss.str("");
ss << "==================================" << std::endl << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
return (g_callbacks == iterations);
}
} // namespace Test
} // namespace Timer