Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
8e203225
Commit
8e203225
authored
Apr 18, 2010
by
Andrew Nguyen
Committed by
Alexandre Julliard
Apr 19, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32/tests: Add tests for buffer allocation in FormatMessage.
parent
ce61b254
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
168 additions
and
0 deletions
+168
-0
format_msg.c
dlls/kernel32/tests/format_msg.c
+168
-0
No files found.
dlls/kernel32/tests/format_msg.c
View file @
8e203225
...
...
@@ -835,6 +835,172 @@ static void test_message_null_buffer_wide(void)
ok
(
error
==
ERROR_INVALID_PARAMETER
,
"last error %u
\n
"
,
error
);
}
static
void
test_message_allocate_buffer
(
void
)
{
DWORD
ret
;
char
*
buf
;
/* While MSDN suggests that FormatMessageA allocates a buffer whose size is
* the larger of the output string and the requested buffer size, the tests
* will not try to determine the actual size of the buffer allocated, as
* the return value of LocalSize cannot be trusted for the purpose, and it should
* in any case be safe for FormatMessageA to allocate in the manner that
* MSDN suggests. */
buf
=
(
char
*
)
0xdeadbeef
;
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
"test"
,
0
,
0
,
(
char
*
)
&
buf
,
0
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
)
{
ok
(
!
strcmp
(
"test"
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
buf
);
LocalFree
(
buf
);
}
buf
=
(
char
*
)
0xdeadbeef
;
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
"test"
,
0
,
0
,
(
char
*
)
&
buf
,
strlen
(
"test"
),
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
)
{
ok
(
!
strcmp
(
"test"
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
buf
);
LocalFree
(
buf
);
}
buf
=
(
char
*
)
0xdeadbeef
;
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
"test"
,
0
,
0
,
(
char
*
)
&
buf
,
strlen
(
"test"
)
+
1
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
)
{
ok
(
!
strcmp
(
"test"
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
buf
);
LocalFree
(
buf
);
}
buf
=
(
char
*
)
0xdeadbeef
;
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
"test"
,
0
,
0
,
(
char
*
)
&
buf
,
strlen
(
"test"
)
+
2
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
)
{
ok
(
!
strcmp
(
"test"
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
buf
);
LocalFree
(
buf
);
}
buf
=
(
char
*
)
0xdeadbeef
;
ret
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
"test"
,
0
,
0
,
(
char
*
)
&
buf
,
1024
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
char
*
)
0xdeadbeef
)
{
ok
(
!
strcmp
(
"test"
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
buf
);
LocalFree
(
buf
);
}
}
static
void
test_message_allocate_buffer_wide
(
void
)
{
static
const
WCHAR
test
[]
=
{
't'
,
'e'
,
's'
,
't'
,
0
};
DWORD
ret
;
WCHAR
*
buf
;
SetLastError
(
0xdeadbeef
);
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
,
NULL
,
0
,
0
,
NULL
,
0
,
NULL
);
if
(
!
ret
&&
GetLastError
()
==
ERROR_CALL_NOT_IMPLEMENTED
)
{
win_skip
(
"FormatMessageW is not implemented
\n
"
);
return
;
}
/* While MSDN suggests that FormatMessageA allocates a buffer whose size is
* the larger of the output string and the requested buffer size, the tests
* will not try to determine the actual size of the buffer allocated, as
* the return value of LocalSize cannot be trusted for the purpose, and it should
* in any case be safe for FormatMessageA to allocate in the manner that
* MSDN suggests. */
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
test
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
0
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
)
{
ok
(
!
lstrcmpW
(
test
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
wine_dbgstr_w
(
buf
));
LocalFree
(
buf
);
}
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
test
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
sizeof
(
test
)
/
sizeof
(
WCHAR
)
-
1
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
)
{
ok
(
!
lstrcmpW
(
test
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
wine_dbgstr_w
(
buf
));
LocalFree
(
buf
);
}
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
test
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
sizeof
(
test
)
/
sizeof
(
WCHAR
),
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
)
{
ok
(
!
lstrcmpW
(
test
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
wine_dbgstr_w
(
buf
));
LocalFree
(
buf
);
}
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
test
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
sizeof
(
test
)
/
sizeof
(
WCHAR
)
+
1
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
)
{
ok
(
!
lstrcmpW
(
test
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
wine_dbgstr_w
(
buf
));
LocalFree
(
buf
);
}
buf
=
(
WCHAR
*
)
0xdeadbeef
;
ret
=
FormatMessageW
(
FORMAT_MESSAGE_FROM_STRING
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
,
test
,
0
,
0
,
(
WCHAR
*
)
&
buf
,
1024
,
NULL
);
ok
(
ret
==
4
,
"Expected FormatMessageA to return 4, got %u
\n
"
,
ret
);
ok
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
,
"Expected output buffer pointer to be valid
\n
"
);
if
(
buf
!=
NULL
&&
buf
!=
(
WCHAR
*
)
0xdeadbeef
)
{
ok
(
!
lstrcmpW
(
test
,
buf
),
"Expected buffer to contain
\"
test
\"
, got %s
\n
"
,
wine_dbgstr_w
(
buf
));
LocalFree
(
buf
);
}
}
static
void
test_message_from_hmodule
(
void
)
{
DWORD
ret
,
error
;
...
...
@@ -903,5 +1069,7 @@ START_TEST(format_msg)
test_message_insufficient_buffer_wide
();
test_message_null_buffer
();
test_message_null_buffer_wide
();
test_message_allocate_buffer
();
test_message_allocate_buffer_wide
();
test_message_from_hmodule
();
}
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