atl: Add support for binary values in IRegistrar.
[wine/multimedia.git] / dlls / atl / tests / registrar.c
blob422608b9479f06c72fd2d95eace4ec029681312a
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>
40 static const char textA[] =
41 "HKCR \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 "}";
55 static void test_registrar(void)
57 IRegistrar *registrar = NULL;
58 HRESULT hr;
59 INT count;
60 WCHAR *textW = NULL;
62 hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)&registrar);
63 if (FAILED(hr))
65 skip("creating IRegistrar failed, hr = 0x%08X\n", hr);
66 return;
69 count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
70 textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
71 if (textW)
73 DWORD dword;
74 DWORD size;
75 LONG lret;
76 HKEY key;
77 BYTE bytes[4];
79 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count);
80 hr = IRegistrar_StringRegister(registrar, textW);
81 ok(SUCCEEDED(hr), "IRegistar_StringRegister failed, hr = 0x%08X\n", hr);
83 lret = RegOpenKeyA(HKEY_CLASSES_ROOT, "eebf73c4-50fd-478f-bbcf-db212221227a", &key);
84 ok(lret == ERROR_SUCCESS, "error %d opening registry key\n", lret);
86 size = sizeof(dword);
87 lret = RegQueryValueExA(key, "dword_unquoted_hex", NULL, NULL, (BYTE*)&dword, &size);
88 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
89 ok(dword != 0xA, "unquoted hex is not supposed to be preserved\n");
91 size = sizeof(dword);
92 lret = RegQueryValueExA(key, "dword_quoted_hex", NULL, NULL, (BYTE*)&dword, &size);
93 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
94 ok(dword != 0xA, "quoted hex is not supposed to be preserved\n");
96 size = sizeof(dword);
97 lret = RegQueryValueExA(key, "dword_unquoted_dec", NULL, NULL, (BYTE*)&dword, &size);
98 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
99 ok(dword == 1, "unquoted dec is not supposed to be %d\n", dword);
101 size = sizeof(dword);
102 lret = RegQueryValueExA(key, "dword_quoted_dec", NULL, NULL, (BYTE*)&dword, &size);
103 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
104 ok(dword == 1, "quoted dec is not supposed to be %d\n", dword);
106 size = 4;
107 lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size);
108 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
109 ok(bytes[0] = 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
110 "binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
111 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
113 size = 4;
114 lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
115 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
116 ok(bytes[0] = 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
117 "binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
118 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
120 hr = IRegistrar_StringUnregister(registrar, textW);
121 ok(SUCCEEDED(hr), "IRegistar_StringUnregister failed, hr = 0x%08X\n", hr);
122 RegCloseKey(key);
124 else
125 skip("allocating memory failed\n");
127 IRegistrar_Release(registrar);
130 START_TEST(registrar)
132 CoInitialize(NULL);
134 test_registrar();
136 CoUninitialize();