ReactOS  0.4.13-dev-464-g6b95727
registrar.c
Go to the documentation of this file.
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 'string' = s 'string' \n"
46 " val 'dword_quoted_dec' = d '1' \n"
47 " val 'dword_unquoted_dec' = d 1 \n"
48 " val 'dword_quoted_hex' = d '0xA' \n"
49 " val 'dword_unquoted_hex' = d 0xA \n"
50 " val 'binary_quoted' = b 'deadbeef' \n"
51 " val 'binary_unquoted' = b deadbeef \n"
52 " } \n"
53 "}";
54 
55 static void test_registrar(void)
56 {
57  IRegistrar *registrar = NULL;
58  HRESULT hr;
59  INT count;
60  WCHAR *textW = NULL;
61 
62  if (!GetProcAddress(GetModuleHandleA("atl.dll"), "AtlAxAttachControl"))
63  {
64  win_skip("Old versions of atl.dll don't support binary values\n");
65  return;
66  }
67 
68  hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)&registrar);
69  if (FAILED(hr))
70  {
71  win_skip("creating IRegistrar failed, hr = 0x%08X\n", hr);
72  return;
73  }
74 
75  count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
76  textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
77  if (textW)
78  {
79  DWORD dword;
80  DWORD size;
81  LONG lret;
82  HKEY key;
83  BYTE bytes[4];
84 
86  hr = IRegistrar_StringRegister(registrar, textW);
87  ok(hr == S_OK, "StringRegister failed: %08x\n", hr);
88  if (FAILED(hr))
89  {
90  IRegistrar_Release(registrar);
91  return;
92  }
93 
94  lret = RegOpenKeyA(HKEY_CURRENT_USER, "eebf73c4-50fd-478f-bbcf-db212221227a", &key);
95  ok(lret == ERROR_SUCCESS, "error %d opening registry key\n", lret);
96 
97  size = sizeof(dword);
98  lret = RegQueryValueExA(key, "dword_unquoted_hex", NULL, NULL, (BYTE*)&dword, &size);
99  ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
100  ok(dword != 0xA, "unquoted hex is not supposed to be preserved\n");
101 
102  size = sizeof(dword);
103  lret = RegQueryValueExA(key, "dword_quoted_hex", NULL, NULL, (BYTE*)&dword, &size);
104  ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
105  ok(dword != 0xA, "quoted hex is not supposed to be preserved\n");
106 
107  size = sizeof(dword);
108  lret = RegQueryValueExA(key, "dword_unquoted_dec", NULL, NULL, (BYTE*)&dword, &size);
109  ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
110  ok(dword == 1, "unquoted dec is not supposed to be %d\n", dword);
111 
112  size = sizeof(dword);
113  lret = RegQueryValueExA(key, "dword_quoted_dec", NULL, NULL, (BYTE*)&dword, &size);
114  ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
115  ok(dword == 1, "quoted dec is not supposed to be %d\n", dword);
116 
117  size = 4;
118  lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size);
119  ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
120  ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
121  "binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
122  0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
123 
124  size = 4;
125  lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
126  ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
127  ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
128  "binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
129  0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
130 
131  hr = IRegistrar_StringUnregister(registrar, textW);
132  ok(SUCCEEDED(hr), "IRegistrar_StringUnregister failed, hr = 0x%08X\n", hr);
133  RegCloseKey(key);
134 
136  }
137  else
138  skip("allocating memory failed\n");
139 
140  IRegistrar_Release(registrar);
141 }
142 
143 static void test_aggregation(void)
144 {
145  IUnknown *unk = (IUnknown*)0xdeadbeef;
146  HRESULT hres;
147 
148  hres = CoCreateInstance(&CLSID_Registrar, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
149  &IID_IUnknown, (void**)&unk);
151  "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
152  ok(!unk || unk == (IUnknown*)0xdeadbeef, "unk = %p\n", unk);
153 }
154 
155 START_TEST(registrar)
156 {
158 
159  test_registrar();
161 
162  CoUninitialize();
163 }
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3257
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
#define CP_ACP
Definition: compat.h:99
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define HKEY_CURRENT_USER
Definition: winreg.h:11
int32_t INT
Definition: typedefs.h:56
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
long LONG
Definition: pedump.c:60
#define ok(value,...)
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HKEY key
Definition: registrar.c:34
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const char textA[]
Definition: registrar.c:40
const GUID IID_IUnknown
unsigned long DWORD
Definition: ntddk_ex.h:95
static void test_aggregation(void)
Definition: registrar.c:143
unsigned char BYTE
Definition: mem.h:68
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
static const WCHAR textW[]
Definition: itemdlg.c:1559
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define broken(x)
Definition: _sntprintf.h:21
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define S_OK
Definition: intsafe.h:59
START_TEST(registrar)
Definition: registrar.c:155
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
#define MultiByteToWideChar
Definition: compat.h:100
#define skip(...)
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
static void test_registrar(void)
Definition: registrar.c:55
#define GetProcAddress(x, y)
Definition: compat.h:410
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57
Definition: path.c:42