ReactOS 0.4.17-dev-769-g1500a35
AssocQueryKey.c File Reference
#include <apitest.h>
#include <windef.h>
#include <shlwapi.h>
#include <pseh/pseh2.h>
#include <shlobj.h>
#include <shlwapi_undoc.h>
Include dependency graph for AssocQueryKey.c:

Go to the source code of this file.

Classes

struct  _MY_KEY_NAME_INFORMATION
 

Macros

#define ok_AqkPath(InitF, AssocKey, pszInit, pszExtra, hrExpected, pszExpectedWin32)
 

Typedefs

typedef enum _MY_KEY_INFORMATION_CLASS MY_KEY_INFORMATION_CLASS
 
typedef struct _MY_KEY_NAME_INFORMATION MY_KEY_NAME_INFORMATION
 
typedef struct _MY_KEY_NAME_INFORMATIONPMY_KEY_NAME_INFORMATION
 
typedef NTSTATUS(__stdcallFN_NtQueryKey) (HANDLE, MY_KEY_INFORMATION_CLASS, PVOID, ULONG, PULONG)
 

Enumerations

enum  {
  HR_FNF = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) , HR_NF = HRESULT_FROM_WIN32(ERROR_NOT_FOUND) , HR_NOASSOC = HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) , HR_ACCDENIED = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) ,
  AF_DEFSTAR = ASSOCF_INIT_DEFAULTTOSTAR , AF_DEFFOLDER = ASSOCF_INIT_DEFAULTTOFOLDER
}
 
enum  _MY_KEY_INFORMATION_CLASS { MyKeyBasicInformation = 0 , MyKeyNodeInformation = 1 , MyKeyFullInformation = 2 , MyKeyNameInformation = 3 }
 

Functions

static void Cleanup (void)
 
static BOOL InitNtQueryKey (VOID)
 
static LPWSTR GetKeyPath (HKEY hKey)
 
static BOOL IsValidClassesRootPath (LPCWSTR path)
 
static HRESULT SHELL_SetRegString (HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszName, UINT Type, LPCWSTR pszData)
 
static HRESULT AQS (ASSOCF flags, ASSOCSTR str, LPCWSTR pszAsso, LPCWSTR pszExtra, LPWSTR pszOut)
 
static HRESULT GetAqkPath (UINT InitF, ASSOCKEY AssocKey, LPCWSTR pszInit, LPCWSTR pszExtra, LPWSTR *ppszKey)
 
static HKEY CreateClassesKey (HKEY hRoot)
 
static HKEY CreateClassesSubKey (HKEY hRoot, LPCWSTR pszSubKey)
 
static void TestClassKey (ASSOCKEY AssocKey)
 
static void TEST_AssocKeys (void)
 
static void TEST_AssocF_Flags (void)
 
static void TEST_PszAssoc (void)
 
static void TEST_InvalidArgs (void)
 
static void TEST_ByExeName (void)
 
static void TEST_Class (void)
 
static void TEST_BaseClass (void)
 
static void TEST_ShellExecClass (void)
 
 START_TEST (AssocQueryKey)
 

Variables

static const WCHAR pszUniqueExt [] = L".RosTestExtShlwapi"
 
static const WCHAR pszUniquePid [] = L"FEF31D544EA64C8EBC50B8719887688A"
 
static const WCHAR pszUniquePid2 [] = L"88FDE0879CD24AEBBEB690988BD87706"
 
static FN_NtQueryKey g_NtQueryKey = NULL
 

Macro Definition Documentation

◆ ok_AqkPath

