| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #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
|