kernel32/tests: Fix some incorrect FormatMessage() tests.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-05-07 16:16:34 +02:00
parent a946e7fbbe
commit f00b88eabd
1 changed files with 22 additions and 30 deletions

View File

@ -140,24 +140,19 @@ static void test_message_from_string_wide(void)
ok(!lstrcmpW(L"test", out), "failed out=%s\n", wine_dbgstr_w(out)); ok(!lstrcmpW(L"test", out), "failed out=%s\n", wine_dbgstr_w(out));
ok(r==4,"failed: r=%d\n", r); ok(r==4,"failed: r=%d\n", r);
/* s doesn't seem to work in format strings */ /* ls is unicode */
r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%!s!", 0, 0, out, ARRAY_SIZE(out), L"test"); r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%1!ls!", 0, 0, out, ARRAY_SIZE(out), L"test");
ok(!lstrcmpW(L"!s!", out), "failed out=%s\n", wine_dbgstr_w(out)); ok(!lstrcmpW(L"test", out), "failed out=%s\n", wine_dbgstr_w(out));
ok(r==3, "failed: r=%d\n", r);
/* nor ls */
r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%!ls!", 0, 0, out, ARRAY_SIZE(out), L"test");
ok(!lstrcmpW(L"!ls!", out), "failed out=%s\n", wine_dbgstr_w(out));
ok(r==4, "failed: r=%d\n", r); ok(r==4, "failed: r=%d\n", r);
/* nor S */ /* S is ascii */
r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%!S!", 0, 0, out, ARRAY_SIZE(out), L"test"); r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%1!S!", 0, 0, out, ARRAY_SIZE(out), "test");
ok(!lstrcmpW(L"!S!", out), "failed out=%s\n", wine_dbgstr_w(out)); ok(!lstrcmpW(L"test", out), "failed out=%s\n", wine_dbgstr_w(out));
ok(r==3, "failed: r=%d\n", r); ok(r==4, "failed: r=%d\n", r);
/* nor ws */ /* ws is unicode */
r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%!ws!", 0, 0, out, ARRAY_SIZE(out), L"test"); r = doitW(FORMAT_MESSAGE_FROM_STRING, L"%1!ws!", 0, 0, out, ARRAY_SIZE(out), L"test");
ok(!lstrcmpW(L"!ws!", out), "failed out=%s\n", wine_dbgstr_w(out)); ok(!lstrcmpW(L"test", out), "failed out=%s\n", wine_dbgstr_w(out));
ok(r==4, "failed: r=%d\n", r); ok(r==4, "failed: r=%d\n", r);
/* as characters */ /* as characters */
@ -423,10 +418,10 @@ static void test_message_from_string(void)
ok(!strcmp("test", out),"failed out=[%s]\n",out); ok(!strcmp("test", out),"failed out=[%s]\n",out);
ok(r==4,"failed: r=%d\n",r); ok(r==4,"failed: r=%d\n",r);
/* s doesn't seem to work in format strings */ /* s is ascii */
r = doit(FORMAT_MESSAGE_FROM_STRING, "%!s!", 0, 0, out, ARRAY_SIZE(out), "test"); r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!s!", 0, 0, out, ARRAY_SIZE(out), "test");
ok(!strcmp("!s!", out),"failed out=[%s]\n",out); ok(!strcmp("test", out),"failed out=[%s]\n",out);
ok(r==3,"failed: r=%d\n",r); ok(r==4,"failed: r=%d\n",r);
/* ls is unicode */ /* ls is unicode */
r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!ls!", 0, 0, out, ARRAY_SIZE(out), L"test"); r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!ls!", 0, 0, out, ARRAY_SIZE(out), L"test");
@ -1051,9 +1046,6 @@ static void test_message_insufficient_buffer(void)
static void test_message_insufficient_buffer_wide(void) static void test_message_insufficient_buffer_wide(void)
{ {
static const WCHAR broken_buf[] = L"\0xxxxx";
static const WCHAR broken2_buf[] = L"tes\0x";
DWORD ret; DWORD ret;
WCHAR out[8]; WCHAR out[8];
@ -1067,8 +1059,6 @@ static void test_message_insufficient_buffer_wide(void)
ok(!lstrcmpW( out, L"xxxxxx" ), ok(!lstrcmpW( out, L"xxxxxx" ),
"Expected the buffer to be untouched\n"); "Expected the buffer to be untouched\n");
/* Windows Server 2003 and newer report failure but copy a
* truncated string to the buffer for non-zero buffer sizes. */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
lstrcpyW( out, L"xxxxxx" ); lstrcpyW( out, L"xxxxxx" );
ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, L"test", 0, 0, out, 1, NULL); ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, L"test", 0, 0, out, 1, NULL);
@ -1076,9 +1066,10 @@ static void test_message_insufficient_buffer_wide(void)
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n", "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
GetLastError()); GetLastError());
ok(!lstrcmpW( out, L"xxxxxx" ) || todo_wine
broken(!memcmp(broken_buf, out, sizeof(broken_buf))), /* W2K3+ */ ok(!memcmp(out, L"\0xxxxx", 6 * sizeof(WCHAR)) ||
"Expected the buffer to be untouched\n"); broken(!lstrcmpW( out, L"xxxxxx" )), /* winxp */
"Expected the buffer to be truncated\n");
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
lstrcpyW( out, L"xxxxxx" ); lstrcpyW( out, L"xxxxxx" );
@ -1087,9 +1078,10 @@ static void test_message_insufficient_buffer_wide(void)
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n", "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
GetLastError()); GetLastError());
ok(!lstrcmpW( out, L"xxxxxx" ) || todo_wine
broken(!memcmp(broken2_buf, out, sizeof(broken2_buf))), /* W2K3+ */ ok(!memcmp(out, L"tes\0xx", 6 * sizeof(WCHAR)) ||
"Expected the buffer to be untouched\n"); broken(!lstrcmpW( out, L"xxxxxx" )), /* winxp */
"Expected the buffer to be truncated\n");
} }
static void test_message_null_buffer(void) static void test_message_null_buffer(void)