diff options
Diffstat (limited to 'test/event.cpp')
-rw-r--r-- | test/event.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/test/event.cpp b/test/event.cpp index 816060cc..9f7b1ed4 100644 --- a/test/event.cpp +++ b/test/event.cpp @@ -2,34 +2,37 @@ /* * Copyright (C) 2019, Google Inc. * - * event.cpp - Event test + * Event test */ #include <iostream> #include <string.h> #include <unistd.h> -#include <libcamera/event_dispatcher.h> -#include <libcamera/event_notifier.h> -#include <libcamera/timer.h> +#include <libcamera/base/event_dispatcher.h> +#include <libcamera/base/event_notifier.h> +#include <libcamera/base/thread.h> +#include <libcamera/base/timer.h> #include "test.h" -#include "thread.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class EventTest : public Test { protected: - void readReady(EventNotifier *notifier) + void readReady() { - size_ = read(notifier->fd(), data_, sizeof(data_)); + size_ = read(notifier_->fd(), data_, sizeof(data_)); notified_ = true; } int init() { + notifier_ = nullptr; + return pipe(pipefd_); } @@ -40,8 +43,8 @@ protected: Timer timeout; ssize_t ret; - EventNotifier readNotifier(pipefd_[0], EventNotifier::Read); - readNotifier.activated.connect(this, &EventTest::readReady); + notifier_ = new EventNotifier(pipefd_[0], EventNotifier::Read); + notifier_->activated.connect(this, &EventTest::readReady); /* Test read notification with data. */ memset(data_, 0, sizeof(data_)); @@ -53,7 +56,7 @@ protected: return TestFail; } - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -65,7 +68,7 @@ protected: /* Test read notification without data. */ notified_ = false; - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -76,7 +79,7 @@ protected: /* Test read notifier disabling. */ notified_ = false; - readNotifier.setEnabled(false); + notifier_->setEnabled(false); ret = write(pipefd_[1], data.data(), data.size()); if (ret < 0) { @@ -84,7 +87,7 @@ protected: return TestFail; } - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -95,9 +98,9 @@ protected: /* Test read notifier enabling. */ notified_ = false; - readNotifier.setEnabled(true); + notifier_->setEnabled(true); - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -111,6 +114,8 @@ protected: void cleanup() { + delete notifier_; + close(pipefd_[0]); close(pipefd_[1]); } @@ -118,6 +123,7 @@ protected: private: int pipefd_[2]; + EventNotifier *notifier_; bool notified_; char data_[16]; ssize_t size_; |