update conformance test files on 1.5 branch

This commit is contained in:
Antonin Descampe 2015-09-15 15:11:12 +02:00
parent 770e81eebc
commit f8013bec95
12 changed files with 1875 additions and 1252 deletions

16
CMake/FindCPPCHECK.cmake Normal file
View File

@ -0,0 +1,16 @@
# cppcheck
#
# Copyright (c) 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
find_program(CPPCHECK_EXECUTABLE
cppcheck
)
mark_as_advanced(
CPPCHECK_EXECUTABLE
)

12
CMake/FindJPYLYZER.cmake Normal file
View File

@ -0,0 +1,12 @@
#
# this module looks for JPYLYZER
# http://jpylyzer.openpreservation.org
#
find_program(JPYLYZER_EXECUTABLE
jpylyzer
)
mark_as_advanced(
JPYLYZER_EXECUTABLE
)

View File

@ -1,5 +1,5 @@
# Tests # Tests
INCLUDE_DIRECTORIES( include_directories(
${OPENJPEG_SOURCE_DIR}/libopenjpeg ${OPENJPEG_SOURCE_DIR}/libopenjpeg
${OPENJPEG_SOURCE_DIR}/applications/codec ${OPENJPEG_SOURCE_DIR}/applications/codec
${OPENJPEG_SOURCE_DIR}/applications/common ${OPENJPEG_SOURCE_DIR}/applications/common
@ -9,50 +9,51 @@ INCLUDE_DIRECTORIES(
) )
# First thing define the common source: # First thing define the common source:
SET(comparePGXimages_SRCS comparePGXimages.c set(compare_images_SRCS compare_images.c
${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c
# ${OPENJPEG_SOURCE_DIR}/applications/codec/converttif.c
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
) )
SET(compare_dump_files_SRCS compare_dump_files.c)
SET(compareRAWimages_SRCS compareRAWimages.c)
if(NOT USE_SYSTEM_GETOPT) set(compare_dump_files_SRCS compare_dump_files.c
list(APPEND comparePGXimages_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
list(APPEND compare_dump_files_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
list(APPEND compareRAWimages_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
endif()
ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS}) set(compare_raw_files_SRCS compare_raw_files.c
TARGET_LINK_LIBRARIES(comparePGXimages ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
add_executable(compare_images ${compare_images_SRCS})
target_link_libraries(compare_images
${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_LIBRARY_NAME}
${PNG_LIBNAME} ${TIFF_LIBNAME} ${PNG_LIBNAME} ${TIFF_LIBNAME}
) )
# To support universal exe: # To support universal exe:
IF(ZLIB_FOUND AND APPLE) if(ZLIB_FOUND AND APPLE)
TARGET_LINK_LIBRARIES(comparePGXimages z) target_link_libraries(compare_images z)
ELSe(ZLIB_FOUND AND APPLE) else(ZLIB_FOUND AND APPLE)
TARGET_LINK_LIBRARIES(comparePGXimages ${Z_LIBNAME}) target_link_libraries(compare_images ${Z_LIBNAME})
ENDIF(ZLIB_FOUND AND APPLE) endif()
ADD_EXECUTABLE(compare_dump_files ${compare_dump_files_SRCS}) add_executable(compare_dump_files ${compare_dump_files_SRCS})
ADD_EXECUTABLE(compareRAWimages ${compareRAWimages_SRCS})
# No image send to the dashboard if lib PNG is not available. # No image send to the dashboard if lib PNG is not available.
IF(NOT HAVE_LIBPNG) if(NOT OPJ_HAVE_LIBPNG)
MESSAGE(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)") message(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)")
ENDIF(NOT HAVE_LIBPNG) endif()
ADD_SUBDIRECTORY(conformance) add_subdirectory(conformance)
ADD_SUBDIRECTORY(nonregression) #add_subdirectory(nonregression)
ADD_SUBDIRECTORY(unit) add_subdirectory(unit)
IF(BUILD_JPIP) if(BUILD_JPIP)
IF(JPIP_SERVER) if(JPIP_SERVER)
#SET(s "http://jpip.example.com/myFCGI?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream") #set(s "http://jpip.example.com/myFCGI?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream")
SET(s "${JPIP_SERVER}?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream") set(s "${JPIP_SERVER}?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream")
SET(p "${CMAKE_CURRENT_BINARY_DIR}/jpip.dat") set(p "${CMAKE_CURRENT_BINARY_DIR}/jpip.dat")
SET(md5 "62b00c620fb0a600c5ffd413cada4674") set(md5 "d41d8cd98f00b204e9800998ecf8427e")
ADD_TEST(NAME TestJPIP1 COMMAND ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p} add_test(NAME TestJPIP1 COMMAND ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p}
-DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/CMake/JPIPTestDriver.cmake) -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/cmake/JPIPTestDriver.cmake)
ENDIF(JPIP_SERVER) endif()
ENDIF(BUILD_JPIP) endif()
add_executable(ppm2rgb3 ppm2rgb3.c)
#add_executable(pdf2jp2 pdf2jp2.c)

View File

@ -1,236 +0,0 @@
/*
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* compareRAWimages.c
*
* Created on: 31 August 2011
* Author: mickael
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "opj_getopt.h"
void compareRAWimages_help_display(void);
typedef struct test_cmp_parameters
{
/** */
char* base_filename;
/** */
char* test_filename;
} test_cmp_parameters;
/*******************************************************************************
* Command line help function
*******************************************************************************/
void compareRAWimages_help_display(void) {
fprintf(stdout,"\nList of parameters for the comparePGX function \n");
fprintf(stdout,"\n");
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n");
fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n");
fprintf(stdout,"\n");
}
/*******************************************************************************
* Parse command line
*******************************************************************************/
int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
{
int sizemembasefile, sizememtestfile;
int index;
const char optlist[] = "b:t:";
int c;
/* Init parameters*/
param->base_filename = NULL;
param->test_filename = NULL;
opj_opterr = 0;
while ((c = opj_getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
sizemembasefile = (int)strlen(opj_optarg)+1;
param->base_filename = (char*) malloc(sizemembasefile);
param->base_filename[0] = '\0';
strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
param->base_filename[strlen(opj_optarg)] = '\0';
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
break;
case 't':
sizememtestfile = (int) strlen(opj_optarg) + 1;
param->test_filename = (char*) malloc(sizememtestfile);
param->test_filename[0] = '\0';
strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
param->test_filename[strlen(opj_optarg)] = '\0';
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
break;
case '?':
if ((opj_optopt == 'b') || (opj_optopt == 't'))
fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
else
if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
return 1;
default:
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
break;
}
if (opj_optind != argc) {
for (index = opj_optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*******************************************************************************
* MAIN
*******************************************************************************/
int main(int argc, char **argv)
{
test_cmp_parameters inParam;
FILE *file_test=NULL, *file_base=NULL;
unsigned char equal = 1;
/* Get parameters from command line*/
if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE)
{
compareRAWimages_help_display();
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
return EXIT_FAILURE;
}
file_test = fopen(inParam.test_filename, "rb");
if (!file_test) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename);
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
return EXIT_FAILURE;
}
file_base = fopen(inParam.base_filename, "rb");
if (!file_base) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename);
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
fclose(file_test);
return EXIT_FAILURE;
}
/* Read simultaneously the two files*/
while (equal)
{
unsigned char value_test = 0;
unsigned char eof_test = 0;
unsigned char value_base = 0;
unsigned char eof_base = 0;
/* Read one byte*/
if (!fread(&value_test, 1, 1, file_test)) {
eof_test = 1;
}
/* Read one byte*/
if (!fread(&value_base, 1, 1, file_base)) {
eof_base = 1;;
}
/* End of file reached by the two files?*/
if (eof_test && eof_base)
break;
/* End of file reached only by one file?*/
if (eof_test || eof_base)
{
fprintf(stdout,"Files have different sizes.\n");
equal = 0;
}
/* Binary values are equal?*/
if (value_test != value_base)
{
fprintf(stdout,"Binary values read in the file are different.\n");
equal = 0;
}
}
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
fclose(file_test);
fclose(file_base);
if (equal)
{
fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n");
return EXIT_SUCCESS;
}
else
return EXIT_FAILURE;
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr> * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -29,13 +29,13 @@
* *
* Created on: 25 juil. 2011 * Created on: 25 juil. 2011
* Author: mickael * Author: mickael
* BASELINE MUST BE GENERATED BY UNIX PLATFORM REGARDING TO THE CRLF PROBLEM
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h>
#include "opj_getopt.h" #include "opj_getopt.h"
@ -50,7 +50,7 @@ typedef struct test_cmp_parameters
/******************************************************************************* /*******************************************************************************
* Command line help function * Command line help function
*******************************************************************************/ *******************************************************************************/
void compare_dump_files_help_display(void) { static void compare_dump_files_help_display(void) {
fprintf(stdout,"\nList of parameters for the compare_dump_files function \n"); fprintf(stdout,"\nList of parameters for the compare_dump_files function \n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n");
@ -60,9 +60,9 @@ void compare_dump_files_help_display(void) {
/******************************************************************************* /*******************************************************************************
* Parse command line * Parse command line
*******************************************************************************/ *******************************************************************************/
int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
{ {
int sizemembasefile, sizememtestfile; size_t sizemembasefile, sizememtestfile;
int index; int index;
const char optlist[] = "b:t:"; const char optlist[] = "b:t:";
int c; int c;
@ -76,43 +76,40 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
while ((c = opj_getopt(argc, argv, optlist)) != -1) while ((c = opj_getopt(argc, argv, optlist)) != -1)
switch (c) switch (c)
{ {
case 'b': case 'b':
sizemembasefile = (int)strlen(opj_optarg)+1; sizemembasefile = strlen(opj_optarg) + 1;
param->base_filename = (char*) malloc(sizemembasefile); param->base_filename = (char*) malloc(sizemembasefile);
param->base_filename[0] = '\0'; strcpy(param->base_filename, opj_optarg);
strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
param->base_filename[strlen(opj_optarg)] = '\0'; break;
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ case 't':
break; sizememtestfile = strlen(opj_optarg) + 1;
case 't': param->test_filename = (char*) malloc(sizememtestfile);
sizememtestfile = (int) strlen(opj_optarg) + 1; strcpy(param->test_filename, opj_optarg);
param->test_filename = (char*) malloc(sizememtestfile); /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
param->test_filename[0] = '\0'; break;
strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); case '?':
param->test_filename[strlen(opj_optarg)] = '\0'; if ( (opj_optopt == 'b') || (opj_optopt == 't') )
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
break; else
case '?': if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
if ( (opj_optopt == 'b') || (opj_optopt == 't') ) else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); return 1;
else default:
if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); break;
return 1;
default:
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
break;
} }
if (opj_optind != argc) if (opj_optind != argc)
{ {
for (index = opj_optind; index < argc; index++) for (index = opj_optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]); fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE; return 1;
} }
return EXIT_SUCCESS; return 0;
} }
/******************************************************************************* /*******************************************************************************
* MAIN * MAIN
*******************************************************************************/ *******************************************************************************/
@ -120,33 +117,30 @@ int main(int argc, char **argv)
{ {
test_cmp_parameters inParam; test_cmp_parameters inParam;
FILE *fbase=NULL, *ftest=NULL; FILE *fbase=NULL, *ftest=NULL;
int chbase, chtest; int same = 0;
int same = 1; char lbase[256];
unsigned long l=1, pos; char strbase[256];
char ltest[256];
char strtest[256];
if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE ) if( parse_cmdline_cmp(argc, argv, &inParam) == 1 )
{ {
compare_dump_files_help_display(); compare_dump_files_help_display();
if (!inParam.base_filename) free(inParam.base_filename); goto cleanup;
if (!inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE;
} }
/* Display Parameters*/ /* Display Parameters*/
printf("******Parameters********* \n"); printf("******Parameters********* \n");
printf(" base_filename = %s\n" printf(" base_filename = %s\n"
" test_filename = %s\n", " test_filename = %s\n",
inParam.base_filename, inParam.test_filename); inParam.base_filename, inParam.test_filename);
printf("************************* \n"); printf("************************* \n");
/* open base file */ /* open base file */
printf("Try to open: %s for reading ... ", inParam.base_filename); printf("Try to open: %s for reading ... ", inParam.base_filename);
if((fbase = fopen(inParam.base_filename, "rb"))==NULL) if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
{ {
printf("Failed.\n"); goto cleanup;
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
} }
printf("Ok.\n"); printf("Ok.\n");
@ -154,105 +148,37 @@ int main(int argc, char **argv)
printf("Try to open: %s for reading ... ", inParam.test_filename); printf("Try to open: %s for reading ... ", inParam.test_filename);
if((ftest = fopen(inParam.test_filename, "rb"))==NULL) if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
{ {
printf("Failed.\n"); goto cleanup;
fclose(fbase);
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
} }
printf("Ok.\n"); printf("Ok.\n");
pos=ftell(fbase); while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest))
while(!feof(fbase))
{ {
chbase = fgetc(fbase); int nbase = sscanf(lbase, "%255[^\r\n]", strbase);
if(ferror(fbase)) int ntest = sscanf(ltest, "%255[^\r\n]", strtest);
assert( nbase != 255 && ntest != 255 );
if( nbase != 1 || ntest != 1 )
{ {
printf("Error reading base file.\n"); fprintf(stderr, "could not parse line from files\n" );
return EXIT_FAILURE; goto cleanup;
} }
if( strcmp( strbase, strtest ) != 0 )
chtest = fgetc(ftest);
if(ferror(ftest))
{ {
printf("Error reading test file.\n"); fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest);
return EXIT_FAILURE; goto cleanup;
}
/* CRLF problem (Baseline must be always generated by unix platform)*/
if (chbase == '\n' && chtest == '\r')
if (fgetc(ftest) == '\n')
chtest = '\n';
if(chbase != chtest)
{
size_t nbytes = 2048;
int CRLF_shift=1;
char *strbase, *strtest, *strbase_d, *strtest_d;
printf("Files differ at line %lu:\n", l);
fseek(fbase,pos,SEEK_SET);
/* Take into account CRLF characters when we write \n into
// dump file when we used WIN platform*/
#ifdef _WIN32
CRLF_shift = 2;
fseek(ftest,pos + l - 1,SEEK_SET);
#else
fseek(ftest,pos,SEEK_SET);
#endif
strbase = (char *) malloc(nbytes + 1);
strtest = (char *) malloc(nbytes + 1);
if (fgets(strbase, nbytes, fbase) == NULL)
fprintf(stderr,"\nWARNING: fgets return a NULL value");
else
{
if (fgets(strtest, nbytes, ftest) == NULL)
fprintf(stderr,"\nWARNING: fgets return a NULL value");
else
{
strbase_d = (char *) malloc(strlen(strbase)+1);
strtest_d = (char *) malloc(strlen(strtest)+1);
strncpy(strbase_d, strbase, strlen(strbase)-1);
strncpy(strtest_d, strtest, strlen(strtest)-CRLF_shift);
strbase_d[strlen(strbase)-1] = '\0';
strtest_d[strlen(strtest)-CRLF_shift] = '\0';
printf("<%s> vs. <%s>\n", strbase_d, strtest_d);
free(strbase_d);free(strtest_d);
}
}
free(strbase);free(strtest);
same = 0;
break;
}
else
{
if (chbase == '\n')
{
l++;
pos = ftell(fbase);
}
} }
} }
same = 1;
printf("\n***** TEST SUCCEED: Files are the same. *****\n");
cleanup:
/*Close File*/ /*Close File*/
fclose(fbase); if(fbase) fclose(fbase);
fclose(ftest); if(ftest) fclose(ftest);
/* Free memory*/ /* Free memory*/
free(inParam.base_filename); free(inParam.base_filename);
free(inParam.test_filename); free(inParam.test_filename);
if(same) return same ? EXIT_SUCCESS : EXIT_FAILURE;
{
printf("\n***** TEST SUCCEED: Files are the same. *****\n");
return EXIT_SUCCESS;
}
else return EXIT_FAILURE;
} }

