1*4c1e83d5SKatayama Hirofumi MZ /*
2*4c1e83d5SKatayama Hirofumi MZ  * PROJECT:     ReactOS api tests
3*4c1e83d5SKatayama Hirofumi MZ  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4*4c1e83d5SKatayama Hirofumi MZ  * PURPOSE:     Tests for SHLoadRegUIStringA/W
5*4c1e83d5SKatayama Hirofumi MZ  * COPYRIGHT:   Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6*4c1e83d5SKatayama Hirofumi MZ  */
7*4c1e83d5SKatayama Hirofumi MZ 
8*4c1e83d5SKatayama Hirofumi MZ #include <apitest.h>
9*4c1e83d5SKatayama Hirofumi MZ #include <shlwapi.h>
10*4c1e83d5SKatayama Hirofumi MZ 
11*4c1e83d5SKatayama Hirofumi MZ typedef HRESULT (WINAPI *FN_SHLoadRegUIStringA)(HKEY hkey, LPCSTR value, LPSTR buf, DWORD size);
12*4c1e83d5SKatayama Hirofumi MZ typedef HRESULT (WINAPI *FN_SHLoadRegUIStringW)(HKEY hkey, LPCWSTR value, LPWSTR buf, DWORD size);
13*4c1e83d5SKatayama Hirofumi MZ 
14*4c1e83d5SKatayama Hirofumi MZ static FN_SHLoadRegUIStringA pSHLoadRegUIStringA = NULL;
15*4c1e83d5SKatayama Hirofumi MZ static FN_SHLoadRegUIStringW pSHLoadRegUIStringW = NULL;
16*4c1e83d5SKatayama Hirofumi MZ 
test_SHLoadRegUIStringA(HKEY hKey)17*4c1e83d5SKatayama Hirofumi MZ static void test_SHLoadRegUIStringA(HKEY hKey)
18*4c1e83d5SKatayama Hirofumi MZ {
19*4c1e83d5SKatayama Hirofumi MZ     HRESULT hr;
20*4c1e83d5SKatayama Hirofumi MZ     CHAR szBuff[MAX_PATH];
21*4c1e83d5SKatayama Hirofumi MZ 
22*4c1e83d5SKatayama Hirofumi MZ     hr = pSHLoadRegUIStringA(hKey, "TestValue1", szBuff, _countof(szBuff));
23*4c1e83d5SKatayama Hirofumi MZ     ok_long(hr, S_OK);
24*4c1e83d5SKatayama Hirofumi MZ     ok_str(szBuff, "%WINDIR%\\TEST");
25*4c1e83d5SKatayama Hirofumi MZ 
26*4c1e83d5SKatayama Hirofumi MZ     hr = pSHLoadRegUIStringA(hKey, "TestValue2", szBuff, _countof(szBuff));
27*4c1e83d5SKatayama Hirofumi MZ     ok_long(hr, S_OK);
28*4c1e83d5SKatayama Hirofumi MZ     ok_str(szBuff, "Test string one.");
29*4c1e83d5SKatayama Hirofumi MZ }
30*4c1e83d5SKatayama Hirofumi MZ 
test_SHLoadRegUIStringW(HKEY hKey)31*4c1e83d5SKatayama Hirofumi MZ static void test_SHLoadRegUIStringW(HKEY hKey)
32*4c1e83d5SKatayama Hirofumi MZ {
33*4c1e83d5SKatayama Hirofumi MZ     HRESULT hr;
34*4c1e83d5SKatayama Hirofumi MZ     WCHAR szBuff[MAX_PATH];
35*4c1e83d5SKatayama Hirofumi MZ 
36*4c1e83d5SKatayama Hirofumi MZ     hr = pSHLoadRegUIStringW(hKey, L"TestValue1", szBuff, _countof(szBuff));
37*4c1e83d5SKatayama Hirofumi MZ     ok_long(hr, S_OK);
38*4c1e83d5SKatayama Hirofumi MZ     ok_wstr(szBuff, L"%WINDIR%\\TEST");
39*4c1e83d5SKatayama Hirofumi MZ 
40*4c1e83d5SKatayama Hirofumi MZ     hr = pSHLoadRegUIStringW(hKey, L"TestValue2", szBuff, _countof(szBuff));
41*4c1e83d5SKatayama Hirofumi MZ     ok_long(hr, S_OK);
42*4c1e83d5SKatayama Hirofumi MZ     ok_wstr(szBuff, L"Test string one.");
43*4c1e83d5SKatayama Hirofumi MZ }
44*4c1e83d5SKatayama Hirofumi MZ 
45*4c1e83d5SKatayama Hirofumi MZ BOOL extract_resource(const WCHAR* Filename, LPCWSTR ResourceName);
46*4c1e83d5SKatayama Hirofumi MZ 
START_TEST(SHLoadRegUIString)47*4c1e83d5SKatayama Hirofumi MZ START_TEST(SHLoadRegUIString)
48*4c1e83d5SKatayama Hirofumi MZ {
49*4c1e83d5SKatayama Hirofumi MZ     LONG error;
50*4c1e83d5SKatayama Hirofumi MZ     HKEY hKey;
51*4c1e83d5SKatayama Hirofumi MZ     DWORD cbValue;
52*4c1e83d5SKatayama Hirofumi MZ     static const WCHAR s_szTestValue1[] = L"%WINDIR%\\TEST";
53*4c1e83d5SKatayama Hirofumi MZ     static const WCHAR s_szTestValue2[] = L"@SHLoadRegUIString.dll%EmptyEnvVar%,-3";
54*4c1e83d5SKatayama Hirofumi MZ     HMODULE hSHLWAPI;
55*4c1e83d5SKatayama Hirofumi MZ 
56*4c1e83d5SKatayama Hirofumi MZ     SetEnvironmentVariableW(L"EmptyEnvVar", L"");
57*4c1e83d5SKatayama Hirofumi MZ 
58*4c1e83d5SKatayama Hirofumi MZ     /* Get procedures */
59*4c1e83d5SKatayama Hirofumi MZ     hSHLWAPI = GetModuleHandleW(L"shlwapi");
60*4c1e83d5SKatayama Hirofumi MZ     pSHLoadRegUIStringA = (FN_SHLoadRegUIStringA)GetProcAddress(hSHLWAPI, (LPCSTR)438);
61*4c1e83d5SKatayama Hirofumi MZ     pSHLoadRegUIStringW = (FN_SHLoadRegUIStringW)GetProcAddress(hSHLWAPI, (LPCSTR)439);
62*4c1e83d5SKatayama Hirofumi MZ     if (!pSHLoadRegUIStringA || !pSHLoadRegUIStringW)
63*4c1e83d5SKatayama Hirofumi MZ     {
64*4c1e83d5SKatayama Hirofumi MZ         skip("No procedure found\n");
65*4c1e83d5SKatayama Hirofumi MZ         return;
66*4c1e83d5SKatayama Hirofumi MZ     }
67*4c1e83d5SKatayama Hirofumi MZ 
68*4c1e83d5SKatayama Hirofumi MZ     if (!extract_resource(L"SHLoadRegUIString.dll", MAKEINTRESOURCEW(101)))
69*4c1e83d5SKatayama Hirofumi MZ     {
70*4c1e83d5SKatayama Hirofumi MZ         skip("File 'SHLoadRegUIString.dll' cannot be extracted\n");
71*4c1e83d5SKatayama Hirofumi MZ         return;
72*4c1e83d5SKatayama Hirofumi MZ     }
73*4c1e83d5SKatayama Hirofumi MZ 
74*4c1e83d5SKatayama Hirofumi MZ     /* Open registry key and write some test values */
75*4c1e83d5SKatayama Hirofumi MZ     error = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software", 0, KEY_READ | KEY_WRITE, &hKey);
76*4c1e83d5SKatayama Hirofumi MZ     ok_long(error, ERROR_SUCCESS);
77*4c1e83d5SKatayama Hirofumi MZ 
78*4c1e83d5SKatayama Hirofumi MZ     cbValue = (lstrlenW(s_szTestValue1) + 1) * sizeof(WCHAR);
79*4c1e83d5SKatayama Hirofumi MZ     error = RegSetValueExW(hKey, L"TestValue1", 0, REG_SZ, (LPBYTE)s_szTestValue1, cbValue);
80*4c1e83d5SKatayama Hirofumi MZ     ok_long(error, ERROR_SUCCESS);
81*4c1e83d5SKatayama Hirofumi MZ 
82*4c1e83d5SKatayama Hirofumi MZ     cbValue = (lstrlenW(s_szTestValue2) + 1) * sizeof(WCHAR);
83*4c1e83d5SKatayama Hirofumi MZ     error = RegSetValueExW(hKey, L"TestValue2", 0, REG_SZ, (LPBYTE)s_szTestValue2, cbValue);
84*4c1e83d5SKatayama Hirofumi MZ     ok_long(error, ERROR_SUCCESS);
85*4c1e83d5SKatayama Hirofumi MZ 
86*4c1e83d5SKatayama Hirofumi MZ     /* The main dish */
87*4c1e83d5SKatayama Hirofumi MZ     test_SHLoadRegUIStringA(hKey);
88*4c1e83d5SKatayama Hirofumi MZ     test_SHLoadRegUIStringW(hKey);
89*4c1e83d5SKatayama Hirofumi MZ 
90*4c1e83d5SKatayama Hirofumi MZ     /* Delete the test values and close the key */
91*4c1e83d5SKatayama Hirofumi MZ     RegDeleteValueW(hKey, L"TestValue1");
92*4c1e83d5SKatayama Hirofumi MZ     RegDeleteValueW(hKey, L"TestValue2");
93*4c1e83d5SKatayama Hirofumi MZ     RegCloseKey(hKey);
94*4c1e83d5SKatayama Hirofumi MZ 
95*4c1e83d5SKatayama Hirofumi MZ     DeleteFileW(L"SHLoadRegUIString.dll");
96*4c1e83d5SKatayama Hirofumi MZ }
97