ReactOS 0.4.17-dev-806-gffa4164
comcat.c
Go to the documentation of this file.
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 COBJMACROS
22
23#include <stdio.h>
24#include <initguid.h>
25#include <windows.h>
26
27#include "objbase.h"
28#include "comcat.h"
29
30#include "wine/test.h"
31
32#define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error %#08lx\n", hr)
33
35{
36 HKEY hkey = 0, hkey2 = 0;
37 DWORD ret;
38
39 ret = RegCreateKeyA(HKEY_CLASSES_ROOT,"CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}", &hkey);
40 if (!ret) ret = RegSetValueA(hkey,NULL,REG_SZ,"ComCat Test key",16);
41 if (!ret) ret = RegCreateKeyA(hkey,
42 "Implemented Categories\\{deadcafe-0000-0000-0000-000000000000}",
43 &hkey2);
44 RegCloseKey(hkey);
45 RegCloseKey(hkey2);
46 return !ret;
47}
48
49static void unregister_testentry(void)
50{
52 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories\\{deadcafe-0000-0000-0000-000000000000}");
54 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories");
56 "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}");
57}
58
59static void do_enum(void)
60{
61 HRESULT hr;
62 REFCLSID rclsid = &CLSID_StdComponentCategoriesMgr;
63 ICatInformation *pICat = (ICatInformation*)0xdeadbeef;
64 GUID the_guid[1];
65 GUID the_cat[1];
66 GUID wanted_guid;
67 ULONG fetched = -1;
68
69 IEnumCLSID *pIEnum =(IEnumCLSID*)0xdeadcafe;
70
71 CLSIDFromString(L"{deadcafe-0000-0000-0000-000000000000}", the_cat);
72 CLSIDFromString(L"{deadcafe-beed-bead-dead-cafebeaddead}", &wanted_guid);
73
75
76 hr = CoCreateInstance(rclsid,NULL,CLSCTX_INPROC_SERVER,
77 &IID_ICatInformation, (void **)&pICat);
78 ok_ole_success(hr, "CoCreateInstance");
79
80 hr = ICatInformation_EnumClassesOfCategories(pICat, -1, NULL, -1, NULL,
81 &pIEnum);
82 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
83
84 IEnumGUID_Release(pIEnum);
85
86 hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL,
87 &pIEnum);
88 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
89
90 hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
91 ok (hr == S_FALSE,"Expected S_FALSE, got 0x%08lx\n", hr);
92 ok (fetched == 0,"Fetched wrong number of guids %lu\n",fetched);
93 IEnumGUID_Release(pIEnum);
94
96 {
97 hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL, &pIEnum);
98 ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
99
100 hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
101 ok (hr == S_OK,"Expected S_OK, got 0x%08lx\n", hr);
102 ok (fetched == 1,"Fetched wrong number of guids %lu\n",fetched);
103 ok (IsEqualGUID(the_guid,&wanted_guid),"Guids do not match\n");
104
105 IEnumGUID_Release(pIEnum);
107 }
108 else skip( "Could not register the test category\n" );
109
110 ICatInformation_Release(pICat);
111
113}
114
115
117{
118 do_enum();
119}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define RegCloseKey(hKey)
Definition: registry.h:49
#define IEnumCLSID
Definition: comcat.idl:40
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1179
LONG WINAPI RegSetValueA(HKEY hKeyOriginal, LPCSTR lpSubKey, DWORD dwType, LPCSTR lpData, DWORD cbData)
Definition: reg.c:4954
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1224
HRESULT WINAPI CLSIDFromString(LPCOLESTR str, LPCLSID clsid)
Definition: combase.c:1470
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:162
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:218
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define REG_SZ
Definition: layer.c:22
#define ok_ole_success(hr, func)
Definition: comcat.c:32
static void unregister_testentry(void)
Definition: comcat.c:49
static void do_enum(void)
Definition: comcat.c:59
static BOOL register_testentry(void)
Definition: comcat.c:34
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFCLSID
Definition: guiddef.h:117
uint32_t ULONG
Definition: typedefs.h:59
#define S_FALSE
Definition: winerror.h:3451
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10