ReactOS 0.4.17-dev-684-ga6524ef
AssocQueryString.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: Test for AssocQueryStringA/W
5 * COPYRIGHT: Copyright 2024-2026 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include <apitest.h>
9#include <shlwapi.h>
10#include <stdio.h>
11#include <versionhelpers.h>
12
15#define NON_EXISTENT_FILENAME_A "C:\\ThisIsNotExistentFile.txt"
16#define NON_EXISTENT_FILENAME_W L"C:\\ThisIsNotExistentFile.txt"
17
18static void TEST_Start(void)
19{
20 ExpandEnvironmentStringsA( "%APPDATA%\\This is a test.txt", s_szTextFileA, _countof(s_szTextFileA));
21 ExpandEnvironmentStringsW(L"%APPDATA%\\This is a test.txt", s_szTextFileW, _countof(s_szTextFileW));
25}
26
27static void TEST_End(void)
28{
30}
31
32/*
33 * "shlwapi_winetest assoc" already has many tests.
34 * We just do additional tests in here.
35 */
36
37static void TEST_AssocQueryStringA(void)
38{
39 /* Note: NT5 differs from NT6 because NT5 converts a NULL pszExtra to L"" */
40 CHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
41 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
42 HRESULT hr;
43 DWORD cch;
44
45 /* ".txt" */
50 {
51 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
52 ok_long(hr, S_OK);
53 ok_int(cch, lstrlenA(szAnswer) + 1);
54 }
55 else
56 {
57 lstrcpynA(szAnswer, ".txt", _countof(szAnswer));
60 }
61 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
62 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
63 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
64
65 /* s_szTextFileA */
70 {
71 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
72 ok_long(hr, S_OK);
73 ok_int(cch, lstrlenA(szAnswer) + 1);
74 }
75 else
76 {
77 lstrcpynA(szAnswer, s_szTextFileA, _countof(szAnswer));
80 }
81 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
82 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
83 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
84
85 /* NON_EXISTENT_FILENAME_A */
90 {
91 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
92 ok_long(hr, S_OK);
93 ok_int(cch, lstrlenA(szAnswer) + 1);
94 }
95 else
96 {
97 lstrcpynA(szAnswer, NON_EXISTENT_FILENAME_A, _countof(szAnswer));
100 }
101 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
102 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
103 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
104}
105
106static void TEST_AssocQueryStringW(void)
107{
108 WCHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
109 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
110 HRESULT hr;
111 DWORD cch;
112
113 /* ".txt" */
114 lstrcpynW(szPath, L".txt", _countof(szPath));
117 ok_long(hr, S_OK);
118 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
119 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
120 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
121 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
122 ok_int(cch, lstrlenW(szAnswer) + 1);
123
124 /* s_szTextFileW */
128 ok_long(hr, S_OK);
129 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
130 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
131 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
132 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
133 ok_int(cch, lstrlenW(szAnswer) + 1);
134
135 /* NON_EXISTENT_FILENAME_W */
139 ok_long(hr, S_OK);
140 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
141 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
142 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
143 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
144 ok_int(cch, lstrlenW(szAnswer) + 1);
145}
146
147static void TEST_TrickyPointers(void)
148{
149 HRESULT hr;
150 CHAR szPathA[MAX_PATH], szOutputA[MAX_PATH];
151 WCHAR szPathW[MAX_PATH], szOutputW[MAX_PATH];
152 DWORD cch;
153 BOOL bVistaPlus = IsWindowsVistaOrGreater();
154
155 lstrcpynA(szPathA, s_szTextFileA, _countof(szPathA));
156 cch = _countof(szOutputA);
158 {
160 }
162 {
163 hr = 0xDEADFACE;
164 }
165 _SEH2_END;
166
167 if (bVistaPlus)
168 ok_long(hr, 0xDEADFACE);
169 else
171
172 lstrcpynW(szPathW, s_szTextFileW, _countof(szPathW));
173 cch = _countof(szOutputW);
175 {
177 }
179 {
180 hr = 0xDEADFACE;
181 }
182 _SEH2_END;
183
184 if (bVistaPlus)
185 ok_long(hr, 0xDEADFACE);
186 else
187 ok_long(hr, S_OK);
188}
189
191{
192 HRESULT hrCoInit = CoInitialize(NULL);
193
194 TEST_Start();
198 TEST_End();
199
200 if (SUCCEEDED(hrCoInit))
202}
static void TEST_TrickyPointers(void)
static WCHAR s_szTextFileW[MAX_PATH]
static void TEST_Start(void)
static void TEST_AssocQueryStringA(void)
static void TEST_AssocQueryStringW(void)
#define NON_EXISTENT_FILENAME_A
static void TEST_End(void)
static CHAR s_szTextFileA[MAX_PATH]
#define NON_EXISTENT_FILENAME_W
#define ok_long(expression, result)
Definition: atltest.h:133
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
#define lstrcpynA
Definition: compat.h:751
#define MAX_PATH
Definition: compat.h:34
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:372
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:492
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4133
int CDECL fclose(FILE *file)
Definition: file.c:3757
FILE *CDECL _wfopen(const wchar_t *path, const wchar_t *mode)
Definition: file.c:4335
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc, LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:612
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:569
#define L(x)
Definition: resources.c:13
#define UlongToPtr(u)
Definition: config.h:106
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
LPCWSTR szPath
Definition: env.c:37
short WCHAR
Definition: pedump.c:58
DWORD * PDWORD
Definition: pedump.c:68
char CHAR
Definition: pedump.c:57
@ ASSOCSTR_EXECUTABLE
Definition: shlwapi.h:887
@ ASSOCF_NONE
Definition: shlwapi.h:858
#define AssocQueryString
Definition: shlwapi.h:1024
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:152
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#define _countof(array)
Definition: sndvol32.h:70
VERSIONHELPERAPI IsWindowsVistaOrGreater()
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210