Introduce the timed events

This commit is contained in:
Florent Le Coz
2014-05-28 17:31:28 +02:00
parent e033b6a3ae
commit 5999e6e0c3
4 changed files with 244 additions and 0 deletions
+24
View File
@@ -3,6 +3,7 @@
*/
#include <xmpp/xmpp_component.hpp>
#include <utils/timed_events.hpp>
#include <xmpp/xmpp_parser.hpp>
#include <utils/encoding.hpp>
#include <logger/logger.hpp>
@@ -16,6 +17,7 @@
#include <string.h>
#include <iostream>
#include <thread>
#include <vector>
#include <assert.h>
@@ -25,6 +27,28 @@ static const std::string reset("");
int main()
{
/**
* Timed events
*/
std::cout << color << "Testing timed events…" << reset << std::endl;
TimedEventsManager te_manager;
// No event.
assert(te_manager.get_timeout() == utils::no_timeout);
assert(te_manager.execute_expired_events() == 0);
// Add a single event
te_manager.add_event(TimedEvent(std::chrono::steady_clock::now() + 50ms, [](){ std::cout << "Timeout expired" << std::endl; }));
// The event should not yet be expired
assert(te_manager.get_timeout() > 0ms);
assert(te_manager.execute_expired_events() == 0);
std::chrono::milliseconds timoute = te_manager.get_timeout();
std::cout << "Sleeping for " << timoute.count() << "ms" << std::endl;
std::this_thread::sleep_for(timoute);
// Event is now expired
assert(te_manager.execute_expired_events() == 1);
assert(te_manager.get_timeout() == utils::no_timeout);
/**
* Encoding
*/