From cfccb6756142c18d6b1ca8d44f7383d03fe2511e Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Tue, 10 Jul 2018 23:49:35 +0200 Subject: [PATCH] fixed some testing bugs --- FlippR-Driver/src/input/Detector.cpp | 6 +++--- FlippR-Driver/src/input/EventNotifier.cpp | 9 ++++++++- FlippR-Driver/src/utilities/BlockingQueue.hpp | 4 +++- FlippR-Driver/tests/input/TestDetector.cpp | 11 ++++++----- FlippR-Driver/tests/input/TestEventHandler.cpp | 2 +- FlippR-Driver/tests/input/TestEventNotifier.cpp | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/FlippR-Driver/src/input/Detector.cpp b/FlippR-Driver/src/input/Detector.cpp index c9f125c..b9701c6 100644 --- a/FlippR-Driver/src/input/Detector.cpp +++ b/FlippR-Driver/src/input/Detector.cpp @@ -25,9 +25,9 @@ Detector::Detector(IInputGPIOInterface* input_gpio_interface, std::mapis_running = false; - detect_thread.join(); + this->detect_thread.join(); delete this->input_gpio_interface; this->input_gpio_interface = NULL; @@ -39,7 +39,7 @@ Detector::~Detector() // Cycles over all s and enqueues an event if detected. void Detector::detect() { - while(is_running) + while(this->is_running) { char address; if(this->check_inputs(address)) diff --git a/FlippR-Driver/src/input/EventNotifier.cpp b/FlippR-Driver/src/input/EventNotifier.cpp index 29d8449..a6c3ab8 100644 --- a/FlippR-Driver/src/input/EventNotifier.cpp +++ b/FlippR-Driver/src/input/EventNotifier.cpp @@ -26,7 +26,8 @@ EventNotifier::~EventNotifier() { is_running = false; - event_queue.release(); + Event end_event(0, 0, "END"); + event_queue.push(end_event); notify_thread.join(); } @@ -54,6 +55,12 @@ void EventNotifier::notify() { Event event = event_queue.pop(); + // TODO schoener machen + if(event.name == "END") + { + return; + } + // getting a guard and calling all registered handlers std::lock_guard event_handler_guard(event_handler_mutex); for(auto handler : event_handler) diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index dec18b9..62bff58 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -32,7 +32,9 @@ public: T pop() { - std::unique_lock lock(this->d_mutex); + // TODO die queue funzt net weil wir nich pushen koennen wenn wir im pop warten + // TODO denk ma ueber future nach + std::unique_lock lock(this->d_mutex); this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); T rc = *this->p_queue.end(); this->p_queue.pop(); diff --git a/FlippR-Driver/tests/input/TestDetector.cpp b/FlippR-Driver/tests/input/TestDetector.cpp index 12821e3..f681f7b 100644 --- a/FlippR-Driver/tests/input/TestDetector.cpp +++ b/FlippR-Driver/tests/input/TestDetector.cpp @@ -55,15 +55,16 @@ SCENARIO("Creating a Detector object", "") Detector detector(&gpio_interface_mock.get(), events, &event_notifier_mock.get()); THEN("a thread should be created") { - REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code()); + REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code()); } AND_WHEN("an event can be found at gpio interface") { - THEN("only the fitting event should be distributed by event notifier") - { - REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2))); - } + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + THEN("only the fitting event should be distributed by event notifier") + { + REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2))); + } } } } diff --git a/FlippR-Driver/tests/input/TestEventHandler.cpp b/FlippR-Driver/tests/input/TestEventHandler.cpp index a074834..48bc246 100644 --- a/FlippR-Driver/tests/input/TestEventHandler.cpp +++ b/FlippR-Driver/tests/input/TestEventHandler.cpp @@ -28,7 +28,7 @@ SCENARIO("An EventHandler gets created", "[construction}") Mock input_driver_mock; Fake(Dtor(input_driver_mock)); When(Method(input_driver_mock, register_event_handler)).AlwaysReturn(); - When(Method(input_driver_mock, operator=)).AlwaysReturn(); + When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn(); WHEN("the event handler gets created") { diff --git a/FlippR-Driver/tests/input/TestEventNotifier.cpp b/FlippR-Driver/tests/input/TestEventNotifier.cpp index 63ff346..eb8f24d 100644 --- a/FlippR-Driver/tests/input/TestEventNotifier.cpp +++ b/FlippR-Driver/tests/input/TestEventNotifier.cpp @@ -33,7 +33,7 @@ SCENARIO("An EventNotifier gets created", "[construction]") } THEN("It creates a notify thread") { - //REQUIRE(typeid(notifier.notify_thread).hash_code() == typeid(std::thread).hash_code()); + REQUIRE(typeid(notifier.notify_thread).hash_code() == typeid(std::thread).hash_code()); } } }