f6067312027499d1b1df6144f29282b86e7156cb
[reactos.git] / rostests / winetests / shlwapi / clsid.c
1 /* Unit test suite for SHLWAPI Class ID functions
2 *
3 * Copyright 2003 Jon Griffiths
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #define WIN32_NO_STATUS
21 #define _INC_WINDOWS
22 #define COM_NO_WINDOWS_H
23
24 //#include <stdio.h>
25
26 #include <wine/test.h>
27 //#include "winbase.h"
28 //#include "winerror.h"
29 //#include "winnls.h"
30 //#include "winuser.h"
31 #include <objbase.h>
32 #include <initguid.h>
33 #include <shlguid.h>
34 #include <shobjidl.h>
35 #include <olectl.h>
36
37 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
38
39 /* This GUID has been removed from the PSDK */
40 DEFINE_OLEGUID(WINE_IID_IDelayedRelease, 0x000214EDL, 0, 0);
41
42 /* Function ptrs for ordinal calls */
43 static HMODULE hShlwapi = 0;
44 static BOOL (WINAPI *pSHLWAPI_269)(LPCSTR, CLSID *) = 0;
45 static DWORD (WINAPI *pSHLWAPI_23)(REFGUID, LPSTR, INT) = 0;
46
47 /* GUIDs to test */
48 static const GUID * TEST_guids[] = {
49 &CLSID_ShellDesktop,
50 &CLSID_ShellLink,
51 &CATID_BrowsableShellExt,
52 &CATID_BrowseInPlace,
53 &CATID_DeskBand,
54 &CATID_InfoBand,
55 &CATID_CommBand,
56 &FMTID_Intshcut,
57 &FMTID_InternetSite,
58 &CGID_Explorer,
59 &CGID_ShellDocView,
60 &CGID_ShellServiceObject,
61 &CGID_ExplorerBarDoc,
62 &IID_INewShortcutHookA,
63 &IID_IShellIcon,
64 &IID_IShellFolder,
65 &IID_IShellExtInit,
66 &IID_IShellPropSheetExt,
67 &IID_IPersistFolder,
68 &IID_IExtractIconA,
69 &IID_IShellDetails,
70 &WINE_IID_IDelayedRelease,
71 &IID_IShellLinkA,
72 &IID_IShellCopyHookA,
73 &IID_IFileViewerA,
74 &IID_ICommDlgBrowser,
75 &IID_IEnumIDList,
76 &IID_IFileViewerSite,
77 &IID_IContextMenu2,
78 &IID_IShellExecuteHookA,
79 &IID_IPropSheetPage,
80 &IID_INewShortcutHookW,
81 &IID_IFileViewerW,
82 &IID_IShellLinkW,
83 &IID_IExtractIconW,
84 &IID_IShellExecuteHookW,
85 &IID_IShellCopyHookW,
86 &IID_IRemoteComputer,
87 &IID_IQueryInfo,
88 &IID_IDockingWindow,
89 &IID_IDockingWindowSite,
90 &CLSID_NetworkPlaces,
91 &CLSID_NetworkDomain,
92 &CLSID_NetworkServer,
93 &CLSID_NetworkShare,
94 &CLSID_MyComputer,
95 &CLSID_Internet,
96 &CLSID_ShellFSFolder,
97 &CLSID_RecycleBin,
98 &CLSID_ControlPanel,
99 &CLSID_Printers,
100 &CLSID_MyDocuments,
101 NULL
102 };
103
104 DEFINE_GUID(IID_Endianness, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
105 0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
106
107 static void test_ClassIDs(void)
108 {
109 const GUID **guids = TEST_guids;
110 char szBuff[256];
111 GUID guid;
112 DWORD dwLen;
113 BOOL bRet;
114 int i = 0;
115 int is_vista = 0;
116
117 if (!pSHLWAPI_269 || !pSHLWAPI_23)
118 return;
119
120 while (*guids)
121 {
122 dwLen = pSHLWAPI_23(*guids, szBuff, 256);
123 if (!i && dwLen == S_OK) is_vista = 1; /* seems to return an HRESULT on vista */
124 ok(dwLen == (is_vista ? S_OK : 39), "wrong size %u for id %d\n", dwLen, i);
125
126 bRet = pSHLWAPI_269(szBuff, &guid);
127 ok(bRet != FALSE, "created invalid string '%s'\n", szBuff);
128
129 if (bRet)
130 ok(IsEqualGUID(*guids, &guid), "GUID created wrong %d\n", i);
131
132 guids++;
133 i++;
134 }
135
136 /* Test endianness */
137 dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 256);
138 ok(dwLen == (is_vista ? S_OK : 39), "wrong size %u for IID_Endianness\n", dwLen);
139
140 ok(!strcmp(szBuff, "{01020304-0506-0708-090A-0B0C0D0E0F0A}"),
141 "Endianness Broken, got '%s'\n", szBuff);
142
143 /* test lengths */
144 szBuff[0] = ':';
145 dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 0);
146 ok(dwLen == (is_vista ? E_FAIL : 0), "accepted bad length\n");
147 ok(szBuff[0] == ':', "wrote to buffer with no length\n");
148
149 szBuff[0] = ':';
150 dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 38);
151 ok(dwLen == (is_vista ? E_FAIL : 0), "accepted bad length\n");
152 ok(szBuff[0] == ':', "wrote to buffer with no length\n");
153
154 szBuff[0] = ':';
155 dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 39);
156 ok(dwLen == (is_vista ? S_OK : 39), "rejected ok length\n");
157 ok(szBuff[0] == '{', "Didn't write to buffer with ok length\n");
158
159 /* Test string */
160 strcpy(szBuff, "{xxx-");
161 bRet = pSHLWAPI_269(szBuff, &guid);
162 ok(bRet == FALSE, "accepted invalid string\n");
163
164 dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 39);
165 ok(dwLen == (is_vista ? S_OK : 39), "rejected ok length\n");
166 ok(szBuff[0] == '{', "Didn't write to buffer with ok length\n");
167 }
168
169 static void test_CLSIDFromProgIDWrap(void)
170 {
171 HRESULT (WINAPI *pCLSIDFromProgIDWrap)(LPCOLESTR,LPCLSID);
172 CLSID clsid = IID_NULL;
173 HRESULT hres;
174
175 static const WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
176
177 pCLSIDFromProgIDWrap = (void*)GetProcAddress(hShlwapi,(char*)435);
178
179 hres = pCLSIDFromProgIDWrap(wszStdPicture, &clsid);
180 ok(hres == S_OK, "CLSIDFromProgIDWrap failed: %08x\n", hres);
181 ok(IsEqualGUID(&CLSID_StdPicture, &clsid), "wrong clsid\n");
182
183 hres = pCLSIDFromProgIDWrap(NULL, &clsid);
184 ok(hres == E_INVALIDARG, "CLSIDFromProgIDWrap failed: %08x, expected E_INVALIDARG\n", hres);
185
186 hres = pCLSIDFromProgIDWrap(wszStdPicture, NULL);
187 ok(hres == E_INVALIDARG, "CLSIDFromProgIDWrap failed: %08x, expected E_INVALIDARG\n", hres);
188 }
189
190 START_TEST(clsid)
191 {
192 hShlwapi = GetModuleHandleA("shlwapi.dll");
193
194 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
195 if(!GetProcAddress(hShlwapi, "SHCreateStreamOnFileEx")){
196 win_skip("Too old shlwapi version\n");
197 return;
198 }
199
200 pSHLWAPI_269 = (void*)GetProcAddress(hShlwapi, (LPSTR)269);
201 pSHLWAPI_23 = (void*)GetProcAddress(hShlwapi, (LPSTR)23);
202
203 test_ClassIDs();
204 test_CLSIDFromProgIDWrap();
205 }