IODA Bundle
test_table_iterator.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <memory>
12 
13 #include "eckit/testing/Test.h"
14 #include "eckit/filesystem/PathName.h"
15 #include "eckit/config/Resource.h"
16 
17 #include "odc/core/TablesReader.h"
18 
19 using namespace eckit::testing;
20 using eckit::Log;
21 
22 
23 // ------------------------------------------------------------------------------------------------------
24 
25 eckit::Resource<eckit::PathName> testDataPath("$TEST_DATA_DIRECTORY", "..");
26 
27 CASE("Test access Table iterator") {
28 
29  eckit::PathName filename = testDataPath / "2000010106.odb";
30 
31  std::unique_ptr<eckit::DataHandle> dh(filename.fileHandle());
32  dh->openForRead();
33 
34  odc::core::TablesReader reader(*dh);
35  auto it = reader.begin();
36  auto end = reader.end();
37 
38  size_t numRows = 0;
39  size_t tableCount = 0;
40  eckit::Offset lastOffset = 0;
41 
42  EXPECT(dh->estimate() == eckit::Length(155557962));
43 
44  while (it != end) {
45  tableCount++;
46 
47  EXPECT(it->rowCount() == (tableCount == 333? 1753 : 10000));
48  EXPECT(it->nextPosition() > lastOffset);
49  EXPECT(it->nextPosition() <= dh->estimate());
50  EXPECT(dh->estimate() == eckit::Length(155557962));
51  lastOffset = it->nextPosition();
52 
53  numRows += it->rowCount();
54  ++it;
55  }
56 
57  EXPECT(dh->estimate() == eckit::Length(155557962));
58  EXPECT(lastOffset == eckit::Offset(155557962));
59  EXPECT(numRows == 3321753);
60 
61  dh->close();
62 }
63 
64 // ------------------------------------------------------------------------------------------------------
65 
66 int main(int argc, char* argv[]) {
67  return run_tests(argc, argv);
68 }
69 
int main(int argc, char *argv[])
eckit::Resource< eckit::PathName > testDataPath("$TEST_DATA_DIRECTORY", "..")
CASE("Test access Table iterator")