File diff suppressed because it is too large Load Diff

193
tests/compare_raw_files.c Normal file
View File

@ -0,0 +1,193 @@
/*
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* compare_raw_files.c
*
* Created on: 31 August 2011
* Author: mickael
*
* This is equivalent to the UNIX `cmp` command
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "opj_getopt.h"
typedef struct test_cmp_parameters
{
/** */
char* base_filename;
/** */
char* test_filename;
} test_cmp_parameters;
/*******************************************************************************
* Command line help function
*******************************************************************************/
static void compare_raw_files_help_display(void) {
fprintf(stdout,"\nList of parameters for the compare_raw_files function \n");
fprintf(stdout,"\n");
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n");
fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n");
fprintf(stdout,"\n");
}
/*******************************************************************************
* Parse command line
*******************************************************************************/
static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
{
size_t sizemembasefile, sizememtestfile;
int index;
const char optlist[] = "b:t:";
int c;
/* Init parameters*/
param->base_filename = NULL;
param->test_filename = NULL;
opj_opterr = 0;
while ((c = opj_getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
sizemembasefile = strlen(opj_optarg)+1;
free(param->base_filename); /* handle dup option */
param->base_filename = (char*) malloc(sizemembasefile);
strcpy(param->base_filename, opj_optarg);
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
break;
case 't':
sizememtestfile = strlen(opj_optarg) + 1;
free(param->test_filename); /* handle dup option */
param->test_filename = (char*) malloc(sizememtestfile);
strcpy(param->test_filename, opj_optarg);
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
break;
case '?':
if ((opj_optopt == 'b') || (opj_optopt == 't'))
fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
else
if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
return 1;
default:
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
break;
}
if (opj_optind != argc) {
for (index = opj_optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return 1;
}
return 0;
}
/*******************************************************************************
* MAIN
*******************************************************************************/
int main(int argc, char **argv)
{
int pos = 0;
test_cmp_parameters inParam;
FILE *file_test=NULL, *file_base=NULL;
unsigned char equal = 0U; /* returns error by default */
/* Get parameters from command line*/
if (parse_cmdline_cmp(argc, argv, &inParam))
{
compare_raw_files_help_display();
goto cleanup;
}
file_test = fopen(inParam.test_filename, "rb");
if (!file_test) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename);
goto cleanup;
}
file_base = fopen(inParam.base_filename, "rb");
if (!file_base) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename);
goto cleanup;
}
/* Read simultaneously the two files*/
equal = 1U;
while (equal)
{
unsigned char value_test = 0;
unsigned char eof_test = 0;
unsigned char value_base = 0;
unsigned char eof_base = 0;
/* Read one byte*/
if (!fread(&value_test, 1, 1, file_test)) {
eof_test = 1;
}
/* Read one byte*/
if (!fread(&value_base, 1, 1, file_base)) {
eof_base = 1;
}
/* End of file reached by the two files?*/
if (eof_test && eof_base)
break;
/* End of file reached only by one file?*/
if (eof_test || eof_base)
{
fprintf(stdout,"Files have different sizes.\n");
equal = 0;
}
/* Binary values are equal?*/
if (value_test != value_base)
{
fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos);
equal = 0;
}
pos++;
}
if(equal) fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n");
cleanup:
if(file_test) fclose(file_test);
if(file_base) fclose(file_base);
/* Free Memory */
free(inParam.base_filename);
free(inParam.test_filename);
return equal ? EXIT_SUCCESS : EXIT_FAILURE;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
# NON-REGRESSION TESTS ON THIS DATASET LOCATED ${OPJ_DATA_ROOT}/input/nonregression # NON-REGRESSION TESTS ON THIS DATASET LOCATED ${OPJ_DATA_ROOT}/input/nonregression
cmake_minimum_required(VERSION 2.8.7)
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary) FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
SET(TEMP ${CMAKE_CURRENT_BINARY_DIR}/Temporary) SET(TEMP ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
@ -8,12 +10,124 @@ SET(INPUT_NR ${OPJ_DATA_ROOT}/input/nonregression)
SET(INPUT_NR_PATH ${INPUT_NR}) SET(INPUT_NR_PATH ${INPUT_NR})
SET(TEMP_PATH ${TEMP}) SET(TEMP_PATH ${TEMP})
set(INPUT_CONF_PATH ${OPJ_DATA_ROOT}/input/conformance)
# need kdu_expand if possible # need kdu_expand if possible
find_package(KAKADU) find_package(KAKADU)
# need jpylyzer if possible
find_package(JPYLYZER)
######################################################################### #########################################################################
# GENERATION OF THE TEST SUITE # GENERATION OF THE TEST SUITE (DUMP)
# Dump all files with the selected extension inside the input directory
# technically opj_dump should simply parse these one, since syntax is ok.
set(BLACKLIST_JPEG2000_TMP
2539.pdf.SIGFPE.706.1712.jp2
0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2
26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2
4035.pdf.SIGSEGV.d8b.3375.jp2
3635.pdf.asan.77.2930.jp2
issue165.jp2
#edf_c2_1103421.jp2
edf_c2_1178956.jp2
edf_c2_1000290.jp2
#edf_c2_1000691.jp2 # ok
#edf_c2_20.jp2 #looks ok as per kdu_jp2info
edf_c2_1377017.jp2
edf_c2_1002767.jp2
#edf_c2_10025.jp2
edf_c2_1000234.jp2
edf_c2_225881.jp2
edf_c2_1000671.jp2
#edf_c2_1013627.jp2 # weird box, but kdu_jp2info ok
edf_c2_1015644.jp2
edf_c2_101463.jp2
edf_c2_1674177.jp2
edf_c2_1673169.jp2
issue429.jp2
issue427-null-image-size.jp2
issue427-illegal-tile-offset.jp2
)
# Define a list of file which should be gracefully rejected:
set(BLACKLIST_JPEG2000
${BLACKLIST_JPEG2000_TMP}
broken1.jp2
broken2.jp2
broken3.jp2
broken4.jp2
gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2
gdal_fuzzer_check_comp_dx_dy.jp2
gdal_fuzzer_check_number_of_tiles.jp2
gdal_fuzzer_unchecked_numresolutions.jp2
mem-b2ace68c-1381.jp2
1851.pdf.SIGSEGV.ce9.948.jp2
1888.pdf.asan.35.988.jp2
issue362-2863.jp2 #kdu_jp2info ok
issue362-2866.jp2
issue362-2894.jp2
issue400.jp2 #kdu_jp2info ok
issue364-38.jp2
issue364-903.jp2 #kdu_jp2info ok
issue393.jp2 #kdu_jp2info ok
issue408.jp2 #kdu_jp2info ok
issue420.jp2 #kdu_jp2info ok
27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc #kdu_jp2info crash
3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc #kdu_jp2info crash
issue476.jp2 #kdu_jp2info ok
issue475.jp2 #kdu_jp2info ok
issue413.jp2 #kdu_jp2info ok
)
file(GLOB_RECURSE OPJ_DATA_NR_LIST
"${INPUT_NR}/*.j2k"
"${INPUT_NR}/*.j2c"
"${INPUT_NR}/*.jp2"
"${INPUT_NR}/*.jpc"
#"${INPUT_NR}/*.jpx"
)
foreach(INPUT_FILENAME ${OPJ_DATA_NR_LIST})
get_filename_component(INPUT_FILENAME_NAME ${INPUT_FILENAME} NAME)
#get_filename_component(INPUT_FILENAME_NAME_WE ${INPUT_FILENAME_NAME} NAME_WE)
# cannot use longest extension function, since some name contains multiples
# dots. Instead write out own shortest extension function:
string(FIND ${INPUT_FILENAME_NAME} "." SHORTEST_EXT_POS REVERSE)
string(SUBSTRING ${INPUT_FILENAME_NAME} 0 ${SHORTEST_EXT_POS} INPUT_FILENAME_NAME_WE)
string(REGEX MATCH ${INPUT_FILENAME_NAME} bad_jpeg2000 ${BLACKLIST_JPEG2000})
# Dump the input image
add_test(NAME NR-${INPUT_FILENAME_NAME}-dump
COMMAND opj_dump
-i ${INPUT_FILENAME}
-o ${TEMP}/${INPUT_FILENAME_NAME}.txt
-v
)
if(bad_jpeg2000)
set_tests_properties(NR-${INPUT_FILENAME_NAME}-dump
PROPERTIES WILL_FAIL TRUE)
else()
# Compare the dump output with the baseline
add_test(NAME NR-${INPUT_FILENAME_NAME}-compare_dump2base
COMMAND compare_dump_files
-b ${BASELINE_NR}/opj_v2_${INPUT_FILENAME_NAME_WE}.txt
-t ${TEMP}/${INPUT_FILENAME_NAME}.txt
)
set_tests_properties(NR-${INPUT_FILENAME_NAME}-compare_dump2base
PROPERTIES DEPENDS
NR-${INPUT_FILENAME_NAME}-dump)
endif()
endforeach()
#########################################################################
# GENERATION OF THE TEST SUITE (DECODE AND ENCODE)
# Read one and more input file(s) (located in ${OPJ_DATA_ROOT}/input/nonregression) # Read one and more input file(s) (located in ${OPJ_DATA_ROOT}/input/nonregression)
# to know which files processed and with which options. # to know which files processed and with which options.
@ -32,7 +146,8 @@ IF (TEST_SUITE_FILES)
# Avoid to process the official test suite # Avoid to process the official test suite
SET(FILE_ALREADY_READ 0) SET(FILE_ALREADY_READ 0)
STRING(REGEX MATCH "test_suite.ctest.in$" FILE_ALREADY_READ ${TEST_SUITE_FILE}) get_filename_component(TEST_SUITE_FILENAME ${TEST_SUITE_FILE} NAME)
string(REGEX MATCH "^test_suite.ctest.in$" FILE_ALREADY_READ ${TEST_SUITE_FILENAME})
IF(NOT FILE_ALREADY_READ) IF(NOT FILE_ALREADY_READ)
# Configure the additional test suite file: # Configure the additional test suite file:
@ -56,6 +171,7 @@ ELSE(TEST_SUITE_FILES)
ENDIF(TEST_SUITE_FILES) ENDIF(TEST_SUITE_FILES)
set(nonregression_filenames_used)
# Parse the command line found in the file(s) # Parse the command line found in the file(s)
SET(IT_TEST_ENC 0) SET(IT_TEST_ENC 0)
SET(IT_TEST_DEC 0) SET(IT_TEST_DEC 0)
@ -68,9 +184,12 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
# Check if the first argument begin by the comment sign # Check if the first argument begin by the comment sign
LIST(GET CMD_ARG_LIST 0 EXE_NAME) LIST(GET CMD_ARG_LIST 0 EXE_NAME)
if(EXE_NAME)
STRING(REGEX MATCH "^#" IGNORE_LINE_FOUND ${EXE_NAME}) STRING(REGEX MATCH "^#" IGNORE_LINE_FOUND ${EXE_NAME})
endif()
IF(IGNORE_LINE_FOUND) if(IGNORE_LINE_FOUND OR NOT EXE_NAME)
#MESSAGE( STATUS "Current line is ignored: ${OPJ_TEST_CMD_LINE}") #MESSAGE( STATUS "Current line is ignored: ${OPJ_TEST_CMD_LINE}")
@ -81,7 +200,7 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
STRING(REGEX MATCH "^!" FAILED_TEST_FOUND ${EXE_NAME}) STRING(REGEX MATCH "^!" FAILED_TEST_FOUND ${EXE_NAME})
IF (FAILED_TEST_FOUND) IF (FAILED_TEST_FOUND)
# Manage the different cases with the failed sign to remove the first argument which must be image_to_j2k # Manage the different cases with the failed sign to remove the first argument which must be opj_compress
SET(FAILED_TEST_FOUND_1 0) SET(FAILED_TEST_FOUND_1 0)
STRING(REGEX MATCH "^!image_to_j2k$|^!j2k_to_image$" FAILED_TEST_FOUND_1 ${EXE_NAME}) STRING(REGEX MATCH "^!image_to_j2k$|^!j2k_to_image$" FAILED_TEST_FOUND_1 ${EXE_NAME})
@ -210,7 +329,7 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
# Compare the decoding file with baseline generated from the kdu_expand and baseline.j2k # Compare the decoding file with baseline generated from the kdu_expand and baseline.j2k
ADD_TEST(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dec-ref-out2base ADD_TEST(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dec-ref-out2base
COMMAND compareRAWimages COMMAND compare_raw_files
-b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${IT_TEST_ENC}.raw -b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${IT_TEST_ENC}.raw
-t ${OUTPUT_FILENAME}.raw -t ${OUTPUT_FILENAME}.raw
) )
@ -222,8 +341,47 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
ENDIF() ENDIF()
ENDIF(FAILED_TEST_FOUND) ENDIF(FAILED_TEST_FOUND)
# Test the encoded file is a valid JP2 file
if (JPYLYZER_EXECUTABLE)
if (${OUTPUT_FILENAME} MATCHES "\\.jp2$")
add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-jpylyser
COMMAND ${JPYLYZER_EXECUTABLE}
${OUTPUT_FILENAME}
)
set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-jpylyser PROPERTIES
DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode
PASS_REGULAR_EXPRESSION "<isValidJP2>True</isValidJP2>"
)
endif()
endif(JPYLYZER_EXECUTABLE)
# If lossless compression (simple test is 4 arguments), decompress & compare
list(LENGTH CMD_ARG_LIST_2 ARG_COUNT)
if (ARG_COUNT EQUAL 4)
# can we compare with the input image ?
if (${INPUT_FILENAME_NAME} MATCHES "\\.tif$")
add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode
COMMAND opj_decompress -i ${OUTPUT_FILENAME} -o ${OUTPUT_FILENAME}.lossless.tif
)
set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode PROPERTIES
DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode
)
add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare
COMMAND compare_images -b ${INPUT_FILENAME} -t ${OUTPUT_FILENAME}.lossless.tif -n 1 -d
)
set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare PROPERTIES
DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode
)
endif()
endif()
endif()
# DECODER TEST SUITE # DECODER TEST SUITE
ELSE(ENC_TEST_FOUND) else()
string(FIND ${INPUT_FILENAME} "nonregression" nr_pos)
if(${nr_pos} GREATER 0)
list(APPEND nonregression_filenames_used ${INPUT_FILENAME_NAME})
endif()
math(EXPR IT_TEST_DEC "${IT_TEST_DEC}+1" ) math(EXPR IT_TEST_DEC "${IT_TEST_DEC}+1" )
# Decode the input image # Decode the input image
@ -240,13 +398,17 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
# if not failed, check against registered md5: # if not failed, check against registered md5:
add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 COMMAND ${CMAKE_COMMAND} add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 COMMAND ${CMAKE_COMMAND}
-DREFFILE:STRING=${CMAKE_CURRENT_SOURCE_DIR}/md5refs.txt -DREFFILE:STRING=${CMAKE_CURRENT_SOURCE_DIR}/md5refs.txt
-DFILENAME:STRING=${INPUT_FILENAME_NAME} -DOUTFILENAME:STRING=${OUTPUT_FILENAME}
-P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake)
set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5
PROPERTIES DEPENDS NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode
)
# FIXME: add a compare2base function base on raw which # FIXME: add a compare2base function base on raw which
# can output png diff files if necesary # can output png diff files if necesary
# ADD_TEST(NAME NR-${filename}-compare2base # add_test(NR-${filename}-compare2base
# COMMAND comparePGXimages # ${EXECUTABLE_OUTPUT_PATH}/compare_images
# -b ${BASELINE_NR}/opj_${filenameRef} # -b ${BASELINE_NR}/opj_${filenameRef}
# -t ${TEMP}/${filename}.pgx # -t ${TEMP}/${filename}.pgx
# -n ${nbComponents} # -n ${nbComponents}
@ -258,30 +420,27 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
# PROPERTIES DEPENDS # PROPERTIES DEPENDS
# NR-${filename}-decode) # NR-${filename}-decode)
# Dump the input image endif()
ADD_TEST(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-dump
COMMAND j2k_dump
-i ${INPUT_FILENAME}
-o ${TEMP}/${INPUT_FILENAME_NAME}.txt
)
# Compare the dump output with the baseline endif()
ADD_TEST(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-compare_dump2base
COMMAND compare_dump_files
-b ${BASELINE_NR}/opj_${INPUT_FILENAME_NAME_WE}.txt
-t ${TEMP}/${INPUT_FILENAME_NAME}.txt
)
SET_TESTS_PROPERTIES(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-compare_dump2base endif()
PROPERTIES DEPENDS
NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-dump)
endforeach()
ENDIF(FAILED_TEST_FOUND) set(existing_filenames)
foreach(f ${OPJ_DATA_NR_LIST})
get_filename_component(ff ${f} NAME)
list(APPEND existing_filenames ${ff})
endforeach()
if(existing_filenames)
list(REMOVE_ITEM existing_filenames ${nonregression_filenames_used})
endif()
ENDIF(ENC_TEST_FOUND) # keep track of new addition:
# if we reach here, then a J2K files was added but no test is present in
ENDIF(IGNORE_LINE_FOUND) # test_suite.ctest.in:
foreach(found_but_no_test ${existing_filenames})
ENDFOREACH(OPJ_TEST_CMD_LINE) add_test(NAME Found-But-No-Test-${found_but_no_test} COMMAND ${CMAKE_COMMAND} -E echo "${found_but_no_test}")
set_tests_properties(Found-But-No-Test-${found_but_no_test} PROPERTIES WILL_FAIL TRUE)
endforeach()

