mirror of
https://github.com/reactos/reactos.git
synced 2024-11-02 04:37:32 +00:00
[CRT_APITEST] Add test for rand_s
This commit is contained in:
parent
f319538d98
commit
3c55252828
|
@ -1137,7 +1137,7 @@ list(APPEND SOURCE_MSVCRT
|
|||
# qsort_s
|
||||
# raise.c
|
||||
# rand.c
|
||||
# rand_s.c
|
||||
rand_s.c
|
||||
# realloc.c
|
||||
# remove.c
|
||||
# rename.c
|
||||
|
|
61
modules/rostests/apitests/crt/rand_s.c
Normal file
61
modules/rostests/apitests/crt/rand_s.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* PROJECT: ReactOS API Tests
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Tests for rand_s
|
||||
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
*/
|
||||
|
||||
#include <apitest.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef TEST_STATIC_CRT
|
||||
errno_t __cdecl rand_s(_Out_ unsigned int* _RandomValue);
|
||||
#endif
|
||||
|
||||
typedef int __cdecl rand_s_t(unsigned int*);
|
||||
rand_s_t *p_rand_s;
|
||||
|
||||
void test_rand_s_performance(void)
|
||||
{
|
||||
unsigned long long start, end;
|
||||
unsigned int val;
|
||||
int i;
|
||||
|
||||
start = __rdtsc();
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
p_rand_s(&val);
|
||||
}
|
||||
end = __rdtsc();
|
||||
printf("rand_s took %llu cycles\n", end - start);
|
||||
}
|
||||
|
||||
START_TEST(rand_s)
|
||||
{
|
||||
unsigned int val;
|
||||
int ret;
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
/* Dynamically load rand_s from mvcrt */
|
||||
HMODULE msvcrt = GetModuleHandleA("msvcrt");
|
||||
p_rand_s = (rand_s_t*)GetProcAddress(msvcrt, "rand_s");
|
||||
if (!p_rand_s)
|
||||
{
|
||||
win_skip("rand_s is not available\n");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
p_rand_s = rand_s;
|
||||
#endif
|
||||
|
||||
/* Test performance */
|
||||
test_rand_s_performance();
|
||||
|
||||
/* Test with NULL pointer */
|
||||
ret = p_rand_s(NULL);
|
||||
ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
|
||||
|
||||
/* Test with valid pointer */
|
||||
ret = p_rand_s(&val);
|
||||
ok(ret == 0, "Expected 0, got %d\n", ret);
|
||||
}
|
|
@ -13,6 +13,7 @@ list(APPEND SOURCE_STATIC
|
|||
fpcontrol.c
|
||||
mbstowcs.c
|
||||
mbtowc.c
|
||||
rand_s.c
|
||||
sprintf.c
|
||||
strcpy.c
|
||||
strlen.c
|
||||
|
|
|
@ -32,6 +32,7 @@ extern void func__vsnprintf(void);
|
|||
extern void func__vsnwprintf(void);
|
||||
extern void func_mbstowcs(void);
|
||||
extern void func_mbtowc(void);
|
||||
extern void func_rand_s(void);
|
||||
extern void func_sprintf(void);
|
||||
extern void func_strcpy(void);
|
||||
extern void func_strlen(void);
|
||||
|
@ -79,6 +80,7 @@ const struct test winetest_testlist[] =
|
|||
{ "ceil", func_ceil },
|
||||
{ "fabs", func_fabs },
|
||||
{ "floor", func_floor },
|
||||
{ "rand_s", func_rand_s },
|
||||
#ifdef _M_AMD64 // x86 / arm need fixing
|
||||
{ "fpcontrol", func_fpcontrol },
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue