-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
test_stream_sqlite.cpp
64 lines (57 loc) · 2.05 KB
/
test_stream_sqlite.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
#include "test_stream_sqlite.h"
#include "../../streams/sqlite/voxel_stream_sqlite.h"
#include "../testing.h"
namespace zylann::voxel::tests {
namespace {
void test_voxel_stream_sqlite_basic(bool with_key_cache) {
zylann::testing::TestDirectory test_dir;
ZN_TEST_ASSERT(test_dir.is_valid());
const String database_path = test_dir.get_path().path_join("database.sqlite");
VoxelBuffer vb1(VoxelBuffer::ALLOCATOR_DEFAULT);
vb1.create(Vector3i(16, 16, 16));
vb1.fill_area(1, Vector3i(5, 5, 5), Vector3i(10, 11, 12), 0);
const Vector3i vb1_pos(1, 2, -3);
{
Ref<VoxelStreamSQLite> stream;
stream.instantiate();
stream->set_key_cache_enabled(with_key_cache);
stream->set_database_path(database_path);
// Save block
{
VoxelStreamSQLite::VoxelQueryData q{ vb1, vb1_pos, 0, VoxelStream::RESULT_ERROR };
stream->save_voxel_block(q);
// Result is not set currently for saves...
// ZN_TEST_ASSERT(q.result == VoxelStream::RESULT_BLOCK_FOUND);
}
// Load it back (caching might take effect)
{
VoxelBuffer loaded_vb1(VoxelBuffer::ALLOCATOR_DEFAULT);
VoxelStreamSQLite::VoxelQueryData q{ loaded_vb1, vb1_pos, 0, VoxelStream::RESULT_ERROR };
stream->load_voxel_block(q);
ZN_TEST_ASSERT(q.result == VoxelStream::RESULT_BLOCK_FOUND);
ZN_TEST_ASSERT(loaded_vb1.equals(vb1));
}
// Flush before the stream object is destroyed
stream->flush();
}
{
// Create new stream object and reopen the database (avoids caching effects).
Ref<VoxelStreamSQLite> stream;
stream.instantiate();
stream->set_key_cache_enabled(with_key_cache);
stream->set_database_path(database_path);
{
VoxelBuffer loaded_vb1(VoxelBuffer::ALLOCATOR_DEFAULT);
VoxelStreamSQLite::VoxelQueryData q{ loaded_vb1, vb1_pos, 0, VoxelStream::RESULT_ERROR };
stream->load_voxel_block(q);
ZN_TEST_ASSERT(q.result == VoxelStream::RESULT_BLOCK_FOUND);
ZN_TEST_ASSERT(loaded_vb1.equals(vb1));
}
}
}
} // namespace
void test_voxel_stream_sqlite_basic() {
test_voxel_stream_sqlite_basic(false);
test_voxel_stream_sqlite_basic(true);
}
} // namespace zylann::voxel::tests