collector/test.cpp

43 lines
1.2 KiB
C++
Raw Normal View History

2022-10-06 05:10:49 +02:00
/**
* @file test.cpp
* The unit test executable
*
* @author Tobias Schmidl
* @copyright Copyright © 2022, Tobias Schmidl
* SPDX-License-Identifier: MIT
*/
#include "monitor.hpp"
2022-09-29 20:31:11 +02:00
#include "version.hpp"
2022-10-06 05:10:49 +02:00
#include "collector.hpp"
2022-09-29 20:31:11 +02:00
#define BOOST_TEST_MODULE Collector test
#include <boost/test/unit_test.hpp>
2022-10-06 05:10:49 +02:00
#include <chrono>
#include <fstream>
#include <future>
#include <thread>
using namespace collector::monitor;
using namespace collector::collector;
using namespace std::chrono_literals;
2022-09-29 20:31:11 +02:00
2022-10-06 05:10:49 +02:00
boost::asio::io_service service;
2022-09-29 20:31:11 +02:00
2022-10-06 05:10:49 +02:00
BOOST_AUTO_TEST_CASE(monitor_test)
2022-09-29 20:31:11 +02:00
{
2022-10-06 05:10:49 +02:00
BOOST_TEST_MESSAGE("Test version " << VERSION);
const std::filesystem::path test_file{ "test_file" };
std::filesystem::remove(test_file);
const auto create_file_result = std::async([&test_file]() {
std::this_thread::sleep_for(2s);
std::ofstream{ test_file };
});
Monitor monitor(service, std::filesystem::current_path());
const auto& watch_result =
monitor.watch(std::regex(test_file.generic_string()),
boost::asio::dir_monitor_event::event_type::added);
BOOST_TEST(std::filesystem::equivalent(test_file,
watch_result.path.generic_string()));
std::filesystem::remove(test_file);
2022-09-29 20:31:11 +02:00
}