MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_instance.cpp File Reference
#include <uuid.h>
#include <catch2/catch_test_macros.hpp>
#include <mxl/flow.h>
#include <mxl/mxl.h>
#include "Utils.hpp"
Include dependency graph for test_instance.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("mxlCreateInstance returns NULL for a NULL domain", "[instance]")
 TEST_CASE ("mxlIsTmpFs returns error for non-existent path", "[mxlIsTmpFs]")
 TEST_CASE ("mxlIsTmpFs returns MXL_ERR_INVALID_ARG for NULL out pointer", "[mxlIsTmpFs]")
 TEST_CASE ("mxlIsTmpFs returns MXL_ERR_INVALID_ARG for NULL path", "[mxlIsTmpFs]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Flow deletion on instance destruction", "[instance]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Flow deletion on writer release", "[instance]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Flow readers / writers caching", "[instance]")

Function Documentation

◆ TEST_CASE() [1/4]

TEST_CASE ( "mxlCreateInstance returns NULL for a NULL domain" ,
"" [instance] )

Definition at line 25 of file test_instance.cpp.

26{
27 REQUIRE(mxlCreateInstance(nullptr, "{}") == nullptr);
28 REQUIRE(mxlCreateInstance(nullptr, nullptr) == nullptr);
29}
MXL_EXPORT mxlInstance mxlCreateInstance(char const *in_mxlDomain, char const *in_options)
Definition mxl.cpp:45
REQUIRE(timeDelta< 33 '366 '667LL)

◆ TEST_CASE() [2/4]

TEST_CASE ( "mxlIsTmpFs returns error for non-existent path" ,
"" [mxlIsTmpFs] )

Definition at line 42 of file test_instance.cpp.

43{
44 bool isTmpFs = true;
45 REQUIRE(mxlIsTmpFs("/this/path/does/not/exist", &isTmpFs) != MXL_STATUS_OK);
46}
@ MXL_STATUS_OK
Definition mxl.h:23
MXL_EXPORT mxlStatus mxlIsTmpFs(char const *in_path, bool *out_isTmpFs)
Definition mxl.cpp:73

◆ TEST_CASE() [3/4]

TEST_CASE ( "mxlIsTmpFs returns MXL_ERR_INVALID_ARG for NULL out pointer" ,
"" [mxlIsTmpFs] )

Definition at line 37 of file test_instance.cpp.

38{
39 REQUIRE(mxlIsTmpFs("/tmp", nullptr) == MXL_ERR_INVALID_ARG);
40}
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35

◆ TEST_CASE() [4/4]

TEST_CASE ( "mxlIsTmpFs returns MXL_ERR_INVALID_ARG for NULL path" ,
"" [mxlIsTmpFs] )

Definition at line 31 of file test_instance.cpp.

32{
33 bool isTmpFs = true;
34 REQUIRE(mxlIsTmpFs(nullptr, &isTmpFs) == MXL_ERR_INVALID_ARG);
35}

◆ TEST_CASE_PERSISTENT_FIXTURE() [1/3]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Flow deletion on instance destruction" ,
"" [instance] )

Definition at line 163 of file test_instance.cpp.

164{
165 auto instanceA = mxlCreateInstance(domain.string().c_str(), nullptr);
166 auto instanceB = mxlCreateInstance(domain.string().c_str(), nullptr);
167
168 mxlFlowWriter writerA = nullptr;
169 mxlFlowWriter writerB = nullptr;
170 mxlFlowConfigInfo flowConfig;
171 bool flowWasCreated = false;
172
173 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
174 REQUIRE(mxlCreateFlowWriter(instanceA, flowDef.c_str(), nullptr, &writerA, &flowConfig, &flowWasCreated) == MXL_STATUS_OK);
176 REQUIRE(mxlCreateFlowWriter(instanceB, flowDef.c_str(), nullptr, &writerB, &flowConfig, &flowWasCreated) == MXL_STATUS_OK);
177 REQUIRE_FALSE(flowWasCreated);
178
179 auto id = uuids::to_string(flowConfig.common.id);
180
181 REQUIRE(flowDirectoryExists(id));
182
183 mxlDestroyInstance(instanceA);
184 REQUIRE(flowDirectoryExists(id));
185
186 mxlDestroyInstance(instanceB);
187 REQUIRE_FALSE(flowDirectoryExists(id));
188}
struct mxlFlowWriter_t * mxlFlowWriter
Definition flow.h:206
MXL_EXPORT mxlStatus mxlCreateFlowWriter(mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
Definition flow.cpp:198
struct mxlFlowConfigInfo_t mxlFlowConfigInfo
MXL_EXPORT mxlStatus mxlDestroyInstance(mxlInstance in_instance)
Definition mxl.cpp:106
std::string readFile(std::filesystem::path const &filepath)
Definition Utils.hpp:78
mxlCommonFlowConfigInfo common
Definition flowinfo.h:178
bool flowWasCreated
auto flowDef

◆ TEST_CASE_PERSISTENT_FIXTURE() [2/3]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Flow deletion on writer release" ,
"" [instance] )

Definition at line 130 of file test_instance.cpp.