#define ok_AqkPath (   InitF,
  AssocKey,
  pszInit,
  pszExtra,
  hrExpected,
  pszExpectedWin32 
)
Value:
do \
{ \
LPCWSTR pszExpected = L"\\REGISTRY\\MACHINE\\" pszExpectedWin32; \
LPWSTR pszPath; \
HRESULT hr = GetAqkPath((InitF), (AssocKey), (pszInit), (pszExtra), &pszPath); \
ok_hr(hr, (hrExpected)); \
if (SUCCEEDED(hr)) \
{ \
ok(pszPath && !_wcsicmp(pszPath, pszExpected), "Got \"%s\", expected \"%s\"\n", \
wine_dbgstr_w(pszPath), wine_dbgstr_w(pszExpected)); \
} \
LocalFree(pszPath); \
} while (0)
static HRESULT GetAqkPath(UINT InitF, ASSOCKEY AssocKey, LPCWSTR pszInit, LPCWSTR pszExtra, LPWSTR *ppszKey)
HRESULT hr
Definition: delayimp.cpp:582
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
#define L(x)
Definition: resources.c:13
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56

Definition at line 126 of file AssocQueryKey.c.

Typedef Documentation

◆ FN_NtQueryKey

Definition at line 55 of file AssocQueryKey.c.

◆ MY_KEY_INFORMATION_CLASS

◆ MY_KEY_NAME_INFORMATION

◆ PMY_KEY_NAME_INFORMATION

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HR_FNF 
HR_NF 
HR_NOASSOC 
HR_ACCDENIED 
AF_DEFSTAR 
AF_DEFFOLDER 

Definition at line 30 of file AssocQueryKey.c.

31{
38};
@ HR_NOASSOC
Definition: AssocQueryKey.c:34
@ HR_FNF
Definition: AssocQueryKey.c:32
@ HR_NF
Definition: AssocQueryKey.c:33
@ AF_DEFFOLDER
Definition: AssocQueryKey.c:37
@ HR_ACCDENIED
Definition: AssocQueryKey.c:35
@ AF_DEFSTAR
Definition: AssocQueryKey.c:36
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
@ ASSOCF_INIT_DEFAULTTOSTAR
Definition: shlwapi.h:862
@ ASSOCF_INIT_DEFAULTTOFOLDER
Definition: shlwapi.h:863
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:1001
#define ERROR_NOT_FOUND
Definition: winerror.h:1014

◆ _MY_KEY_INFORMATION_CLASS

Enumerator
MyKeyBasicInformation 
MyKeyNodeInformation 
MyKeyFullInformation 
MyKeyNameInformation 

Definition at line 40 of file AssocQueryKey.c.

