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
26 #include <wine/test.h>
41 static BOOL
is_process_limited(void)
43 static BOOL (WINAPI
*pOpenProcessToken
)(HANDLE
, DWORD
, PHANDLE
) = NULL
;
46 if (!pOpenProcessToken
)
48 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
49 pOpenProcessToken
= (void*)GetProcAddress(hadvapi32
, "OpenProcessToken");
50 if (!pOpenProcessToken
)
54 if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
57 TOKEN_ELEVATION_TYPE type
= TokenElevationTypeDefault
;
60 ret
= GetTokenInformation(token
, TokenElevationType
, &type
, sizeof(type
), &size
);
62 return (ret
&& type
== TokenElevationTypeLimited
);
68 static const char textA
[] =
71 " ForceRemove eebf73c4-50fd-478f-bbcf-db212221227a \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"
83 static void test_registrar(void)
85 IRegistrar
*registrar
= NULL
;
90 if (!GetProcAddress(GetModuleHandleA("atl.dll"), "AtlAxAttachControl"))
92 win_skip("Old versions of atl.dll don't support binary values\n");
96 hr
= CoCreateInstance(&CLSID_Registrar
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRegistrar
, (void**)®istrar
);
99 skip("creating IRegistrar failed, hr = 0x%08X\n", hr
);
103 count
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
104 textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
113 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, count
);
114 hr
= IRegistrar_StringRegister(registrar
, textW
);
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
);
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
);
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]);
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
);
166 HeapFree(GetProcessHeap(), 0, textW
);
169 skip("allocating memory failed\n");
171 IRegistrar_Release(registrar
);
174 static void test_aggregation(void)
176 IUnknown
*unk
= (IUnknown
*)0xdeadbeef;
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
)