diff options
| author | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-07-26 13:49:27 +0000 |
|---|---|---|
| committer | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-07-26 13:49:27 +0000 |
| commit | 1776120dba3610c83a27602dbcf6fcf9a9fa5d7d (patch) | |
| tree | 80169951b3a5faf6dd4e58a6d3d7f4523f461090 /tests | |
| parent | f4601aff8bc00cdd379814bbae9cbc8a3bbab3c1 (diff) | |
correct CRLF problem between unix baseline and win platform test file generated by j2k_dump
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compare_dump_files.c | 27 |
1 files changed, 21 insertions, 6 deletions
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 <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); |
