ReactOS 0.4.15-dev-8135-g1bc6c90
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 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
14 ASSOCF cfFlags,
16 LPCSTR pszAssoc,
17 LPCSTR pszExtra,
18 LPSTR pszOut,
19 DWORD *pcchOut);
21 ASSOCF cfFlags,
23 LPCWSTR pszAssoc,
24 LPCWSTR pszExtra,
25 LPWSTR pszOut,
26 DWORD *pcchOut);
27
33#define NON_EXISTENT_FILENAME_A "C:\\ThisIsNotExistentFile.txt"
34#define NON_EXISTENT_FILENAME_W L"C:\\ThisIsNotExistentFile.txt"
35
36static void TEST_Start(void)
37{
38 ExpandEnvironmentStringsA( "%APPDATA%\\This is a test.txt", s_szTextFileA, _countof(s_szTextFileA));
39 ExpandEnvironmentStringsW(L"%APPDATA%\\This is a test.txt", s_szTextFileW, _countof(s_szTextFileW));
43}
44
45static void TEST_End(void)
46{
48}
49
50/*
51 * "shlwapi_winetest assoc" already has many tests.
52 * We just do additional tests in here.
53 */
54
55static void TEST_AssocQueryStringA(void)
56{
57 CHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
58 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
59 HRESULT hr;
60 DWORD cch;
61
62 /* ".txt" */
67 {
68 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
69 ok_long(hr, S_OK);
70 ok_int(cch, lstrlenA(szAnswer) + 1);
71 }
72 else
73 {
74 lstrcpynA(szAnswer, ".txt", _countof(szAnswer));
77 }
78 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
79 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
80 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
81
82 /* s_szTextFileA */
87 {
88 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
89 ok_long(hr, S_OK);
90 ok_int(cch, lstrlenA(szAnswer) + 1);
91 }
92 else
93 {
94 lstrcpynA(szAnswer, s_szTextFileA, _countof(szAnswer));
97 }
98 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
99 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
100 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
101
102 /* NON_EXISTENT_FILENAME_A */
107 {
108 ExpandEnvironmentStringsA("%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
109 ok_long(hr, S_OK);
110 ok_int(cch, lstrlenA(szAnswer) + 1);
111 }
112 else
113 {
114 lstrcpynA(szAnswer, NON_EXISTENT_FILENAME_A, _countof(szAnswer));
117 }
118 lstrcpynA(szDebug1, wine_dbgstr_a(szPath), _countof(szDebug1));
119 lstrcpynA(szDebug2, wine_dbgstr_a(szAnswer), _countof(szDebug2));
120 ok(lstrcmpiA(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
121}
122
123static void TEST_AssocQueryStringW(void)
124{
125 WCHAR szPath[MAX_PATH], szAnswer[MAX_PATH];
126 CHAR szDebug1[MAX_PATH], szDebug2[MAX_PATH];
127 HRESULT hr;
128 DWORD cch;
129
130 /* ".txt" */
131 lstrcpynW(szPath, L".txt", _countof(szPath));
134 ok_long(hr, S_OK);
135 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
136 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
137 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
138 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
139 ok_int(cch, lstrlenW(szAnswer) + 1);
140
141 /* s_szTextFileW */
145 ok_long(hr, S_OK);
146 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
147 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
148 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
149 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
150 ok_int(cch, lstrlenW(szAnswer) + 1);
151
152 /* NON_EXISTENT_FILENAME_W */
156 ok_long(hr, S_OK);
157 ExpandEnvironmentStringsW(L"%WINDIR%\\system32\\notepad.exe", szAnswer, _countof(szAnswer));
158 lstrcpynA(szDebug1, wine_dbgstr_w(szPath), _countof(szDebug1));
159 lstrcpynA(szDebug2, wine_dbgstr_w(szAnswer), _countof(szDebug2));
160 ok(lstrcmpiW(szPath, szAnswer) == 0, "%s vs %s\n", szDebug1, szDebug2);
161 ok_int(cch, lstrlenW(szAnswer) + 1);
162}
163
165{
166 HRESULT hrCoInit = CoInitialize(NULL);
167
168 s_hSHLWAPI = LoadLibraryW(L"shlwapi.dll");
172 {
173 skip("AssocQueryStringA or AssocQueryStringW not found: %p, %p\n",
175 return;
176 }
177
178 TEST_Start();
181 TEST_End();
182
184
185 if (SUCCEEDED(hrCoInit))
187}
HRESULT(WINAPI * FN_AssocQueryStringW)(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
static FN_AssocQueryStringA s_fnAssocQueryStringA
static HINSTANCE s_hSHLWAPI
static WCHAR s_szTextFileW[MAX_PATH]
static void TEST_Start(void)
static void TEST_AssocQueryStringA(void)
HRESULT(WINAPI * FN_AssocQueryStringA)(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc, LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
static void TEST_AssocQueryStringW(void)
#define NON_EXISTENT_FILENAME_A
static void TEST_End(void)
static CHAR s_szTextFileA[MAX_PATH]
static FN_AssocQueryStringW s_fnAssocQueryStringW
#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 skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#define lstrcpynA
Definition: compat.h:751
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
#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:399
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4261
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4223
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
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
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#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
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define L(x)
Definition: ntvdm.h:50
const WCHAR * str
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:187
HRESULT hr
Definition: shlfolder.c:183
ASSOCSTR
Definition: shlwapi.h:602
@ ASSOCSTR_EXECUTABLE
Definition: shlwapi.h:604
DWORD ASSOCF
Definition: shlwapi.h:599
#define AssocQueryString
Definition: shlwapi.h:698
#define _countof(array)
Definition: sndvol32.h:70
VERSIONHELPERAPI IsWindowsVistaOrGreater()
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175