2 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
\r
3 * Copyright (c) 2002-2007, Professor Benoit Macq
\r
4 * Copyright (c) 2003-2007, Francois-Olivier Devaux
\r
5 * All rights reserved.
\r
7 * Redistribution and use in source and binary forms, with or without
\r
8 * modification, are permitted provided that the following conditions
\r
10 * 1. Redistributions of source code must retain the above copyright
\r
11 * notice, this list of conditions and the following disclaimer.
\r
12 * 2. Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in the
\r
14 * documentation and/or other materials provided with the distribution.
\r
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
26 * POSSIBILITY OF SUCH DAMAGE.
\r
30 #include <windows.h>
\r
36 #define OPJ_Bin_Dir "OPJ_Binaries"
\r
38 int doprocess(char programme[4096],char command_line[4096]) {
\r
42 int exit=STILL_ACTIVE;
\r
43 STARTUPINFO siStartupInfo;
\r
44 PROCESS_INFORMATION piProcessInfo;
\r
46 memset(&siStartupInfo, 0, sizeof(siStartupInfo));
\r
47 memset(&piProcessInfo, 0, sizeof(piProcessInfo));
\r
48 siStartupInfo.cb = sizeof(siStartupInfo);
\r
50 if(CreateProcess(programme, // Application name
\r
51 command_line, // Application arguments
\r
55 CREATE_DEFAULT_ERROR_MODE,
\r
57 0, // Working directory
\r
59 &piProcessInfo) == FALSE)
\r
63 while(exit==STILL_ACTIVE) {
\r
65 GetExitCodeProcess(piProcessInfo.hProcess,&exit);
\r
70 #else // #ifndef WIN32
\r
71 printf("\n%s\n", command_line);
\r
72 system(command_line);
\r
79 char MD5_process(char *input_filename, char *md5_filename) {
\r
82 unsigned char data[1024];
\r
83 FILE *input_file, *md5_file;
\r
85 input_file = fopen(input_filename, "rb");
\r
87 printf("Error opening file %s\n", input_filename);
\r
91 md5_file = fopen(md5_filename, "wb");
\r
93 printf("Error opening file %s\n", md5_filename);
\r
97 MD5Init (&mdContext);
\r
98 while ((bytes = fread (data, 1, 1024, input_file)) != 0)
\r
99 MD5Update (&mdContext, data, bytes);
\r
100 MD5Final (&mdContext);
\r
102 fwrite(mdContext.digest,16,1,md5_file);
\r
104 fclose(input_file);
\r
110 char fcompare(char *input_filename, char *output_filename) {
\r
111 FILE *input_file, *output_file;
\r
112 unsigned char input_buffer[17], output_buffer[17];
\r
115 input_file = fopen(input_filename, "rb");
\r
117 printf("Error opening file %s\n", input_filename);
\r
121 output_file = fopen(output_filename, "rb");
\r
122 if (!output_file) {
\r
123 printf("Error opening file %s\n", output_filename);
\r
127 fread(input_buffer,16,1,input_file);
\r
128 fread(output_buffer,16,1,output_file);
\r
129 fclose(input_file);
\r
130 fclose(output_file);
\r
131 input_buffer[16] = 0;
\r
132 output_buffer[16] = 0;
\r
134 comparison = strcmp(input_buffer, output_buffer);
\r
141 int main(int argc, char* argv[]) {
\r
142 FILE *param_file, *md5_file;
\r
145 char md5_filename[4096], tempmd5_filename[4096], temp[4096], report_filename[4096];
\r
146 char output_filename[4096];
\r
147 char input_cmdline[4096];
\r
148 char command_line[4096], exefile[4096];
\r
149 int task_counter = 0, word_counter;
\r
150 char bin_dir[4096];
\r
151 unsigned int word_pointer;
\r
154 int num_failed = 0;
\r
155 int num_inexistant = 0;
\r
156 int num_passed = 0;
\r
159 printf("Error with command line. \nExpected: OPJ_Validate parameter_filename bin_directory\n Example: OPJ_Validate parameters_01.txt version1.1.a\n\n");
\r
163 param_file = fopen(argv[1],"rb");
\r
165 printf("Error opening parameter file %s\n",argv[1]);
\r
169 sprintf(bin_dir,"%s/%s",OPJ_Bin_Dir,argv[2]);
\r
170 sprintf(tempmd5_filename,"temp/tempmd5.txt");
\r
171 sprintf(report_filename,"%s/report.txt",bin_dir);
\r
172 report_file = fopen(report_filename, "wb");
\r
173 if (!report_file) {
\r
174 printf("Unable to open report file %s", report_filename);
\r
178 while (fgets(line, 4096, param_file) != NULL) {
\r
180 if (line[0] != '#' && line[0] != 0x0d) { // If not a comment line
\r
181 sscanf(line, "%s", temp);
\r
183 sprintf(input_cmdline,"");
\r
184 sscanf(line+word_pointer,"%s",ch);
\r
185 sprintf(exefile,"%s/%s",bin_dir,ch);
\r
187 while (sscanf(line+word_pointer,"%s",ch) > 0) {
\r
188 if (word_counter == 4)
\r
189 strcpy(output_filename, ch);
\r
190 word_pointer += strlen(ch)+1;
\r
191 sprintf(input_cmdline,"%s%s ",input_cmdline, ch);
\r
194 sprintf(md5_filename,"%s.md5",output_filename);
\r
196 sprintf(command_line,"%s/%s",bin_dir,input_cmdline);
\r
197 printf("Task %d\nMD5 file: %s\nCommand line: \"%s\"\n",task_counter, md5_filename,command_line);
\r
198 fprintf(report_file,"Task %d\n MD5 file: %s\n Command line: \"%s\"\n",task_counter, md5_filename,command_line);
\r
200 if (doprocess(exefile,command_line)) {
\r
201 printf("Error executing: \"%s\" \n", command_line);
\r
202 fprintf(report_file,"Task %d failed because command line is not valid.\n\n", task_counter);
\r
206 // Check if MD5 reference exists
\r
207 md5_file = fopen(md5_filename,"rb");
\r
210 if (MD5_process(output_filename, tempmd5_filename))
\r
213 comparison = fcompare(tempmd5_filename, md5_filename);
\r
214 if (comparison == -1)
\r
216 else if (comparison) {
\r
217 printf("ERROR: %s and %s are different.\nThe codec seems to behave differently.\n\n", tempmd5_filename, md5_filename);
\r
218 fprintf(report_file,"ERROR: %s and %s are different.\nThe codec seems to behave differently.\n\n", tempmd5_filename, md5_filename);
\r
222 printf("%s and %s are the same.\nTask %d OK\n\n",tempmd5_filename, md5_filename, task_counter);
\r
223 fprintf(report_file," %s and %s are the same.\nTask %d OK\n\n",tempmd5_filename, md5_filename, task_counter);
\r
226 remove(tempmd5_filename);
\r
229 if (MD5_process(output_filename, md5_filename))
\r
231 printf("... MD5 of %s was inexistant. It has been created\n\n", output_filename);
\r
232 fprintf(report_file,"MD5 of %s was inexistant. It has been created\n\n", output_filename);
\r
239 printf("\n\REPORT;\n%d tests num_passed\n%d tests num_failed\n%d MD5 were num_inexistant\n", num_passed, num_failed, num_inexistant);
\r
240 fprintf(report_file,"\n\REPORT;\n%d tests num_passed\n%d tests num_failed\n%d MD5 were num_inexistant\n", num_passed, num_failed, num_inexistant);
\r
241 fclose(param_file);
\r
242 fclose(report_file);
\r