MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_options.cpp File Reference
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <string>
#include <catch2/catch_test_macros.hpp>
#include "mxl-internal/DomainWatcher.hpp"
#include "mxl-internal/Instance.hpp"
#include "mxl-internal/PathUtils.hpp"
#include "mxl-internal/PosixFlowIoFactory.hpp"
#include "../../tests/Utils.hpp"
Include dependency graph for test_options.cpp:

Go to the source code of this file.

Functions

 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : Default value", "[options]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : Domain + Instance config", "[options]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : Domain config", "[options]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : Instance config", "[options]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : invalid configs", "[options]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Options : Missing and inaccessible domain config", "[options]")

Function Documentation

◆ TEST_CASE_PERSISTENT_FIXTURE() [1/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : Default value" ,
"" [options] )

Definition at line 23 of file test_options.cpp.

23 : Default value", "[options]")
24{
25 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
26 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
27 auto const instance = std::make_shared<Instance>(domain, "", std::move(flowIoFactory), domainWatcher);
28
29 REQUIRE(instance->getHistoryDurationNs() == 200'000'000ULL); // default value
30}

◆ TEST_CASE_PERSISTENT_FIXTURE() [2/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : Domain + Instance config" ,
"" [options] )

Definition at line 59 of file test_options.cpp.

59 : Domain + Instance config", "[options]")
60{
61 // write the domain options file
62 auto const domainOptionsFile = makeDomainOptionsFilePath(domain);
63 std::ofstream ofs(domainOptionsFile);
64 REQUIRE(ofs.is_open());
65 ofs << options_500;
66 ofs.close();
67
68 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
69 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
70 auto const instance = std::make_shared<Instance>(domain, options_250, std::move(flowIoFactory), domainWatcher);
71
72 // We should use the domain config, not the instance config. We don't want per-instance history durations.
73 REQUIRE(instance->getHistoryDurationNs() == 500'000'000ULL);
74}

◆ TEST_CASE_PERSISTENT_FIXTURE() [3/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : Domain config" ,
"" [options] )

Definition at line 32 of file test_options.cpp.

32 : Domain config", "[options]")
33{
34 // write the domain options file
35 auto const domainOptionsFile = makeDomainOptionsFilePath(domain);
36 std::ofstream ofs(domainOptionsFile);
37 REQUIRE(ofs.is_open());
38 ofs << options_500;
39 ofs.close();
40
41 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
42 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
43 auto const instance = std::make_shared<Instance>(domain, "", std::move(flowIoFactory), domainWatcher);
44
45 REQUIRE(instance->getHistoryDurationNs() == 500'000'000ULL); // domain value
46}

◆ TEST_CASE_PERSISTENT_FIXTURE() [4/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : Instance config" ,
"" [options] )

Definition at line 48 of file test_options.cpp.

48 : Instance config", "[options]")
49{
50 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
51 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
52 auto const instance = std::make_shared<Instance>(domain, options_250, std::move(flowIoFactory), domainWatcher);
53
54 // We should get the default value, not the instance config value.
55 // We don't want per-instance history durations.
56 REQUIRE(instance->getHistoryDurationNs() == 200'000'000ULL);
57}

◆ TEST_CASE_PERSISTENT_FIXTURE() [5/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : invalid configs" ,
"" [options] )

Definition at line 76 of file test_options.cpp.

76 : invalid configs", "[options]")
77{
78 // write the domain options file
79 auto const domainOptionsFile = makeDomainOptionsFilePath(domain);
80 std::ofstream ofs(domainOptionsFile);
81 REQUIRE(ofs.is_open());
82 ofs << "abc";
83 ofs.close();
84
85 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
86 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
87 auto const instance = std::make_shared<Instance>(domain, "def", std::move(flowIoFactory), domainWatcher);
88
89 REQUIRE(instance->getHistoryDurationNs() == 200'000'000ULL); // default value
90}

◆ TEST_CASE_PERSISTENT_FIXTURE() [6/6]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Options : Missing and inaccessible domain config" ,
"" [options] )

Definition at line 92 of file test_options.cpp.

92 : Missing and inaccessible domain config", "[options]")
93{
94 auto const path = makeDomainOptionsFilePath(domain);
95 std::filesystem::remove(path); // The persistent fixture is shared between sections.
96 SECTION("Missing options use the fallback")
97 {}
98 SECTION("A dangling symlink uses the fallback")
99 {
100 std::filesystem::create_symlink("missing-options.json", path);
101 }
102 SECTION("An unresolvable symlink uses the fallback")
103 {
104 std::filesystem::create_symlink(path.filename(), path);
105 }
106 auto domainWatcher = std::make_shared<DomainWatcher>(domain);
107 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
108 auto const instance = std::make_shared<Instance>(domain, "", std::move(flowIoFactory), domainWatcher);
109 REQUIRE(instance->getHistoryDurationNs() == 200'000'000ULL);
110}