Commit 2cc5f1e4 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Add handling of %ws, %S and %C to _vns(w)printf, improve sprintf

tests.
parent ca7b25ca
......@@ -484,8 +484,8 @@
@ cdecl _unloaddll(long)
@ cdecl _unlock(long)
@ cdecl _utime(str ptr)
@ cdecl _vsnprintf(ptr long ptr ptr) vsnprintf
@ cdecl _vsnwprintf(ptr long wstr long)
@ cdecl _vsnprintf(ptr long ptr ptr) MSVCRT_vsnprintf
@ cdecl _vsnwprintf(ptr long wstr long) MSVCRT_vsnwprintf
@ cdecl _waccess(wstr long)
@ stub _wasctime #(ptr) MSVCRT__wasctime
@ cdecl _wchdir(wstr)
......@@ -693,7 +693,7 @@
@ cdecl signal(long long) MSVCRT_signal
@ cdecl sin(double)
@ cdecl sinh(double)
@ varargs sprintf(ptr str)
@ varargs sprintf(ptr str) MSVCRT_sprintf
@ cdecl sqrt(double)
@ cdecl srand(long)
@ varargs sscanf(str str) MSVCRT_sscanf
......
......@@ -3,6 +3,7 @@
*
* Copyright 2002 Uwe Bonnes
* Copyright 2004 Aneurin Price
* Copyright 2005 Mike McCormack
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -26,54 +27,213 @@
static void test_sprintf( void )
{
char buffer[100];
const char *I64d = "%I64d";
const char *O4c = "%04c";
const char *O4s = "%04s";
const char *hash012p = "%#012p";
const char *format;
double pnumber=789456123;
/** WCHAR widestring[]={'w','i','d','e','s','t','r','i','n','g',0};**/
sprintf(buffer,"%+#23.15e",pnumber);
todo_wine
{
ok(strstr(buffer,"e+008") != 0,"Sprintf different \"%s\"\n",buffer);
}
sprintf(buffer,I64d,((ULONGLONG)0xffffffff)*0xffffffff);
todo_wine
{
ok(strlen(buffer) == 11,"Problem with long long \"%s\"\n",buffer);
}
sprintf(buffer,"%lld",((ULONGLONG)0xffffffff)*0xffffffff);
todo_wine
{
ok(strlen(buffer) == 1,"Problem with \"ll\" interpretation \"%s\"\n",buffer);
}
/** This one actually crashes WINE at the moment, when using builtin msvcrt.dll.
sprintf(buffer,"%S",widestring);
todo_wine
{
ok(strlen(buffer) == 10,"Problem with \"%%S\" interpretation \"%s\"\n",buffer);
}
**/
sprintf(buffer,O4c,'1');
todo_wine
{
ok(!strcmp(buffer,"0001"),"Character not zero-prefixed \"%s\"\n",buffer);
}
sprintf(buffer,"%p",(void *)57);
todo_wine
{
ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
}
sprintf(buffer,hash012p,(void *)57);
todo_wine
{
ok(!strcmp(buffer," 0X00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
}
sprintf(buffer,O4s,"foo");/**Warning again**/
todo_wine
{
ok(!strcmp(buffer,"0foo"),"String not zero-prefixed \"%s\"\n",buffer);
}
int x, r;
WCHAR wide[] = { 'w','i','d','e',0};
format = "%+#23.15e";
r = sprintf(buffer,format,pnumber);
todo_wine {
ok(!strcmp(buffer,"+7.894561230000000e+008"),"exponent format incorrect\n");
}
ok( r==23, "return count wrong\n");
todo_wine {
format = "%I64d";
r = sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
ok(!strcmp(buffer,"-8589934591"),"Problem with long long\n");
ok( r==11, "return count wrong\n");
}
format = "%lld";
r = sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
ok(!strcmp(buffer, "1"), "Problem with \"ll\" interpretation\n");
ok( r==1, "return count wrong\n");
format = "%S";
r = sprintf(buffer,format,wide);
ok(!strcmp(buffer,"wide"),"Problem with wide string format\n");
ok( r==4, "return count wrong\n");
format = "%04c";
r = sprintf(buffer,format,'1');
ok(!strcmp(buffer,"0001"),"Character not zero-prefixed \"%s\"\n",buffer);
ok( r==4, "return count wrong\n");
format = "%p";
r = sprintf(buffer,format,(void *)57);
ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
ok( r==8, "return count wrong\n");
format = "%#012p";
r = sprintf(buffer,format,(void *)57);
ok(!strcmp(buffer," 0X00000039"),"Pointer formatted incorrectly\n");
ok( r==12, "return count wrong\n");
format = "%04s";
r = sprintf(buffer,format,"foo");
ok(!strcmp(buffer,"0foo"),"String not zero-prefixed \"%s\"\n",buffer);
ok( r==4, "return count wrong\n");
format = "%#-012p";
r = sprintf(buffer,format,(void *)57);
ok(!strcmp(buffer,"0X00000039 "),"Pointer formatted incorrectly\n");
ok( r==12, "return count wrong\n");
format = "hello";
r = sprintf(buffer, format);
ok(!strcmp(buffer,"hello"), "failed\n");
ok( r==5, "return count wrong\n");
format = "%ws";
r = sprintf(buffer, format, wide);
ok(!strcmp(buffer,"wide"), "failed\n");
ok( r==4, "return count wrong\n");
format = "%-10ws";
r = sprintf(buffer, format, wide );
ok(!strcmp(buffer,"wide "), "failed\n");
ok( r==10, "return count wrong\n");
format = "%10ws";
r = sprintf(buffer, format, wide );
ok(!strcmp(buffer," wide"), "failed\n");
ok( r==10, "return count wrong\n");
format = "%#+ -03whlls";
r = sprintf(buffer, format, wide );
ok(!strcmp(buffer,"wide"), "failed\n");
ok( r==4, "return count wrong\n");
format = "%w0s";
r = sprintf(buffer, format, wide );
ok(!strcmp(buffer,"0s"), "failed\n");
ok( r==2, "return count wrong\n");
format = "%w-s";
r = sprintf(buffer, format, wide );
ok(!strcmp(buffer,"-s"), "failed\n");
ok( r==2, "return count wrong\n");
format = "%b";
r = sprintf(buffer, format);
ok(!strcmp(buffer,"b"), "failed\n");
ok( r==1, "return count wrong\n");
format = "%3c";
r = sprintf(buffer, format,'a');
ok(!strcmp(buffer," a"), "failed\n");
ok( r==3, "return count wrong\n");
format = "%3d";
r = sprintf(buffer, format,1234);
ok(!strcmp(buffer,"1234"), "failed\n");
ok( r==4, "return count wrong\n");
format = "%3h";
r = sprintf(buffer, format);
ok(!strcmp(buffer,""), "failed\n");
ok( r==0, "return count wrong\n");
format = "%j%k%m%q%r%t%v%y%z";
r = sprintf(buffer, format);
ok(!strcmp(buffer,"jkmqrtvyz"), "failed\n");
ok( r==9, "return count wrong\n");
format = "asdf%n";
x = 0;
r = sprintf(buffer, format, &x );
ok(x == 4, "should write to x\n");
ok(!strcmp(buffer,"asdf"), "failed\n");
ok( r==4, "return count wrong\n");
format = "%-1d";
r = sprintf(buffer, format,2);
ok(!strcmp(buffer,"2"), "failed\n");
ok( r==1, "return count wrong\n");
format = "%2.4f";
r = sprintf(buffer, format,8.6);
ok(!strcmp(buffer,"8.6000"), "failed\n");
ok( r==6, "return count wrong\n");
todo_wine {
format = "%2.4e";
r = sprintf(buffer, format,8.6);
ok(!strcmp(buffer,"8.6000e+000"), "failed\n");
ok( r==11, "return count wrong\n");
}
format = "%2.4g";
r = sprintf(buffer, format,8.6);
ok(!strcmp(buffer,"8.6"), "failed\n");
ok( r==3, "return count wrong\n");
format = "%-i";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,"-1"), "failed\n");
ok( r==2, "return count wrong\n");
format = "%-i";
r = sprintf(buffer, format,1);
ok(!strcmp(buffer,"1"), "failed\n");
ok( r==1, "return count wrong\n");
format = "%+i";
r = sprintf(buffer, format,1);
ok(!strcmp(buffer,"+1"), "failed\n");
ok( r==2, "return count wrong\n");
format = "%o";
r = sprintf(buffer, format,10);
ok(!strcmp(buffer,"12"), "failed\n");
ok( r==2, "return count wrong\n");
format = "%p";
r = sprintf(buffer, format,0);
ok(!strcmp(buffer,"00000000"), "failed\n");
ok( r==8, "return count wrong\n");
format = "%s";
r = sprintf(buffer, format,0);
ok(!strcmp(buffer,"(null)"), "failed\n");
ok( r==6, "return count wrong\n");
format = "%s";
r = sprintf(buffer, format,"%%%%");
ok(!strcmp(buffer,"%%%%"), "failed\n");
ok( r==4, "return count wrong\n");
format = "%u";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,"4294967295"), "failed\n");
ok( r==10, "return count wrong\n");
format = "%w";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,""), "failed\n");
ok( r==0, "return count wrong\n");
format = "%h";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,""), "failed\n");
ok( r==0, "return count wrong\n");
format = "%z";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,"z"), "failed\n");
ok( r==1, "return count wrong\n");
format = "%j";
r = sprintf(buffer, format,-1);
ok(!strcmp(buffer,"j"), "failed\n");
ok( r==1, "return count wrong\n");
format = "x%cx";
r = sprintf(buffer, format, 0x100+'X');
ok(!strcmp(buffer,"xXx"), "failed\n");
ok( r==3, "return count wrong\n");
}
static void test_swprintf( void )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment