-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathResourceStorageTest.cpp
More file actions
85 lines (72 loc) · 2.77 KB
/
ResourceStorageTest.cpp
File metadata and controls
85 lines (72 loc) · 2.77 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
/**
* Copyright (c) 2017 HERE Europe B.V.
* See the LICENSE file in the root of this project for license details.
*/
#include "test_structures.hpp"
#include <flatdata/flatdata.h>
#include "catch_amalgamated.hpp"
using test_structures::AStruct;
using test_structures::TestIndexType32;
namespace flatdata
{
namespace test
{
const char* const resource_name = "resource1";
const char* const correct_schema = "foo";
const char* const incorrect_schema = "bar";
TEST_CASE( "schema is checked for multivector", "[ResourceStorage]" )
{
std::unique_ptr< ResourceStorage > a = MemoryResourceStorage::create( );
auto create = [ & ] {
auto v
= a->create_multi_vector< TestIndexType32, AStruct >( resource_name, correct_schema );
v.close( );
};
REQUIRE_NOTHROW( create( ) );
REQUIRE_FALSE(
( a->read< MultiArrayView< TestIndexType32, AStruct > >( resource_name, incorrect_schema )
.is_initialized( ) ) );
REQUIRE(
( a->read< MultiArrayView< TestIndexType32, AStruct > >( resource_name, correct_schema )
.is_initialized( ) ) );
}
TEST_CASE( "schema is checked for external vector", "[ResourceStorage]" )
{
std::unique_ptr< ResourceStorage > a = MemoryResourceStorage::create( );
auto create = [ & ] {
auto v = a->create_external_vector< AStruct >( resource_name, correct_schema );
v.close( );
};
REQUIRE_NOTHROW( create( ) );
REQUIRE_FALSE(
( a->read< ArrayView< AStruct > >( resource_name, incorrect_schema ).is_initialized( ) ) );
REQUIRE(
( a->read< ArrayView< AStruct > >( resource_name, correct_schema ).is_initialized( ) ) );
}
TEST_CASE( "schema is checked for written structure", "[ResourceStorage]" )
{
std::unique_ptr< ResourceStorage > a = MemoryResourceStorage::create( );
auto create = [ & ] {
std::vector< uint8_t > data( AStruct::size_in_bytes( ) );
AStruct v( data.data( ) );
a->write( resource_name, correct_schema, v );
};
REQUIRE_NOTHROW( create( ) );
REQUIRE_FALSE( ( a->read< AStruct >( resource_name, incorrect_schema ).is_initialized( ) ) );
REQUIRE( ( a->read< AStruct >( resource_name, correct_schema ).is_initialized( ) ) );
}
TEST_CASE( "schema is checked for written vector", "[ResourceStorage]" )
{
std::unique_ptr< ResourceStorage > a = MemoryResourceStorage::create( );
auto create = [ & ] {
Vector< AStruct > v;
a->write( resource_name, correct_schema, v );
};
REQUIRE_NOTHROW( create( ) );
REQUIRE_FALSE(
( a->read< ArrayView< AStruct > >( resource_name, incorrect_schema ).is_initialized( ) ) );
REQUIRE(
( a->read< ArrayView< AStruct > >( resource_name, correct_schema ).is_initialized( ) ) );
}
} // namespace test
} // namespace flatdata