summaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-05-27 01:12:46 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-05-28 17:31:28 +0200
commit5999e6e0c32e6897b88f59f0743b4bb1fc9c521c (patch)
tree7c8523be49b221e5bd0bb5753e8695fae41ecb84 /src/test.cpp
parente033b6a3ae2923b040eb08cfa5376efe0a3da898 (diff)
downloadbiboumi-5999e6e0c32e6897b88f59f0743b4bb1fc9c521c.tar.gz
biboumi-5999e6e0c32e6897b88f59f0743b4bb1fc9c521c.tar.bz2
biboumi-5999e6e0c32e6897b88f59f0743b4bb1fc9c521c.tar.xz
biboumi-5999e6e0c32e6897b88f59f0743b4bb1fc9c521c.zip
Introduce the timed events
Diffstat (limited to 'src/test.cpp')
-rw-r--r--src/test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test.cpp b/src/test.cpp
index f624bc2..fe89b5a 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -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>
@@ -26,6 +28,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
*/
std::cout << color << "Testing encoding…" << reset << std::endl;