41{
@ MyKeyNodeInformation
Definition: AssocQueryKey.c:43
@ MyKeyNameInformation
Definition: AssocQueryKey.c:45
@ MyKeyBasicInformation
Definition: AssocQueryKey.c:42
@ MyKeyFullInformation
Definition: AssocQueryKey.c:44
enum _MY_KEY_INFORMATION_CLASS MY_KEY_INFORMATION_CLASS

Function Documentation

◆ AQS()

static HRESULT AQS ( ASSOCF  flags,
ASSOCSTR  str,
LPCWSTR  pszAsso,
LPCWSTR  pszExtra,
LPWSTR  pszOut 
)
static

Definition at line 109 of file AssocQueryKey.c.

110{
112 return AssocQueryStringW(flags, str, pszAsso, pszExtra, pszOut, &cch);
113}
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:569
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
const WCHAR * str
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432

Referenced by TestClassKey().

◆ Cleanup()

static void Cleanup ( void  )
static

Definition at line 23 of file AssocQueryKey.c.

24{
28}
static const WCHAR pszUniquePid2[]
Definition: AssocQueryKey.c:21
static const WCHAR pszUniqueExt[]
Definition: AssocQueryKey.c:19
static const WCHAR pszUniquePid[]
Definition: AssocQueryKey.c:20
DWORD WINAPI SHDeleteKeyW(HKEY hkey, const WCHAR *subkey)
Definition: main.c:1886
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by START_TEST(), and TestClassKey().

◆ CreateClassesKey()

static HKEY CreateClassesKey ( HKEY  hRoot)
static

Definition at line 140 of file AssocQueryKey.c.

141{
143 return hRoot;
144 if (RegCreateKeyExW(hRoot, L"Software\\Classes", 0, NULL, 0, KEY_WRITE | KEY_READ, NULL, &hRoot, NULL))
145 return NULL;
146 return hRoot;
147}
#define NULL
Definition: types.h:112
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
static HTREEITEM hRoot
Definition: treeview.c:383
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_WRITE
Definition: nt_native.h:1034

Referenced by CreateClassesSubKey().

◆ CreateClassesSubKey()

static HKEY CreateClassesSubKey ( HKEY  hRoot,
LPCWSTR  pszSubKey 
)
static

Definition at line 149 of file AssocQueryKey.c.

150{
152 if (hRoot && pszSubKey)
153 {
154 HKEY hSubKey;
158 return err ? NULL : hSubKey;
159 }
160 return hRoot;
161}
static HKEY CreateClassesKey(HKEY hRoot)
#define RegCloseKey(hKey)
Definition: registry.h:49
long LONG
Definition: pedump.c:60
_In_opt_ LPCSTR pszSubKey
Definition: shlwapi.h:783
#define err(...)

Referenced by TestClassKey().

◆ GetAqkPath()

static HRESULT GetAqkPath ( UINT  InitF,
ASSOCKEY  AssocKey,
LPCWSTR  pszInit,
LPCWSTR  pszExtra,
LPWSTR ppszKey 
)
static

Definition at line 115 of file AssocQueryKey.c.

116{
117 HKEY hKey = NULL;
118 HRESULT hr = AssocQueryKeyW((ASSOCF)InitF, AssocKey, pszInit, pszExtra, &hKey);
119 if (ppszKey)
120 *ppszKey = GetKeyPath(hKey);
121 if (SUCCEEDED(hr) && hKey)
123 return hr == S_OK && !hKey ? S_FALSE : hr;
124}
static LPWSTR GetKeyPath(HKEY hKey)
Definition: AssocQueryKey.c:67
HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc, LPCWSTR pszExtra, HKEY *phkeyOut)
Definition: assoc.c:497
FxAutoRegKey hKey
#define S_OK
Definition: intsafe.h:52
DWORD ASSOCF
Definition: shlwapi.h:967
#define S_FALSE
Definition: winerror.h:3451

Referenced by TEST_ByExeName(), and TestClassKey().

◆ GetKeyPath()

static LPWSTR GetKeyPath ( HKEY  hKey)
static

Definition at line 67 of file AssocQueryKey.c.

68{
69 if (!g_NtQueryKey || !hKey)
70 return NULL;
71
72 ULONG needed = 0;
74
75 if (!needed)
76 return NULL;
77
78 SIZE_T cb = needed + sizeof(WCHAR);
79 PBYTE buf = (PBYTE)_alloca(cb);
81
82 ULONG returned = 0;
84
85 if (status < 0)
86 return NULL;
87
89 return StrDupW(info->Name); // needs LocalFree
90}
static FN_NtQueryKey g_NtQueryKey
Definition: AssocQueryKey.c:56
struct _MY_KEY_NAME_INFORMATION * PMY_KEY_NAME_INFORMATION
LONG NTSTATUS
Definition: precomp.h:26
WCHAR *WINAPI StrDupW(const WCHAR *str)
Definition: string.c:317
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ZeroMemory
Definition: minwinbase.h:31
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59

Referenced by GetAqkPath(), TEST_AssocF_Flags(), TEST_AssocKeys(), TEST_PszAssoc(), and TEST_ShellExecClass().

◆ InitNtQueryKey()

static BOOL InitNtQueryKey ( VOID  )
static

Definition at line 58 of file AssocQueryKey.c.

59{
60 HMODULE hNTDLL = GetModuleHandleW(L"ntdll.dll");
61 if (!hNTDLL) return FALSE;
62 g_NtQueryKey = (FN_NtQueryKey)GetProcAddress(hNTDLL, "NtQueryKey");
63 return g_NtQueryKey != NULL;
64}
NTSTATUS(__stdcall * FN_NtQueryKey)(HANDLE, MY_KEY_INFORMATION_CLASS, PVOID, ULONG, PULONG)
Definition: AssocQueryKey.c:55
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838