142
tests/pdf2jp2.c Normal file
View File

@ -0,0 +1,142 @@
/*
* Copyright (c) 2014, Mathieu Malaterre <mathieu.malaterre@voxxl.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Extract all JP2 files contained within a PDF file.
*
* Technically you could simply use mutool, eg:
*
* $ mutool show -be -o obj58.jp2 Bug691816.pdf 58
*
* to extract a given JP2 file from within a PDF
* However it happens sometimes that the PDF is itself corrupted, this tools is
* a lame PDF parser which only extract stream contained in JPXDecode box
* only work on linux since I need memmem function
*/
/*
* Add support for other signatures:
*
* obj<</Subtype/Image/Length 110494/Filter/JPXDecode/BitsPerComponent 8/ColorSpace/DeviceRGB/Width 712/Height 1052>>stream
*/
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <assert.h>
int main(int argc, char *argv[])
{
#define NUMJP2 32
int i, c = 0;
long offets[NUMJP2];
char buffer[512];
#define BUFLEN 4096
int cont = 1;
FILE *f;
size_t nread;
char haystack[BUFLEN];
const char needle[] = "JPXDecode";
const size_t nlen = strlen( needle );
const size_t flen = BUFLEN - nlen;
char *fpos = haystack + nlen;
const char *filename;
if( argc < 2 ) return 1;
filename = argv[1];
memset( haystack, 0, nlen );
f = fopen( filename, "rb" );
while( cont )
{
const char *ret;
size_t hlen;
nread = fread(fpos, 1, flen, f);
hlen = nlen + nread;
ret = memmem( haystack, hlen, needle, nlen);
if( ret )
{
const long cpos = ftell(f);
const ptrdiff_t diff = ret - haystack;
assert( diff >= 0 );
/*fprintf( stdout, "Found it: %lx\n", (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff);*/
offets[c++] = (ptrdiff_t)cpos - (ptrdiff_t)hlen + diff;
}
cont = (nread == flen);
memcpy( haystack, haystack + nread, nlen );
}
assert( feof( f ) );
for( i = 0; i < c; ++i )
{
int s, len = 0;
char *r;
const int ret = fseek(f, offets[i], SEEK_SET);
assert( ret == 0 );
r = fgets(buffer, sizeof(buffer), f);
assert( r );
/*fprintf( stderr, "DEBUG: %s", r );*/
s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len);
if( s == 0 )
{ // try again harder
const int ret = fseek(f, offets[i] - 40, SEEK_SET); // 40 is magic number
assert( ret == 0 );
r = fgets(buffer, sizeof(buffer), f);
assert( r );
const char needle2[] = "/Length";
char * s2 = strstr(buffer, needle2);
s = sscanf(s2, "/Length %d/", &len);
}
if( s == 1 )
{
FILE *jp2;
int j;
char jp2fn[512];
sprintf( jp2fn, "%s.%d.jp2", filename, i );
jp2 = fopen( jp2fn, "wb" );
for( j = 0; j < len; ++j )
{
int v = fgetc(f);
int ret2 = fputc(v, jp2);
assert( ret2 != EOF );
}
fclose( jp2 );
#if 0
/* TODO need to check we reached endstream */
r = fgets(buffer, sizeof(buffer), f);
fprintf( stderr, "DEBUG: [%s]", r );
r = fgets(buffer, sizeof(buffer), f);
fprintf( stderr, "DEBUG: [%s]", r );
#endif
}
}
fclose(f);
return 0;
}

