-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfixed_length_string_test.cpp
More file actions
224 lines (220 loc) · 6.88 KB
/
Copy pathfixed_length_string_test.cpp
File metadata and controls
224 lines (220 loc) · 6.88 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifdef H5CPP_CATCH2_V2
#include <catch2/catch.hpp>
#else
#include <catch2/catch_all.hpp>
#endif
#include <h5cpp/hdf5.hpp>
using namespace hdf5;
SCENARIO("testing reading of fixed-size string attributes")
{
auto h5py_file = file::open("../h5py_test_string_attributes.h5", file::AccessFlags::ReadOnly);
auto root_group = h5py_file.root();
SECTION("null-terminated string attribute of size 4")
{
SECTION("written string was empty")
{
auto attribute = root_group.attributes["fixed_size_string_nullterm_empty"];
WHEN("reading back the value into a std::string with trimming disabled")
{
std::string value;
attribute.read(value);
THEN("the std::string should be of length 4 and start with \\0")
{
REQUIRE(value.size() == 4);
REQUIRE(value[0] == '\0');
}
}
WHEN("reading back the value into a std::string with trimming enabled")
{
std::string value;
attribute.read(value, true);
THEN("the std::string should be empty (i.e., contain \"\", without trailing \\0)")
{
REQUIRE(value == "");
}
}
}
SECTION("written string was \"1\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullterm_part"];
WHEN("reading back the value into a std::string with trimming disabled")
{
std::string value;
attribute.read(value);
THEN("the std::string should be of length 4 and start with \"1\\0\"")
{
REQUIRE(value.size() == 4);
REQUIRE(value[0] == '1');
REQUIRE(value[1] == '\0');
}
}
WHEN("reading back the value into a std::string with trimming enabled")
{
std::string value;
attribute.read(value, true);
THEN("the std::string should contain the string \"1\" (without trailing \\0)")
{
REQUIRE(value == "1");
}
}
}
SECTION("written string was \"123\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullterm_full"];
WHEN("reading back the value into a std::string with trimming disabled")
{
std::string value;
attribute.read(value);
THEN("the std::string should of length 4 and contain \"123\0\"")
{
std::string expected("123\0", 4);
REQUIRE(value == expected);
}
}
WHEN("reading back the value into a std::string with trimming enabled")
{
std::string value;
attribute.read(value, true);
THEN("the std::string should contain the entire string '123' (without trailing \\0)")
{
REQUIRE(value == "123");
}
}
}
SECTION("written string was \"1234\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullterm_trunc"];
WHEN("reading back the value into a std::string with trimming disabled")
{
std::string value;
attribute.read(value);
THEN("the std::string should be of length 4 and contain the truncated string \"123\0\"")
{
std::string expected("123\0",4);
REQUIRE(value == expected);
}
}
WHEN("reading back the value into a std::string with trimming enabled")
{
std::string value;
attribute.read(value, true);
THEN("the std::string should be of length 4 and contain the truncated string '123' (without trailing \\0)")
{
REQUIRE(value == "123");
}
}
}
}
SECTION("null-padded string attribute of size 4")
{
SECTION("written string was empty")
{
auto attribute = root_group.attributes["fixed_size_string_nullpad_empty"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should consist only \\0 characters")
{
std::string expected("\0\0\0\0", 4);
REQUIRE(value == expected);
}
}
}
SECTION("written string was \"1\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullpad_part"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the string '1' (without any \\0-padding)")
{
std::string expected("1\0\0\0", 4);
REQUIRE(value == expected);
}
}
}
SECTION("written string was \"1234\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullpad_full"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the entire string '1234' (without any \\0-padding)")
{
REQUIRE(value == "1234");
}
}
}
SECTION("written string was \"12345\"")
{
auto attribute = root_group.attributes["fixed_size_string_nullpad_trunc"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the truncated string '1234' (without any \\0-padding)")
{
REQUIRE(value == "1234");
}
}
}
}
SECTION("space-padded string attribute of size 4")
{
SECTION("written string was empty")
{
auto attribute = root_group.attributes["fixed_size_string_spacepad_empty"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain only spaces")
{
REQUIRE(value == " ");
}
}
}
SECTION("written string was \"1\"")
{
auto attribute = root_group.attributes["fixed_size_string_spacepad_part"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the string '1 ' ('1' with three padding spaces)")
{
REQUIRE(value == "1 ");
}
}
}
SECTION("written string was \"1234\"")
{
auto attribute = root_group.attributes["fixed_size_string_spacepad_full"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the entire string '1234' (without any space-padding)")
{
REQUIRE(value == "1234");
}
}
}
SECTION("written string was \"12345\"")
{
auto attribute = root_group.attributes["fixed_size_string_spacepad_trunc"];
WHEN("reading back the value into a std::string")
{
std::string value;
attribute.read(value);
THEN("the std::string should contain the truncated string '1234' (without any space-padding)")
{
REQUIRE(value == "1234");
}
}
}
}
}