From 1776120dba3610c83a27602dbcf6fcf9a9fa5d7d Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 26 Jul 2011 13:49:27 +0000 Subject: [PATCH] correct CRLF problem between unix baseline and win platform test file generated by j2k_dump --- CHANGES | 1 + tests/compare_dump_files.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index c3a24e90..05ee2532 100644 --- 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 diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index a8f573ae..2340dfb7 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -3,6 +3,7 @@ * * Created on: 25 juil. 2011 * Author: mickael + * BASELINE MUST BE GENERATED BY UNIX PLATFORM REGARDING TO THE CRLF PROBLEM */ #include @@ -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);