139
tests/ppm2rgb3.c Normal file
View File

@ -0,0 +1,139 @@
/*
* Copyright (c) 2014, Mathieu Malaterre <mathieu.malaterre@voxxl.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Technically on UNIX, one can simply call `ppmtorgb3`, but on my system it
* did not work. So I had to write my own.
*/
#include <stdio.h> /* fprintf */
#include <string.h> /* strcmp */
#include <stdlib.h> /* malloc */
static const char magic[] = "P6";
static int readheader( FILE *ppm, int *X, int *Y, int *bpp )
{
char buffer[256];
char strbuffer[256];
char *line;
int n;
*X = *Y = *bpp = 0;
line = fgets(buffer, sizeof(buffer), ppm);
if( !line ) return 0;
n = sscanf(buffer, "%255[^\r\n]", strbuffer);
if( n != 1 ) return 0;
if( strcmp(strbuffer, magic ) != 0 ) return 0;
/* skip comments */
while( fgets(buffer, sizeof(buffer), ppm) && *buffer == '#' )
{
}
n = sscanf(buffer, "%d %d", X,Y);
if( n != 2 ) return 0;
line = fgets(buffer, sizeof(buffer), ppm);
if( !line ) return 0;
n = sscanf(buffer, "%d", bpp);
if( n != 1 ) return 0;
if( *bpp != 255 ) return 0;
return 1;
}
static int writeoutput( const char *fn, FILE *ppm, int X, int Y, int bpp )
{
FILE *outf[] = {NULL, NULL, NULL};
int i, x, y = 0;
char outfn[256];
static const char *exts[3] = {
"red",
"grn",
"blu"
};
char *image_line = NULL;
int ok = 0;
/* write single comp as PGM: P5 */
for( i = 0; i < 3; ++i )
{
#ifdef _MSC_VER
#define snprintf _snprintf /* Visual Studio */
#endif
snprintf( outfn, sizeof(outfn), "%s.%s.pgm", fn, exts[i] );
outf[i] = fopen( outfn, "wb" );
if( !outf[i] ) goto cleanup;
/* write header */
fprintf( outf[i], "P5\n" );
fprintf( outf[i], "%d %d\n", X, Y );
fprintf( outf[i], "%d\n", bpp );
}
/* write pixel data */
image_line = (char*)malloc( (size_t)X * 3 * sizeof(char) );
if( !image_line ) goto cleanup;
while( fread(image_line, sizeof(char), (size_t)X * 3, ppm) == (size_t)X * 3 )
{
for( x = 0; x < X; ++x )
for( i = 0; i < 3; ++i )
if( fputc( image_line[3*x+i], outf[i] ) == EOF ) goto cleanup;
++y;
}
if( y == Y )
ok = 1;
cleanup:
free(image_line);
for( i = 0; i < 3; ++i )
if( outf[i] ) fclose( outf[i] );
return ok;
}
int main(int argc, char *argv[])
{
const char *fn;
FILE *ppm = NULL;
int X, Y, bpp;
int ok = 0;
if( argc < 2 )
{
fprintf( stderr, "%s input.ppm\n", argv[0] );
goto cleanup;
}
fn = argv[1];
ppm = fopen( fn, "rb" );
if( !readheader( ppm, &X, &Y, &bpp ) ) goto cleanup;
if( !writeoutput(fn, ppm, X, Y, bpp ) ) goto cleanup;
ok = 1;
cleanup:
if(ppm) fclose(ppm);
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}

7
tests/unit/testempty0.c Normal file
View File

@ -0,0 +1,7 @@
#include "openjpeg.h"
int main(int argc, char **argv) {
(void)argc;
(void)argv;
return 0;
}