2 * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
28 * compare_dump_files.c
30 * Created on: 25 juil. 2011
40 #include "opj_getopt.h"
42 typedef struct test_cmp_parameters
48 } test_cmp_parameters;
50 /*******************************************************************************
51 * Command line help function
52 *******************************************************************************/
53 static void compare_dump_files_help_display(void) {
54 fprintf(stdout,"\nList of parameters for the compare_dump_files function \n");
56 fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n");
57 fprintf(stdout," -t \t REQUIRED \t filename to the test dump file image\n");
60 /*******************************************************************************
62 *******************************************************************************/
63 static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
65 size_t sizemembasefile, sizememtestfile;
67 const char optlist[] = "b:t:";
71 param->base_filename = NULL;
72 param->test_filename = NULL;
76 while ((c = opj_getopt(argc, argv, optlist)) != -1)
80 sizemembasefile = strlen(opj_optarg) + 1;
81 param->base_filename = (char*) malloc(sizemembasefile);
82 strcpy(param->base_filename, opj_optarg);
83 /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
86 sizememtestfile = strlen(opj_optarg) + 1;
87 param->test_filename = (char*) malloc(sizememtestfile);
88 strcpy(param->test_filename, opj_optarg);
89 /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
92 if ( (opj_optopt == 'b') || (opj_optopt == 't') )
93 fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
95 if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
96 else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
99 fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
103 if (opj_optind != argc)
105 for (index = opj_optind; index < argc; index++)
106 fprintf(stderr,"Non-option argument %s\n", argv[index]);
113 /*******************************************************************************
115 *******************************************************************************/
116 int main(int argc, char **argv)
118 test_cmp_parameters inParam;
119 FILE *fbase=NULL, *ftest=NULL;
126 if( parse_cmdline_cmp(argc, argv, &inParam) == 1 )
128 compare_dump_files_help_display();
132 /* Display Parameters*/
133 printf("******Parameters********* \n");
134 printf(" base_filename = %s\n"
135 " test_filename = %s\n",
136 inParam.base_filename, inParam.test_filename);
137 printf("************************* \n");
140 printf("Try to open: %s for reading ... ", inParam.base_filename);
141 if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
148 printf("Try to open: %s for reading ... ", inParam.test_filename);
149 if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
155 while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest))
157 int nbase = sscanf(lbase, "%511[^\r\n]", strbase);
158 int ntest = sscanf(ltest, "%511[^\r\n]", strtest);
159 assert( nbase != 511 && ntest != 511 );
160 if( nbase != 1 || ntest != 1 )
162 fprintf(stderr, "could not parse line from files\n" );
165 if( strcmp( strbase, strtest ) != 0 )
167 fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest);
173 printf("\n***** TEST SUCCEED: Files are the same. *****\n");
176 if(fbase) fclose(fbase);
177 if(ftest) fclose(ftest);
180 free(inParam.base_filename);
181 free(inParam.test_filename);
183 return same ? EXIT_SUCCESS : EXIT_FAILURE;