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 #include "precomp.h"
21 
22 #include <olectl.h>
23 #include <initguid.h>
24 
25 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
26 
27 /* This GUID has been removed from the PSDK */
28 DEFINE_OLEGUID(WINE_IID_IDelayedRelease,     0x000214EDL, 0, 0);
29 
30 /* Function ptrs for ordinal calls */
31 static HMODULE hShlwapi = 0;
32 static BOOL (WINAPI *pSHLWAPI_269)(LPCSTR, CLSID *) = 0;
33 static DWORD (WINAPI *pSHLWAPI_23)(REFGUID, LPSTR, INT) = 0;
34 
35 /* GUIDs to test */
36 static const GUID * TEST_guids[] = {
37   &CLSID_ShellDesktop,
38   &CLSID_ShellLink,
39   &CATID_BrowsableShellExt,
40   &CATID_BrowseInPlace,
41   &CATID_DeskBand,
42   &CATID_InfoBand,
43   &CATID_CommBand,
44   &FMTID_Intshcut,
45   &FMTID_InternetSite,
46   &CGID_Explorer,
47   &CGID_ShellDocView,
48   &CGID_ShellServiceObject,
49   &CGID_ExplorerBarDoc,
50   &IID_INewShortcutHookA,
51   &IID_IShellIcon,
52   &IID_IShellFolder,
53   &IID_IShellExtInit,
54   &IID_IShellPropSheetExt,
55   &IID_IPersistFolder,
56   &IID_IExtractIconA,
57   &IID_IShellDetails,
58   &WINE_IID_IDelayedRelease,
59   &IID_IShellLinkA,
60   &IID_IShellCopyHookA,
61   &IID_IFileViewerA,
62   &IID_ICommDlgBrowser,
63   &IID_IEnumIDList,
64   &IID_IFileViewerSite,
65   &IID_IContextMenu2,
66   &IID_IShellExecuteHookA,
67   &IID_IPropSheetPage,
68   &IID_INewShortcutHookW,
69   &IID_IFileViewerW,
70   &IID_IShellLinkW,
71   &IID_IExtractIconW,
72   &IID_IShellExecuteHookW,
73   &IID_IShellCopyHookW,
74   &IID_IRemoteComputer,
75   &IID_IQueryInfo,
76   &IID_IDockingWindow,
77   &IID_IDockingWindowSite,
78   &CLSID_NetworkPlaces,
79   &CLSID_NetworkDomain,
80   &CLSID_NetworkServer,
81   &CLSID_NetworkShare,
82   &CLSID_MyComputer,
83   &CLSID_Internet,
84   &CLSID_ShellFSFolder,
85   &CLSID_RecycleBin,
86   &CLSID_ControlPanel,
87   &CLSID_Printers,
88   &CLSID_MyDocuments,
89   NULL
90 };
91 
92 DEFINE_GUID(IID_Endianness, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
93             0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
94 
95 static void test_ClassIDs(void)
96 {
97   const GUID **guids = TEST_guids;
98   char szBuff[256];
99   GUID guid;
100   DWORD dwLen;
101   BOOL bRet;
102   int i = 0;
103   BOOL is_vista = FALSE;
104 
105   if (!pSHLWAPI_269 || !pSHLWAPI_23)
106     return;
107 
108   while (*guids)
109   {
110     dwLen = pSHLWAPI_23(*guids, szBuff, 256);
111     if (!i && dwLen == S_OK) is_vista = TRUE;  /* seems to return an HRESULT on vista */
112     ok(dwLen == (is_vista ? S_OK : 39), "wrong size %u for id %d\n", dwLen, i);
113 
114     bRet = pSHLWAPI_269(szBuff, &guid);
115     ok(bRet != FALSE, "created invalid string '%s'\n", szBuff);
116 
117     if (bRet)
118       ok(IsEqualGUID(*guids, &guid), "GUID created wrong %d\n", i);
119 
120     guids++;
121     i++;
122   }
123 
124   /* Test endianness */
125   dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 256);
126   ok(dwLen == (is_vista ? S_OK : 39), "wrong size %u for IID_Endianness\n", dwLen);
127 
128   ok(!strcmp(szBuff, "{01020304-0506-0708-090A-0B0C0D0E0F0A}"),
129      "Endianness Broken, got '%s'\n", szBuff);
130 
131   /* test lengths */
132   szBuff[0] = ':';
133   dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 0);
134   ok(dwLen == (is_vista ? E_FAIL : 0), "accepted bad length\n");
135   ok(szBuff[0] == ':', "wrote to buffer with no length\n");
136 
137   szBuff[0] = ':';
138   dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 38);
139   ok(dwLen == (is_vista ? E_FAIL : 0), "accepted bad length\n");
140   ok(szBuff[0] == ':', "wrote to buffer with no length\n");
141 
142   szBuff[0] = ':';
143   dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 39);
144   ok(dwLen == (is_vista ? S_OK : 39), "rejected ok length\n");
145   ok(szBuff[0] == '{', "Didn't write to buffer with ok length\n");
146 
147   /* Test string */
148   strcpy(szBuff, "{xxx-");
149   bRet = pSHLWAPI_269(szBuff, &guid);
150   ok(bRet == FALSE, "accepted invalid string\n");
151 
152   dwLen = pSHLWAPI_23(&IID_Endianness, szBuff, 39);
153   ok(dwLen == (is_vista ? S_OK : 39), "rejected ok length\n");
154   ok(szBuff[0] == '{', "Didn't write to buffer with ok length\n");
155 }
156 
157 static void test_CLSIDFromProgIDWrap(void)
158 {
159     HRESULT (WINAPI *pCLSIDFromProgIDWrap)(LPCOLESTR,LPCLSID);
160     CLSID clsid = IID_NULL;
161     HRESULT hres;
162 
163     static const WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
164 
165     pCLSIDFromProgIDWrap = (void*)GetProcAddress(hShlwapi,(char*)435);
166 
167     hres = pCLSIDFromProgIDWrap(wszStdPicture, &clsid);
168     ok(hres == S_OK, "CLSIDFromProgIDWrap failed: %08x\n", hres);
169     ok(IsEqualGUID(&CLSID_StdPicture, &clsid), "wrong clsid\n");
170 
171     hres = pCLSIDFromProgIDWrap(NULL, &clsid);
172     ok(hres == E_INVALIDARG, "CLSIDFromProgIDWrap failed: %08x, expected E_INVALIDARG\n", hres);
173 
174     hres = pCLSIDFromProgIDWrap(wszStdPicture, NULL);
175     ok(hres == E_INVALIDARG, "CLSIDFromProgIDWrap failed: %08x, expected E_INVALIDARG\n", hres);
176 }
177 
178 START_TEST(clsid)
179 {
180   hShlwapi = GetModuleHandleA("shlwapi.dll");
181 
182   /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
183   if(!GetProcAddress(hShlwapi, "SHCreateStreamOnFileEx")){
184       win_skip("Too old shlwapi version\n");
185       return;
186   }
187 
188   pSHLWAPI_269 = (void*)GetProcAddress(hShlwapi, (LPSTR)269);
189   pSHLWAPI_23 = (void*)GetProcAddress(hShlwapi, (LPSTR)23);
190 
191   test_ClassIDs();
192   test_CLSIDFromProgIDWrap();
193 }
194