eccodes/tests/unit_tests.cc

955 lines
32 KiB
C++
Raw Normal View History

2013-12-19 15:29:19 +00:00
/*
2020-01-28 14:32:34 +00:00
* (C) Copyright 2005- ECMWF.
2013-12-19 15:29:19 +00:00
*
* 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 "grib_api_internal.h"
2023-12-16 12:53:34 +00:00
#include "eccodes.h"
2013-12-19 15:29:19 +00:00
2022-10-20 13:38:17 +00:00
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
2017-04-05 15:47:19 +00:00
int assertion_caught = 0;
int logging_caught = 0;
2017-04-05 15:47:19 +00:00
typedef enum
{
IBM_FLOAT,
IEEE_FLOAT
} FloatRep;
2013-12-19 15:29:19 +00:00
2017-09-01 16:36:16 +00:00
static void compare_doubles(const double d1, const double d2, const double epsilon)
2013-12-19 15:29:19 +00:00
{
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(fabs(d1 - d2) < epsilon);
2013-12-19 15:29:19 +00:00
}
2017-09-01 16:36:16 +00:00
static void check_float_representation(const double val, const double expected, const FloatRep rep)
2013-12-19 15:29:19 +00:00
{
double out = 0;
const double tolerance = 1e-9;
if (rep == IBM_FLOAT)
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(grib_nearest_smaller_ibm_float(val, &out) == GRIB_SUCCESS);
else
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(grib_nearest_smaller_ieee_float(val, &out) == GRIB_SUCCESS);
/*printf("%s: d1=%10.20f, out=%10.20f\n", (rep==IBM_FLOAT)?"ibm":"ieee", val, out);*/
2013-03-25 14:23:07 +00:00
compare_doubles(out, expected, tolerance);
2013-12-19 15:29:19 +00:00
}
2013-03-25 14:23:07 +00:00
2024-02-24 18:24:16 +00:00
static void test_get_package_name()
{
printf("Running %s ...\n", __func__);
const char* pn = codes_get_package_name();
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(pn != NULL);
ECCODES_ASSERT(strlen(pn) > 1);
2024-02-24 18:24:16 +00:00
printf("Package name = %s\n", pn);
}
static void test_get_git_sha1()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2024-02-24 18:24:16 +00:00
const char* sha1 = codes_get_git_sha1();
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(sha1 != NULL);
2024-02-24 18:24:16 +00:00
printf("Git SHA1 = %s\n", sha1);
}
static void test_get_build_date()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
const char* bdate = codes_get_build_date();
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(bdate != NULL);
/* Should be of the format YYYY.MM.DD or empty (not implemented) */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strlen(bdate) == 0 || isdigit(bdate[0]) );
}
2017-09-01 16:36:16 +00:00
static void test_grib_nearest_smaller_ibmfloat()
2013-12-19 15:29:19 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2013-12-19 15:29:19 +00:00
check_float_representation(-1.0, -1.0, IBM_FLOAT);
check_float_representation(0.0, 0.0, IBM_FLOAT);
check_float_representation(1.0, 1.0, IBM_FLOAT);
check_float_representation(1.1, 1.0999994277954, IBM_FLOAT);
2013-12-19 15:29:19 +00:00
check_float_representation(10.6, 10.599999427795, IBM_FLOAT);
check_float_representation(7.85, 7.8499994277954, IBM_FLOAT);
}
2017-09-01 16:36:16 +00:00
static void test_grib_nearest_smaller_ieeefloat()
2013-12-19 15:29:19 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2013-12-19 15:29:19 +00:00
check_float_representation(-1.0, -1.0, IEEE_FLOAT);
check_float_representation(0.0, 0.0, IEEE_FLOAT);
check_float_representation(1.0, 1.0, IEEE_FLOAT);
check_float_representation(1.1, 1.0999999046325, IEEE_FLOAT);
2013-12-19 15:29:19 +00:00
check_float_representation(10.6, 10.599999427795, IEEE_FLOAT);
check_float_representation(7.85, 7.8499999046325, IEEE_FLOAT);
}
2013-03-25 14:23:07 +00:00
2017-09-01 16:36:16 +00:00
static void test_gaussian_latitudes(int order)
2013-03-25 14:23:07 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
int ret = 0;
2014-07-21 12:22:20 +00:00
const int num = 2 * order;
double lat1 = 0, lat2 = 0;
double* lats = (double*)malloc(sizeof(double) * num);
2023-08-05 11:37:42 +00:00
2023-12-16 12:53:34 +00:00
ret = codes_get_gaussian_latitudes(order, lats);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(ret == GRIB_SUCCESS);
2014-07-21 12:22:20 +00:00
lat1 = lats[0];
lat2 = lats[num - 1];
2014-07-21 12:22:20 +00:00
/* Check first and last latitudes are the same with opposite sign */
compare_doubles(lat1, -lat2, 1.0e-6);
free(lats);
}
2024-12-13 12:11:49 +00:00
static void test_grib_get_reduced_row_legacy()
{
printf("Running %s ...\n", __func__);
long npoints=0, ilon_first=0, ilon_last=0;
grib_get_reduced_row_legacy(25, 0.0, 100.0, &npoints, &ilon_first, &ilon_last);
// printf("Result: npoints=%ld, ilon_first=%ld, ilon_last=%ld\n", npoints, ilon_first, ilon_last);
grib_get_reduced_row_legacy(25, 90.0, 100.0, &npoints, &ilon_first, &ilon_last);
grib_get_reduced_row_legacy(25, 295.0, 300.0, &npoints, &ilon_first, &ilon_last);
grib_get_reduced_row_legacy(25, -20.0, 30.0, &npoints, &ilon_first, &ilon_last);
grib_get_reduced_row_legacy(25, 301, 300.0, &npoints, &ilon_first, &ilon_last);
grib_get_reduced_row_legacy(200, 0.0, 359.0, &npoints, &ilon_first, &ilon_last);
}
2017-09-01 16:36:16 +00:00
static void test_gaussian_latitude_640()
2014-07-21 12:22:20 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
/* Test latitudes for one specific Gaussian number */
const int order = 640;
const int num = 2 * order;
int ret = 0;
2017-09-01 16:36:16 +00:00
const double tolerance = 1e-6;
double* lats = (double*)malloc(sizeof(double) * num);
2023-12-16 12:53:34 +00:00
ret = codes_get_gaussian_latitudes(order, lats);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(ret == GRIB_SUCCESS);
2013-03-25 14:23:07 +00:00
2017-09-01 16:36:16 +00:00
compare_doubles(lats[0], 89.892396, tolerance);
compare_doubles(lats[1], 89.753005, tolerance);
compare_doubles(lats[2], 89.612790, tolerance);
compare_doubles(lats[3], 89.472390, tolerance);
compare_doubles(lats[4], 89.331918, tolerance);
compare_doubles(lats[5], 89.191413, tolerance);
compare_doubles(lats[6], 89.050889, tolerance);
compare_doubles(lats[7], 88.910352, tolerance);
compare_doubles(lats[8], 88.769808, tolerance);
compare_doubles(lats[9], 88.629259, tolerance);
compare_doubles(lats[10], 88.488706, tolerance);
compare_doubles(lats[11], 88.348150, tolerance);
compare_doubles(lats[12], 88.207592, tolerance);
compare_doubles(lats[13], 88.067032, tolerance);
compare_doubles(lats[14], 87.926471, tolerance);
compare_doubles(lats[15], 87.785908, tolerance);
2023-03-07 21:57:22 +00:00
2017-09-01 16:36:16 +00:00
compare_doubles(lats[1262], -87.504781, tolerance);
compare_doubles(lats[1263], -87.645345, tolerance);
compare_doubles(lats[1264], -87.785908, tolerance);
compare_doubles(lats[1265], -87.926471, tolerance);
compare_doubles(lats[1266], -88.067032, tolerance);
compare_doubles(lats[1267], -88.207592, tolerance);
compare_doubles(lats[1268], -88.348150, tolerance);
compare_doubles(lats[1269], -88.488706, tolerance);
compare_doubles(lats[1270], -88.629259, tolerance);
compare_doubles(lats[1271], -88.769808, tolerance);
compare_doubles(lats[1272], -88.910352, tolerance);
compare_doubles(lats[1273], -89.050889, tolerance);
compare_doubles(lats[1274], -89.191413, tolerance);
compare_doubles(lats[1275], -89.331918, tolerance);
compare_doubles(lats[1276], -89.472390, tolerance);
compare_doubles(lats[1277], -89.612790, tolerance);
compare_doubles(lats[1278], -89.753005, tolerance);
compare_doubles(lats[1279], -89.892396, tolerance);
2013-03-25 14:23:07 +00:00
2017-09-01 16:36:16 +00:00
free(lats);
2013-03-25 14:23:07 +00:00
}
2017-09-01 16:36:16 +00:00
static void test_string_splitting()
2016-10-07 14:12:27 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
int i = 0;
2016-10-07 14:12:27 +00:00
char input[80] = "Born|To|Be|Wild";
char** list = 0;
list = string_split(input, "|");
2024-12-20 12:58:07 +00:00
if (!list) { ECCODES_ASSERT(!"List is NULL"); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(i == 4);
if (!list[0] || !STR_EQUAL(list[0], "Born")) ECCODES_ASSERT(0);
if (!list[1] || !STR_EQUAL(list[1], "To")) ECCODES_ASSERT(0);
if (!list[2] || !STR_EQUAL(list[2], "Be")) ECCODES_ASSERT(0);
if (!list[3] || !STR_EQUAL(list[3], "Wild")) ECCODES_ASSERT(0);
ECCODES_ASSERT(list[4] == NULL);
2020-03-26 11:11:00 +00:00
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
2016-10-07 14:12:27 +00:00
strcpy(input, "12345|a gap|");
list = string_split(input, "|");
2024-12-20 12:58:07 +00:00
if (!list) { ECCODES_ASSERT(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(i == 2);
if (!list[0] || !STR_EQUAL(list[0], "12345")) ECCODES_ASSERT(0);
if (!list[1] || !STR_EQUAL(list[1], "a gap")) ECCODES_ASSERT(0);
ECCODES_ASSERT(list[2] == NULL);
2020-03-26 11:11:00 +00:00
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
2016-10-07 14:18:03 +00:00
strcpy(input, "Steppenwolf");
list = string_split(input, ",");
2024-12-20 12:58:07 +00:00
if (!list) { ECCODES_ASSERT(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(i == 1);
if (!list[0] || !STR_EQUAL(list[0], "Steppenwolf")) ECCODES_ASSERT(0);
ECCODES_ASSERT(list[1] == NULL);
2020-03-26 11:11:00 +00:00
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
2016-10-07 14:18:03 +00:00
/* Note: currently cannot cope with */
/* input being NULL */
/* input being empty */
/* input having several adjacent delimiters e.g. 'A||B|||C' */
2016-10-07 14:12:27 +00:00
}
2017-04-05 15:47:19 +00:00
static void my_assertion_proc(const char* message)
{
printf("It's OK. I caught the assertion: %s\n", message);
2017-04-05 15:47:19 +00:00
assertion_caught = 1;
}
2017-09-01 16:36:16 +00:00
static void test_assertion_catching()
2017-04-05 15:47:19 +00:00
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
char empty[] = "";
2024-08-25 15:18:10 +00:00
char** list = NULL;
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(assertion_caught == 0);
2017-04-05 15:47:19 +00:00
codes_set_codes_assertion_failed_proc(&my_assertion_proc);
2022-12-26 14:37:01 +00:00
2017-04-05 15:47:19 +00:00
/* Do something illegal */
list = string_split(empty, " ");
2017-04-05 15:47:19 +00:00
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(assertion_caught == 1);
ECCODES_ASSERT(list == NULL);
2017-04-05 15:47:19 +00:00
/* Restore everything */
codes_set_codes_assertion_failed_proc(NULL);
assertion_caught = 0;
2024-08-25 15:18:10 +00:00
// for (i = 0; list[i] != NULL; ++i)
// free(list[i]);
free(list);
2017-04-05 15:47:19 +00:00
}
static void my_logging_proc(const grib_context* c, int level, const char* mesg)
{
logging_caught = 1;
}
static void test_logging_proc()
{
grib_context* context = grib_context_get_default();
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(logging_caught == 0);
/* Override default behaviour */
grib_context_set_logging_proc(context, my_logging_proc);
2023-08-04 21:17:04 +00:00
grib_context_log(context, GRIB_LOG_ERROR, "test_logging_proc: This error will be handled by me");
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(logging_caught == 1);
/* Restore the logging proc */
logging_caught = 0;
grib_context_set_logging_proc(context, NULL);
2023-08-04 21:17:04 +00:00
grib_context_log(context, GRIB_LOG_ERROR, "test_logging_proc: This error will come out as normal");
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(logging_caught == 0);
}
2024-08-25 15:33:52 +00:00
static void my_print_proc(const grib_context* c, void* descriptor, const char* mesg)
{
}
static void test_print_proc()
{
grib_context* context = grib_context_get_default();
grib_context_set_print_proc(context, my_print_proc);
grib_context_set_print_proc(context, NULL);
}
static void test_concept_condition_strings()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
int err = 0;
char result[1024] = {0,};
2022-02-24 15:16:55 +00:00
grib_context* context = NULL;
grib_handle* h = grib_handle_new_from_samples(context, "GRIB2");
2024-08-27 13:53:26 +00:00
if (!h) return;
err = get_concept_condition_string(h, "typeOfLevel", NULL, result);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(strcmp(result, "typeOfFirstFixedSurface=1,typeOfSecondFixedSurface=255") == 0);
err = get_concept_condition_string(h, "paramId", NULL, result);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(strcmp(result, "discipline=0,parameterCategory=0,parameterNumber=0") == 0);
err = get_concept_condition_string(h, "gridType", NULL, result);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(strcmp(result, "gridDefinitionTemplateNumber=0,PLPresent=0") == 0);
err = get_concept_condition_string(h, "stepType", NULL, result);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(strcmp(result, "selectStepTemplateInstant=1,stepTypeInternal=instant") == 0);
grib_handle_delete(h);
}
2023-08-04 21:17:04 +00:00
static void test_string_trimming()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
char a[] = " Standing ";
char b[] = " Weeping ";
char c[] = " Silhouette ";
char d[] = " The Forest Of October ";
char e[] = "\t\n Apostle In Triumph \r ";
char* pA = a;
char* pB = b;
char* pC = c;
char* pD = d;
char* pE = e;
2022-06-10 19:51:39 +00:00
string_lrtrim(&pA, 0, 1); /*right only*/
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(pA, " Standing")==0 );
2022-06-10 19:51:39 +00:00
string_lrtrim(&pB, 1, 0); /*left only*/
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(pB, "Weeping ")==0 );
2022-06-10 19:51:39 +00:00
string_lrtrim(&pC, 1, 1); /*both ends*/
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(pC, "Silhouette")==0 );
2022-06-10 19:51:39 +00:00
string_lrtrim(&pD, 1, 1); /*make sure other spaces are not removed*/
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(pD, "The Forest Of October")==0 );
2022-06-10 19:51:39 +00:00
string_lrtrim(&pE, 1, 1); /* Other chars */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(pE, "Apostle In Triumph")==0 );
}
static void test_string_ends_with()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", "tmpl") == 1 );
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", ".tmpl") == 1 );
ECCODES_ASSERT( string_ends_with("", "") == 1 );
ECCODES_ASSERT( string_ends_with(".", ".") == 1 );
ECCODES_ASSERT( string_ends_with("Bam", "") == 1 );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", "tmp") == 0 );
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", "tmpl0") == 0 );
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", "1.tmpl") == 0 );
ECCODES_ASSERT( string_ends_with("GRIB2.tmpl", " ") == 0 );
}
static void test_string_to_long()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
long lVal = 0;
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_to_long("0", &lVal, 1) == GRIB_SUCCESS);
ECCODES_ASSERT( lVal == 0 );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_to_long("42", &lVal, 1) == GRIB_SUCCESS);
ECCODES_ASSERT( lVal == 42 );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_to_long("-1", &lVal, 1) == GRIB_SUCCESS);
ECCODES_ASSERT( lVal == -1 );
ECCODES_ASSERT( string_to_long("+999", &lVal, 1) == GRIB_SUCCESS);
ECCODES_ASSERT( lVal == 999 );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_to_long("15MB", &lVal, 0) == GRIB_SUCCESS);
ECCODES_ASSERT( lVal == 15 );
// illegal cases
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( string_to_long("4000000000000000000000", &lVal, 1) == GRIB_INVALID_ARGUMENT);
ECCODES_ASSERT( string_to_long("XY", &lVal, 1) == GRIB_INVALID_ARGUMENT);
ECCODES_ASSERT( string_to_long("A6", &lVal, 1) == GRIB_INVALID_ARGUMENT);
ECCODES_ASSERT( string_to_long("5K", &lVal, 1) == GRIB_INVALID_ARGUMENT);
}
2023-08-04 21:17:04 +00:00
static void test_string_replace_char()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2023-08-04 21:17:04 +00:00
2023-08-05 11:37:42 +00:00
char input[32] = {0,};
2023-08-04 21:17:04 +00:00
strncpy(input, "Mask Of Zoro", sizeof(input));
string_replace_char(input, ' ', '-');
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(STR_EQUAL(input, "Mask-Of-Zoro"));
2023-08-04 21:17:04 +00:00
}
static void test_string_remove_char()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2023-08-04 21:17:04 +00:00
char input[64] = "a:b:c";
string_remove_char(input, ':');
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(STR_EQUAL(input, "abc"));
2023-08-04 21:17:04 +00:00
}
2022-02-24 15:16:55 +00:00
static void test_gribex_mode()
{
grib_context* c = grib_context_get_default();
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2022-02-24 15:16:55 +00:00
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( grib_get_gribex_mode(c) == 0 ); /* default is OFF */
2022-02-24 15:16:55 +00:00
grib_gribex_mode_on(c);
2023-12-16 13:07:36 +00:00
codes_gribex_mode_on(c);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( grib_get_gribex_mode(c) == 1 );
2022-02-24 15:16:55 +00:00
grib_gribex_mode_off(c);
2023-12-16 13:07:36 +00:00
codes_gribex_mode_off(c);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( grib_get_gribex_mode(c) == 0 );
ECCODES_ASSERT( codes_get_gribex_mode(c) == 0 );
2023-12-16 13:07:36 +00:00
}
static void test_gts_header_mode()
{
grib_context* c = grib_context_get_default();
printf("Running %s ...\n", __func__);
grib_gts_header_on(c);
codes_gts_header_on(c);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(c->gts_header_on == 1);
2023-12-16 13:07:36 +00:00
grib_gts_header_off(c);
codes_gts_header_off(c);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(c->gts_header_on == 0);
2023-12-16 13:07:36 +00:00
}
2024-09-19 12:10:50 +00:00
static void test_data_quality_checks()
{
grib_context* c = grib_context_get_default();
printf("Running %s ...\n", __func__);
grib_context_set_data_quality_checks(c, 1);//warning
grib_context_set_data_quality_checks(c, 2);//error
grib_context_set_data_quality_checks(c, 0);//no checks
}
2023-12-16 13:07:36 +00:00
static void test_bufr_multi_element_constant_arrays()
{
grib_context* c = grib_context_get_default();
printf("Running %s ...\n", __func__);
codes_bufr_multi_element_constant_arrays_on(c);
codes_bufr_multi_element_constant_arrays_off(c);
2022-02-24 15:16:55 +00:00
}
2022-10-20 13:38:17 +00:00
static void test_grib_binary_search()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2022-10-20 13:38:17 +00:00
double array_asc[] = {-0.1, 33.4, 56.1, 101.8};
double array_desc[] = {88, 78, 0, -88};
const size_t idx_asc_max = NUMBER(array_asc) - 1;
const size_t idx_desc_max = NUMBER(array_desc) - 1;
size_t idx_upper=0, idx_lower = 0;
grib_binary_search(array_asc, idx_asc_max, 56.0, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 1 && idx_upper == 2);
2022-10-20 13:38:17 +00:00
grib_binary_search(array_asc, idx_asc_max, 56.1, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 2 && idx_upper == 3);
2022-10-20 13:38:17 +00:00
grib_binary_search(array_asc, idx_asc_max, -0.1, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 0 && idx_upper == 1);
2022-10-20 13:38:17 +00:00
grib_binary_search(array_desc, idx_desc_max, 88, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 0 && idx_upper == 1);
2022-10-20 13:38:17 +00:00
grib_binary_search(array_desc, idx_desc_max, -88, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 2 && idx_upper == 3);
2022-10-20 13:38:17 +00:00
grib_binary_search(array_desc, idx_desc_max, 1, &idx_upper, &idx_lower);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(idx_lower == 1 && idx_upper == 2);
2022-10-20 13:38:17 +00:00
}
2022-10-26 12:02:45 +00:00
static void test_parse_keyval_string()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2022-10-26 12:02:45 +00:00
int err = 0;
int values_required = 1;
int count = 0;
grib_values values1[128] = {{0},};
grib_values values2[128] = {{0},};
grib_values values3[128] = {{0},};
2022-10-26 12:02:45 +00:00
const int max_count = 128;
char input1[] = "key1=value1,key2!=value2";
char input2[] = "x=14";
char input3[] = "mars.level=0.978";
count = max_count;
err = parse_keyval_string(NULL, input1,
2022-11-07 12:22:49 +00:00
values_required, GRIB_TYPE_UNDEFINED, values1, &count);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !err );
ECCODES_ASSERT( count == 2 );
grib_print_values("print values test: values1", values1, stdout, count);
2023-08-14 12:35:55 +00:00
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(values1[0].name, "key1")==0 );
ECCODES_ASSERT( strcmp(values1[0].string_value, "value1")==0 );
ECCODES_ASSERT( values1[0].equal == 1 );
ECCODES_ASSERT( strcmp(values1[1].name, "key2")==0 );
ECCODES_ASSERT( strcmp(values1[1].string_value, "value2")==0 );
ECCODES_ASSERT( values1[1].equal == 0 );
2022-10-26 12:02:45 +00:00
/* Note how the input is modified by the tokenizer (thanks to strtok_r) */
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(input1, "key1=value1")==0 );
2022-11-07 12:22:49 +00:00
free( (void*)values1[0].name );
free( (void*)values1[1].name );
free( (void*)values1[0].string_value );
free( (void*)values1[1].string_value );
2022-10-26 12:02:45 +00:00
count = max_count;
err = parse_keyval_string(NULL, input2,
2022-11-07 12:22:49 +00:00
values_required, GRIB_TYPE_LONG, values2, &count);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !err );
ECCODES_ASSERT( count == 1 );
grib_print_values("print values test: values2", values2, stdout, count);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(values2[0].name, "x")==0 );
ECCODES_ASSERT( values2[0].long_value == 14 );
ECCODES_ASSERT( values2[0].equal == 1 );
2022-11-07 12:22:49 +00:00
free( (void*)values2[0].name );
2022-10-26 12:02:45 +00:00
count = max_count;
err = parse_keyval_string(NULL, input3,
2022-11-07 12:22:49 +00:00
values_required, GRIB_TYPE_DOUBLE, values3, &count);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !err );
ECCODES_ASSERT( count == 1 );
grib_print_values("print values test: values3", values3, stdout, count);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( strcmp(values3[0].name, "mars.level")==0 );
2022-11-07 12:22:49 +00:00
free( (void*)values3[0].name );
2022-10-26 12:02:45 +00:00
}
2024-08-27 15:23:22 +00:00
static void test_time_conversions()
{
printf("Running %s ...\n", __func__);
long result = convert_to_minutes(120, 13); // 120s = 2mins
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(result == 2);
2024-08-27 15:23:22 +00:00
}
static void test_dates()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( is_date_valid(1979,12, 1, 0,0,0) );
ECCODES_ASSERT( is_date_valid(1900, 1, 1, 0,0,0) );
ECCODES_ASSERT( is_date_valid(1964, 4, 6, 0,0,0) );
ECCODES_ASSERT( is_date_valid(2023, 3, 4, 0,0,0) );
ECCODES_ASSERT( is_date_valid(2023, 3, 4, 12,0,0) );
ECCODES_ASSERT( is_date_valid(2023, 3, 4, 0,10,0) );
ECCODES_ASSERT( is_date_valid(2023, 3, 4, 0,0,59) );
ECCODES_ASSERT( is_date_valid(0000, 3, 4, 0,0,0) );
ECCODES_ASSERT( is_date_valid(2020, 2, 29, 0,0,0) );//leap year
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid( 10, -1, 1, 0,0,0) );// bad months
ECCODES_ASSERT( !is_date_valid(1900, 0, 1, 0,0,0) );
ECCODES_ASSERT( !is_date_valid(1900, 13, 1, 0,0,0) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid(1900, 5, 0, 0,0,0) ); // bad days
ECCODES_ASSERT( !is_date_valid(2000, 5, 32, 0,0,0) );
ECCODES_ASSERT( !is_date_valid(2000, 5, -7, 0,0,0) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid(2000, 5, 8, 99,0,0) );//bad hours
ECCODES_ASSERT( !is_date_valid(2000, 5, 9, -1,0,0) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid(2000, 5, 8, 0, 61,0) );//bad mins
ECCODES_ASSERT( !is_date_valid(2000, 5, 9, 0,-1, 0) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid(2000, 5, 8, 0, 1, -1) );//bad secs
ECCODES_ASSERT( !is_date_valid(2000, 5, 9, 0, 1, 60) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( !is_date_valid(2023, 2, 29, 0,0,0) );//Feb
}
void test_scale_factor_scaled_values()
{
2023-08-05 11:37:42 +00:00
printf("Running %s ...\n", __func__);
int err =0;
int64_t value, factor;
const int64_t scaled_value_max = 4294967295; // usually 4 octets
const int64_t scale_factor_max = 255; // usually 1 octet
err = compute_scaled_value_and_scale_factor(0, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 0);
ECCODES_ASSERT(factor == 0);
err = compute_scaled_value_and_scale_factor(1, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 1);
ECCODES_ASSERT(factor == 0);
err = compute_scaled_value_and_scale_factor(1.5, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 15);
ECCODES_ASSERT(factor == 1);
err = compute_scaled_value_and_scale_factor(4.56, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 456);
ECCODES_ASSERT(factor == 2);
err = compute_scaled_value_and_scale_factor(-0.003, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == -3);
ECCODES_ASSERT(factor == 3);
err = compute_scaled_value_and_scale_factor(145.889, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 145889);
ECCODES_ASSERT(factor == 3);
err = compute_scaled_value_and_scale_factor(1111.00009, scaled_value_max, scale_factor_max, &value, &factor);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
ECCODES_ASSERT(value == 111100009);
ECCODES_ASSERT(factor == 5);
}
2023-08-21 21:02:03 +00:00
void test_iarray()
{
2023-08-23 16:00:49 +00:00
printf("Running %s ...\n", __func__);
2024-10-12 15:06:41 +00:00
2024-10-12 13:55:04 +00:00
grib_iarray* a = grib_iarray_new(10, 10);
2023-08-21 21:02:03 +00:00
grib_iarray_push(a, 42);
2023-08-23 16:00:49 +00:00
grib_iarray_push(a, 10000);
grib_iarray_print("iarray", a);
2024-10-12 13:55:04 +00:00
grib_iarray* b = grib_iarray_new(1, 1);
2023-08-23 16:00:49 +00:00
grib_iarray_push(b, 0);
grib_iarray_push(b, -1);
grib_iarray_push(b, +1);
2024-10-12 15:06:41 +00:00
grib_viarray* va = grib_viarray_new(1, 1);
grib_viarray_push(va, a);
grib_viarray_push(va, b);
2023-08-23 16:00:49 +00:00
grib_viarray_print("viarray", va);
2023-08-21 21:02:03 +00:00
grib_iarray_delete(a);
2023-08-23 16:00:49 +00:00
grib_iarray_delete(b);
2024-10-12 15:06:41 +00:00
grib_viarray_delete(va);
2023-08-21 21:02:03 +00:00
}
void test_darray()
{
2023-08-23 16:00:49 +00:00
printf("Running %s ...\n", __func__);
2024-10-12 14:26:50 +00:00
2024-10-12 13:48:36 +00:00
grib_darray* a = grib_darray_new(10, 10);
grib_darray_push(a, 42.009);
grib_darray_push(a, -1.11);
grib_darray_push(a, 5099);
2023-08-23 16:00:49 +00:00
grib_darray_print("darray", a);
2024-10-12 13:48:36 +00:00
grib_darray* b = grib_darray_new(5, 1);
grib_darray_push(b, 8);
grib_darray_push(b, 12);
2023-08-23 16:00:49 +00:00
2024-10-12 14:20:11 +00:00
grib_vdarray* va = grib_vdarray_new(1, 1);
2024-10-12 14:26:50 +00:00
grib_vdarray_push(va, a);
grib_vdarray_push(va, b);
2023-08-23 16:00:49 +00:00
grib_vdarray_print("vdarray", va);
2024-10-12 13:48:36 +00:00
grib_darray_delete(a);
grib_darray_delete(b);
2024-10-12 14:26:50 +00:00
grib_vdarray_delete(va);
2023-08-21 21:02:03 +00:00
}
void test_sarray()
{
2023-08-23 16:00:49 +00:00
printf("Running %s ...\n", __func__);
2024-10-12 15:06:41 +00:00
grib_sarray* a = grib_sarray_new(10, 10);
2024-01-16 13:54:10 +00:00
char ants_s[] = "ants";
char bugs_s[] = "bugs";
2024-10-12 15:06:41 +00:00
grib_sarray_push(a, ants_s);
grib_sarray_push(a, bugs_s);
2023-08-23 16:00:49 +00:00
grib_sarray_print("sarray", a);
2023-12-10 14:04:22 +00:00
2024-10-12 15:06:41 +00:00
grib_vsarray* va = grib_vsarray_new(1, 1);
grib_vsarray_push(va, a);
2023-12-10 14:04:22 +00:00
grib_vsarray_print("vsarray", va);
2024-10-12 15:06:41 +00:00
grib_sarray_delete(a);
grib_vsarray_delete(va);
2023-08-21 21:02:03 +00:00
}
2023-08-23 13:26:56 +00:00
void test_codes_get_product_name()
{
2023-08-23 16:00:49 +00:00
printf("Running %s ...\n", __func__);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( STR_EQUAL("ANY", codes_get_product_name(PRODUCT_ANY)) );
ECCODES_ASSERT( STR_EQUAL("GRIB", codes_get_product_name(PRODUCT_GRIB)) );
ECCODES_ASSERT( STR_EQUAL("BUFR", codes_get_product_name(PRODUCT_BUFR)) );
ECCODES_ASSERT( STR_EQUAL("GTS", codes_get_product_name(PRODUCT_GTS)) );
ECCODES_ASSERT( STR_EQUAL("METAR", codes_get_product_name(PRODUCT_METAR)) );
ECCODES_ASSERT( STR_EQUAL("TAF", codes_get_product_name(PRODUCT_TAF)) );
2023-08-23 13:26:56 +00:00
}
2023-08-23 13:41:29 +00:00
void test_codes_get_type_name()
{
2023-08-23 16:00:49 +00:00
printf("Running %s ...\n", __func__);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( STR_EQUAL("long", codes_get_type_name(GRIB_TYPE_LONG)) );
ECCODES_ASSERT( STR_EQUAL("string", grib_get_type_name(GRIB_TYPE_STRING)) );
ECCODES_ASSERT( STR_EQUAL("double", grib_get_type_name(GRIB_TYPE_DOUBLE)) );
ECCODES_ASSERT( STR_EQUAL("bytes", grib_get_type_name(GRIB_TYPE_BYTES)) );
ECCODES_ASSERT( STR_EQUAL("label", grib_get_type_name(GRIB_TYPE_LABEL)) );
ECCODES_ASSERT( STR_EQUAL("section", grib_get_type_name(GRIB_TYPE_SECTION)) );
2023-08-23 13:41:29 +00:00
}
2024-07-25 16:00:36 +00:00
void test_grib2_choose_PDTN()
{
printf("Running %s ...\n", __func__);
int det = true;
int instant = true;
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 0 == grib2_choose_PDTN(0, det, instant) );
ECCODES_ASSERT( 8 == grib2_choose_PDTN(0, det, !instant) );
ECCODES_ASSERT( 1 == grib2_choose_PDTN(0, !det, instant) );
ECCODES_ASSERT( 11 == grib2_choose_PDTN(0, !det, !instant) );
2024-07-25 16:00:36 +00:00
}
2024-01-14 00:13:59 +00:00
void test_grib2_select_PDTN()
{
printf("Running %s ...\n", __func__);
2024-01-14 14:39:23 +00:00
int eps = 1;
int instant = 1;
int chemical = 1;
int chemical_srcsink = 1;
int chemical_distfn = 1;
int aerosol = 1;
int aerosol_optical = 1;
2024-01-14 14:39:23 +00:00
// arguments = eps instant chemical chemical_srcsink chemical_distfn aerosol aerosol_optical
// Chemicals
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 40 == grib2_select_PDTN(!eps, instant, chemical, 0, 0, 0, 0) );
ECCODES_ASSERT( 41 == grib2_select_PDTN(eps, instant, chemical, 0, 0, 0, 0) );
ECCODES_ASSERT( 42 == grib2_select_PDTN(!eps, !instant, chemical, 0, 0, 0, 0) );
ECCODES_ASSERT( 43 == grib2_select_PDTN(eps, !instant, chemical, 0, 0, 0, 0) );
2024-01-14 14:39:23 +00:00
// Chemical source/sink
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 76 == grib2_select_PDTN(!eps, instant, !chemical, chemical_srcsink, 0,0,0) );
ECCODES_ASSERT( 77 == grib2_select_PDTN(eps, instant, !chemical, chemical_srcsink, 0,0,0) );
ECCODES_ASSERT( 78 == grib2_select_PDTN(!eps, !instant, !chemical, chemical_srcsink, 0,0,0) );
ECCODES_ASSERT( 79 == grib2_select_PDTN(eps, !instant, !chemical, chemical_srcsink, 0,0,0) );
// Chemical distrib. function
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 58 == grib2_select_PDTN(eps, instant, 0, 0, chemical_distfn, 0, 0) );
ECCODES_ASSERT( 68 == grib2_select_PDTN(eps, !instant, 0, 0, chemical_distfn, 0, 0) );
ECCODES_ASSERT( 57 == grib2_select_PDTN(!eps, instant, 0, 0, chemical_distfn, 0, 0) );
ECCODES_ASSERT( 67 == grib2_select_PDTN(!eps, !instant, 0, 0, chemical_distfn, 0, 0) );
2024-01-14 14:39:23 +00:00
// Aerosols
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 50 == grib2_select_PDTN(!eps, instant, 0, 0, 0, aerosol, 0) );
ECCODES_ASSERT( 46 == grib2_select_PDTN(!eps, !instant, 0, 0, 0, aerosol, 0) );
ECCODES_ASSERT( 45 == grib2_select_PDTN(eps, instant, 0, 0, 0, aerosol, 0) );
ECCODES_ASSERT( 85 == grib2_select_PDTN(eps, !instant, 0, 0, 0, aerosol, 0) );
// Aerosol optical
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 49 == grib2_select_PDTN(eps, instant, 0, 0, 0, 0, aerosol_optical) );
ECCODES_ASSERT( 48 == grib2_select_PDTN(!eps, instant, 0, 0, 0, 0, aerosol_optical) );
2024-01-14 14:39:23 +00:00
// Plain vanilla
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 0 == grib2_select_PDTN(!eps, instant, !chemical, !chemical_srcsink, !chemical_distfn, !aerosol, 0) );
ECCODES_ASSERT( 1 == grib2_select_PDTN(1,1,0,0,0, !aerosol,0) );
ECCODES_ASSERT( 8 == grib2_select_PDTN(0,0,0,0,0, !aerosol,0) );
ECCODES_ASSERT( 11 == grib2_select_PDTN(1,0,0,0,0, !aerosol,0) );
2024-01-14 14:39:23 +00:00
//printf("%d\n", grib2_select_PDTN(!eps, instant, !chemical, !chemical_srcsink, !chemical_distfn, aerosol, 0) );
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 1 == grib2_is_PDTN_EPS(1) );
ECCODES_ASSERT( 1 == grib2_is_PDTN_EPS(11) );
ECCODES_ASSERT( 0 == grib2_is_PDTN_EPS(0) );
2024-01-14 00:13:59 +00:00
}
2024-01-28 17:32:29 +00:00
void test_codes_get_error_message()
{
printf("Running %s ...\n", __func__);
const char* errmsg = grib_get_error_message(6666);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( STR_EQUAL(errmsg, "Unknown error -6666"));
2024-01-28 17:32:29 +00:00
}
void test_codes_context_set_debug()
{
printf("Running %s ...\n", __func__);
grib_context* context = NULL;
int err = 0;
printf("\tEnable debugging...\n");
grib_context_set_debug(context, -1);
grib_handle* h = grib_handle_new_from_samples(context, "GRIB2");
2024-08-27 13:53:26 +00:00
if (!h) return;
err = grib_set_long(h, "paramId", 167);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
printf("\tDisable debugging...\n");
grib_context_set_debug(context, 0);
err = grib_set_long(h, "edition", 1);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
printf("\tEnable debugging again (verbose)...\n");
grib_context_set_debug(context, 1);
grib_handle_delete(h);
grib_context_set_debug(context, 0);
}
2024-08-27 19:13:37 +00:00
void test_codes_is_feature_enabled()
2024-08-27 13:53:26 +00:00
{
printf("Running %s ...\n", __func__);
const char* features[] = {
"AEC",
"MEMFS",
"JPG",
"PNG",
"ECCODES_THREADS",
"ECCODES_OMP_THREADS",
"NETCDF",
"FORTRAN",
2024-08-27 15:23:22 +00:00
"GEOGRAPHY",
2024-08-27 13:53:26 +00:00
NULL};
for (int i = 0; features[i]; ++i) {
const char* f = features[i];
printf("\tFeature %s enabled?\t%d\n", f, codes_is_feature_enabled(f));
}
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT( 0 == codes_is_feature_enabled("total rubbish") );
2024-08-27 13:53:26 +00:00
}
2024-08-28 10:28:46 +00:00
void test_codes_get_features()
2024-08-27 16:48:39 +00:00
{
printf("Running %s ...\n", __func__);
size_t len = 512;
2024-08-27 19:13:37 +00:00
char* features = (char*)calloc(len, sizeof(char));
2024-08-28 10:28:46 +00:00
int err = codes_get_features(features, &len, CODES_FEATURES_ALL);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!err);
2024-08-28 10:28:46 +00:00
printf("\tFeatures are: '%s'\n", features);
len = 512;
err = codes_get_features(features, &len, CODES_FEATURES_ENABLED);
2024-08-27 16:48:39 +00:00
printf("\tEnabled features are: '%s'\n", features);
2024-08-28 10:28:46 +00:00
len = 512;
err = codes_get_features(features, &len, CODES_FEATURES_DISABLED);
printf("\tDisabled features are: '%s'\n", features);
2024-08-27 16:48:39 +00:00
free(features);
}
2024-08-27 13:53:26 +00:00
2024-10-12 13:18:34 +00:00
static void test_grib_get_binary_scale_fact()
{
printf("Running %s ...\n", __func__);
int err = 0;
2024-12-18 12:19:59 +00:00
long result = grib_get_binary_scale_fact(INFINITY, 0, 0, &err);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(err == GRIB_OUT_OF_RANGE);
ECCODES_ASSERT(result == 0);
2024-10-12 13:18:34 +00:00
result = grib_get_binary_scale_fact(100, 0, 65, &err); // bpv too big
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(err == GRIB_OUT_OF_RANGE);
ECCODES_ASSERT(result == 0);
2024-10-12 13:18:34 +00:00
result = grib_get_binary_scale_fact(100, 0, 0, &err); // bpv 0
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(err == GRIB_ENCODING_ERROR);
ECCODES_ASSERT(result == 0);
2024-10-12 13:18:34 +00:00
}
2024-10-30 16:42:18 +00:00
static void test_filepool()
{
printf("Running %s ...\n", __func__);
grib_file_pool_print("file_pool contents", stdout);
}
2013-03-25 14:23:07 +00:00
int main(int argc, char** argv)
{
2022-10-26 12:02:45 +00:00
printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version());
2024-08-19 11:15:22 +00:00
printf("codes_print_api_version gives: ");
codes_print_api_version(stdout);
printf("\n");
2022-10-20 13:38:17 +00:00
2024-12-13 12:11:49 +00:00
test_grib_get_reduced_row_legacy();
test_codes_context_set_debug();
2024-01-28 17:32:29 +00:00
test_codes_get_error_message();
2024-10-12 13:18:34 +00:00
test_grib_get_binary_scale_fact();
2024-01-28 17:32:29 +00:00
2023-08-21 21:02:03 +00:00
test_iarray();
test_darray();
test_sarray();
2023-08-23 13:26:56 +00:00
test_codes_get_product_name();
2023-08-23 13:41:29 +00:00
test_codes_get_type_name();
2023-08-23 13:26:56 +00:00
test_scale_factor_scaled_values();
test_dates();
2024-08-27 15:23:22 +00:00
test_time_conversions();
test_logging_proc();
2024-08-25 15:33:52 +00:00
test_print_proc();
2022-10-20 13:38:17 +00:00
test_grib_binary_search();
2022-10-26 12:02:45 +00:00
test_parse_keyval_string();
2022-12-26 14:37:01 +00:00
test_get_git_sha1();
2024-02-24 18:24:16 +00:00
test_get_package_name();
test_get_build_date();
2022-02-24 15:16:55 +00:00
test_gribex_mode();
2023-12-16 13:07:36 +00:00
test_gts_header_mode();
test_bufr_multi_element_constant_arrays();
2024-09-19 12:10:50 +00:00
test_data_quality_checks();
2017-04-05 15:47:19 +00:00
test_concept_condition_strings();
2017-04-05 15:47:19 +00:00
test_assertion_catching();
2014-07-21 12:22:20 +00:00
test_gaussian_latitude_640();
test_gaussian_latitudes(32);
test_gaussian_latitudes(48);
test_gaussian_latitudes(80);
test_gaussian_latitudes(128);
test_gaussian_latitudes(160);
test_gaussian_latitudes(200);
test_gaussian_latitudes(256);
test_gaussian_latitudes(320);
test_gaussian_latitudes(400);
test_gaussian_latitudes(512);
test_gaussian_latitudes(640);
test_gaussian_latitudes(1024);
test_gaussian_latitudes(1280);
test_gaussian_latitudes(2000);
test_grib_nearest_smaller_ibmfloat();
test_grib_nearest_smaller_ieeefloat();
2016-10-07 14:12:27 +00:00
test_string_splitting();
2023-08-04 21:17:04 +00:00
test_string_ends_with();
test_string_to_long();
test_string_trimming();
test_string_replace_char();
test_string_remove_char();
2016-10-07 14:12:27 +00:00
2024-01-14 14:39:23 +00:00
test_grib2_select_PDTN();
2024-07-25 16:00:36 +00:00
test_grib2_choose_PDTN();
2024-08-27 19:13:37 +00:00
test_codes_is_feature_enabled();
2024-08-28 10:28:46 +00:00
test_codes_get_features();
2024-10-30 16:42:18 +00:00
test_filepool();
2024-01-14 14:39:23 +00:00
2014-07-21 12:22:20 +00:00
return 0;
2013-03-25 14:23:07 +00:00
}