From 52f75237f63d4b9def09fa451299fae87ba51a88 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 11 Dec 2020 19:27:33 +0000 Subject: [PATCH] ECC-403: C and Python API tests --- examples/C/bufr_missing.c | 8 ++++++-- examples/python/bufr_get_keys.py | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/C/bufr_missing.c b/examples/C/bufr_missing.c index 2ff58225f..bbb7adef4 100644 --- a/examples/C/bufr_missing.c +++ b/examples/C/bufr_missing.c @@ -15,7 +15,7 @@ */ #include "eccodes.h" - +#include int main(int argc, char* argv[]) { @@ -26,6 +26,7 @@ int main(int argc, char* argv[]) double doubleVal; int err = 0; + int is_missing = 0; int cnt = 0; const char* infile = "../../data/bufr/syno_1.bufr"; @@ -51,7 +52,6 @@ int main(int argc, char* argv[]) /* the value of this key is missing in the message*/ CODES_CHECK(codes_get_double(h, "relativeHumidity", &doubleVal), 0); - printf(" relativeHumidity: %.2f\n", doubleVal); /* we will print "value missing" */ if (doubleVal == CODES_MISSING_DOUBLE) { @@ -61,6 +61,10 @@ int main(int argc, char* argv[]) printf(" --> value present\n"); } + is_missing = codes_is_missing(h, "relativeHumidity", &err); + assert(!err); + assert(is_missing == 1); + /* delete handle */ codes_handle_delete(h); diff --git a/examples/python/bufr_get_keys.py b/examples/python/bufr_get_keys.py index a204c69a2..35a1c6a0f 100644 --- a/examples/python/bufr_get_keys.py +++ b/examples/python/bufr_get_keys.py @@ -60,6 +60,7 @@ def example(): print(' %s: %s' % (key, codes_get(bufr, key))) except CodesInternalError as err: print('Error with key="%s" : %s' % (key, err.msg)) + assert codes_is_missing(bufr, key) == 0 # Native type float key = 'airTemperatureAt2M' @@ -67,6 +68,7 @@ def example(): print(' %s: %s' % (key, codes_get(bufr, key))) except CodesInternalError as err: print('Error with key="%s" : %s' % (key, err.msg)) + assert codes_is_missing(bufr, key) == 0 # Native type string key = 'typicalDate' @@ -75,6 +77,9 @@ def example(): except CodesInternalError as err: print('Error with key="%s" : %s' % (key, err.msg)) + assert codes_is_missing(bufr, 'relativeHumidity') == 1 + assert codes_is_missing(bufr, '#5#cloudAmount') == 1 + # -------------------------------- # get values for an array # --------------------------------