summaryrefslogtreecommitdiff
path: root/tests/compare_dump_files.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/compare_dump_files.c')
-rw-r--r--tests/compare_dump_files.c217
1 files changed, 104 insertions, 113 deletions
diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c
index 946c92a5..c14cb716 100644
--- a/tests/compare_dump_files.c
+++ b/tests/compare_dump_files.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
+ * 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
@@ -39,75 +39,72 @@
#include "opj_getopt.h"
-typedef struct test_cmp_parameters
-{
- /** */
- char* base_filename;
- /** */
- char* test_filename;
+typedef struct test_cmp_parameters {
+ /** */
+ char* base_filename;
+ /** */
+ char* test_filename;
} test_cmp_parameters;
/*******************************************************************************
* Command line help function
*******************************************************************************/
-static void compare_dump_files_help_display(void) {
- fprintf(stdout,"\nList of parameters for the compare_dump_files function \n");
- fprintf(stdout,"\n");
- fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n");
- fprintf(stdout," -t \t REQUIRED \t filename to the test dump file image\n");
- fprintf(stdout,"\n");
+static void compare_dump_files_help_display(void)
+{
+ fprintf(stdout,"\nList of parameters for the compare_dump_files function \n");
+ fprintf(stdout,"\n");
+ fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n");
+ fprintf(stdout," -t \t REQUIRED \t filename to the test dump file 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;
- 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;
- 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;
+ 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;
+ 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;
+ 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;
+ return 0;
}
/*******************************************************************************
@@ -115,70 +112,64 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
*******************************************************************************/
int main(int argc, char **argv)
{
- test_cmp_parameters inParam;
- FILE *fbase=NULL, *ftest=NULL;
- int same = 0;
- char lbase[256];
- char strbase[256];
- char ltest[256];
- char strtest[256];
-
- if( parse_cmdline_cmp(argc, argv, &inParam) == 1 )
- {
- compare_dump_files_help_display();
- goto cleanup;
+ test_cmp_parameters inParam;
+ FILE *fbase=NULL, *ftest=NULL;
+ int same = 0;
+ char lbase[256];
+ char strbase[256];
+ char ltest[256];
+ char strtest[256];
+
+ if( parse_cmdline_cmp(argc, argv, &inParam) == 1 ) {
+ compare_dump_files_help_display();
+ goto cleanup;
}
- /* Display Parameters*/
- printf("******Parameters********* \n");
- printf(" base_filename = %s\n"
- " test_filename = %s\n",
- inParam.base_filename, inParam.test_filename);
- printf("************************* \n");
-
- /* open base file */
- printf("Try to open: %s for reading ... ", inParam.base_filename);
- if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
- {
- goto cleanup;
+ /* Display Parameters*/
+ printf("******Parameters********* \n");
+ printf(" base_filename = %s\n"
+ " test_filename = %s\n",
+ inParam.base_filename, inParam.test_filename);
+ printf("************************* \n");
+
+ /* open base file */
+ printf("Try to open: %s for reading ... ", inParam.base_filename);
+ if((fbase = fopen(inParam.base_filename, "rb"))==NULL) {
+ goto cleanup;
}
- printf("Ok.\n");
+ printf("Ok.\n");
- /* open test file */
- printf("Try to open: %s for reading ... ", inParam.test_filename);
- if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
- {
- goto cleanup;
+ /* open test file */
+ printf("Try to open: %s for reading ... ", inParam.test_filename);
+ if((ftest = fopen(inParam.test_filename, "rb"))==NULL) {
+ goto cleanup;
}
- printf("Ok.\n");
-
- while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest))
- {
- int nbase = sscanf(lbase, "%255[^\r\n]", strbase);
- int ntest = sscanf(ltest, "%255[^\r\n]", strtest);
- assert( nbase != 255 && ntest != 255 );
- if( nbase != 1 || ntest != 1 )
- {
- fprintf(stderr, "could not parse line from files\n" );
- goto cleanup;
- }
- if( strcmp( strbase, strtest ) != 0 )
- {
- fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest);
- goto cleanup;
- }
+ printf("Ok.\n");
+
+ while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest)) {
+ int nbase = sscanf(lbase, "%255[^\r\n]", strbase);
+ int ntest = sscanf(ltest, "%255[^\r\n]", strtest);
+ assert( nbase != 255 && ntest != 255 );
+ if( nbase != 1 || ntest != 1 ) {
+ fprintf(stderr, "could not parse line from files\n" );
+ goto cleanup;
+ }
+ if( strcmp( strbase, strtest ) != 0 ) {
+ fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest);
+ goto cleanup;
+ }
}
- same = 1;
- printf("\n***** TEST SUCCEED: Files are the same. *****\n");
+ same = 1;
+ printf("\n***** TEST SUCCEED: Files are the same. *****\n");
cleanup:
- /*Close File*/
- if(fbase) fclose(fbase);
- if(ftest) fclose(ftest);
+ /*Close File*/
+ if(fbase) fclose(fbase);
+ if(ftest) fclose(ftest);
- /* Free memory*/
- free(inParam.base_filename);
- free(inParam.test_filename);
+ /* Free memory*/
+ free(inParam.base_filename);
+ free(inParam.test_filename);
- return same ? EXIT_SUCCESS : EXIT_FAILURE;
+ return same ? EXIT_SUCCESS : EXIT_FAILURE;
}