diff --git a/tests/directory.hpp b/tests/directory.hpp index 5c441b4..9b2721a 100755 --- a/tests/directory.hpp +++ b/tests/directory.hpp @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -76,6 +77,19 @@ class directory BOOST_REQUIRE(boost::filesystem::equivalent(boost::filesystem::current_path(), boost::filesystem::initial_path())); } + void write_file(const char *file, const char *buffer) + { + boost::filesystem::current_path(full_path); + BOOST_REQUIRE(boost::filesystem::equivalent(full_path, boost::filesystem::current_path())); + BOOST_REQUIRE(boost::filesystem::exists(file)); + boost::filesystem::ofstream ofs(file); + BOOST_CHECK(ofs); + ofs << buffer; + ofs.close(); + boost::filesystem::current_path(boost::filesystem::initial_path()); + BOOST_REQUIRE(boost::filesystem::equivalent(boost::filesystem::current_path(), boost::filesystem::initial_path())); + } + private: boost::filesystem::path full_path; }; diff --git a/tests/test_async.cpp b/tests/test_async.cpp index 9b6e2e6..52fb516 100755 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -47,16 +47,6 @@ void rename_file_handler_new(const boost::filesystem::path& expected_path, const BOOST_CHECK_EQUAL(ev.type, boost::asio::dir_monitor_event::renamed_new_name); } -void modify_file_handler(const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev) -{ - boost::filesystem::path fullpath = boost::filesystem::canonical(TEST_DIR1); - fullpath /= TEST_FILE2; - - BOOST_CHECK_EQUAL(ec, boost::system::error_code()); - BOOST_CHECK_EQUAL(ev.path, fullpath); - BOOST_CHECK_EQUAL(ev.type, boost::asio::dir_monitor_event::modified); -} - BOOST_AUTO_TEST_CASE(rename_file) { directory dir(TEST_DIR1); @@ -76,6 +66,28 @@ BOOST_AUTO_TEST_CASE(rename_file) io_service.reset(); } +void modify_file_handler(const boost::filesystem::path& expected_path, const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev) +{ + BOOST_CHECK_EQUAL(ec, boost::system::error_code()); + BOOST_CHECK_THE_SAME_PATHS_RELATIVE(ev.path, expected_path); + BOOST_CHECK_EQUAL(ev.type, boost::asio::dir_monitor_event::modified); +} + +BOOST_AUTO_TEST_CASE(modify_file) +{ + directory dir(TEST_DIR1); + auto test_file2 = dir.create_file(TEST_FILE2); + + boost::asio::dir_monitor dm(io_service); + dm.add_directory(TEST_DIR1); + + dir.write_file(TEST_FILE2, TEST_FILE1); + + dm.async_monitor(boost::bind(&modify_file_handler, boost::ref(test_file2), _1, _2)); + io_service.run(); + io_service.reset(); +} + void remove_file_handler(const boost::filesystem::path& expected_path, const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev) { BOOST_CHECK_EQUAL(ec, boost::system::error_code()); diff --git a/tests/test_sync.cpp b/tests/test_sync.cpp index eb70fe3..85b4362 100755 --- a/tests/test_sync.cpp +++ b/tests/test_sync.cpp @@ -65,6 +65,22 @@ BOOST_AUTO_TEST_CASE(remove_file) BOOST_CHECK_EQUAL(ev.type, boost::asio::dir_monitor_event::removed); } +BOOST_AUTO_TEST_CASE(modify_file) +{ + directory dir(TEST_DIR1); + auto test_file1 = dir.create_file(TEST_FILE1); + + boost::asio::dir_monitor dm(io_service); + dm.add_directory(TEST_DIR1); + + dir.write_file(TEST_FILE1, TEST_FILE2); + + boost::asio::dir_monitor_event ev = dm.monitor(); + + BOOST_CHECK_THE_SAME_PATHS_RELATIVE(ev.path, test_file1); + BOOST_CHECK_EQUAL(ev.type, boost::asio::dir_monitor_event::modified); +} + BOOST_AUTO_TEST_CASE(multiple_events) { directory dir(TEST_DIR1);