# HG changeset patch # User ali # Date 1327708791 0 # Node ID cf332d440466601401a5a8ce21918dee775cec27 # Parent 721e468c10f34914f9b79eb346e13dc95ddfdd27 Add a testcase for embedded LFs diff -r 721e468c10f3 -r cf332d440466 test/compatibility/Makefile.am --- a/test/compatibility/Makefile.am Fri Jan 27 21:40:35 2012 +0000 +++ b/test/compatibility/Makefile.am Fri Jan 27 23:59:51 2012 +0000 @@ -2,6 +2,6 @@ TESTS=missing-space.tst spaced-punctuation.tst html-tag.tst html-symbol.tst \ spaced-doublequote.tst mismatched-quotes.tst he-be.tst digits.tst \ extra-period.tst ellipsis.tst short-line.tst abbreviation.tst \ - example.tst non-ascii.tst + example.tst non-ascii.tst embedded-lf.tst dist_pkgdata_DATA=$(TESTS) diff -r 721e468c10f3 -r cf332d440466 test/compatibility/embedded-lf.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compatibility/embedded-lf.tst Fri Jan 27 23:59:51 2012 +0000 @@ -0,0 +1,10 @@ +**************** INPUT **************** +Katherine was assailed by a sudden doubt. Had she mailed that letter? Yes,␊she was certain of that. She had run out to the mail box at ten o'clock +at night especially to mail it. What had gone wrong? Why wasn't there␊someone to meet her? +**************** EXPECTED **************** + +Katherine was assailed by a sudden doubt. Had she mailed that letter? Yes, + Line 1 - No CR? + +at night especially to mail it. What had gone wrong? Why wasn't there + Line 3 - No CR? diff -r 721e468c10f3 -r cf332d440466 test/harness/testcase.c --- a/test/harness/testcase.c Fri Jan 27 21:40:35 2012 +0000 +++ b/test/harness/testcase.c Fri Jan 27 23:59:51 2012 +0000 @@ -3,10 +3,6 @@ #include #include #include -#ifdef WIN32 -#include -#endif -#include #include #include "testcase.h" @@ -15,86 +11,12 @@ return g_quark_from_static_string("testcase-error-quark"); } -#if !HAVE_MKSTEMP /* - * An insecure implementation of mkstemp(), for those platforms that - * don't support it. + * As write(), but with error handling. */ -int mkstemp(char *template) +static size_t write_file(int fd,const char *buf,size_t count,GError **error) { - int fd; - char *s; - for(;;) - { - s=g_strdup(template); - mktemp(s); - if (!*s) - { - errno=EEXIST; - g_free(s); - return -1; - } - fd=open(s,O_RDWR|O_CREAT|O_EXCL,0600); - if (fd>0) - { - strcpy(template,s); - g_free(s); - return fd; - } - else - g_free(s); - } -} -#endif /* !HAVE_MKSTEMP */ - -/* - * As write(), but always convert NL to CR NL. - */ -static size_t write_text(int fd,const char *buf,size_t count,GError **error) -{ - size_t i; - FILE *fp; - fd=dup(fd); - if (fd<0) - return -1; -#ifdef WIN32 - if (_setmode(fd,_O_BINARY)<0) - { - close(fd); - g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno), - "Failed to set mode of bookloupe input file to binary: %s", - g_strerror(errno)); - return -1; - } -#endif - fp=fdopen(fd,"wb"); - if (!fp) - { - close(fd); - g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno), - "Failed to open stream to bookloupe input file: %s", - g_strerror(errno)); - return -1; - } - for(i=0;istr; - col=differs_at-(bol-string->str); + col=0; + s=bol; + endp=string->str+differs_at; + while(sstr,col,""); g_string_free(string,TRUE); } +/* + * Replace \n with \r\n and U+240A (visible symbol for LF) with \n + */ +char *unix2dos(const char *text) +{ + gunichar c; + const gunichar visible_lf=0x240A; + GString *string; + string=g_string_new(NULL); + while(*text) + { + c=g_utf8_get_char(text); + text=g_utf8_next_char(text); + if (c=='\n') + g_string_append(string,"\r\n"); + else if (c==visible_lf) + g_string_append_c(string,'\n'); + else + g_string_append_unichar(string,c); + } + return g_string_free(string,FALSE); +} + gboolean spawn_bootloupe(const char *encoding,const char *standard_input, char **standard_output,char **filename,GError **error) { gboolean r; int fd,exit_status; size_t n,pos,offset; - FILE *fp; char input[]="TEST-XXXXXX"; char *command[3]; - char *output,*s; + char *output,*s,*t; GError *tmp_err=NULL; if (standard_input) { if (encoding) { - s=g_convert(standard_input,-1,encoding,"UTF-8",NULL,&n,&tmp_err); + t=unix2dos(standard_input); + s=g_convert(t,-1,encoding,"UTF-8",NULL,&n,&tmp_err); + g_free(t); if (!s) { g_propagate_prefixed_error(error,tmp_err, @@ -158,7 +127,7 @@ } else { - s=g_strdup(standard_input); + s=unix2dos(standard_input); n=strlen(s); } } @@ -167,8 +136,8 @@ n=0; s=NULL; } - fd=mkstemp(input); - if (n && write_text(fd,s,n,error)!=n) + fd=g_mkstemp(input); + if (n && write_file(fd,s,n,error)!=n) { g_free(s); close(fd); diff -r 721e468c10f3 -r cf332d440466 test/harness/testcaseio.c --- a/test/harness/testcaseio.c Fri Jan 27 21:40:35 2012 +0000 +++ b/test/harness/testcaseio.c Fri Jan 27 23:59:51 2012 +0000 @@ -39,7 +39,7 @@ else if (!testcase->expected && !strcmp(tag,"EXPECTED")) testcase->expected=g_strdup(text); else if (!testcase->encoding && !strcmp(tag,"ENCODING")) - testcase->encoding=g_strdup(text); + testcase->encoding=g_strchomp(g_strdup(text)); else { fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag);