forked from OpenNavigationSurface/BAG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.h
75 lines (58 loc) · 2.12 KB
/
test_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstdio> // std::remove
#include <cstdlib>
#include <string>
#include <utility>
#include <sys/stat.h> // stat
#include <iostream>
#include <random>
#include <bag_dataset.h>
namespace TestUtils {
//! Helper structure to generate a random file name and delete it when the
//! instance leaves scope.
struct RandomFileGuard final {
RandomFileGuard() noexcept
{
// Get random number
std::random_device rd;
std::mt19937 gen(rd());
uint32_t randNum = gen();
// Generate temporary file path
std::ostringstream fnameStream;
#ifdef _WIN32
fnameStream << std::getenv("TEMP") << "\\";
#else
fnameStream << "/tmp/";
#endif
fnameStream << "bagtempfile-" << randNum;
m_fileName = fnameStream.str();
}
RandomFileGuard(const RandomFileGuard&) = delete;
RandomFileGuard(RandomFileGuard&&) = delete;
RandomFileGuard& operator=(const RandomFileGuard&) = delete;
RandomFileGuard& operator=(RandomFileGuard&&) = delete;
~RandomFileGuard() noexcept
{
// Remove the file if it exists.
struct stat buffer;
if (stat(m_fileName.c_str(), &buffer) == 0)
std::remove(m_fileName.c_str());
}
//! Implicit conversion to a const std::string&.
operator const std::string&() const & noexcept
{
return m_fileName;
}
std::string m_fileName;
};
void copyFile(const std::string& source, const std::string& dest);
// Outputs needed to create georeferenced metadata layer:
// const string & elevationLayerName
// std::shared_ptr<BAG::Dataset> dataset
std::pair<std::shared_ptr<BAG::Dataset>, std::string>
createBag(const std::string metadataFileName,
const std::string bagFileName);
void create_NOAA_OCS_Metadata(const std::string& elevationLayerName,
std::shared_ptr<BAG::Dataset> dataset);
void create_unknown_metadata(const std::string& elevationLayerName,
const std::shared_ptr<BAG::Dataset>& dataset);
} // namespace TestUtils