Referenced by START_TEST().

◆ IsValidClassesRootPath()

static BOOL IsValidClassesRootPath ( LPCWSTR  path)
static

Definition at line 92 of file AssocQueryKey.c.

93{
95 if (!path)
96 return FALSE;
97 if (path == StrStrIW(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\"))
98 return TRUE;
99 base = StrStrIW(path, L"\\REGISTRY\\USER\\");
100 return base && StrStrIW(path, L"_CLASSES\\") > base;
101}
#define TRUE
Definition: types.h:120
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:380

Referenced by TEST_ShellExecClass().

◆ SHELL_SetRegString()

static HRESULT SHELL_SetRegString ( HKEY  hKey,
LPCWSTR  pszSubKey,
LPCWSTR  pszName,
UINT  Type,
LPCWSTR  pszData 
)
static

Definition at line 103 of file AssocQueryKey.c.

104{
105 ULONG err = SHSetValueW(hKey, pszSubKey, pszName, Type, pszData, (lstrlenW(pszData) + 1) * sizeof(*pszData));
106 return HRESULT_FROM_WIN32(err);
107}
Type
Definition: Type.h:7
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI SHSetValueW(HKEY hkey, const WCHAR *subkey, const WCHAR *value, DWORD type, const void *data, DWORD data_len)
Definition: main.c:2292

Referenced by TestClassKey().

◆ START_TEST()

START_TEST ( AssocQueryKey  )

Definition at line 617 of file AssocQueryKey.c.

618{
619 if (!InitNtQueryKey())
620 {
621 skip("NtQueryKey not found\n");
622 return;
623 }
624
625 HRESULT hrCoInit = CoInitialize(NULL);
626
632 TEST_Class();
635
636 Cleanup();
637 if (SUCCEEDED(hrCoInit))
639}
static void Cleanup(void)
Definition: AssocQueryKey.c:23
static BOOL InitNtQueryKey(VOID)
Definition: AssocQueryKey.c:58
static void TEST_Class(void)
static void TEST_ByExeName(void)
static void TEST_ShellExecClass(void)
static void TEST_PszAssoc(void)
static void TEST_AssocKeys(void)
static void TEST_AssocF_Flags(void)
static void TEST_BaseClass(void)
static void TEST_InvalidArgs(void)
#define skip(...)
Definition: atltest.h:64
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531

◆ TEST_AssocF_Flags()

static void TEST_AssocF_Flags ( void  )
static

Definition at line 359 of file AssocQueryKey.c.

360{
361 const ASSOCF cases[] =
362 {
377 };
378
379 for (size_t i = 0; i < _countof(cases); ++i)
380 {
381 HKEY hKey = NULL;
382 HRESULT hr = AssocQueryKeyW(cases[i], ASSOCKEY_CLASS, L".reg", NULL, &hKey);
383 ok_hr(hr, S_OK);
384
386 if (hKey)
388
389 LPCWSTR pszExpectedLM = L"\\REGISTRY\\MACHINE\\";
390 LPCWSTR pszExpectedCU = L"\\REGISTRY\\USER\\";
391 if (cases[i] & ASSOCF_PER_MACHINE_ONLY)
392 pszExpectedCU = pszExpectedLM;
393 ok(path &&
394 (StrStrIW(path, pszExpectedLM) || StrStrIW(path, pszExpectedCU)),
395 "path was %s\n", wine_dbgstr_w(path));
397 }
398}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
#define ok(value,...)
Definition: atltest.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
@ ASSOCKEY_CLASS
Definition: shlwapi.h:921
@ ASSOCF_REMAPRUNDLL
Definition: shlwapi.h:867
@ ASSOCF_NOFIXUPS
Definition: shlwapi.h:868
@ ASSOCF_PER_MACHINE_ONLY
Definition: shlwapi.h:878
@ ASSOCF_IGNOREBASECLASS
Definition: shlwapi.h:869
@ ASSOCF_INIT_NOREMAPCLSID
Definition: shlwapi.h:859
@ ASSOCF_VERIFY
Definition: shlwapi.h:866
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:870
@ ASSOCF_NOUSERSETTINGS
Definition: shlwapi.h:864
@ ASSOCF_NONE
Definition: shlwapi.h:858
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:865
#define _countof(array)
Definition: sndvol32.h:70

Referenced by START_TEST().

◆ TEST_AssocKeys()

static void TEST_AssocKeys ( void  )
static

Definition at line 294 of file AssocQueryKey.c.

295{
296 {
297 HKEY hKey = NULL;
299 ok_hr(hr, S_OK);
300
302 if (hKey)
304
305 ok(path &&
306 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
307 StrStrIW(path, L"regfile"),
308 "path was %s\n", wine_dbgstr_w(path));
310 }
311
312 {
313 HKEY hKey = NULL;
315 ok_hr(hr, S_OK);
316
318 if (hKey)
320
321 ok(path && StrStrIW(path,
322 L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\Applications\\regedit.exe"),
323 "path was %s\n", wine_dbgstr_w(path));
325 }
326
327 {
328 HKEY hKey = NULL;
330 ok_hr(hr, S_OK);
331
333 if (hKey)
335
336 ok(path &&
337 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
338 StrStrIW(path, L"Classes\\regfile"),
339 "path was %s\n", wine_dbgstr_w(path));
341 }
342
343 {
344 HKEY hKey = NULL;
346 ok_hr(hr, S_OK);
347
349 if (hKey)
351
352 ok(path && !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\exefile"),
353 "path was %s\n", wine_dbgstr_w(path));
355 }
356}
@ ASSOCKEY_SHELLEXECCLASS
Definition: shlwapi.h:919
@ ASSOCKEY_APP
Definition: shlwapi.h:920

Referenced by START_TEST().

◆ TEST_BaseClass()

static void TEST_BaseClass ( void  )
static

Definition at line 587 of file AssocQueryKey.c.

588{
589 ok_AqkPath(AF_DEFSTAR, ASSOCKEY_BASECLASS, pszUniqueExt, NULL, S_OK, L"SOFTWARE\\Classes\\*");
590 ok_AqkPath(AF_DEFFOLDER, ASSOCKEY_BASECLASS, L"Folder", NULL, S_OK, L"SOFTWARE\\Classes\\Folder");
591 ok_AqkPath(AF_DEFFOLDER, ASSOCKEY_BASECLASS, L"Directory", NULL, S_OK, L"SOFTWARE\\Classes\\Folder");
592}
#define ok_AqkPath(InitF, AssocKey, pszInit, pszExtra, hrExpected, pszExpectedWin32)
@ ASSOCKEY_BASECLASS
Definition: shlwapi.h:922

Referenced by START_TEST().

◆ TEST_ByExeName()

static void TEST_ByExeName ( void  )
static

Definition at line 547 of file AssocQueryKey.c.

548{
549 HRESULT hr;
550 BOOL nt5 = LOBYTE(GetVersion()) < 6;
551 WCHAR notepadPath[MAX_PATH];
552 GetSystemDirectoryW(notepadPath, MAX_PATH);
553 lstrcatW(notepadPath, L"\\notepad.exe");
554
555 // Full path
557 S_OK, L"SOFTWARE\\Classes\\Applications\\notepad.exe");
558
559 // Filename.exe
561 S_OK, L"SOFTWARE\\Classes\\Applications\\regedit.exe");
562
563 // Filename (no extension)
565 S_OK, L"SOFTWARE\\Classes\\Applications\\regedit.exe");
566
567 // Filename.exe with Extra
568 ok_AqkPath(ASSOCF_OPEN_BYEXENAME, ASSOCKEY_APP, L"regedit.exe", L"Extra",
569 S_OK, L"SOFTWARE\\Classes\\Applications\\regedit.exe");
570
571 // Non existent
572 ok_AqkPath(ASSOCF_INIT_BYEXENAME, ASSOCKEY_APP, L"__does_not_exist__.exe", NULL,
573 nt5 ? HR_FNF : HR_NOASSOC, -0);
574
575 // Without BYEXENAME
576 hr = GetAqkPath(ASSOCF_NONE, ASSOCKEY_APP, L"regedit.exe", NULL, NULL);
577 ok_hr(hr, nt5 ? E_FAIL : HR_NOASSOC);
578}
#define E_FAIL
Definition: ddrawi.h:102
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LOBYTE(W)
Definition: jmemdos.c:487
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
@ ASSOCF_OPEN_BYEXENAME
Definition: shlwapi.h:861
@ ASSOCF_INIT_BYEXENAME
Definition: shlwapi.h:860

