Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/atl/tests/registrar.c
4389 views
1
/*
2
* ATL test program
3
*
4
* Copyright 2010 Damjan Jovanovic
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
#include <stdarg.h>
22
#include <stdio.h>
23
24
#define COBJMACROS
25
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>
39
40
static const char textA[] =
41
"HKCU \n"
42
"{ \n"
43
" ForceRemove eebf73c4-50fd-478f-bbcf-db212221227a \n"
44
" { \n"
45
" val 'str1' = s 'string' \n"
46
" val 'str2' = s 'str\\\"ing' \n"
47
" val 'str3' = s 'str''ing' \n"
48
" val 'dword_quoted_dec' = d '1' \n"
49
" val 'dword_unquoted_dec' = d 1 \n"
50
" val 'dword_quoted_hex' = d '0xA' \n"
51
" val 'dword_unquoted_hex' = d 0xA \n"
52
" val 'dword_negative' = d -2147483648 \n"
53
" val 'dword_ulong' = d 2147483649 \n"
54
" val 'dword_max' = d 4294967295 \n"
55
" val 'dword_overrange' = d 4294967296 \n"
56
" val 'binary_quoted' = b 'deadbeef' \n"
57
" val 'binary_unquoted' = b dead0123 \n"
58
" } \n"
59
"}";
60
61
static void test_registrar(void)
62
{
63
IRegistrar *registrar = NULL;
64
HRESULT hr;
65
INT count;
66
int i;
67
WCHAR *textW = NULL;
68
struct dword_test
69
{
70
const char *name;
71
BOOL preserved;
72
LONGLONG value;
73
} dword_tests[] =
74
{
75
{ "dword_unquoted_dec", TRUE, 1 },
76
{ "dword_quoted_dec", TRUE, 1 },
77
{ "dword_quoted_hex", FALSE, 0xA },
78
{ "dword_unquoted_hex", FALSE, 0xA },
79
{ "dword_negative", FALSE, -2147483648 },
80
{ "dword_ulong", TRUE, 2147483649 },
81
{ "dword_max", TRUE, 4294967295 },
82
{ "dword_overrange", FALSE, 4294967296 },
83
};
84
85
if (!GetProcAddress(GetModuleHandleA("atl.dll"), "AtlAxAttachControl"))
86
{
87
win_skip("Old versions of atl.dll don't support binary values\n");
88
return;
89
}
90
91
hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)&registrar);
92
if (FAILED(hr))
93
{
94
win_skip("creating IRegistrar failed, hr = 0x%08lX\n", hr);
95
return;
96
}
97
98
count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
99
textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
100
if (textW)
101
{
102
DWORD dword;
103
DWORD size;
104
LONG lret;
105
HKEY key;
106
BYTE bytes[4];
107
char buffer[16];
108
109
MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count);
110
hr = IRegistrar_StringRegister(registrar, textW);
111
ok(hr == S_OK, "StringRegister failed: %08lx\n", hr);
112
if (FAILED(hr))
113
{
114
IRegistrar_Release(registrar);
115
return;
116
}
117
118
lret = RegOpenKeyA(HKEY_CURRENT_USER, "eebf73c4-50fd-478f-bbcf-db212221227a", &key);
119
ok(lret == ERROR_SUCCESS, "error %ld opening registry key\n", lret);
120
121
size = sizeof(buffer);
122
lret = RegQueryValueExA(key, "str1", NULL, NULL, (BYTE*)buffer, &size);
123
ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %ld\n", lret);
124
ok(!strcmp( buffer, "string"), "wrong data %s\n", debugstr_a(buffer));
125
126
size = sizeof(buffer);
127
lret = RegQueryValueExA(key, "str2", NULL, NULL, (BYTE*)buffer, &size);
128
ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %ld\n", lret);
129
ok(!strcmp( buffer, "str\\\"ing"), "wrong data %s\n", debugstr_a(buffer));
130
131
size = sizeof(buffer);
132
lret = RegQueryValueExA(key, "str3", NULL, NULL, (BYTE*)buffer, &size);
133
ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %ld\n", lret);
134
ok(!strcmp( buffer, "str'ing"), "wrong data %s\n", debugstr_a(buffer));
135
136
for (i = 0; i < ARRAYSIZE(dword_tests); i++)
137
{
138
size = sizeof(dword);
139
lret = RegQueryValueExA(key, dword_tests[i].name, NULL, NULL, (BYTE*)&dword, &size);
140
ok(lret == ERROR_SUCCESS, "Test %d: RegQueryValueExA failed %ld.\n", i, lret);
141
if (dword_tests[i].preserved)
142
ok(dword == dword_tests[i].value, "Test %d: got unexpected value %lu.\n", i, dword);
143
else
144
ok(dword != dword_tests[i].value, "Test %d: is not supposed to be preserved.\n", i);
145
}
146
147
size = 4;
148
lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size);
149
ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %ld\n", lret);
150
ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
151
"binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
152
0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
153
154
size = 4;
155
lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
156
ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %ld\n", lret);
157
ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0x01 && bytes[3] == 0x23,
158
"binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
159
0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
160
161
hr = IRegistrar_StringUnregister(registrar, textW);
162
ok(SUCCEEDED(hr), "IRegistrar_StringUnregister failed, hr = 0x%08lX\n", hr);
163
RegCloseKey(key);
164
165
HeapFree(GetProcessHeap(), 0, textW);
166
}
167
else
168
skip("allocating memory failed\n");
169
170
IRegistrar_Release(registrar);
171
}
172
173
static void test_aggregation(void)
174
{
175
IUnknown *unk = (IUnknown*)0xdeadbeef;
176
HRESULT hres;
177
178
hres = CoCreateInstance(&CLSID_Registrar, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
179
&IID_IUnknown, (void**)&unk);
180
ok(hres == CLASS_E_NOAGGREGATION || broken(hres == E_INVALIDARG),
181
"CoCreateInstance failed: %08lx, expected CLASS_E_NOAGGREGATION\n", hres);
182
ok(!unk || unk == (IUnknown*)0xdeadbeef, "unk = %p\n", unk);
183
}
184
185
START_TEST(registrar)
186
{
187
CoInitialize(NULL);
188
189
test_registrar();
190
test_aggregation();
191
192
CoUninitialize();
193
}
194
195