Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding test for jasper warnings #458

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()

Expand Down Expand Up @@ -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.
Expand All @@ -238,3 +250,4 @@ endif()




3 changes: 3 additions & 0 deletions tests/data/ref_tst_jasper_warning.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Testing JPEG functions.
Testing enc_jpeg2000()/dec_jpeg2000() call...ok!
SUCCESS!
21 changes: 21 additions & 0 deletions tests/run_jasper_warning_test.sh
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions tests/tst_jasper_warning.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#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;
}
Loading