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);