Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
8a1656bd
Commit
8a1656bd
authored
May 13, 2020
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32/tests: Add some tests for FormatMessageA/W buffer sizes.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
7b012817
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
2 deletions
+85
-2
format_msg.c
dlls/kernel32/tests/format_msg.c
+85
-2
No files found.
dlls/kernel32/tests/format_msg.c
View file @
8a1656bd
...
...
@@ -1009,7 +1009,7 @@ static void test_message_insufficient_buffer(void)
{
static
const
char
init_buf
[]
=
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
};
static
const
char
expected_buf
[]
=
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
};
DWORD
ret
;
DWORD
ret
,
size
,
i
;
CHAR
out
[
5
];
SetLastError
(
0xdeadbeef
);
...
...
@@ -1041,11 +1041,63 @@ static void test_message_insufficient_buffer(void)
GetLastError
());
ok
(
!
memcmp
(
expected_buf
,
out
,
sizeof
(
expected_buf
)),
"Expected the buffer to be untouched
\n
"
);
for
(
size
=
32700
;
size
<
32800
;
size
++
)
{
char
*
tmp
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
);
char
*
buf
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
tmp
[
i
]
=
'A'
+
i
%
26
;
tmp
[
size
-
1
]
=
0
;
SetLastError
(
0xdeadbeef
);
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
,
tmp
,
0
,
0
,
buf
,
size
,
NULL
);
if
(
size
<
32768
)
{
ok
(
ret
==
size
-
1
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
!
strcmp
(
tmp
,
buf
),
"wrong buffer
\n
"
);
}
else
{
ok
(
ret
==
0
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"wrong error %u
\n
"
,
GetLastError
()
);
}
SetLastError
(
0xdeadbeef
);
ret
=
doit
(
FORMAT_MESSAGE_FROM_STRING
,
"%1"
,
0
,
0
,
buf
,
size
,
tmp
);
if
(
size
<
32768
)
{
ok
(
ret
==
size
-
1
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
!
strcmp
(
tmp
,
buf
),
"wrong buffer
\n
"
);
}
else
{
ok
(
ret
==
0
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
||
broken
(
GetLastError
()
==
ERROR_MORE_DATA
),
/* winxp */
"wrong error %u
\n
"
,
GetLastError
()
);
}
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
SetLastError
(
0xdeadbeef
);
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
tmp
,
0
,
0
,
(
char
*
)
&
buf
,
size
,
NULL
);
if
(
size
<
32768
)
{
ok
(
ret
==
size
-
1
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
!
strcmp
(
tmp
,
buf
),
"wrong buffer
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
}
else
{
ok
(
ret
==
0
,
"%u: got %u
\n
"
,
size
,
ret
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"wrong error %u
\n
"
,
GetLastError
()
);
}
HeapFree
(
GetProcessHeap
(),
0
,
tmp
);
}
}
static
void
test_message_insufficient_buffer_wide
(
void
)
{
DWORD
ret
;
DWORD
ret
,
size
,
i
;
WCHAR
out
[
8
];
SetLastError
(
0xdeadbeef
);
...
...
@@ -1079,6 +1131,28 @@ static void test_message_insufficient_buffer_wide(void)
ok
(
!
memcmp
(
out
,
L"tes
\0
xx"
,
6
*
sizeof
(
WCHAR
))
||
broken
(
!
lstrcmpW
(
out
,
L"xxxxxx"
)),
/* winxp */
"Expected the buffer to be truncated
\n
"
);
for
(
size
=
1000
;
size
<
1000000
;
size
+=
size
/
10
)
{
WCHAR
*
tmp
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
*
sizeof
(
WCHAR
)
);
WCHAR
*
buf
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
*
sizeof
(
WCHAR
)
);
for
(
i
=
0
;
i
<
size
;
i
++
)
tmp
[
i
]
=
'A'
+
i
%
26
;
tmp
[
size
-
1
]
=
0
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
,
tmp
,
0
,
0
,
buf
,
size
,
NULL
);
ok
(
ret
==
size
-
1
||
broken
(
!
ret
),
/* winxp */
"got %u
\n
"
,
ret
);
if
(
!
ret
)
break
;
ok
(
!
lstrcmpW
(
tmp
,
buf
),
"wrong buffer
\n
"
);
ret
=
doitW
(
FORMAT_MESSAGE_FROM_STRING
,
L"%1"
,
0
,
0
,
buf
,
size
,
tmp
);
ok
(
ret
==
size
-
1
,
"got %u
\n
"
,
ret
);
ok
(
!
lstrcmpW
(
tmp
,
buf
),
"wrong buffer
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
tmp
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
size
,
NULL
);
ok
(
ret
==
size
-
1
,
"got %u
\n
"
,
ret
);
ok
(
!
lstrcmpW
(
tmp
,
buf
),
"wrong buffer
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
tmp
);
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
}
}
static
void
test_message_null_buffer
(
void
)
...
...
@@ -1279,6 +1353,15 @@ static void test_message_allocate_buffer_wide(void)
ok
(
GetLastError
()
==
ERROR_NO_WORK_DONE
||
broken
(
GetLastError
()
==
0xdeadbeef
),
"Expected GetLastError() to return ERROR_NO_WORK_DONE, got %u
\n
"
,
GetLastError
());
SetLastError
(
0xdeadbeef
);
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
doitW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
L"%1"
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
0
,
L""
);
ok
(
ret
==
0
,
"Expected FormatMessageW to return 0, got %u
\n
"
,
ret
);
ok
(
buf
==
NULL
,
"Expected output buffer pointer to be NULL
\n
"
);
ok
(
GetLastError
()
==
ERROR_NO_WORK_DONE
||
broken
(
GetLastError
()
==
0xdeadbeef
),
"Expected GetLastError() to return ERROR_NO_WORK_DONE, got %u
\n
"
,
GetLastError
());
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
L"test"
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
0
,
NULL
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment