ReactOS 0.4.17-dev-284-g529f3c6
SHGetFileDescription.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for SHGetFileDescriptionA/W
5 * COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include <apitest.h>
9#include <shlwapi.h>
10#include <strsafe.h>
11
14
17
18static BOOL LoadFunctions(void)
19{
20 HMODULE hSHLWAPI = GetModuleHandleW(L"shlwapi.dll");
21 if (!hSHLWAPI)
22 hSHLWAPI = LoadLibraryW(L"shlwapi.dll");
23 if (!hSHLWAPI)
24 return FALSE;
25
28
30}
31
33{
34 WCHAR sys[MAX_PATH];
35 if (!GetSystemDirectoryW(sys, _countof(sys)))
36 return FALSE;
37
38 StringCchPrintfW(g_notepad, _countof(sys), L"%ls\\notepad.exe", sys);
39 StringCchPrintfW(g_winver, _countof(sys), L"%ls\\winver.exe", sys);
41}
42
43static void TEST_QuerySizeOnly(void)
44{
45 UINT cch = 0;
47
48 ok_int(ret, TRUE);
49 ok(cch > 0, "cch was %u\n", cch);
50}
51
53{
54 WCHAR buf[256] = L"";
57
58 ok_int(ret, TRUE);
59 ok(buf[0] != UNICODE_NULL, "buf was empty\n");
60 ok(0 < cch && cch <= _countof(buf), "cch was %u\n", cch);
61 trace("buf: %s\n", wine_dbgstr_w(buf));
62}
63
65{
66 WCHAR buf[256] = L"";
69
70 ok_int(ret, TRUE);
71 ok(buf[0] != UNICODE_NULL, "buf was empty\n");
72 ok(0 < cch && cch <= _countof(buf), "cch was %u\n", cch);
73 trace("buf: %s\n", wine_dbgstr_w(buf));
74}
75
76static void TEST_NonExistentFile(void)
77{
78 WCHAR buf[256] = L"";
80 BOOL ret = g_fnSHGetFileDescriptionW(L"C:\\This\\Does\\Not\\Exist.exe", NULL, NULL,
81 buf, &cch);
83}
84
85static void TEST_DirectoryPath(void)
86{
87 WCHAR sys[MAX_PATH];
89
90 WCHAR buf[256] = L"";
93
94 ok_int(ret, TRUE);
95 ok(_wcsicmp(buf, L"System32") == 0, "buf was %s\n", wine_dbgstr_w(buf));
96}
97
98static void TEST_TinyBuffer(void)
99{
100 WCHAR buf[1] = { L'X' };
101 UINT cch = 1;
103
104 ok_int(ret, TRUE);
106 ok_int(cch, 1);
107}
108
109static void TEST_CustomVerKey(void)
110{
111 WCHAR buf[256] = L"";
112 UINT cch = _countof(buf);
114 L"\\StringFileInfo\\040904B0\\FileDescription",
115 NULL, buf, &cch);
116 ok_int(ret, TRUE);
117 ok(buf[0] != UNICODE_NULL, "buf was empty\n");
118}
119
120static void TEST_InvalidVerKey(void)
121{
122 WCHAR buf[256] = L"", bufNorm[256] = L"";
123 UINT cch = _countof(buf), cchNorm = _countof(bufNorm);
124
126 L"\\StringFileInfo\\FFFFFFFF\\NoSuchKey",
127 NULL, buf, &cch);
128 BOOL retNormal = g_fnSHGetFileDescriptionW(g_notepad, NULL, NULL, bufNorm, &cchNorm);
129
130 ok_int(retInvalid, TRUE);
131 ok_int(retNormal, TRUE);
132 ok(buf[0] != UNICODE_NULL, "buf was empty\n");
133 ok(lstrcmpW(buf, bufNorm) == 0, "buf was %s, bufNorm was %s\n", wine_dbgstr_w(buf),
134 wine_dbgstr_w(bufNorm));
135}
136
138{
139 if (!LoadFunctions())
140 {
141 skip("SHGetFileDescription not found\n");
142 return;
143 }
144
145 if (!BuildSystemPaths())
146 {
147 skip("notepad.exe and/or winver.exe not found\n");
148 return;
149 }
150
159}
static void TEST_GetDescriptionNotepad(void)
static void TEST_TinyBuffer(void)
BOOL(WINAPI * FN_SHGetFileDescriptionW)(PCWSTR, PCWSTR, PCWSTR, PWSTR, PUINT)
static void TEST_InvalidVerKey(void)
static FN_SHGetFileDescriptionW g_fnSHGetFileDescriptionW
static BOOL LoadFunctions(void)
static void TEST_QuerySizeOnly(void)
static void TEST_GetDescriptionWinver(void)
static void TEST_NonExistentFile(void)
static BOOL BuildSystemPaths(void)
static void TEST_CustomVerKey(void)
static void TEST_DirectoryPath(void)
static WCHAR g_notepad[MAX_PATH]
static WCHAR g_winver[MAX_PATH]
#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 TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
BOOL WINAPI PathFileExistsW(const WCHAR *path)
Definition: path.c:2583
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define wine_dbgstr_w
Definition: kernel32.h:34
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#define SHGetFileDescription
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define WINAPI
Definition: msvc.h:6
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581