[CRT_APITEST] Fix tests for _sn(w)printf

- Dynamically load function from the appropriate DLL
- Fix a test for crtdll
This commit is contained in:
Timo Kreuzer
2025-09-11 16:11:57 +03:00
parent 4df8fbf9c2
commit e1f843b929
6 changed files with 37 additions and 4 deletions

View File

@@ -1,2 +1,5 @@
#include <stdio.h>
#define func__sntprintf func__snprintf
typedef int (__cdecl *PFN_sntprintf)(char *_Dest, size_t _Count, const char *_Format, ...);
#define str_sntprintf "_snprintf"
#include "_sntprintf.h"

View File

@@ -13,6 +13,23 @@
#include <ndk/mmfuncs.h>
#include <ndk/rtlfuncs.h>
#ifndef TEST_STATIC_CRT
static PFN_sntprintf p_sntprintf;
static BOOL Init(void)
{
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
p_sntprintf = (PFN_sntprintf)GetProcAddress(hdll, str_sntprintf);
ok(p_sntprintf != NULL, "Failed to load %s from %s\n", str_sntprintf, TEST_DLL_NAME);
return (p_sntprintf != NULL);
}
#undef _sntprintf
#define _sntprintf p_sntprintf
#endif // !TEST_STATIC_CRT
/* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
#undef broken
#define broken(x) 0
@@ -23,6 +40,14 @@ START_TEST(_sntprintf)
size_t BufferSize = sizeof(Buffer) / sizeof(Buffer[0]);
int Result;
#ifndef TEST_STATIC_CRT
if (!Init())
{
skip("Skipping tests, because %s is not available\n", str_sntprintf);
return;
}
#endif
StartSeh()
Result = _sntprintf(NULL, 0, _T("Hello"));
#ifdef TEST_CRTDLL
@@ -35,7 +60,9 @@ START_TEST(_sntprintf)
StartSeh()
Result = _sntprintf(NULL, 1, _T("Hello"));
ok_int(Result, (GetNTVersion() >= _WIN32_WINNT_VISTA) ? -1 : 5);
#if defined(_UNICODE) || defined(TEST_CRTDLL)
#if defined(TEST_CRTDLL)
EndSeh(STATUS_ACCESS_VIOLATION);
#elif defined(_UNICODE)
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);

View File

@@ -1,3 +1,6 @@
#define _UNICODE
#include <wchar.h>
#define func__sntprintf func__snwprintf
typedef int (__cdecl *PFN_sntprintf)(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, ...);
#define str_sntprintf "_snwprintf"
#include "_sntprintf.h"

View File

@@ -30,7 +30,7 @@ elseif(ARCH STREQUAL "amd64")
endif()
add_executable(crtdll_apitest testlist.c ${SOURCE_CRTDLL} ${crtdll_apitest_asm})
target_compile_definitions(crtdll_apitest PRIVATE TEST_CRTDLL)
target_compile_definitions(crtdll_apitest PRIVATE TEST_CRTDLL TEST_DLL_NAME="crtdll.dll")
target_link_libraries(crtdll_apitest wine ${PSEH_LIB})
set_module_type(crtdll_apitest win32cui)
add_importlibs(crtdll_apitest crtdll msvcrt kernel32 ntdll)

View File

@@ -81,7 +81,7 @@ list(APPEND SOURCE
add_executable(msvcrt_apitest ${SOURCE})
add_dependencies(msvcrt_apitest asm)
target_compile_definitions(msvcrt_apitest PRIVATE TEST_MSVCRT)
target_compile_definitions(msvcrt_apitest PRIVATE TEST_MSVCRT TEST_DLL_NAME="msvcrt.dll")
target_link_libraries(msvcrt_apitest wine ${PSEH_LIB})
set_module_type(msvcrt_apitest win32cui)
add_importlibs(msvcrt_apitest msvcrt kernel32 ntdll)

View File

@@ -26,7 +26,7 @@ list(APPEND SOURCE_CRT_TESTS
)
add_library(ntdll_crt_test_lib ${SOURCE_CRT_TESTS})
target_compile_definitions(ntdll_crt_test_lib PRIVATE TEST_NTDLL)
target_compile_definitions(ntdll_crt_test_lib PRIVATE TEST_NTDLL TEST_DLL_NAME="ntdll.dll")
target_link_libraries(ntdll_crt_test_lib ${PSEH_LIB})
add_dependencies(ntdll_crt_test_lib psdk)