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