Referenced by START_TEST().

◆ TEST_Class()

static void TEST_Class ( void  )
static

Definition at line 581 of file AssocQueryKey.c.

582{
584}
static void TestClassKey(ASSOCKEY AssocKey)

Referenced by START_TEST().

◆ TEST_InvalidArgs()

static void TEST_InvalidArgs ( void  )
static

Definition at line 465 of file AssocQueryKey.c.

466{
467 // phkeyOut == NULL
468 {
469 BOOL threw = FALSE;
471
473 {
475 }
477 {
478 hr = 0xDEADFACE;
479 threw = TRUE;
480 }
481 _SEH2_END;
482
483 ok_hr(hr, 0xDEADFACE);
484 ok_int(threw, TRUE);
485 }
486
487 // pszAssoc == NULL
488 {
489 BOOL threw = FALSE;
491 HKEY hKey = NULL;
492
494 {
496 }
498 {
499 hr = 0xDEADFACE;
500 threw = TRUE;
501 }
502 _SEH2_END;
503
504 ok(hKey == NULL, "hKey was not NULL\n");
505 if (hKey)
507
509 ok_int(threw, FALSE);
510 }
511
512 // pszAssoc == ""
513 {
514 HKEY hKey = NULL;
516 if (hKey)
519 }
520
521 // Invalid ASSOCKEY value
522 {
523 HKEY hKey = NULL;
524 BOOL threw = FALSE;
526
528 {
529 hr = AssocQueryKeyW(ASSOCF_NONE, (ASSOCKEY)0xFFFF, L".txt", NULL, &hKey);
530 }
532 {
533 hr = 0xDEADFACE;
534 threw = TRUE;
535 }
536 _SEH2_END;
537
538 ok(hKey == NULL, "hKey was not NULL\n");
539 if (hKey)
541
543 ok_int(threw, FALSE);
544 }
545}
#define ok_int(expression, result)
Definition: atltest.h:134
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
ASSOCKEY
Definition: shlwapi.h:918
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define E_UNEXPECTED
Definition: winerror.h:3528

