correct CRLF problem between unix baseline and win platform test file generated by...
authorMickael Savinaud <savmickael@users.noreply.github.com>
Tue, 26 Jul 2011 13:49:27 +0000 (13:49 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Tue, 26 Jul 2011 13:49:27 +0000 (13:49 +0000)
CHANGES
tests/compare_dump_files.c

diff --git a/CHANGES b/CHANGES
index c3a24e9055d658d1c7ab3a205e2dd2d947ec31aa..05ee2532b970f84d9886f4c46748a6d2f01cb0bc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,7 @@ What's New for OpenJPEG
 July 26, 2011
 ! [mickael] delete double semi-colon at end of line which generate crash on win platform
 ! [mickael] use ansi c function fgets instead of GNU function getline to avoid build error with win platform
+! [mickael] correct CRLF problem between unix baseline and win platform test file generated by j2k_dump
 
 July 25, 2011
 * [mickael] fixed issue 74 for trunk
index a8f573ae0be99dbe9db7539c2ef28d911d1f2b75..2340dfb72999101ef662e997b15336b37189c239 100644 (file)
@@ -3,6 +3,7 @@
  *
  *  Created on: 25 juil. 2011
  *      Author: mickael
+ * BASELINE MUST BE GENERATED BY UNIX PLATFORM REGARDING TO THE CRLF PROBLEM
  */
 
 #include <stdio.h>
@@ -93,7 +94,7 @@ int main(int argc, char **argv)
 {
   test_cmp_parameters inParam;
   FILE *fbase=NULL, *ftest=NULL;
-  char chbase, chtest;
+  int chbase, chtest;
   int same = 1;
   unsigned long l=1, pos;
 
@@ -153,25 +154,39 @@ int main(int argc, char **argv)
       return EXIT_FAILURE;
       }
 
+    // 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);
       fgets(strbase, nbytes, fbase);
       fgets(strtest, nbytes, ftest);
-      strbase_d = (char *) malloc(strlen(strbase));
-      strtest_d = (char *) malloc(strlen(strtest));
+      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)-1);
-      strbase_d[strlen(strbase)] = '\0';
-      strtest_d[strlen(strtest)] = '\0';
+      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);free(strtest);