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