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