msvcrt: Fix malloc_func_t/free_func_t calling convention.
[wine] / dlls / comcat / tests / 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 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 0x%08x\n", hr)
33
34 static BOOL register_testentry(void)
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
49 static void unregister_testentry(void)
50 {
51         RegDeleteKeyA(HKEY_CLASSES_ROOT,
52                         "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories\\{deadcafe-0000-0000-0000-000000000000}");
53         RegDeleteKeyA(HKEY_CLASSES_ROOT,
54                         "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}\\Implemented Categories");
55         RegDeleteKeyA(HKEY_CLASSES_ROOT,
56                         "CLSID\\{deadcafe-beed-bead-dead-cafebeaddead}");
57 }
58
59 static 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         static WCHAR szCatID[] = {
70                         '{',
71                         'd','e','a','d','c','a','f','e',
72                         '-','0','0','0','0','-','0','0','0','0',
73                         '-','0','0','0','0',
74                         '-','0','0','0','0','0','0','0','0','0','0','0','0',
75                         '}',0};
76         static WCHAR szGuid[] = {
77                         '{',
78                         'd','e','a','d','c','a','f','e','-',
79                         'b','e','e','d','-',
80                         'b','e','a','d','-',
81                         'd','e','a','d','-',
82                         'c','a','f','e','b','e','a','d','d','e','a','d',
83                         '}',0};
84
85         IEnumCLSID *pIEnum =(IEnumCLSID*)0xdeadcafe;
86
87         CLSIDFromString(szCatID,the_cat);
88         CLSIDFromString(szGuid,&wanted_guid);
89
90         OleInitialize(NULL);
91
92         hr = CoCreateInstance(rclsid,NULL,CLSCTX_INPROC_SERVER,
93                         &IID_ICatInformation, (void **)&pICat);
94         ok_ole_success(hr, "CoCreateInstance");
95
96         hr = ICatInformation_EnumClassesOfCategories(pICat, -1, NULL, -1, NULL,
97                         &pIEnum);
98         ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
99
100         IEnumGUID_Release(pIEnum);
101         
102         hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL, 
103                         &pIEnum);
104         ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
105
106         hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
107         ok (hr == S_FALSE,"Expected S_FALSE, got 0x%08x\n", hr);
108         ok (fetched == 0,"Fetched wrong number of guids %u\n",fetched);
109         IEnumGUID_Release(pIEnum);
110
111         if (register_testentry())
112         {
113             hr = ICatInformation_EnumClassesOfCategories(pICat, 1, the_cat, -1, NULL, &pIEnum);
114             ok_ole_success(hr,"ICatInformation_EnumClassesOfCategories");
115
116             hr = IEnumGUID_Next(pIEnum,1,the_guid, &fetched);
117             ok (hr == S_OK,"Expected S_OK, got 0x%08x\n", hr);
118             ok (fetched == 1,"Fetched wrong number of guids %u\n",fetched);
119             ok (IsEqualGUID(the_guid,&wanted_guid),"Guids do not match\n");
120
121             IEnumGUID_Release(pIEnum);
122             unregister_testentry();
123         }
124         else skip( "Could not register the test category\n" );
125
126         ICatInformation_Release(pICat);
127
128         OleUninitialize();
129 }
130
131
132 START_TEST(comcat)
133 {
134         do_enum(); 
135 }