Skip to content

Commit

Permalink
Testing: keys iterator get functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Nov 1, 2024
1 parent 8795b6d commit d538f7e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/grib_keys_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

int main(int argc, char* argv[])
{
FILE* f = NULL;
grib_handle* h = NULL;
int err = 0;
int err = 0;

Assert(argc == 2);
f = fopen(argv[1], "rb");
FILE* f = fopen(argv[1], "rb");
Assert(f);

while ((h = grib_handle_new_from_file(0, f, &err)) != NULL) {
Expand All @@ -39,6 +38,8 @@ int main(int argc, char* argv[])
int type = 0;
GRIB_CHECK(grib_get_native_type(h, name, &type), 0);
Assert( type > 0 && type < 7 );
int ktype = grib_keys_iterator_get_native_type(kiter);
Assert(type == ktype);
const char* type_name = grib_get_type_name(type);
Assert( !STR_EQUAL(type_name, "unknown") );
printf("%s = %s (%d)\n", name, type_name, type);
Expand All @@ -48,6 +49,16 @@ int main(int argc, char* argv[])
size_t vlen = MAX_VAL_LEN;
GRIB_CHECK(grib_get_string(h, name, value, &vlen), name);
Assert( strlen(value) > 0 );
int e = grib_keys_iterator_get_string(kiter, value, &vlen);
Assert(!e);
Assert( STR_EQUAL(name, value) );
}
if (STR_EQUAL(name, "editionNumber")) {
long lVal = 0;
size_t llen = 1;
int e = grib_keys_iterator_get_long(kiter, &lVal, &llen);
Assert(!e);
Assert(lVal == 1 || lVal == 2);
}
}

Expand Down

0 comments on commit d538f7e

Please sign in to comment.