131{
132 auto instanceA = mxlCreateInstance(domain.string().c_str(), nullptr);
133 auto instanceB = mxlCreateInstance(domain.string().c_str(), nullptr);
134
135 mxlFlowWriter writerA = nullptr;
136 mxlFlowWriter writerB = nullptr;
137 mxlFlowConfigInfo flowConfig;
138 bool flowWasCreated = false;
139
140 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
141 REQUIRE(mxlCreateFlowWriter(instanceA, flowDef.c_str(), nullptr, &writerA, &flowConfig, &flowWasCreated) == MXL_STATUS_OK);
143 REQUIRE(mxlCreateFlowWriter(instanceB, flowDef.c_str(), nullptr, &writerB, &flowConfig, &flowWasCreated) == MXL_STATUS_OK);
144 REQUIRE_FALSE(flowWasCreated);
145
146 auto id = uuids::to_string(flowConfig.common.id);
147
148 // The flow directory should exists after the flow has been created
149 REQUIRE(flowDirectoryExists(id));
150
151 // The flow directory should still exists after the first writer has been released
152 mxlReleaseFlowWriter(instanceA, writerA);
153 REQUIRE(flowDirectoryExists(id));
154
155 // The flow directory should have been removed after the second writer has been released
156 mxlReleaseFlowWriter(instanceB, writerB);
157 REQUIRE_FALSE(flowDirectoryExists(id));
158
161}
MXL_EXPORT mxlStatus mxlReleaseFlowWriter(mxlInstance instance, mxlFlowWriter writer)
Definition flow.cpp:262

◆ TEST_CASE_PERSISTENT_FIXTURE() [3/3]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Flow readers / writers caching" ,
"" [instance] )

Definition at line 64 of file test_instance.cpp.

65{
66 auto const opts = "{}";
67 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
68 REQUIRE(instance != nullptr);
69
70 mxlFlowWriter audioWriter;
71 mxlFlowWriter videoWriter;
72 mxlFlowWriter metaWriter;
74 bool flowWasCreated;
75 auto flowDef = mxl::tests::readFile("data/audio_flow.json");
76 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &audioWriter, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
78 auto const audioFlowId = uuids::to_string(configInfo.common.id);
79 flowDef = mxl::tests::readFile("data/v210_flow.json");
80 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &videoWriter, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
82 auto const videoFlowId = uuids::to_string(configInfo.common.id);
83 flowDef = mxl::tests::readFile("data/data_flow.json");
84 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &metaWriter, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
86 auto const metaFlowId = uuids::to_string(configInfo.common.id);
87
88 REQUIRE(audioFlowId != videoFlowId);
89 REQUIRE(audioFlowId != metaFlowId);
90 REQUIRE(videoFlowId != metaFlowId);
91
92 REQUIRE(audioWriter != videoWriter);
93 REQUIRE(audioWriter != metaWriter);
94 REQUIRE(videoWriter != metaWriter);
95
96 mxlFlowReader audioReader;
97 REQUIRE(mxlCreateFlowReader(instance, audioFlowId.c_str(), "", &audioReader) == MXL_STATUS_OK);
98 REQUIRE(audioReader != nullptr);
99 mxlFlowReader audioReader2;
100 REQUIRE(mxlCreateFlowReader(instance, audioFlowId.c_str(), "", &audioReader2) == MXL_STATUS_OK);
101 REQUIRE(audioReader2 != nullptr);
102 mxlFlowReader videoReader;
103 REQUIRE(mxlCreateFlowReader(instance, videoFlowId.c_str(), "", &videoReader) == MXL_STATUS_OK);
104 REQUIRE(videoReader != nullptr);
105 mxlFlowReader metaReader;
106 REQUIRE(mxlCreateFlowReader(instance, metaFlowId.c_str(), "", &metaReader) == MXL_STATUS_OK);
107 REQUIRE(metaReader != nullptr);
108
109 REQUIRE(audioReader == audioReader2);
110 REQUIRE(audioReader != videoReader);
111 REQUIRE(audioReader != metaReader);
112 REQUIRE(videoReader != metaReader);
113
114 REQUIRE(static_cast<void*>(audioReader) != static_cast<void*>(audioWriter));
115 REQUIRE(static_cast<void*>(audioReader) != static_cast<void*>(videoWriter));
116 REQUIRE(static_cast<void*>(audioReader) != static_cast<void*>(metaWriter));
117
118 REQUIRE(mxlReleaseFlowReader(instance, audioReader) == MXL_STATUS_OK);
119 REQUIRE(mxlReleaseFlowReader(instance, audioReader2) == MXL_STATUS_OK);
120 REQUIRE(mxlReleaseFlowReader(instance, videoReader) == MXL_STATUS_OK);
121 REQUIRE(mxlReleaseFlowReader(instance, metaReader) == MXL_STATUS_OK);
122
123 REQUIRE(mxlReleaseFlowWriter(instance, audioWriter) == MXL_STATUS_OK);
124 REQUIRE(mxlReleaseFlowWriter(instance, videoWriter) == MXL_STATUS_OK);
125 REQUIRE(mxlReleaseFlowWriter(instance, metaWriter) == MXL_STATUS_OK);
126
128}
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
Definition flow.cpp:177
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
MXL_EXPORT mxlStatus mxlCreateFlowReader(mxlInstance instance, char const *flowId, char const *options, mxlFlowReader *reader)
Definition flow.cpp:136
mxlFlowConfigInfo configInfo