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 #define WIN32_NO_STATUS 22 #define _INC_WINDOWS 23 #define COM_NO_WINDOWS_H 24 25 //#include <stdarg.h> 26 //#include <stdio.h> 27 28 #define COBJMACROS 29 30 #include <wine/test.h> 31 //#include <windef.h> 32 //#include <winbase.h> 33 //#include <winuser.h> 34 //#include <wingdi.h> 35 #include <winnls.h> 36 #include <winreg.h> 37 //#include <winerror.h> 38 //#include <winnt.h> 39 //#include <wtypes.h> 40 #include <objbase.h> 41 //#include <olectl.h> 42 //#include <ocidl.h> 43 //#include <initguid.h> 44 #include <atliface.h> 45 46 static const char textA[] = 47 "HKCU \n" 48 "{ \n" 49 " ForceRemove eebf73c4-50fd-478f-bbcf-db212221227a \n" 50 " { \n" 51 " val 'string' = s 'string' \n" 52 " val 'dword_quoted_dec' = d '1' \n" 53 " val 'dword_unquoted_dec' = d 1 \n" 54 " val 'dword_quoted_hex' = d '0xA' \n" 55 " val 'dword_unquoted_hex' = d 0xA \n" 56 " val 'binary_quoted' = b 'deadbeef' \n" 57 " val 'binary_unquoted' = b deadbeef \n" 58 " } \n" 59 "}"; 60 61 static void test_registrar(void) 62 { 63 IRegistrar *registrar = NULL; 64 HRESULT hr; 65 INT count; 66 WCHAR *textW = NULL; 67 68 if (!GetProcAddress(GetModuleHandleA("atl.dll"), "AtlAxAttachControl")) 69 { 70 win_skip("Old versions of atl.dll don't support binary values\n"); 71 return; 72 } 73 74 hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)®istrar); 75 if (FAILED(hr)) 76 { 77 win_skip("creating IRegistrar failed, hr = 0x%08X\n", hr); 78 return; 79 } 80 81 count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); 82 textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR)); 83 if (textW) 84 { 85 DWORD dword; 86 DWORD size; 87 LONG lret; 88 HKEY key; 89 BYTE bytes[4]; 90 91 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count); 92 hr = IRegistrar_StringRegister(registrar, textW); 93 ok(hr == S_OK, "StringRegister failed: %08x\n", hr); 94 if (FAILED(hr)) 95 { 96 IRegistrar_Release(registrar); 97 return; 98 } 99 100 lret = RegOpenKeyA(HKEY_CURRENT_USER, "eebf73c4-50fd-478f-bbcf-db212221227a", &key); 101 ok(lret == ERROR_SUCCESS, "error %d opening registry key\n", lret); 102 103 size = sizeof(dword); 104 lret = RegQueryValueExA(key, "dword_unquoted_hex", NULL, NULL, (BYTE*)&dword, &size); 105 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret); 106 ok(dword != 0xA, "unquoted hex is not supposed to be preserved\n"); 107 108 size = sizeof(dword); 109 lret = RegQueryValueExA(key, "dword_quoted_hex", NULL, NULL, (BYTE*)&dword, &size); 110 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret); 111 ok(dword != 0xA, "quoted hex is not supposed to be preserved\n"); 112 113 size = sizeof(dword); 114 lret = RegQueryValueExA(key, "dword_unquoted_dec", NULL, NULL, (BYTE*)&dword, &size); 115 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret); 116 ok(dword == 1, "unquoted dec is not supposed to be %d\n", dword); 117 118 size = sizeof(dword); 119 lret = RegQueryValueExA(key, "dword_quoted_dec", NULL, NULL, (BYTE*)&dword, &size); 120 ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret); 121 ok(dword == 1, "quoted dec is not supposed to be %d\n", dword); 122 123 size = 4; 124 lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size); 125 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret); 126 ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef, 127 "binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n", 128 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]); 129 130 size = 4; 131 lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size); 132 ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret); 133 ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef, 134 "binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n", 135 0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]); 136 137 hr = IRegistrar_StringUnregister(registrar, textW); 138 ok(SUCCEEDED(hr), "IRegistrar_StringUnregister failed, hr = 0x%08X\n", hr); 139 RegCloseKey(key); 140 141 HeapFree(GetProcessHeap(), 0, textW); 142 } 143 else 144 skip("allocating memory failed\n"); 145 146 IRegistrar_Release(registrar); 147 } 148 149 static void test_aggregation(void) 150 { 151 IUnknown *unk = (IUnknown*)0xdeadbeef; 152 HRESULT hres; 153 154 hres = CoCreateInstance(&CLSID_Registrar, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 155 &IID_IUnknown, (void**)&unk); 156 ok(hres == CLASS_E_NOAGGREGATION || broken(hres == E_INVALIDARG), 157 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres); 158 ok(!unk || unk == (IUnknown*)0xdeadbeef, "unk = %p\n", unk); 159 } 160 161 START_TEST(registrar) 162 { 163 CoInitialize(NULL); 164 165 test_registrar(); 166 test_aggregation(); 167 168 CoUninitialize(); 169 } 170