collector/test.cpp
2022-10-06 11:22:08 +02:00

42 lines
1.2 KiB
C++

/**
* @file test.cpp
* The unit test executable
*
* @author Tobias Schmidl
* @copyright Copyright © 2022, Tobias Schmidl
* SPDX-License-Identifier: MIT
*/
#include "monitor.hpp"
#include "version.hpp"
#include "collector.hpp"
#define BOOST_TEST_MODULE Collector test
#include <boost/test/unit_test.hpp>
#include <chrono>
#include <fstream>
#include <future>
#include <thread>
using namespace collector::monitor;
using namespace collector::collector;
using namespace std::chrono_literals;
boost::asio::io_service service;
BOOST_AUTO_TEST_CASE(monitor_test)
{
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);
}