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