Newer
Older
#include "catch.hpp"
//---- Mocks -------------------------------------------------------------------
#include <ftl/rgbd/source.hpp>
#include <ftl/config.h>
static std::string last_type = "";
namespace ftl {
namespace rgbd {
class SnapshotReader {
public:
SnapshotReader(const std::string &) {}
namespace detail {
class ImageSource : public ftl::rgbd::detail::Source {
public:
ImageSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
last_type = "image";
}
ImageSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) {
last_type = "image";
}
bool compute(int n, int b) { return true; };
bool isReady() { return true; };
};
class StereoVideoSource : public ftl::rgbd::detail::Source {
public:
StereoVideoSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
last_type = "video";
}
StereoVideoSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) {
last_type = "video";
}
bool compute(int n, int b) { return true; };
bool isReady() { return true; };
};
class NetSource : public ftl::rgbd::detail::Source {
public:
NetSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
last_type = "net";
}
bool compute(int n, int b) { return true; };
class SnapshotSource : public ftl::rgbd::detail::Source {
public:
SnapshotSource(ftl::rgbd::Source *host, ftl::rgbd::Snapshot &r, const std::string &) : ftl::rgbd::detail::Source(host) {
bool compute(int n, int b) { return true; };
class RealsenseSource : public ftl::rgbd::detail::Source {
public:
RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
last_type = "realsense";
}
bool compute(int n, int b) { return true; };
bool isReady() { return true; };
};
class MiddleburySource : public ftl::rgbd::detail::Source {
public:
MiddleburySource(ftl::rgbd::Source *host, const std::string &dir) : ftl::rgbd::detail::Source(host) {
last_type = "middlebury";
}
bool compute(int n, int b) { return true; };
}
}
}
//---- Sources -----------------------------------------------------------------
// Prevent these headers...
#define _FTL_RGBD_STEREOVIDEO_HPP_
#define _FTL_RGBD_NET_HPP_
#define _FTL_RGBD_SNAPSHOT_SOURCE_HPP_
#define _FTL_RGBD_IMAGE_HPP_
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "../src/source.cpp"
//---- Tests -------------------------------------------------------------------
using ftl::rgbd::Source;
using ftl::config::json_t;
TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
json_t global = {{"$id","ftl://test"}};
ftl::config::configure(global);
SECTION("with valid image file uri") {
json_t cfg = {
{"$id","ftl://test/1"},
{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( src->isReady() );
REQUIRE( last_type == "image");
}
SECTION("with valid video file uri") {
json_t cfg = {
{"$id","ftl://test/2"},
{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/video.mp4"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( src->isReady() );
REQUIRE( last_type == "video");
}
SECTION("with valid net uri") {
json_t cfg = {
{"$id","ftl://test/2"},
{"uri","ftl://utu.fi/dummy"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( src->isReady() );
REQUIRE( last_type == "net");
}
SECTION("with an invalid uri") {
json_t cfg = {
{"$id","ftl://test/2"},
{"uri","not a uri"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( !src->isReady() );
}
SECTION("with an invalid file uri") {
json_t cfg = {
{"$id","ftl://test/2"},
{"uri","file:///not/a/file"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( !src->isReady() );
}
SECTION("with a missing file") {
json_t cfg = {
{"$id","ftl://test/2"},
{"uri","file:///data/image2.png"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( !src->isReady() );
}
}
TEST_CASE("Source::set(uri)", "[rgbd]") {
json_t global = {{"$id","ftl://test"}};
ftl::config::configure(global);
SECTION("change to different valid URI type") {
json_t cfg = {
{"$id","ftl://test/1"},
{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"}
};
Source *src = ftl::create<Source>(cfg);
REQUIRE( src );
REQUIRE( src->isReady() );
REQUIRE( last_type == "image" );
src->set("uri", "file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/video.mp4");
REQUIRE( src->isReady() );
REQUIRE( last_type == "video" );
}
}