2020 * SOFTWARE.
2121 */
2222#include < notify-cpp/fanotify.h>
23+ #include < notify-cpp/event.h>
2324#include < notify-cpp/notify_controller.h>
2425
2526#include " filesystem_event_helper.hpp"
2627
27- #include < boost/test/unit_test.hpp >
28+ #include " doctest.h "
2829
30+ #include < thread>
2931#include < chrono>
3032#include < filesystem>
3133#include < fstream>
3537using namespace notifycpp ;
3638
3739
38- BOOST_FIXTURE_TEST_CASE (shouldNotifyOnMultipleEvents, FilesystemEventHelper )
40+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldNotifyOnMultipleEvents " )
3941{
4042 FanotifyController notifier = FanotifyController ();
4143
@@ -63,29 +65,29 @@ BOOST_FIXTURE_TEST_CASE(shouldNotifyOnMultipleEvents, FilesystemEventHelper)
6365
6466 auto futureOpen = promisedOpen_.get_future ();
6567 auto futureCloseNoWrite = promisedCloseNoWrite_.get_future ();
66- BOOST_CHECK (futureOpen.wait_for (timeout_) == std::future_status::ready);
67- BOOST_CHECK (futureOpen.get ().getEvent () == Event::open);
68- BOOST_CHECK (futureCloseNoWrite.wait_for (timeout_) == std::future_status::ready);
69- BOOST_CHECK (futureCloseNoWrite.get ().getEvent () == Event::close_write);
68+ CHECK (futureOpen.wait_for (timeout_) == std::future_status::ready);
69+ CHECK_EQ (futureOpen.get ().getEvent (), Event::open);
70+ CHECK (futureCloseNoWrite.wait_for (timeout_) == std::future_status::ready);
71+ CHECK (futureCloseNoWrite.get ().getEvent () == Event::close_write);
7072 thread.join ();
7173}
7274
73- BOOST_AUTO_TEST_CASE ( EventOperatorTest)
75+ TEST_CASE ( " EventOperatorTest" )
7476{
75- BOOST_CHECK ((Event::all & Event::close_write) == Event::close_write);
76- BOOST_CHECK ((Event::all & Event::moved_from) == Event::moved_from);
77- BOOST_CHECK ((Event::move & Event::moved_from) == Event::moved_from);
78- BOOST_CHECK (!((Event::move & Event::open) = = Event::open));
79- BOOST_CHECK (toString (Event::access) == std::string (" access" ));
77+ CHECK_EQ ((Event::all & Event::close_write), Event::close_write);
78+ CHECK_EQ ((Event::all & Event::moved_from), Event::moved_from);
79+ CHECK_EQ ((Event::move & Event::moved_from), Event::moved_from);
80+ CHECK (!((Event::move & Event::open) ! = Event::open));
81+ CHECK_EQ (toString (Event::access), std::string (" access" ));
8082}
8183
82- BOOST_FIXTURE_TEST_CASE (shouldNotAcceptNotExistingPaths, FilesystemEventHelper )
84+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldNotAcceptNotExistingPaths " )
8385{
84- BOOST_CHECK_THROW (FanotifyController ().watchPathRecursively (std::filesystem::path (" /not/existing/path/" )), std::invalid_argument);
85- BOOST_CHECK_THROW (FanotifyController ().watchFile (std::filesystem::path (" /not/existing/file" )), std::invalid_argument);
86+ CHECK_THROWS_AS (FanotifyController ().watchPathRecursively (std::filesystem::path (" /not/existing/path/" )), std::invalid_argument);
87+ CHECK_THROWS_AS (FanotifyController ().watchFile (std::filesystem::path (" /not/existing/file" )), std::invalid_argument);
8688}
8789
88- BOOST_FIXTURE_TEST_CASE (shouldNotifyOnOpenEvent, FilesystemEventHelper )
90+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldNotifyOnOpenEvent " )
8991{
9092 NotifyController notifier = FanotifyController ().watchFile ({testFileOne_, Event::close}).onEvent (Event::close, [&](Notification notification) {
9193 promisedOpen_.set_value (notification);
@@ -96,16 +98,16 @@ BOOST_FIXTURE_TEST_CASE(shouldNotifyOnOpenEvent, FilesystemEventHelper)
9698 openFile (testFileOne_);
9799
98100 auto futureOpenEvent = promisedOpen_.get_future ();
99- BOOST_CHECK (futureOpenEvent.wait_for (timeout_) == std::future_status::ready);
101+ CHECK (futureOpenEvent.wait_for (timeout_) == std::future_status::ready);
100102 const auto notify = futureOpenEvent.get ();
101- BOOST_CHECK_EQUAL (notify.getEvent (), Event::close);
103+ CHECK_EQ (notify.getEvent (), Event::close);
102104 auto fullpath = std::filesystem::current_path ();
103105 fullpath /= testFileOne_;
104- BOOST_CHECK_EQUAL (notify.getPath (), fullpath);
106+ CHECK_EQ (notify.getPath (), fullpath);
105107 thread.join ();
106108}
107109
108- BOOST_FIXTURE_TEST_CASE (shouldStopRunOnce, FilesystemEventHelper )
110+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldStopRunOnce " )
109111{
110112 NotifyController notifier = FanotifyController ().watchFile (testFileOne_);
111113
@@ -116,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(shouldStopRunOnce, FilesystemEventHelper)
116118 thread.join ();
117119}
118120
119- BOOST_FIXTURE_TEST_CASE (shouldStopRun, FilesystemEventHelper )
121+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldStopRun " )
120122{
121123 FanotifyController notifier = FanotifyController ();
122124 notifier.watchFile (testFileOne_);
@@ -128,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE(shouldStopRun, FilesystemEventHelper)
128130 thread.join ();
129131}
130132
131- BOOST_FIXTURE_TEST_CASE (shouldIgnoreFile, FilesystemEventHelper )
133+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldIgnoreFile " )
132134{
133135 NotifyController notifier = FanotifyController ().ignore (testFileOne_).watchFile ({testFileOne_, Event::close}).onEvent (Event::close, [&](Notification notification) {
134136 promisedOpen_.set_value (notification);
@@ -139,12 +141,12 @@ BOOST_FIXTURE_TEST_CASE(shouldIgnoreFile, FilesystemEventHelper)
139141 openFile (testFileOne_);
140142
141143 auto futureOpenEvent = promisedOpen_.get_future ();
142- BOOST_CHECK (futureOpenEvent.wait_for (timeout_) == std::future_status::timeout);
144+ CHECK (futureOpenEvent.wait_for (timeout_) == std::future_status::timeout);
143145 notifier.stop ();
144146 thread.join ();
145147}
146148
147- BOOST_FIXTURE_TEST_CASE (shouldUnwatchPath, FilesystemEventHelper )
149+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldUnwatchPath " )
148150{
149151 std::promise<Notification> timeoutObserved;
150152 std::chrono::milliseconds timeout (100 );
@@ -155,12 +157,12 @@ BOOST_FIXTURE_TEST_CASE(shouldUnwatchPath, FilesystemEventHelper)
155157 std::thread thread ([¬ifier]() { notifier.runOnce (); });
156158
157159 openFile (testFileOne_);
158- BOOST_CHECK (promisedOpen_.get_future ().wait_for (timeout_) != std::future_status::ready);
160+ CHECK (promisedOpen_.get_future ().wait_for (timeout_) != std::future_status::ready);
159161 notifier.stop ();
160162 thread.join ();
161163}
162164
163- BOOST_FIXTURE_TEST_CASE (shouldCallUserDefinedUnexpectedExceptionObserver, FilesystemEventHelper )
165+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldCallUserDefinedUnexpectedExceptionObserver " )
164166{
165167 std::promise<void > observerCalled;
166168
@@ -173,11 +175,11 @@ BOOST_FIXTURE_TEST_CASE(shouldCallUserDefinedUnexpectedExceptionObserver, Filesy
173175
174176 openFile (testFileOne_);
175177
176- BOOST_CHECK (observerCalled.get_future ().wait_for (timeout_) == std::future_status::ready);
178+ CHECK (observerCalled.get_future ().wait_for (timeout_) == std::future_status::ready);
177179 thread.join ();
178180}
179181
180- BOOST_FIXTURE_TEST_CASE (shouldWatchPathRecursively, FilesystemEventHelper )
182+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldWatchPathRecursively " )
181183{
182184 FanotifyController notifier = FanotifyController ();
183185 notifier.watchPathRecursively (testDirectory_)
@@ -195,13 +197,13 @@ BOOST_FIXTURE_TEST_CASE(shouldWatchPathRecursively, FilesystemEventHelper)
195197 openFile (testFileOne_);
196198
197199 auto futureOpen = promisedOpen_.get_future ();
198- BOOST_CHECK (futureOpen.wait_for (timeout_) == std::future_status::ready);
200+ CHECK (futureOpen.wait_for (timeout_) == std::future_status::ready);
199201
200202 notifier.stop ();
201203 thread.join ();
202204}
203205
204- BOOST_FIXTURE_TEST_CASE (shouldIgnoreFileOnce, FilesystemEventHelper )
206+ TEST_CASE_FIXTURE (FilesystemEventHelper, " shouldIgnoreFileOnce " )
205207{
206208 size_t counter = 0 ;
207209 FanotifyController notifier = FanotifyController ();
@@ -220,7 +222,7 @@ BOOST_FIXTURE_TEST_CASE(shouldIgnoreFileOnce, FilesystemEventHelper)
220222 openFile (testFileOne_);
221223
222224 auto futureOpen = _promisedCounter.get_future ();
223- BOOST_CHECK (futureOpen.wait_for (std::chrono::seconds (1 )) == std::future_status::ready);
225+ CHECK (futureOpen.wait_for (std::chrono::seconds (1 )) == std::future_status::ready);
224226 notifier.stop ();
225227 thread.join ();
226228}
0 commit comments