Damjan Jovanovic : atl: Improve IRegistrar dword parsing.
Alexandre Julliard
julliard at winehq.org
Wed Nov 24 11:28:40 CST 2010
Module: wine
Branch: master
Commit: d2a221d2b5d915c2925568f14a97c7566fbca013
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d2a221d2b5d915c2925568f14a97c7566fbca013
Author: Damjan Jovanovic <damjan.jov at gmail.com>
Date: Wed Nov 24 11:09:05 2010 +0200
atl: Improve IRegistrar dword parsing.
---
dlls/atl/registrar.c | 12 ++---
dlls/atl/tests/Makefile.in | 3 +-
dlls/atl/tests/registrar.c | 120 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 126 insertions(+), 9 deletions(-)
diff --git a/dlls/atl/registrar.c b/dlls/atl/registrar.c
index eb33b3b..9a1154a 100644
--- a/dlls/atl/registrar.c
+++ b/dlls/atl/registrar.c
@@ -285,15 +285,11 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO
}
break;
case 'd': {
- WCHAR *end;
DWORD dw;
- if(*iter == '0' && iter[1] == 'x') {
- iter += 2;
- dw = strtolW(iter, &end, 16);
- }else {
- dw = strtolW(iter, &end, 10);
- }
- iter = end;
+ hres = get_word(&iter, buf);
+ if(FAILED(hres))
+ break;
+ dw = atoiW(buf->str);
lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_DWORD,
(PBYTE)&dw, sizeof(dw));
if(lres != ERROR_SUCCESS) {
diff --git a/dlls/atl/tests/Makefile.in b/dlls/atl/tests/Makefile.in
index 5cb209e..b397c85 100644
--- a/dlls/atl/tests/Makefile.in
+++ b/dlls/atl/tests/Makefile.in
@@ -3,6 +3,7 @@ IMPORTS = uuid atl oleaut32 ole32 rpcrt4 user32 gdi32 advapi32
C_SRCS = \
atl_ax.c \
- module.c
+ module.c \
+ registrar.c
@MAKE_TEST_RULES@
diff --git a/dlls/atl/tests/registrar.c b/dlls/atl/tests/registrar.c
new file mode 100644
index 0000000..cd2b755
--- /dev/null
+++ b/dlls/atl/tests/registrar.c
@@ -0,0 +1,120 @@
+/*
+ * ATL test program
+ *
+ * Copyright 2010 Damjan Jovanovic
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include <wine/test.h>
+#include <windef.h>
+#include <winbase.h>
+#include <winuser.h>
+#include <wingdi.h>
+#include <winnls.h>
+#include <winerror.h>
+#include <winnt.h>
+#include <wtypes.h>
+#include <olectl.h>
+#include <ocidl.h>
+#include <initguid.h>
+#include <atliface.h>
+
+static const char textA[] =
+"HKCR \n"
+"{ \n"
+" ForceRemove eebf73c4-50fd-478f-bbcf-db212221227a \n"
+" { \n"
+" val 'string' = s 'string' \n"
+" val 'dword_quoted_dec' = d '1' \n"
+" val 'dword_unquoted_dec' = d 1 \n"
+" val 'dword_quoted_hex' = d '0xA' \n"
+" val 'dword_unquoted_hex' = d 0xA \n"
+" } \n"
+"}";
+
+static void test_registrar(void)
+{
+ IRegistrar *registrar = NULL;
+ HRESULT hr;
+ INT count;
+ WCHAR *textW = NULL;
+
+ hr = CoCreateInstance(&CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, &IID_IRegistrar, (void**)®istrar);
+ if (FAILED(hr))
+ {
+ skip("creating IRegistrar failed, hr = 0x%08X\n", hr);
+ return;
+ }
+
+ count = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
+ textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
+ if (textW)
+ {
+ DWORD dword;
+ DWORD size;
+ LONG lret;
+ HKEY key;
+
+ MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count);
+ hr = IRegistrar_StringRegister(registrar, textW);
+ ok(SUCCEEDED(hr), "IRegistar_StringRegister failed, hr = 0x%08X\n", hr);
+
+ lret = RegOpenKeyA(HKEY_CLASSES_ROOT, "eebf73c4-50fd-478f-bbcf-db212221227a", &key);
+ ok(lret == ERROR_SUCCESS, "error %d opening registry key\n", lret);
+
+ size = sizeof(dword);
+ lret = RegQueryValueExA(key, "dword_unquoted_hex", NULL, NULL, (BYTE*)&dword, &size);
+ ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
+ ok(dword != 0xA, "unquoted hex is not supposed to be preserved\n");
+
+ size = sizeof(dword);
+ lret = RegQueryValueExA(key, "dword_quoted_hex", NULL, NULL, (BYTE*)&dword, &size);
+ ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
+ ok(dword != 0xA, "quoted hex is not supposed to be preserved\n");
+
+ size = sizeof(dword);
+ lret = RegQueryValueExA(key, "dword_unquoted_dec", NULL, NULL, (BYTE*)&dword, &size);
+ ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
+ ok(dword == 1, "unquoted dec is not supposed to be %d\n", dword);
+
+ size = sizeof(dword);
+ lret = RegQueryValueExA(key, "dword_quoted_dec", NULL, NULL, (BYTE*)&dword, &size);
+ ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
+ ok(dword == 1, "quoted dec is not supposed to be %d\n", dword);
+
+ hr = IRegistrar_StringUnregister(registrar, textW);
+ ok(SUCCEEDED(hr), "IRegistar_StringUnregister failed, hr = 0x%08X\n", hr);
+ RegCloseKey(key);
+ }
+ else
+ skip("allocating memory failed\n");
+
+ IRegistrar_Release(registrar);
+}
+
+START_TEST(registrar)
+{
+ CoInitialize(NULL);
+
+ test_registrar();
+
+ CoUninitialize();
+}
More information about the wine-cvs
mailing list