ReactOS 0.4.16-dev-112-g52265ae
CachedGetUserFromSid.c File Reference
#include <apitest.h>
#include <lmcons.h>
#include <wchar.h>
Include dependency graph for CachedGetUserFromSid.c:

Go to the source code of this file.

Functions

static VOID (WINAPI *pCachedGetUserFromSid)(PSID pSid
 
static void test_Sid_Null (void)
 
 START_TEST (CachedGetUserFromSid)
 

Variables

static LPWSTR pUserName
 
static LPWSTR PULONG pcwcUserName
 

Function Documentation

◆ START_TEST()

START_TEST ( CachedGetUserFromSid  )

Definition at line 61 of file CachedGetUserFromSid.c.

62{
63 const char szFunction[] = "CachedGetUserFromSid";
64 void* pFunction;
65
66 // TODO: Dynamically checking, until ReactOS implements this dll.
68 DWORD dwLE;
69
70 hModule = LoadLibraryW(L"utildll.dll");
71 if (!hModule)
72 {
73 dwLE = GetLastError();
74 ok(FALSE, "LoadLibraryW(\"%S\") failed! (dwLE = %lu)\n", L"utildll.dll", dwLE);
75 skip("No DLL\n");
76 return;
77 }
78
79 pFunction = (void*)GetProcAddress(hModule, szFunction);
80 if (!pFunction)
81 {
82 dwLE = GetLastError();
83 ok(FALSE, "GetProcAddress(\"%s\") failed! (dwLE = %lu)\n", szFunction, dwLE);
84 skip("No function\n");
86 return;
87 }
88
89 pCachedGetUserFromSid = pFunction;
90
92
94}
static void test_Sid_Null(void)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define FALSE
Definition: types.h:117
HMODULE hModule
Definition: animate.c:44
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ test_Sid_Null()

static void test_Sid_Null ( void  )
static

Definition at line 15 of file CachedGetUserFromSid.c.

16{
17 const WCHAR szUserNameFromNull[] = L"(unknown)";
18 const ULONG cchUserNameFromNull = (ULONG)wcslen(szUserNameFromNull);
19
20 WCHAR szUserName[UNLEN + 1];
21 ULONG cchUserName;
22
23 // First, full success case, to load result into cache.
24 // Otherwise, expect misbehavior/corruption/crash!
25 // Same issues with 'NULL' or '0' arguments.
26 // Behavior changed on NT6.0 then NT6.1+...
27
28 wmemset(szUserName, L'?', _countof(szUserName));
29 cchUserName = _countof(szUserName);
30 pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
31 ok(cchUserName == cchUserNameFromNull, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull, cchUserName);
32 ok(wcscmp(szUserName, szUserNameFromNull) == 0, "szUserName: expected \"%S\", got \"%.*S\"\n", szUserNameFromNull, (int)cchUserName, szUserName);
33
34 wmemset(szUserName, L'?', _countof(szUserName));
35 cchUserName = 1;
36 pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
37 ok(cchUserName == 0, "cchUserName: expected 0, got %lu\n", cchUserName);
38 ok(szUserName[0] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
39
40 wmemset(szUserName, L'?', _countof(szUserName));
41 cchUserName = 2;
42 pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
43 ok(cchUserName == 1, "cchUserName: expected 0, got %lu\n", cchUserName);
44 ok(szUserName[1] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
45 ok(wcsncmp(szUserName, szUserNameFromNull, 1) == 0, "szUserName: expected \"%.*S\", got \"%.*S\"\n", 1, szUserNameFromNull, (int)cchUserName, szUserName);
46
47 wmemset(szUserName, L'?', _countof(szUserName));
48 cchUserName = cchUserNameFromNull;
49 pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
50 ok(cchUserName == cchUserNameFromNull - 1, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull - 1, cchUserName);
51 ok(szUserName[cchUserNameFromNull - 1] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
52 ok(wcsncmp(szUserName, szUserNameFromNull, cchUserNameFromNull - 1) == 0, "szUserName: expected \"%.*S\", got \"%.*S\"\n", (int)cchUserNameFromNull - 1, szUserNameFromNull, (int)cchUserName, szUserName);
53
54 wmemset(szUserName, L'?', _countof(szUserName));
55 cchUserName = cchUserNameFromNull + 1;
56 pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
57 ok(cchUserName == cchUserNameFromNull, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull, cchUserName);
58 ok(wcscmp(szUserName, szUserNameFromNull) == 0, "szUserName: expected \"%S\", got \"%.*S\"\n", szUserNameFromNull, (int)cchUserName, szUserName);
59}
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
wchar_t *__cdecl wmemset(_Out_writes_all_(_N) wchar_t *_S, _In_ wchar_t _C, _In_ size_t _N)
Definition: wchar.h:2611
#define UNICODE_NULL
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define _countof(array)
Definition: sndvol32.h:70
#define UNLEN
Definition: sspi.c:28
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ VOID()

static VOID ( WINAPI pCachedGetUserFromSid)
static

Variable Documentation

◆ pcwcUserName

LPWSTR PULONG pcwcUserName

Definition at line 13 of file CachedGetUserFromSid.c.

Referenced by CachedGetUserFromSid().

◆ pUserName