ReactOS 0.4.17-dev-357-ga8f14ff
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 CHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
40 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
41 HRESULT hr;
42 DWORD cch;
43
44 /* ".txt" */
49 {
50 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
51 ok_long(hr, S_OK);
52 ok_int(cch, lstrlenA(szAnswer) + 1);
53 }
54 else
55 {
56 lstrcpynA(szAnswer, ".txt", _countof(szAnswer));
59 }
60 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
61 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
62 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
63
64 /* s_szTextFileA */
69 {
70 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
71 ok_long(hr, S_OK);
72 ok_int(cch, lstrlenA(szAnswer) + 1);
73 }
74 else
75 {
76 lstrcpynA(szAnswer, s_szTextFileA, _countof(szAnswer));
79 }
80 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
81 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
82 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
83
84 /* NON_EXISTENT_FILENAME_A */
89 {
90 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
91 ok_long(hr, S_OK);
92 ok_int(cch, lstrlenA(szAnswer) + 1);
93 }
94 else
95 {
96 lstrcpynA(szAnswer, NON_EXISTENT_FILENAME_A, _countof(szAnswer));
99 }
100 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
101 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
102 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
103}
104
105static void TEST_AssocQueryStringW(void)
106{
107 WCHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
108 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
109 HRESULT hr;
110 DWORD cch;
111
112 /* ".txt" */
113 lstrcpynW(szPath, L".txt", _countof(szPath));
116 ok_long(hr, S_OK);
117 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
118 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
119 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
120 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
121 ok_int(cch, lstrlenW(szAnswer) + 1);
122
123 /* s_szTextFileW */
127 ok_long(hr, S_OK);
128 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
129 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
130 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
131 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
132 ok_int(cch, lstrlenW(szAnswer) + 1);
133
134 /* NON_EXISTENT_FILENAME_W */
138 ok_long(hr, S_OK);
139 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
140 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
141 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
142 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
143 ok_int(cch, lstrlenW(szAnswer) + 1);
144}
145
146static void TEST_TrickyPointers(void)
147{
148 HRESULT hr;
149 CHAR szPathA[MAX_PATH], szOutputA[MAX_PATH];
150 WCHAR szPathW[MAX_PATH], szOutputW[MAX_PATH];
151 DWORD cch;
152 BOOL bVistaPlus = IsWindowsVistaOrGreater();
153
154 lstrcpynA(szPathA, s_szTextFileA, _countof(szPathA));
155 cch = _countof(szOutputA);
157 {
159 }
161 {
162 hr = 0xDEADFACE;
163 }
164 _SEH2_END;
165
166 if (bVistaPlus)
167 ok_long(hr, 0xDEADFACE);
168 else
170
171 lstrcpynW(szPathW, s_szTextFileW, _countof(szPathW));
172 cch = _countof(szOutputW);
174 {
176 }
178 {
179 hr = 0xDEADFACE;
180 }
181 _SEH2_END;
182
183 if (bVistaPlus)
184 ok_long(hr, 0xDEADFACE);
185 else
186 ok_long(hr, S_OK);
187}
188
190{
191 HRESULT hrCoInit = CoInitialize(NULL);
192
193 TEST_Start();
197 TEST_End();
198
199 if (SUCCEEDED(hrCoInit))
201}
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:479
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:436
#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:1014
#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