11 #include "odc_ecbuild_config.h"
13 #include "eckit/eckit_config.h"
14 #include "eckit/config/Resource.h"
15 #include "eckit/system/SystemInfo.h"
16 #include "eckit/filesystem/PathName.h"
17 #include "eckit/testing/Test.h"
26 using namespace eckit::testing;
33 CASE(
"Test reading with iterators") {
34 SETUP(
"An odb file containing some pre-prepared data") {
43 writer->setNumberOfColumns(3);
49 for (
size_t i = 1;
i <= 10;
i++) {
59 #if __cplusplus > 199711L
60 SECTION(
"Test select iterator for each") {
62 odc::Select oda(
"select * from \"" + tmpODB.path() +
"\";", tmpODB.path());
70 EXPECT(int(n) == count);
77 SECTION(
"Test read iterator for_each") {
87 EXPECT(int(n) == count);
95 SECTION(
"Test select data in explicit loop") {
97 odc::Select oda(
"select * from \"" + tmpODB.path() +
"\";", tmpODB.path());
102 EXPECT((*it)[0] ==
count);
103 EXPECT((*it)[1] ==
count);
109 SECTION(
"Test read data in explicit loop") {
126 CASE(
"Test bugfix 01, quote <<UnitTest problem fixed with p4 change 23687>>") {
128 unsigned char REF_DATA[] = {
129 0x0,0x0,0x0,0x60,0x9b,0x5e,0x41,0x40,
130 0x0,0x0,0x0,0x20,0xcc,0xf,0x11,0xc0,
131 0x0,0x0,0x0,0x60,0x66,0x46,0x6b,0x40,
132 0x0,0x0,0x0,0x0,0x77,0xc8,0x3b,0x40,
133 0x0,0x0,0x0,0x80,0xed,0xb,0xef,0xbf,
134 0x0,0x0,0x0,0xc0,0xcc,0xcc,0x6b,0x40,
135 0x0,0x0,0x0,0x80,0x6,0xff,0x48,0x40,
136 0x0,0x0,0x0,0x80,0x81,0xec,0xeb,0x3f,
137 0x0,0x0,0x0,0x60,0x66,0x26,0x6b,0x40,
138 0x0,0x0,0x0,0x0,0xc7,0x18,0x45,0x40,
139 0x0,0x0,0x0,0xc0,0x56,0x91,0xe7,0x3f,
140 0x0,0x0,0x0,0xc0,0xcc,0xec,0x6a,0x40,
141 0x0,0x0,0x0,0x0,0xc7,0x18,0x45,0x40,
142 0x0,0x0,0x0,0xc0,0x56,0x91,0xe7,0xbf,
143 0x0,0x0,0x0,0xc0,0xcc,0xec,0x6a,0x40,
144 0x0,0x0,0x0,0xa0,0xa5,0x7c,0x45,0x40,
145 0x0,0x0,0x0,0x40,0xc7,0x2,0xf8,0xbf,
146 0x0,0x0,0x0,0x60,0x66,0xe6,0x6a,0x40,
147 0x0,0x0,0x0,0x60,0xf9,0xcb,0x45,0x40,
148 0x0,0x0,0x0,0x80,0x9,0x63,0x8,0xc0,
149 0x0,0x0,0x0,0x60,0x66,0xe6,0x6a,0x40,
150 0x0,0x0,0x0,0x40,0xa3,0x22,0x36,0x40
153 if(eckit::system::SystemInfo::isBigEndian()) {
154 for (
int i = 0;
i <
sizeof(REF_DATA) / 8;
i++)
156 for (
int j = 0; j < 4; j++)
157 std::swap(REF_DATA[
i * 8 + j], REF_DATA[(
i + 1) * 8 - 1 - j]);
162 const double *OBSVALUE =
reinterpret_cast<const double*
>(REF_DATA);
164 eckit::Resource<eckit::PathName>
testDataPath(
"$TEST_DATA_DIRECTORY",
"..");
165 std::stringstream ss_select;
166 ss_select <<
"select obsvalue from \"" << (
testDataPath /
"2000010106.odb") <<
"\";";
173 it !=
oda.end() &&
count <
sizeof(REF_DATA)/
sizeof(
double);
177 EXPECT((*it)[0] == OBSVALUE[
count] );
182 CASE(
"Test bugfix 02, quote <<UnitTest problem fixed with p4 change 23687>>") {
184 std::vector<double> VALUE;
191 TemporaryODB(
const std::vector<double>& values) {
195 writer->setNumberOfColumns(1);
199 for (
size_t i = 0;
i < values.size(); ++
i) {
200 (*writer)[0] = values[
i];
207 TemporaryODB tmpODB(VALUE);
209 odc::Select oda(
"select * from \"" + tmpODB.path() +
"\";", tmpODB.path());
214 EXPECT((*it)[0] == VALUE[
count]);
222 int main(
int argc,
char* argv[]) {
223 return run_tests(argc, argv);
static void count(void *counter, const double *data, size_t n)
eckit::Resource< eckit::PathName > testDataPath("$TEST_DATA_DIRECTORY", "..")
int main(int argc, char *argv[])
CASE("Test reading with iterators")