70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
#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
|