srs-control 0.2.2
Loading...
Searching...
No Matches
UnitTestConfig.cpp
Go to the documentation of this file.
4#include <catch2/catch_message.hpp>
5#include <catch2/catch_test_macros.hpp>
6#include <fmt/format.h>
7#include <magic_enum/magic_enum.hpp>
8#include <string>
9#include <vector>
10
11TEST_CASE("ConfigHandler")
12{
13 auto app_config = srs::Config{};
14
15 SECTION("write")
16 {
17 auto filename = std::string{};
18 SECTION("yaml") { filename = "test_config_output.yaml"; }
19 SECTION("json") { filename = "test_config_output.json"; }
20 auto is_not_ok = srs::config::output_config_to_file(app_config, filename, true);
21
22 if (is_not_ok)
23 {
24 UNSCOPED_INFO(is_not_ok.value());
25 }
26 REQUIRE_FALSE(is_not_ok);
27 auto res = srs::common::get_file_size(filename);
28 if (not res)
29 {
30 UNSCOPED_INFO(fmt::format("get file size error: {}", res.error()));
31 }
32 REQUIRE(res);
33 CHECK(res.value() > 0);
34 }
35
36 SECTION("read")
37 {
38 auto filename = std::string{};
39 SECTION("yaml") { filename = TEST_YAML_CONFIG_INPUT_FILENAME; }
40 SECTION("json") { filename = TEST_JSON_CONFIG_INPUT_FILENAME; }
41
42 auto is_not_ok = srs::config::set_config_from_file(app_config, filename, false);
43 if (is_not_ok)
44 {
45 UNSCOPED_INFO(is_not_ok.value());
46 }
47 REQUIRE_FALSE(is_not_ok);
48
49 CHECK(app_config.fec_control_local_port == 6017);
50 CHECK(app_config.fec_control_remote_port == 6610);
51 CHECK(app_config.fec_data_receive_ports == std::vector{ 6001 });
52 CHECK(app_config.data_buffer_size == 6000);
53 CHECK(app_config.remote_fec_ips == std::vector{ std::string{ "10.0.0.100" } });
54 CHECK(app_config.buffer_queue_capacity == 100);
55 CHECK(app_config.output_filenames == std::vector{ std::string{ "test.output" } });
56 CHECK(app_config.output_split == 2);
57 CHECK(app_config.time_wait_after_acq_off_ms == 100);
58 CHECK(app_config.warn_if_data_drop);
59 CHECK(magic_enum::enum_name(app_config.data_print_mode) == std::string{ "print_raw" });
60 }
61}
TEST_CASE("ConfigHandler")
auto get_file_size(std::string_view filename) -> std::expected< std::size_t, std::string >
auto output_config_to_file(const auto &config, std::string_view filename, bool is_overwrite=false) -> std::optional< std::string >
auto set_config_from_file(auto &config, std::string_view filename, bool is_default_generated=true) -> std::optional< std::string >
Main configuration struct.