Referenced by START_TEST().

◆ TEST_PszAssoc()

static void TEST_PszAssoc ( void  )
static

Definition at line 401 of file AssocQueryKey.c.

402{
403 const wchar_t* exts[] =
404 {
405 L".txt", L".htm", L".reg", L".xml", L".png", L".jpg", L".zip"
406 };
407
408 for (size_t i = 0; i < _countof(exts); ++i)
409 {
410 HKEY hKey = NULL;
412 ok_hr(hr, S_OK);
413
415 if (hKey)
417
418 ok(path &&
419 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")),
420 "path was %s\n", wine_dbgstr_w(path));
422 }
423
424 // Direct ProgID
425 {
426 HKEY hKey = NULL;
428 ok_hr(hr, S_OK);
429
431 if (hKey)
433
434 ok(path &&
435 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
436 StrStrIW(path, L"regfile"),
437 "path was %s\n", wine_dbgstr_w(path));
439 }
440 {
441 HKEY hKey = NULL;
443 ok_hr(hr, S_OK);
444
446 if (hKey)
448
449 ok(path && !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\exefile"),
450 "path was %s\n", wine_dbgstr_w(path));
452 }
453
454 // ProgID: InternetShortcut
455 {
456 HKEY hKey = NULL;
457 HRESULT hr = AssocQueryKeyW(ASSOCF_NONE, ASSOCKEY_CLASS, L"InternetShortcut", NULL, &hKey);
458 ok_hr(hr, S_OK);
459 if (hKey)
461 }
462}
static const struct encodedExtensions exts[]
Definition: encode.c:2738

