ReactOS 0.4.17-dev-1133-gc25e4fd
ShellFolder.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Tests for IShellFolder
5 * COPYRIGHT: Copyright 2026 Whindmar Saksit <whindsaks@proton.me>
6 */
7
8#include "shelltest.h"
9#include <shellutils.h>
10#include <shlguid_undoc.h>
11
13{
16 if (FAILED(hr))
17 return NULL;
18 IShellFolder2 *pFolder;
19 hr = SHELL_BindToObject(NULL, pidl, NULL, IID_PPV_ARG(IShellFolder2, &pFolder));
20 ILFree(pidl);
21 return SUCCEEDED(hr) ? pFolder : NULL;
22}
23
24static void TestFolderSearch()
25{
26 const bool nt5 = LOBYTE(GetVersion()) < 6;
27 static const struct {
28 BYTE csidl;
29 HRESULT hr;
30 const GUID *pExpected;
31 } defs[] =
32 {
34 { CSIDL_DRIVES, nt5 ? S_OK : E_NOTIMPL, nt5 ? &CLSID_ShellSearchExt : NULL },
35 { CSIDL_CONTROLS, nt5 ? S_OK : E_NOTIMPL, nt5 ? &CLSID_ShellSearchExt : NULL },
36 { CSIDL_BITBUCKET, nt5 ? S_OK : E_NOTIMPL, nt5 ? &CLSID_ShellSearchExt : NULL },
41 };
42 for (SIZE_T i = 0; i < _countof(defs); ++i)
43 {
44 CComPtr<IShellFolder2> pFolder(CreateFolder2Instance(defs[i].csidl));
45 if (!pFolder)
46 {
47 skip("Can't create special folder %d\n", defs[i].csidl);
48 continue;
49 }
50 GUID invalid = IID_IPersistFolder3;
51 GUID guid = invalid;
52 HRESULT hr = pFolder->GetDefaultSearchGUID(&guid);
53 ok(hr == defs[i].hr, "Unexpected result %#x for %d\n", hr, defs[i].csidl);
54 ok(IsEqualGUID(guid, defs[i].pExpected ? *defs[i].pExpected : invalid), "GUID mismatch for %d!\n", defs[i].csidl);
55 }
56
57 static const struct {
58 BYTE csidl;
59 HRESULT hr;
60 bool NullOutput;
61 } enums[] =
62 {
63 { CSIDL_DESKTOP, E_NOTIMPL, true },
64 { CSIDL_DRIVES, E_NOTIMPL, true },
65 { CSIDL_CONTROLS, E_NOTIMPL, true },
66 { CSIDL_BITBUCKET, E_NOTIMPL, true },
67 { CSIDL_SYSTEM, E_NOTIMPL, true },
68 { CSIDL_FONTS, E_NOTIMPL, true },
69 { CSIDL_COOKIES, E_NOTIMPL, true },
70 };
71 for (SIZE_T i = 0; i < _countof(enums); ++i)
72 {
73 CComPtr<IShellFolder2> pFolder(CreateFolder2Instance(enums[i].csidl));
74 if (!pFolder)
75 {
76 skip("Can't create special folder %d\n", enums[i].csidl);
77 continue;
78 }
79 IEnumExtraSearch *invalid = (IEnumExtraSearch*)(SIZE_T)0xBAADF00Dul;
80 IEnumExtraSearch *pEnum = invalid;
81 HRESULT hr = pFolder->EnumSearches(&pEnum);
82 ok(hr == enums[i].hr, "Unexpected result %#x for %d\n", hr, enums[i].csidl);
83 ok(pEnum == (enums[i].NullOutput ? NULL : invalid), "Result mismatch for %d!\n", enums[i].csidl);
84 if (pEnum && pEnum != invalid)
85 pEnum->Release();
86 }
87}
88
90{
91 const bool nt5 = LOBYTE(GetVersion()) < 6;
92 static const struct {
93 BYTE csidl;
94 HRESULT hr;
95 BYTE col;
96 } defs[] =
97 {
104 { CSIDL_NETWORK, nt5 ? E_NOTIMPL : S_OK, 0 },
108 };
109 for (SIZE_T i = 0; i < _countof(defs); ++i)
110 {
111 CComPtr<IShellFolder2> pFolder(CreateFolder2Instance(defs[i].csidl));
112 if (!pFolder)
113 {
114 skip("Can't create special folder %d\n", defs[i].csidl);
115 continue;
116 }
117 ULONG invalid = (ULONG)-42;
118 ULONG sort = invalid, disp = invalid;
119 HRESULT hr = pFolder->GetDefaultColumn(0, &sort, &disp);
120 ok(hr == defs[i].hr, "Unexpected result %#x for %d\n", hr, defs[i].csidl);
121 ULONG expected = SUCCEEDED(hr) ? defs[i].col : invalid;
122 ok(sort == expected, "Unexpected output %#x for %d\n", sort, defs[i].csidl);
123 ok(disp == expected, "Unexpected output %#x for %d\n", disp, defs[i].csidl);
124 }
125}
126
128{
129 // Note: We are just testing the first column here, specific tests should be performed in the tests for each folder.
130 const bool nt5 = LOBYTE(GetVersion()) < 6;
131 static const struct {
132 BYTE csidl;
133 HRESULT hr;
134 BYTE type;
135 } states[] =
136 {
147 };
148 for (SIZE_T i = 0; i < _countof(states); ++i)
149 {
150 CComPtr<IShellFolder2> pFolder(CreateFolder2Instance(states[i].csidl));
151 if (!pFolder)
152 {
153 skip("Can't create special folder %d\n", states[i].csidl);
154 continue;
155 }
156 UINT invalid = SHCOLSTATE_TYPEMASK;
157 SHCOLSTATEF flags = invalid;
158 HRESULT hr = pFolder->GetDefaultColumnState(0, &flags);
159 ok(hr == states[i].hr, "Unexpected result %#x for %d\n", hr, states[i].csidl);
160 UINT expected = SUCCEEDED(states[i].hr) ? states[i].type : invalid;
161 ok((flags & SHCOLSTATE_TYPEMASK) == expected, "Unexpected output %#x for %d\n", flags, states[i].csidl);
162 }
163}
164
166{
167 CCoInit ComInit;
168
172}
#define IID_PPV_ARG(Itype, ppType)
static IShellFolder2 * CreateFolder2Instance(WORD csidl)
Definition: ShellFolder.cpp:12
static void TestGetDefaultColumn()
Definition: ShellFolder.cpp:89
static void TestGetDefaultColumnState()
static void TestFolderSearch()
Definition: ShellFolder.cpp:24
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
static struct @576 sort
GUID guid
Definition: version.c:147
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:3385
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
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
unsigned int UINT
Definition: sysinfo.c:13
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define LOBYTE(W)
Definition: jmemdos.c:487
static const struct encodedInt enums[]
Definition: encode.c:361
BOOL expected
Definition: store.c:2000
static IShellFolder ShellFolder
Definition: ordinal.c:2637
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1051
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define CSIDL_FONTS
Definition: shlobj.h:2210
#define CSIDL_CONNECTIONS
Definition: shlobj.h:2239
#define CSIDL_COOKIES
Definition: shlobj.h:2223
#define CSIDL_PRINTERS
Definition: shlobj.h:2195
#define CSIDL_SYSTEM
Definition: shlobj.h:2227
#define CSIDL_DESKTOP
Definition: shlobj.h:2191
#define CSIDL_NETWORK
Definition: shlobj.h:2208
#define CSIDL_DRIVES
Definition: shlobj.h:2207
#define CSIDL_CONTROLS
Definition: shlobj.h:2194
#define CSIDL_BITBUCKET
Definition: shlobj.h:2201
@ SHCOLSTATE_TYPEMASK
Definition: shtypes.idl:124
@ SHCOLSTATE_TYPE_STR
Definition: shtypes.idl:121
DWORD SHCOLSTATEF
Definition: shtypes.idl:142
#define _countof(array)
Definition: sndvol32.h:70
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
unsigned char BYTE
Definition: xxhash.c:193