summaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
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;