-
Notifications
You must be signed in to change notification settings - Fork 15
/
io_tests.cpp
180 lines (162 loc) · 4.47 KB
/
io_tests.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
//
//=======================================================================
// Copyright 2017
// Author: Alex Hagen-Zanker
// University of Surrey
//
// Distributed under the MIT Licence (https://opensource.org/licenses/MIT)
//=======================================================================
//
#define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
#include <gtest/gtest.h>
#include <pronto/raster/io.h>
#include <pronto/raster/gdal_raster_view.h>
#include <pronto/raster/raster_algebra_operators.h>
#include <pronto/raster/raster_variant.h>
#include <filesystem>
#include <variant>
#include <vector>
namespace pr = pronto::raster;
namespace fs = std::filesystem;
bool test_access_settings()
{
auto s1 = pr::access_settings(pr::read_only, pr::single_pass);
return true;
}
bool test_create_temp()
{
auto r = pr::create_temp<int>(5, 3);
int count = 0;
for (auto&& i : r) {
i = count++;
}
std::vector<int> check_vector;
for (auto&& i : r) {
check_vector.push_back(i);
}
return check_vector == std::vector<int>
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
}
bool test_create_temp_uncasted()
{
auto r = pr::create_temp_uncasted<int>(5, 3);
int count = 0;
for (auto&& i : r) {
i = count++;
}
std::vector<int> check_vector;
for (auto&& i : r) {
check_vector.push_back(i);
}
return check_vector == std::vector<int>
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
}
bool test_create()
{
{
auto r = pr::create<int>("temp.tif", 5, 3);
int count = 0;
for (auto&& i : r) {
i = count++;
}
} // leave scope
bool check_exist = fs::exists("temp.tif");
fs::remove("temp.tif");
bool check_not_exist = !fs::exists("temp.tif");
return check_exist && check_not_exist;
}
bool test_open()
{
{
auto r = pr::create<int>("temp.tif", 5, 3);
int count = 0;
for (auto&& i : r) {
i = count++;
}
} // leave scope
bool check_exist = fs::exists("temp.tif");
bool check_contents;
{
auto r = pronto::raster::open<int, pr::iteration_type::multi_pass, pr::access::read_only>("temp.tif");
std::vector<int> check_vector;
for (auto&& i : r) {
check_vector.push_back(i);
}
check_contents = check_vector == std::vector<int>
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
}
fs::remove("temp.tif");
bool check_not_exist = !fs::exists("temp.tif");
return check_exist && check_not_exist && check_contents;
}
bool test_open_variant()
{
{
auto r = pr::create<int>("temp.tif", 5, 3);
int count = 0;
for (auto&& i : r) {
i = count++;
}
} // leave scope
bool check_exist = fs::exists("temp.tif");
bool check_contents;
{
auto r = pronto::raster::open_variant("temp.tif");
auto two_r = r + r;
std::vector<int> check_vector;
auto copy = [&](auto ras) {
using value_type = pr::recursive_optional_value_type<decltype(ras)::iterator::value_type>;
auto r2 = pr::optional_to_nodata(ras, static_cast<value_type>(- 999));
for (auto&& v : r2)
{
check_vector.push_back(static_cast<int>(v));
};
};
std::visit(copy, two_r);
check_contents = check_vector == std::vector<int>
{0, 2,4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28};
}
fs::remove("temp.tif");
bool check_not_exist = !fs::exists("temp.tif");
return check_exist && check_not_exist && check_contents;
}
bool test_create_open_large()
{
int rows = 2000;
int cols = 1500;
{
auto view = pr::create<int>("temp.tif", rows, cols);
int count = 0;
for (auto&& i : view) {
i = count++;
}
}
bool check_exist = fs::exists("temp.tif");
bool check_contents;
{
auto view = pr::open<int, pr::iteration_type::multi_pass, pr::access::read_only>("temp.tif");
std::vector<int> check_vector;
for (auto&& i : view) {
check_vector.push_back(i);
}
int check_last = check_vector.back() == (rows * cols - 1);
check_vector.resize(15);
check_contents = check_vector == std::vector<int>
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
&& check_last;
}
fs::remove("temp.tif");
bool check_not_exist = !fs::exists("temp.tif");
return check_exist && check_not_exist && check_contents;
}
TEST(RasterTest, IO) {
EXPECT_TRUE(test_access_settings());
EXPECT_TRUE(test_create_temp());
EXPECT_TRUE(test_create_temp_uncasted());
EXPECT_TRUE(test_create());
EXPECT_TRUE(test_open());
EXPECT_TRUE(test_open_variant());
#ifdef NDEBUG // Don't debug large data file
EXPECT_TRUE(test_create_open_large());
#endif
}