From f44ce5cc557330cdf42327a7e4a319d3e54805ef Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 1 Aug 2022 12:00:29 +0100 Subject: [PATCH] Testing: Enable assert macro (even in release mode) --- tests/bits.c | 23 +++++++++-------------- tests/bufr_check_descriptors.c | 1 - tests/bufr_ecc-1288.c | 11 +++++++++++ tests/bufr_ecc-517.c | 2 ++ tests/bufr_extract_headers.c | 1 + tests/bufr_get_element.c | 1 + tests/bufr_keys_iter.c | 1 + tests/codes_new_from_samples.c | 7 +++---- tests/codes_set_samples_path.c | 1 - tests/extract_offsets.c | 2 ++ tests/grib_bpv_limit.c | 7 +++---- tests/grib_nearest_test.c | 2 +- tests/ibm.c | 8 +++----- tests/values_to_ascii.c | 3 +-- 14 files changed, 38 insertions(+), 32 deletions(-) diff --git a/tests/bits.c b/tests/bits.c index 0163f88e7..f44583af7 100644 --- a/tests/bits.c +++ b/tests/bits.c @@ -10,8 +10,6 @@ #include #include -#include - #include "grib_api_internal.h" @@ -23,6 +21,7 @@ void test_bits(double x, unsigned long mode) { + int err = 0; double y = 0, z = 0, w = 0, t = 0; double dy = 0, dz = 0, dw = 0, dt = 0; unsigned long i = 0, j = 0, k = 0, l = 0; @@ -39,7 +38,8 @@ void test_bits(double x, unsigned long mode) dw = w - x; if (!(mode & NO_NEAREST_SMALLER_IBM_FLOAT)) { - t = grib_nearest_smaller_ibm_float(x); + err = grib_nearest_smaller_ibm_float(x, &t); + Assert(!err); l = grib_ibm_to_long(y); dt = t - x; } @@ -94,19 +94,14 @@ void print_machine_parameters() int main(int argc, char* argv[]) { - double x, y, z, w, d, eps, epst, epsh; - double dt = 0; - unsigned long i, j, n, nc, c, m; - unsigned long seed = 123; - unsigned char ibm[4]; - float xf = 0; - int r; + double x, y, z, d, eps, epst, epsh; + unsigned long i, j, nc, c; + /*unsigned char ibm[4];*/ unsigned long iminp = 0x00100000, imaxp = 0x7fffffff; unsigned long iminn = 0x80100000, imaxn = 0xffffffff; double dminp = 0, dmaxp = 0, dminn = 0, dmaxn = 0; double dminpn = 0, dmaxpp = 0, dminnn = 0, dmaxnp = 0; unsigned long A; - long e; int k, cc; dminp = grib_long_to_ibm(iminp); @@ -124,7 +119,7 @@ int main(int argc, char* argv[]) printf("grib_ibm_to_long(%.20e)=0x%lX grib_long_to_ibm(0x%lX)=%.20e grib_ibm_nearest_smaller_to_long(%.20e)=0x%lX\n", x, i, i, grib_long_to_ibm(i), x, j); printf("grib_long_to_ibm(grib_ibm_nearest_smaller_to_long(%.20e))=%.20e\n", x, grib_long_to_ibm(j)); - exit(0); + /* exit(0); */ /* if (argc > 1 ) { @@ -242,9 +237,9 @@ int main(int argc, char* argv[]) } A = (i & 0x7f000000) >> 24; - e = A - 70; + /*e = A - 70;*/ eps = 1; - m = (i & 0xffffff); + /*m = (i & 0xffffff);*/ /* printf("---m=0x%lX\n",m); */ eps = grib_ibm_table_e(A); diff --git a/tests/bufr_check_descriptors.c b/tests/bufr_check_descriptors.c index a457e0730..755db8a7d 100644 --- a/tests/bufr_check_descriptors.c +++ b/tests/bufr_check_descriptors.c @@ -8,7 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include #include "grib_api_internal.h" static const size_t MIN_NUM_COLUMNS = 8; diff --git a/tests/bufr_ecc-1288.c b/tests/bufr_ecc-1288.c index 5477f4d0e..be38bae60 100644 --- a/tests/bufr_ecc-1288.c +++ b/tests/bufr_ecc-1288.c @@ -1,4 +1,15 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + #include "eccodes.h" +#undef NDEBUG #include #ifndef HAVE_FSEEKO diff --git a/tests/bufr_ecc-517.c b/tests/bufr_ecc-517.c index 4c1ed0187..2e4f28ba0 100644 --- a/tests/bufr_ecc-517.c +++ b/tests/bufr_ecc-517.c @@ -7,7 +7,9 @@ * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ + #include "eccodes.h" +#undef NDEBUG #include int main(int argc, char** argv) diff --git a/tests/bufr_extract_headers.c b/tests/bufr_extract_headers.c index cf6c8314d..cf8934f93 100644 --- a/tests/bufr_extract_headers.c +++ b/tests/bufr_extract_headers.c @@ -9,6 +9,7 @@ */ #include "eccodes.h" +#undef NDEBUG #include #define MAX_KEYS 100 diff --git a/tests/bufr_get_element.c b/tests/bufr_get_element.c index e135b81c9..14332b3ce 100644 --- a/tests/bufr_get_element.c +++ b/tests/bufr_get_element.c @@ -9,6 +9,7 @@ */ #include "eccodes.h" +#undef NDEBUG #include static void compare_doubles(const double d1, const double d2, const double epsilon) diff --git a/tests/bufr_keys_iter.c b/tests/bufr_keys_iter.c index c419e818a..c96a54f9e 100644 --- a/tests/bufr_keys_iter.c +++ b/tests/bufr_keys_iter.c @@ -9,6 +9,7 @@ */ #include "eccodes.h" +#undef NDEBUG #include static void usage(const char* prog) diff --git a/tests/codes_new_from_samples.c b/tests/codes_new_from_samples.c index 642e90f8d..6dddc35a6 100644 --- a/tests/codes_new_from_samples.c +++ b/tests/codes_new_from_samples.c @@ -8,7 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include #include "grib_api_internal.h" typedef struct sample_t { @@ -48,11 +47,11 @@ int main(int argc, char** argv) printf("Testing codes_handle_new_from_samples on %s\n", name); h = codes_handle_new_from_samples(0, name); - assert(h); - assert(samples[i].expected_kind == h->product_kind); + Assert(h); + Assert(samples[i].expected_kind == h->product_kind); GRIB_CHECK(grib_get_string(h, "identifier", identifier, &len), 0); - assert( strcmp(samples[i].expected_ID, identifier) == 0 ); + Assert( strcmp(samples[i].expected_ID, identifier) == 0 ); grib_handle_delete(h); } diff --git a/tests/codes_set_samples_path.c b/tests/codes_set_samples_path.c index 368dcf3b7..4c2cf7767 100644 --- a/tests/codes_set_samples_path.c +++ b/tests/codes_set_samples_path.c @@ -8,7 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include #include "grib_api_internal.h" /* Windows always has a colon in pathnames e.g. C:\temp\file. So instead we use semi-colons as delimiter */ diff --git a/tests/extract_offsets.c b/tests/extract_offsets.c index be70a0e04..e103d966b 100644 --- a/tests/extract_offsets.c +++ b/tests/extract_offsets.c @@ -9,6 +9,8 @@ */ #include "eccodes.h" + +#undef NDEBUG #include int main(int argc, char* argv[]) diff --git a/tests/grib_bpv_limit.c b/tests/grib_bpv_limit.c index a1749fcd0..c0cccd152 100644 --- a/tests/grib_bpv_limit.c +++ b/tests/grib_bpv_limit.c @@ -13,8 +13,7 @@ * setting the wrong number of bpv should result in an error */ -#include -#include "grib_api.h" +#include "grib_api_internal.h" static double compare_double_absolute(double a, double b, double tolerance) { @@ -55,9 +54,9 @@ int main(int argc, char** argv) for (i = 0; i < 255; i++) { FILE* in = fopen(filename, "rb"); - assert(in); + Assert(in); h = grib_handle_new_from_file(0, in, &err); - assert(h); + Assert(h); /* get the size of the values array*/ GRIB_CHECK(grib_get_size(h, "values", &values_len), 0); diff --git a/tests/grib_nearest_test.c b/tests/grib_nearest_test.c index cf561f13e..5731f6bb2 100644 --- a/tests/grib_nearest_test.c +++ b/tests/grib_nearest_test.c @@ -18,7 +18,7 @@ #include #include #include -#include + #include "eccodes.h" static void usage(const char* prog) diff --git a/tests/ibm.c b/tests/ibm.c index 82f725029..d7a5050c8 100644 --- a/tests/ibm.c +++ b/tests/ibm.c @@ -9,8 +9,6 @@ */ #include -#include - #include "grib_api_internal.h" @@ -18,15 +16,15 @@ int main(int argc, char* argv[]) { unsigned long i = 0; - assert(grib_ibm_to_long(grib_long_to_ibm(i)) == i); + Assert(grib_ibm_to_long(grib_long_to_ibm(i)) == i); for (i = 1; i < 0x7fffffff; i++) { unsigned long j = i | 0x80000000; if (grib_ibm_to_long(grib_long_to_ibm(i)) != i) { printf("i=%ld i=%lx e=%g x=%lx\n", i, i, grib_long_to_ibm(i), grib_ibm_to_long(grib_long_to_ibm(i))); - assert(grib_ibm_to_long(grib_long_to_ibm(i)) == i); + Assert(grib_ibm_to_long(grib_long_to_ibm(i)) == i); } - assert(grib_ibm_to_long(grib_long_to_ibm(j)) == j); + Assert(grib_ibm_to_long(grib_long_to_ibm(j)) == j); if ((i % 100000) == 0) printf("i = %08lx %08lx %g %g\n", i, j, grib_long_to_ibm(i), grib_long_to_ibm(j)); } diff --git a/tests/values_to_ascii.c b/tests/values_to_ascii.c index ba52232c1..8c8aa1635 100644 --- a/tests/values_to_ascii.c +++ b/tests/values_to_ascii.c @@ -8,14 +8,13 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include #include #ifndef ECCODES_ON_WINDOWS #include #endif -#include "grib_api.h" +#include "grib_api_internal.h" int main(int argc, char** argv) {