Testing: Increase coverage

This commit is contained in:
Shahram Najm 2023-12-17 16:39:18 +00:00
parent 42be7969f2
commit 8e5132f0be
2 changed files with 42 additions and 5 deletions

View File

@ -17,13 +17,19 @@ int main(int argc, char* argv[])
grib_handle* h1 = NULL;
grib_handle* h2 = NULL;
int err = 0;
size_t count = 0;
size_t num_diffs = 0, i = 0;
char** list_provided_keys = NULL;
Assert(argc == 3);
f1 = fopen(argv[1], "rb");
f2 = fopen(argv[2], "rb");
Assert(f1 && f2);
if (argc == 4) {
// List of keys is also given on the command line
char* input = argv[3];
list_provided_keys = string_split(input, ",");
}
while ((h1 = grib_handle_new_from_file(0, f1, &err)) != NULL && (h2 = grib_handle_new_from_file(0, f2, &err)) != NULL) {
grib_keys_iterator* kiter = NULL;
@ -36,10 +42,11 @@ int main(int argc, char* argv[])
while (grib_keys_iterator_next(kiter)) {
const char* name = grib_keys_iterator_get_name(kiter);
Assert(name);
//printf(".... %s \n",name);
err = codes_compare_key(h1, h2, name, 0);
if (err) {
fprintf(stderr, "key: %s (%s)\n", name, grib_get_error_message(err));
++count;
++num_diffs;
}
}
@ -49,14 +56,33 @@ int main(int argc, char* argv[])
codes_compare_key(h1, h2, "paramId", 0); // concept
codes_compare_key(h1, h2, "identifier", 0); // ascii
if (list_provided_keys) {
for (i = 0; list_provided_keys[i] != NULL; ++i) {
const char* pkey = list_provided_keys[i];
printf("Comparing provided key %s ...\n", list_provided_keys[i]);
err = codes_compare_key(h1, h2, pkey, 0);
if (err) {
fprintf(stderr, "key: %s (%s)\n", pkey, grib_get_error_message(err));
++num_diffs;
}
}
}
grib_keys_iterator_delete(kiter);
grib_handle_delete(h1);
grib_handle_delete(h2);
}
fclose(f1);
fclose(f2);
if (count > 0) {
fprintf(stderr, "\nComparison failed: %zu differences\n", count);
if (list_provided_keys) {
for (i = 0; list_provided_keys[i] != NULL; ++i) free(list_provided_keys[i]);
free(list_provided_keys);
}
if (num_diffs > 0) {
fprintf(stderr, "\nComparison failed: %zu differences\n", num_diffs);
return 1;
}
return 0;

View File

@ -63,5 +63,16 @@ EOF
diff $tempRef $tempLog
# Local definitions
# ----------------------
sample1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
tempGribA=temp.${label}.A.grib
tempGribB=temp.${label}.B.grib
${tools_dir}/grib_set -s localDefinitionNumber=16,verifyingMonth=11 $sample1 $tempGribA
${tools_dir}/grib_set -s localDefinitionNumber=16,verifyingMonth=11 $sample1 $tempGribB
${test_dir}/codes_compare_keys $tempGribA $tempGribB endOfInterval
rm -f $tempGribA $tempGribB
# Clean up
rm -f $tempLog $tempRef $tempGrib