Referenced by START_TEST().

◆ TEST_ShellExecClass()

static void TEST_ShellExecClass ( void  )
static

Definition at line 596 of file AssocQueryKey.c.

597{
598 static const LPCWSTR cases[] = { L".txt", L".htm", L".html", L"txtfile" };
599 for (size_t i = 0; i < _countof(cases); ++i)
600 {
601 HKEY hKey = NULL;
603 ok_hr(hr, S_OK);
604
606 if (hKey)
608
609 ok(IsValidClassesRootPath(path), "path was %s\n", wine_dbgstr_w(path));
611 }
612
614 // TODO: ASSOCF_VERIFY
615}
static BOOL IsValidClassesRootPath(LPCWSTR path)
Definition: AssocQueryKey.c:92

Referenced by START_TEST().

◆ TestClassKey()

static void TestClassKey ( ASSOCKEY  AssocKey)
static

Definition at line 163 of file AssocQueryKey.c.

164{
165 BOOL nt5 = LOBYTE(GetVersion()) < 6;
166 HKEY hSource, hClass, hClass2;
167 HRESULT hr, hrExpect;
168 WCHAR buf[MAX_PATH], *pszPath;
169 Cleanup();
170
171 // A ProgId that does not exist
173 hrExpect = nt5 ? (E_FAIL) : (AssocKey == ASSOCKEY_SHELLEXECCLASS ? HR_NOASSOC : HR_NF);
174 ok_hr(hr, hrExpect);
175
176 // An extension that does not exist (could map to Unknown)
178 hrExpect = nt5 ? E_FAIL : S_OK;
179 ok_hr(hr, hrExpect);
180
181 // An extension that does not exist
183 hrExpect = nt5 ? E_FAIL : (AssocKey == ASSOCKEY_SHELLEXECCLASS ? HR_NOASSOC : S_OK);
184 ok_hr(hr, hrExpect);
185
187 if (!hSource)
188 {
189 skip("Could not create test key\n");
190 return;
191 }
192
193 // An extension with no ProgId (could map to Unknown)
195 hrExpect = nt5 && AssocKey == ASSOCKEY_SHELLEXECCLASS ? HR_FNF : S_OK;
196 ok_hr(hr, hrExpect);
197
198 // An extension with no ProgId
200 hrExpect = AssocKey == ASSOCKEY_SHELLEXECCLASS ? (nt5 ? HR_FNF : HR_NOASSOC) : S_OK;
201 ok_hr(hr, hrExpect);
202
203 // An extension with only a fallback command
204 if (SHELL_SetRegString(hSource, L"shell\\open\\command", NULL, REG_SZ, L"calc.exe"))
205 {
206 skip("Could not create test key\n");
207 }
208 else
209 {
211 ok_hr(hr, S_OK);
212
214 ok_hr(hr, S_OK);
215
217 ok_hr(hr, S_OK); // Strange but true
218
219 hr = GetAqkPath(ASSOCF_INIT_IGNOREUNKNOWN, AssocKey, pszUniqueExt, L"badverb", NULL);
220 hrExpect = AssocKey == ASSOCKEY_SHELLEXECCLASS ? (nt5 ? HR_FNF : HR_NOASSOC) : S_OK;
221 ok_hr(hr, hrExpect);
222 SHDeleteKeyW(hSource, L"shell");
223 }
224
225 // ProgId
227 {
228 skip("Could not create test key\n");
229 }
230 else
231 {
233 if (SHELL_SetRegString(hClass, L"shell\\calcverb\\command", NULL, REG_SZ, L"calc.exe"))
234 {
235 skip("Could not create test key\n");
236 goto skip_progidtests;
237 }
238
240 ok_hr(hr, S_OK);
241
242 hr = GetAqkPath(ASSOCF_INIT_IGNOREUNKNOWN, AssocKey, pszUniqueExt, L"calcverb", NULL);
243 ok_hr(hr, S_OK);
244
246 hrExpect = AssocKey == ASSOCKEY_SHELLEXECCLASS ? (nt5 ? HR_FNF : HR_NOASSOC) : S_OK;
247 ok_hr(hr, hrExpect);
248
250 ok_hr(hr, S_OK);
251
252 // CurVer redirection
254 {
255 skip("Could not create test key\n");
256 goto skip_progidtests;
257 }
258 else
259 {
260 LPCWSTR pszExe2 = L"calc.exe";
261 ASSOCMAKEVERB verbs2[] =
262 {
263 { L"calcverb2", NULL, NULL, pszExe2, L"CurVerParam" },
264 };
265 ASSOCMAKESHELL shell2 = { verbs2, _countof(verbs2), 0 };
266 AssocMakeShell(0, hClass2, pszExe2, &shell2);
267 SHELL_SetRegString(hClass, L"CurVer", NULL, REG_SZ, pszUniquePid2);
268
269 hr = GetAqkPath(ASSOCF_NONE, AssocKey, pszUniqueExt, NULL, &pszPath);
270 ok_hr(hr, S_OK);
271 ok(pszPath && StrStrIW(pszPath, pszUniquePid2), "CurVer ProgId redirection\n");
272 LocalFree(pszPath), pszPath = NULL;
273
275 ok(SUCCEEDED(hr) && StrStrIW(buf, verbs2[0].pszArgs), "CurVer ProgId redirection\n");
276
277 SHDeleteKeyW(hClass2, L"");
278 RegCloseKey(hClass2);
279 }
280
281skip_progidtests:
282 SHDeleteKeyW(hClass, L"");
283 RegCloseKey(hClass);
284 }
285
286 if (hSource)
287 {
288 SHDeleteKeyW(hSource, L"");
289 RegCloseKey(hSource);
290 }
291}
static HRESULT AQS(ASSOCF flags, ASSOCSTR str, LPCWSTR pszAsso, LPCWSTR pszExtra, LPWSTR pszOut)
static HKEY CreateClassesSubKey(HKEY hRoot, LPCWSTR pszSubKey)
static HRESULT SHELL_SetRegString(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszName, UINT Type, LPCWSTR pszData)
#define REG_SZ
Definition: layer.c:22
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:886
HRESULT WINAPI AssocMakeShell(SIZE_T Unknown, _In_ HKEY hClass, _In_ LPCWSTR pszExe, _In_ const ASSOCMAKESHELL *pAMS)
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by TEST_Class(), and TEST_ShellExecClass().

Variable Documentation

◆ g_NtQueryKey

FN_NtQueryKey g_NtQueryKey = NULL
static

Definition at line 56 of file AssocQueryKey.c.

Referenced by GetKeyPath(), and InitNtQueryKey().

◆ pszUniqueExt

const WCHAR pszUniqueExt[] = L".RosTestExtShlwapi"
static

Definition at line 19 of file AssocQueryKey.c.

Referenced by Cleanup(), TEST_BaseClass(), and TestClassKey().

◆ pszUniquePid

const WCHAR pszUniquePid[] = L"FEF31D544EA64C8EBC50B8719887688A"
static

Definition at line 20 of file AssocQueryKey.c.

Referenced by Cleanup(), and TestClassKey().

◆ pszUniquePid2

const WCHAR pszUniquePid2[] = L"88FDE0879CD24AEBBEB690988BD87706"
static

Definition at line 21 of file AssocQueryKey.c.

Referenced by Cleanup(), and TestClassKey().