[COMCAT_WINETEST]
[reactos.git] / rostests / winetests / comcat / comcat.c
1 /*
2 * tests for comcat functions
3 *
4 * Copyright 2006 Aric Stewart for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26
27 #include <wine/test.h>
28
29 //#include <stdio.h>
30 //#include <initguid.h>
31 //#include <windows.h>
32 #include <winreg.h>
33 //#include "objbase.h"
34 #include <ole2.h>
35 #include <comcat.h>
36
37 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
38
39 static BOOL register_testentry(void)
40 {
41 HKEY hkey = 0, hkey2 = 0;
42 DWORD ret;
43
44 ret = RegCreateKeyA(HKEY_CLASSES_ROOT,"CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}", &hkey);
45 if (!ret) ret = RegSetValueA(hkey,NULL,REG_SZ,"ComCat Test key",16);
46 if (!ret) ret = RegCreateKeyA(hkey,
47 "Implemented Categories\\{deadcafe-0000-0000-0000-000000000000}",
48 &hkey2);
49 RegCloseKey(hkey);
50 RegCloseKey(hkey2);
51 return !ret;
52 }
53
54 static void unregister_testentry(void)
55 {
56 RegDeleteKeyA(HKEY_CLASSES_ROOT,
57 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories\\{deadcafe-0000-0000-0000-000000000000}");
58 RegDeleteKeyA(HKEY_CLASSES_ROOT,
59 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories");
60 RegDeleteKeyA(HKEY_CLASSES_ROOT,
61 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}");
62 }
63
64 static void do_enum(void)
65 {
66 HRESULT hr;
67 REFCLSID rclsid = &CLSID_StdComponentCategoriesMgr;
68 ICatInformation *pICat = (ICatInformation*)0xdeadbeef;
69 GUID the_guid[1];
70 GUID the_cat[1];
71 GUID wanted_guid;
72 ULONG fetched = -1;
73
74 static const WCHAR szCatID[] = {
75 '{',
76 'd','e','a','d','c','a','f','e',
77 '-','0','0','0','0','-','0','0','0','0',
78 '-','0','0','0','0',
79 '-','0','0','0','0','0','0','0','0','0','0','0','0',
80 '}',0};
81 static const WCHAR szGuid[] = {
82 '{',
83 'd','e','a','d','c','a','f','e','-',
84 'b','e','e','d','-',
85 'b','e','a','d','-',
86 'd','e','a','d','-',
87 'c','a','f','e','b','e','a','d','d','e','a','d',
88 '}',0};
89
90 IEnumCLSID *pIEnum =(IEnumCLSID*)0xdeadcafe;
91
92 CLSIDFromString(szCatID,the_cat);
93 CLSIDFromString(szGuid,&wanted_guid);
94
95 OleInitialize(NULL);
96
97 hr = CoCreateInstance(rclsid,NULL,CLSCTX_INPROC_SERVER,
98 &IID_ICatInformation, (void **)&pICat);
99 ok_ole_success(hr, "CoCreateInstance");
100
101 hr = ICatInformation_EnumClassesOfCategories(pICat, -1, NULL, -1, NULL,
102 &pIEnum);
103 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
104
105 IEnumGUID_Release(pIEnum);
106
107 hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL,
108 &pIEnum);
109 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
110
111 hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
112 ok (hr == S_FALSE,"Expected S_FALSE, got 0x%08x\n", hr);
113 ok (fetched == 0,"Fetched wrong number of guids %u\n",fetched);
114 IEnumGUID_Release(pIEnum);
115
116 if (register_testentry())
117 {
118 hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL, &pIEnum);
119 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
120
121 hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
122 ok (hr == S_OK,"Expected S_OK, got 0x%08x\n", hr);
123 ok (fetched == 1,"Fetched wrong number of guids %u\n",fetched);
124 ok (IsEqualGUID(the_guid,&wanted_guid),"Guids do not match\n");
125
126 IEnumGUID_Release(pIEnum);
127 unregister_testentry();
128 }
129 else skip( "Could not register the test category\n" );
130
131 ICatInformation_Release(pICat);
132
133 OleUninitialize();
134 }
135
136
137 START_TEST(comcat)
138 {
139 do_enum();
140 }