forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-middle-flat.cpp
More file actions
115 lines (93 loc) · 3.01 KB
/
Copy pathtest-middle-flat.cpp
File metadata and controls
115 lines (93 loc) · 3.01 KB
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
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cassert>
#include <sstream>
#include <stdexcept>
#include <memory>
#include "osmtypes.hpp"
#include "output-null.hpp"
#include "options.hpp"
#include "middle-pgsql.hpp"
#include <sys/types.h>
#include <unistd.h>
#include "tests/middle-tests.hpp"
#include "tests/common-pg.hpp"
#include "tests/common-cleanup.hpp"
#define FLAT_NODES_FILE_NAME "tests/test_middle_flat.flat.nodes.bin"
/* This is basically the same as test-middle-pgsql, but with flat nodes. */
void run_tests(options_t options)
{
options.append = false;
options.create = true;
options.flat_node_cache_enabled = true;
// flat nodes truncates the file each time it's started, so we can reuse the same file
options.flat_node_file = boost::optional<std::string>(FLAT_NODES_FILE_NAME);
{
test_middle_helper<middle_pgsql_t> t(options);
if (t.test_node_set() != 0) {
throw std::runtime_error("test_node_set failed.");
}
}
{
test_middle_helper<middle_pgsql_t> t(options);
if (t.test_nodes_comprehensive_set() != 0) {
throw std::runtime_error("test_nodes_comprehensive_set failed.");
}
}
/* This should work, but doesn't. More tests are needed that look at updates
without the complication of ways.
*/
{
// First make sure we have an empty table.
{
test_middle_helper<middle_pgsql_t> t(options);
}
// Switch to append mode because this tests updates
options.append = true;
options.create = false;
test_middle_helper<middle_pgsql_t> t(options);
t.commit();
if (t.test_way_set() != 0) {
throw std::runtime_error("test_way_set failed.");
}
}
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
std::unique_ptr<pg::tempdb> db;
try {
db.reset(new pg::tempdb);
} catch (const std::exception &e) {
std::cerr << "Unable to setup database: " << e.what() << "\n";
return 77; // <-- code to skip this test.
}
try {
options_t options;
options.database_options = db->database_options;
options.cache = 1;
options.num_procs = 1;
options.prefix = "osm2pgsql_test";
options.slim = true;
// remove flat nodes file on exit - it's 20GB and bad manners to
// leave that lying around on the filesystem.
cleanup::file flat_nodes_file(FLAT_NODES_FILE_NAME);
options.alloc_chunkwise = ALLOC_SPARSE | ALLOC_DENSE; // what you get with optimized
run_tests(options);
options.alloc_chunkwise = ALLOC_SPARSE;
run_tests(options);
options.alloc_chunkwise = ALLOC_DENSE;
run_tests(options);
options.alloc_chunkwise = ALLOC_DENSE | ALLOC_DENSE_CHUNK; // what you get with chunk
run_tests(options);
} catch (const std::exception &e) {
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "UNKNOWN ERROR" << std::endl;
return 1;
}
return 0;
}