Skip to content

Commit 5272cc2

Browse files
committed
[CRT_APITEST] Fix tests for sprintf
- Dynamically load function from the appropriate DLL - Fix tests for crtdll and user32
1 parent ba592da commit 5272cc2

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

modules/rostests/apitests/crt/sprintf.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
#endif
2727
#endif
2828

29+
#ifndef TEST_STATIC_CRT
30+
31+
typedef int (__cdecl *PFN_sprintf)(char *_Dest, const char *_Format, ...);
32+
static PFN_sprintf p_sprintf;
33+
34+
static BOOL Init(void)
35+
{
36+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
37+
#ifdef TEST_USER32
38+
p_sprintf = (PFN_sprintf)GetProcAddress(hdll, "wsprintfA");
39+
#else
40+
p_sprintf = (PFN_sprintf)GetProcAddress(hdll, "sprintf");
41+
#endif
42+
ok(p_sprintf != NULL, "Failed to load sprintf from %s\n", TEST_DLL_NAME);
43+
return (p_sprintf != NULL);
44+
}
45+
#define sprintf p_sprintf
46+
47+
#endif // !TEST_STATIC_CRT
48+
2949
/* NOTE: This test is not only used for all the CRT apitests, but also for
3050
* user32's wsprintf. Make sure to test them all */
3151
START_TEST(sprintf)
@@ -34,15 +54,27 @@ START_TEST(sprintf)
3454
CHAR Buffer[128];
3555
PCHAR String;
3656

57+
#ifndef TEST_STATIC_CRT
58+
if (!Init())
59+
{
60+
skip("Skipping tests, because sprintf is not available\n");
61+
return;
62+
}
63+
#endif
64+
3765
/* basic parameter tests */
3866
StartSeh()
3967
Length = sprintf(NULL, NULL);
68+
#if defined(TEST_CRTDLL) || defined(TEST_USER32)
69+
EndSeh(STATUS_ACCESS_VIOLATION);
70+
#else
4071
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
72+
#endif
4173

4274
StartSeh()
4375
Length = sprintf(NULL, "");
4476
ok_int(Length, (GetNTVersion() >= _WIN32_WINNT_VISTA) ? -1 : 0);
45-
#if TEST_CRTDLL || TEST_USER32
77+
#if defined(TEST_CRTDLL) || defined(TEST_USER32)
4678
EndSeh(STATUS_ACCESS_VIOLATION);
4779
#else
4880
EndSeh(STATUS_SUCCESS);
@@ -51,7 +83,7 @@ START_TEST(sprintf)
5183
StartSeh()
5284
Length = sprintf(NULL, "Hello");
5385
ok_int(Length, (GetNTVersion() >= _WIN32_WINNT_VISTA) ? -1 : 5);
54-
#if TEST_CRTDLL || TEST_USER32
86+
#if defined(TEST_CRTDLL) || defined(TEST_USER32)
5587
EndSeh(STATUS_ACCESS_VIOLATION);
5688
#else
5789
EndSeh(STATUS_SUCCESS);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define sprintf wsprintfA
21
#define func_sprintf func_wsprintf
32
#define TEST_USER32 1
3+
#define TEST_DLL_NAME "user32.dll"
44
#include "../crt/sprintf.c"

0 commit comments

Comments
 (0)