diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5da1d694..2c6dd066 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -69,6 +69,7 @@ set(REF_FILES "gdaswave.t00z.wcoast.0p16.f000.grib2.idx" "testgrib2.grb2" "ref_testgrib2.grb2.degrib2" "ref_gdaswave_2.grib1.idx" + "ref_tst_jasper_warning.txt" ) # Copy extra files if needed. @@ -89,12 +90,17 @@ FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../src/CodeFlag.xml FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../src/Template.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) -# Run a C program test. -function(g2c_test name) +# Build a C program test. +function(g2c_build_test name) add_executable(${name} ${name}.c util.c) target_link_libraries(${name} PUBLIC g2c::g2c) target_link_libraries(${name} PRIVATE ${LIBXML2_LIBRARIES}) target_include_directories(${name} PRIVATE "${LIBXML2_INCLUDE_DIR}") +endfunction() + +# Run a C program test. +function(g2c_test name) + g2c_build_test(${name}) add_test(NAME ${name} COMMAND ${name}) endfunction() @@ -217,6 +223,12 @@ if(USE_Jasper OR USE_OpenJPEG) g2c_test(tst_jpeg) g2c_test(tst_addfield3) g2c_test(tst_addfield4) + g2c_build_test(tst_jasper_warning) +endif() + +# Test for warnings from jasper. +if(USE_Jasper) + gu_test(run_jasper_warning_test) endif() # Run these shell tests, which require Jasper. @@ -238,3 +250,4 @@ endif() + diff --git a/tests/data/ref_tst_jasper_warning.txt b/tests/data/ref_tst_jasper_warning.txt new file mode 100644 index 00000000..d6eb9645 --- /dev/null +++ b/tests/data/ref_tst_jasper_warning.txt @@ -0,0 +1,3 @@ +Testing JPEG functions. +Testing enc_jpeg2000()/dec_jpeg2000() call...ok! +SUCCESS! diff --git a/tests/run_jasper_warning_test.sh b/tests/run_jasper_warning_test.sh new file mode 100644 index 00000000..fad9fa5a --- /dev/null +++ b/tests/run_jasper_warning_test.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# This is a test script for the NCEPLIBS-g2c project. +# +# This script runs a simple program that uses the jasper library, and +# then compares the output to expected output, to ensure that jasper +# is not writing any warning messages to stdout. +# +# Ed Hartnett, 10/26/23 + +set -e +echo "" +echo "*** Running jasper warning test" +set -x +pwd +./tst_jasper_warning &> tst_jasper_warning.txt + +# Check against expected output. +diff -w tst_jasper_warning.txt data/ref_tst_jasper_warning.txt + +echo "*** SUCCESS!" +exit 0 diff --git a/tests/tst_jasper_warning.c b/tests/tst_jasper_warning.c new file mode 100644 index 00000000..df50b43a --- /dev/null +++ b/tests/tst_jasper_warning.c @@ -0,0 +1,48 @@ +/* This is a test for the NCEPLIBS-g2c project. This test is for the + * JPEG jasper library. It tests that jasper is not writing any + * warnings to stdout. + * + * Ed Hartnett 10/26/23 + */ + +#include +#include +#include "grib2_int.h" + +#define DATA_LEN 4 +#define PACKED_LEN 200 + +int +main() +{ + printf("Testing JPEG functions.\n"); + /* g2c_set_log_level(10); */ + printf("Testing enc_jpeg2000()/dec_jpeg2000() call..."); + { + unsigned char data[DATA_LEN] = {1, 2, 3, 4}; + g2int width = 2, height = 2, nbits = 4; + g2int ltype = 0, ratio = 0, retry = 0, jpclen = PACKED_LEN; + char outjpc[PACKED_LEN]; + g2int outfld[DATA_LEN]; + int i; + int ret; + + /* Encode some data. */ + if ((ret = enc_jpeg2000(data, width, height, nbits, ltype, + ratio, retry, outjpc, jpclen)) < 0) + return G2C_ERROR; + + /* Now decode it. */ + if ((ret = dec_jpeg2000(outjpc, jpclen, outfld))) + return G2C_ERROR; + + for (i = 0; i < DATA_LEN; i++) + { + if (outfld[i] != data[i]) + return G2C_ERROR; + } + } + printf("ok!\n"); + printf("SUCCESS!\n"); + return 0; +}