atl/tests: Use BOOL type where appropriate.
[wine.git] / dlls / atl / tests / registrar.c
blobc05b672591d99ec336ce4c5e3b2724c990423d3d
1 /*
2 * ATL test program
4 * Copyright 2010 Damjan Jovanovic
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include <wine/test.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winuser.h>
30 #include <wingdi.h>
31 #include <winnls.h>
32 #include <winerror.h>
33 #include <winnt.h>
34 #include <wtypes.h>
35 #include <olectl.h>
36 #include <ocidl.h>
37 #include <initguid.h>
38 #include <atliface.h>
41 static BOOL is_process_limited(void)
43 static BOOL (WINAPI *pOpenProcessToken)(HANDLE, DWORD, PHANDLE) = NULL;
44 HANDLE token;
46 if (!pOpenProcessToken)
48 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
49 pOpenProcessToken = (void*)GetProcAddress(hadvapi32, "OpenProcessToken");
50 if (!pOpenProcessToken)
51 return FALSE;
54 if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
56 BOOL ret;
57 TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
58 DWORD size;
60 ret = GetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
61 CloseHandle(token);
62 return (ret && type == TokenElevationTypeLimited);
64 return FALSE;
68 static const char textA[] =
69 "HKCR \n"
70 "{ \n"
71 " ForceRemove eebf73c4-50fd-478f-bbcf-db212221227a \n"
72 " { \n"
73 " val 'string' = s 'string' \n"
74 " val 'dword_quoted_dec' = d '1' \n"
75 " val 'dword_unquoted_dec' = d 1 \n"
76 " val 'dword_quoted_hex' = d '0xA' \n"
77 " val 'dword_unquoted_hex' = d 0xA \n"
78 " val 'binary_quoted' = b 'deadbeef' \n"
79 " val 'binary_unquoted' = b deadbeef \n"
80 " } \n"
81 "}";
83 static void test_registrar(void)
85 IRegistrar *registrar = NULL;
86 HRESULT hr;
87 INT count;
88 WCHAR *textW = NULL;
90 if (!GetProcAddress(GetModuleHandleA("atl.dll"), "AtlAxAttachControl"))
92 win_skip("Old versions of atl.dll don't support binary values\n");
93 return;
96 hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)&registrar);
97 if (FAILED(hr))
99 skip("creating IRegistrar failed, hr = 0x%08X\n", hr);
100 return;
103 count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
104 textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
105 if (textW)
107 DWORD dword;
108 DWORD size;
109 LONG lret;
110 HKEY key;
111 BYTE bytes[4];
113 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count);
114 hr = IRegistrar_StringRegister(registrar, textW);
115 if (FAILED(hr))
117 BOOL is_limited = is_process_limited();
118 ok(hr == DISP_E_EXCEPTION && is_limited,
119 "IRegistrar_StringRegister failed, hr = 0x%08X, is_limited=%d\n", hr, is_limited);
120 skip("Skipping registrar tests\n");
121 IRegistrar_Release(registrar);
122 return;
125 lret = RegOpenKeyA(HKEY_CLASSES_ROOT, "eebf73c4-50fd-478f-bbcf-db212221227a", &key);
126 ok(lret == ERROR_SUCCESS, "error %d opening registry key\n", lret);
128 size = sizeof(dword);
129 lret = RegQueryValueExA(key, "dword_unquoted_hex", NULL, NULL, (BYTE*)&dword, &size);
130 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
131 ok(dword != 0xA, "unquoted hex is not supposed to be preserved\n");
133 size = sizeof(dword);
134 lret = RegQueryValueExA(key, "dword_quoted_hex", NULL, NULL, (BYTE*)&dword, &size);
135 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
136 ok(dword != 0xA, "quoted hex is not supposed to be preserved\n");
138 size = sizeof(dword);
139 lret = RegQueryValueExA(key, "dword_unquoted_dec", NULL, NULL, (BYTE*)&dword, &size);
140 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
141 ok(dword == 1, "unquoted dec is not supposed to be %d\n", dword);
143 size = sizeof(dword);
144 lret = RegQueryValueExA(key, "dword_quoted_dec", NULL, NULL, (BYTE*)&dword, &size);
145 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
146 ok(dword == 1, "quoted dec is not supposed to be %d\n", dword);
148 size = 4;
149 lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size);
150 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
151 ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
152 "binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
153 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
155 size = 4;
156 lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
157 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
158 ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
159 "binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
160 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
162 hr = IRegistrar_StringUnregister(registrar, textW);
163 ok(SUCCEEDED(hr), "IRegistrar_StringUnregister failed, hr = 0x%08X\n", hr);
164 RegCloseKey(key);
166 HeapFree(GetProcessHeap(), 0, textW);
168 else
169 skip("allocating memory failed\n");
171 IRegistrar_Release(registrar);
174 static void test_aggregation(void)
176 IUnknown *unk = (IUnknown*)0xdeadbeef;
177 HRESULT hres;
179 hres = CoCreateInstance(&CLSID_Registrar, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
180 &IID_IUnknown, (void**)&unk);
181 ok(hres == CLASS_E_NOAGGREGATION || broken(hres == E_INVALIDARG),
182 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
183 ok(!unk || unk == (IUnknown*)0xdeadbeef, "unk = %p\n", unk);
186 START_TEST(registrar)
188 CoInitialize(NULL);
190 test_registrar();
191 test_aggregation();
193 CoUninitialize();