Skip to content

Commit e1f843b

Browse files
committed
[CRT_APITEST] Fix tests for _sn(w)printf
- Dynamically load function from the appropriate DLL - Fix a test for crtdll
1 parent 4df8fbf commit e1f843b

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
#include <stdio.h>
12
#define func__sntprintf func__snprintf
3+
typedef int (__cdecl *PFN_sntprintf)(char *_Dest, size_t _Count, const char *_Format, ...);
4+
#define str_sntprintf "_snprintf"
25
#include "_sntprintf.h"

modules/rostests/apitests/crt/_sntprintf.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
#include <ndk/mmfuncs.h>
1414
#include <ndk/rtlfuncs.h>
1515

16+
#ifndef TEST_STATIC_CRT
17+
18+
static PFN_sntprintf p_sntprintf;
19+
20+
static BOOL Init(void)
21+
{
22+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
23+
p_sntprintf = (PFN_sntprintf)GetProcAddress(hdll, str_sntprintf);
24+
ok(p_sntprintf != NULL, "Failed to load %s from %s\n", str_sntprintf, TEST_DLL_NAME);
25+
return (p_sntprintf != NULL);
26+
}
27+
28+
#undef _sntprintf
29+
#define _sntprintf p_sntprintf
30+
31+
#endif // !TEST_STATIC_CRT
32+
1633
/* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
1734
#undef broken
1835
#define broken(x) 0
@@ -23,6 +40,14 @@ START_TEST(_sntprintf)
2340
size_t BufferSize = sizeof(Buffer) / sizeof(Buffer[0]);
2441
int Result;
2542

43+
#ifndef TEST_STATIC_CRT
44+
if (!Init())
45+
{
46+
skip("Skipping tests, because %s is not available\n", str_sntprintf);
47+
return;
48+
}
49+
#endif
50+
2651
StartSeh()
2752
Result = _sntprintf(NULL, 0, _T("Hello"));
2853
#ifdef TEST_CRTDLL
@@ -35,7 +60,9 @@ START_TEST(_sntprintf)
3560
StartSeh()
3661
Result = _sntprintf(NULL, 1, _T("Hello"));
3762
ok_int(Result, (GetNTVersion() >= _WIN32_WINNT_VISTA) ? -1 : 5);
38-
#if defined(_UNICODE) || defined(TEST_CRTDLL)
63+
#if defined(TEST_CRTDLL)
64+
EndSeh(STATUS_ACCESS_VIOLATION);
65+
#elif defined(_UNICODE)
3966
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
4067
#else
4168
EndSeh(STATUS_SUCCESS);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#define _UNICODE
2+
#include <wchar.h>
23
#define func__sntprintf func__snwprintf
4+
typedef int (__cdecl *PFN_sntprintf)(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, ...);
5+
#define str_sntprintf "_snwprintf"
36
#include "_sntprintf.h"

modules/rostests/apitests/crtdll/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ elseif(ARCH STREQUAL "amd64")
3030
endif()
3131

3232
add_executable(crtdll_apitest testlist.c ${SOURCE_CRTDLL} ${crtdll_apitest_asm})
33-
target_compile_definitions(crtdll_apitest PRIVATE TEST_CRTDLL)
33+
target_compile_definitions(crtdll_apitest PRIVATE TEST_CRTDLL TEST_DLL_NAME="crtdll.dll")
3434
target_link_libraries(crtdll_apitest wine ${PSEH_LIB})
3535
set_module_type(crtdll_apitest win32cui)
3636
add_importlibs(crtdll_apitest crtdll msvcrt kernel32 ntdll)

modules/rostests/apitests/msvcrt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ list(APPEND SOURCE
8181

8282
add_executable(msvcrt_apitest ${SOURCE})
8383
add_dependencies(msvcrt_apitest asm)
84-
target_compile_definitions(msvcrt_apitest PRIVATE TEST_MSVCRT)
84+
target_compile_definitions(msvcrt_apitest PRIVATE TEST_MSVCRT TEST_DLL_NAME="msvcrt.dll")
8585
target_link_libraries(msvcrt_apitest wine ${PSEH_LIB})
8686
set_module_type(msvcrt_apitest win32cui)
8787
add_importlibs(msvcrt_apitest msvcrt kernel32 ntdll)

modules/rostests/apitests/ntdll/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ list(APPEND SOURCE_CRT_TESTS
2626
)
2727

2828
add_library(ntdll_crt_test_lib ${SOURCE_CRT_TESTS})
29-
target_compile_definitions(ntdll_crt_test_lib PRIVATE TEST_NTDLL)
29+
target_compile_definitions(ntdll_crt_test_lib PRIVATE TEST_NTDLL TEST_DLL_NAME="ntdll.dll")
3030
target_link_libraries(ntdll_crt_test_lib ${PSEH_LIB})
3131
add_dependencies(ntdll_crt_test_lib psdk)
3232

0 commit comments

Comments
 (0)