|
| 1 | +/* |
| 2 | + * (C) Copyright 1996- 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 |
| 8 | + * nor does it submit to any jurisdiction. |
| 9 | + */ |
| 10 | + |
| 11 | +/// @date Apr 2024 |
| 12 | +/// @author Christopher Bradley |
| 13 | + |
| 14 | +#include "eccodes.h" |
| 15 | + |
| 16 | +#include "eckit/testing/Test.h" |
| 17 | +#include "eckit/io/FileHandle.h" |
| 18 | + |
| 19 | +#include "metkit/codes/GribHandle.h" |
| 20 | +#include "metkit/codes/GribAccessor.h" |
| 21 | + |
| 22 | +using namespace eckit::testing; |
| 23 | + |
| 24 | +namespace metkit { |
| 25 | +namespace grib { |
| 26 | +namespace test { |
| 27 | + |
| 28 | +//----------------------------------------------------------------------------- |
| 29 | + |
| 30 | +// Test that a gribhandle will point to the correct message in a file, given an offset. |
| 31 | +CASE( "File with two messages" ) { |
| 32 | + |
| 33 | + // The test file has two messages of different packing types, with some junk data in between. |
| 34 | + eckit::PathName path("synthetic_2msgs.grib"); |
| 35 | + |
| 36 | + off_t* offsets; |
| 37 | + grib_context* c = nullptr; |
| 38 | + int n = 0; |
| 39 | + int err = codes_extract_offsets_malloc(c, path.asString().c_str(), PRODUCT_GRIB, &offsets, &n, 1); |
| 40 | + EXPECT(!err); |
| 41 | + EXPECT(n == 2); |
| 42 | + |
| 43 | + GribAccessor<std::string> packingType("packingType"); |
| 44 | + std::vector<std::string> expected = {"grid_simple", "grid_ccsds"}; |
| 45 | + |
| 46 | + eckit::FileHandle dh(path); |
| 47 | + dh.openForRead(); |
| 48 | + |
| 49 | + for (int i = 0; i < n; i++) { |
| 50 | + GribHandle h(dh, offsets[i]); |
| 51 | + EXPECT(packingType(h) == expected[i]); |
| 52 | + } |
| 53 | + |
| 54 | + free(offsets); |
| 55 | + dh.close(); |
| 56 | +} |
| 57 | + |
| 58 | +//----------------------------------------------------------------------------- |
| 59 | + |
| 60 | +} // namespace test |
| 61 | +} // namespace grib |
| 62 | +} // namespace metkit |
| 63 | + |
| 64 | +int main(int argc, char **argv) |
| 65 | +{ |
| 66 | + return run_tests ( argc, argv ); |
| 67 | +} |
0 commit comments