On Tue, 2008-10-07 at 21:23 +0400, Nikolay Sivov wrote:
Changelog(try5, try6): - rebased with current git Changelog(try4): - tests for string length added - configure.ac in the same patch Changelog: - implemented GetRoleText[A/W] with tests
From 82eeac4de0a082b3c665d9f46a84fa634d847b91 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov <bunglehead(a)gmail.com> Date: Tue, 7 Oct 2008 21:10:37 +0400 Subject: Impl. GetRoleText[A/W]
--- configure.ac | 1 + dlls/oleacc/Makefile.in | 4 +- dlls/oleacc/main.c | 74 +++++++++++++++++++++++++ dlls/oleacc/oleacc.rc | 24 ++++++++ dlls/oleacc/oleacc.spec | 4 +- dlls/oleacc/oleacc_En.rc | 90 ++++++++++++++++++++++++++++++ dlls/oleacc/tests/Makefile.in | 13 +++++ dlls/oleacc/tests/main.c | 121 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 328 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac index dac47c6..e68ccf3 100644 --- a/configure.ac +++ b/configure.ac @@ -1942,6 +1942,7 @@ WINE_CONFIG_MAKEFILE([dlls/odbccp32/tests/Makefile],[dlls/Maketest.rules],[dlls] WINE_CONFIG_MAKEFILE([dlls/ole32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) WINE_CONFIG_MAKEFILE([dlls/ole32/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS]) WINE_CONFIG_MAKEFILE([dlls/oleacc/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) +WINE_CONFIG_MAKEFILE([dlls/oleacc/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS]) WINE_CONFIG_MAKEFILE([dlls/oleaut32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) WINE_CONFIG_MAKEFILE([dlls/oleaut32/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS]) WINE_CONFIG_MAKEFILE([dlls/olecli32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) diff --git a/dlls/oleacc/Makefile.in b/dlls/oleacc/Makefile.in index 5822916..882edcb 100644 --- a/dlls/oleacc/Makefile.in +++ b/dlls/oleacc/Makefile.in @@ -4,11 +4,13 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = oleacc.dll IMPORTLIB = oleacc -IMPORTS = kernel32 +IMPORTS = kernel32 user32
C_SRCS = \ main.c
+RC_SRCS = oleacc.rc + @MAKE_DLL_RULES@
@DEPENDENCIES@ # everything below this line is overwritten by make depend diff --git a/dlls/oleacc/main.c b/dlls/oleacc/main.c index 9a6f765..5076e00 100644 --- a/dlls/oleacc/main.c +++ b/dlls/oleacc/main.c @@ -24,10 +24,13 @@ #include "winuser.h" #include "ole2.h"
+#include "wine/unicode.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(oleacc);
+static HINSTANCE oleacc_handle = 0; + HRESULT WINAPI CreateStdAccessibleObject( HWND hwnd, LONG idObject, REFIID riidInterface, void** ppvObject ) { @@ -50,6 +53,21 @@ HRESULT WINAPI AccessibleObjectFromWindow( HWND hwnd, DWORD dwObjectID, return E_NOTIMPL; }
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, + LPVOID lpvReserved) +{ + TRACE("%p, %d, %p\n", hinstDLL, fdwReason, lpvReserved); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + oleacc_handle = hinstDLL; + DisableThreadLibraryCalls(hinstDLL); + break; + } + return TRUE; +} + HRESULT WINAPI DllRegisterServer(void) { FIXME("\n"); @@ -67,3 +85,59 @@ void WINAPI GetOleaccVersionInfo(DWORD* pVersion, DWORD* pBuild) *pVersion = MAKELONG(2,4); /* Windows XP version of oleacc: 4.2.5406.0 */ *pBuild = MAKELONG(0,5406); } + +UINT WINAPI GetRoleTextW(DWORD role, LPWSTR lpRole, UINT rolemax) +{ + INT ret; + WCHAR *resptr; + + TRACE("%u %p %u\n", role, lpRole, rolemax); + + /* return role text length */ + if(!lpRole) + return LoadStringW(oleacc_handle, role, (LPWSTR)&resptr, 0); + + ret = LoadStringW(oleacc_handle, role, lpRole, rolemax); + if(!(ret > 0)){ + if(rolemax > 0) lpRole[0] = '\0'; + return 0; + } + + return ret; +} + +UINT WINAPI GetRoleTextA(DWORD role, LPSTR lpRole, UINT rolemax) +{ + UINT length; + WCHAR *roletextW; + + TRACE("%u %p %u\n", role, lpRole, rolemax); + + length = GetRoleTextW(role, NULL, 0); + if((length == 0) || (lpRole && !rolemax)) + return 0; + + roletextW = HeapAlloc(GetProcessHeap(), 0, (length + 1)*sizeof(WCHAR)); + if(!roletextW) + return 0; + + GetRoleTextW(role, roletextW, length + 1); + + length = WideCharToMultiByte( CP_ACP, 0, roletextW, -1, NULL, 0, NULL, NULL ); + + if(!lpRole){ + HeapFree(GetProcessHeap(), 0, roletextW); + return length - 1; + } + + WideCharToMultiByte( CP_ACP, 0, roletextW, -1, lpRole, rolemax, NULL, NULL ); + + if(rolemax < length){ + lpRole[rolemax-1] = '\0'; + length = rolemax; + } + + HeapFree(GetProcessHeap(), 0, roletextW); + + return length - 1; +} diff --git a/dlls/oleacc/oleacc.rc b/dlls/oleacc/oleacc.rc new file mode 100644 index 0000000..0795a9b --- /dev/null +++ b/dlls/oleacc/oleacc.rc @@ -0,0 +1,24 @@ +/* + * Top level resource file for oleacc + * + * Copyright 2008 Nikolay Sivov + * + * 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 "windef.h" +#include "oleacc.h" + +#include "oleacc_En.rc" diff --git a/dlls/oleacc/oleacc.spec b/dlls/oleacc/oleacc.spec index 23b84b3..75b743a 100644 --- a/dlls/oleacc/oleacc.spec +++ b/dlls/oleacc/oleacc.spec @@ -8,8 +8,8 @@ @ stdcall -private DllRegisterServer() @ stdcall -private DllUnregisterServer() @ stdcall GetOleaccVersionInfo(ptr ptr) -@ stub GetRoleTextA -@ stub GetRoleTextW +@ stdcall GetRoleTextA(long ptr long) +@ stdcall GetRoleTextW(long wstr long) @ stub GetStateTextA @ stub GetStateTextW @ stub IID_IAccessible diff --git a/dlls/oleacc/oleacc_En.rc b/dlls/oleacc/oleacc_En.rc new file mode 100644 index 0000000..992d29c --- /dev/null +++ b/dlls/oleacc/oleacc_En.rc @@ -0,0 +1,90 @@ +/* + * English resources for oleacc + * + * Copyright 2008 Nikolay Sivov + * + * 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 + */ + +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE DISCARDABLE +{ + 0 "unknown object" /* undocumented */ + ROLE_SYSTEM_TITLEBAR "title bar" + ROLE_SYSTEM_MENUBAR "menu bar" + ROLE_SYSTEM_SCROLLBAR "scroll bar" + ROLE_SYSTEM_GRIP "grip" + ROLE_SYSTEM_SOUND "sound" + ROLE_SYSTEM_CURSOR "cursor" + ROLE_SYSTEM_CARET "caret" + ROLE_SYSTEM_ALERT "alert" + ROLE_SYSTEM_WINDOW "window" + ROLE_SYSTEM_CLIENT "client" + ROLE_SYSTEM_MENUPOPUP "popup menu" + ROLE_SYSTEM_MENUITEM "menu item" + ROLE_SYSTEM_TOOLTIP "tool tip" + ROLE_SYSTEM_APPLICATION "application" + ROLE_SYSTEM_DOCUMENT "document" + ROLE_SYSTEM_PANE "pane" + ROLE_SYSTEM_CHART "chart" + ROLE_SYSTEM_DIALOG "dialog" + ROLE_SYSTEM_BORDER "border" + ROLE_SYSTEM_GROUPING "grouping" + ROLE_SYSTEM_SEPARATOR "separator" + ROLE_SYSTEM_TOOLBAR "tool bar" + ROLE_SYSTEM_STATUSBAR "status bar" + ROLE_SYSTEM_TABLE "table" + ROLE_SYSTEM_COLUMNHEADER "column header" + ROLE_SYSTEM_ROWHEADER "row header" + ROLE_SYSTEM_COLUMN "column" + ROLE_SYSTEM_ROW "row" + ROLE_SYSTEM_CELL "cell" + ROLE_SYSTEM_LINK "link" + ROLE_SYSTEM_HELPBALLOON "help balloon" + ROLE_SYSTEM_CHARACTER "character" + ROLE_SYSTEM_LIST "list" + ROLE_SYSTEM_LISTITEM "list item" + ROLE_SYSTEM_OUTLINE "outline" + ROLE_SYSTEM_OUTLINEITEM "outline item" + ROLE_SYSTEM_PAGETAB "page tab" + ROLE_SYSTEM_PROPERTYPAGE "property page" + ROLE_SYSTEM_INDICATOR "indicator" + ROLE_SYSTEM_GRAPHIC "graphic" + ROLE_SYSTEM_STATICTEXT "static text" + ROLE_SYSTEM_TEXT "text" + ROLE_SYSTEM_PUSHBUTTON "push button" + ROLE_SYSTEM_CHECKBUTTON "check button" + ROLE_SYSTEM_RADIOBUTTON "radio button" + ROLE_SYSTEM_COMBOBOX "combo box" + ROLE_SYSTEM_DROPLIST "drop down" + ROLE_SYSTEM_PROGRESSBAR "progress bar" + ROLE_SYSTEM_DIAL "dial" + ROLE_SYSTEM_HOTKEYFIELD "hot key field" + ROLE_SYSTEM_SLIDER "slider" + ROLE_SYSTEM_SPINBUTTON "spin box" + ROLE_SYSTEM_DIAGRAM "diagram" + ROLE_SYSTEM_ANIMATION "animation" + ROLE_SYSTEM_EQUATION "equation" + ROLE_SYSTEM_BUTTONDROPDOWN "drop down button" + ROLE_SYSTEM_BUTTONMENU "menu button" + ROLE_SYSTEM_BUTTONDROPDOWNGRID "grid drop down button" + ROLE_SYSTEM_WHITESPACE "white space" + ROLE_SYSTEM_PAGETABLIST "page tab list" + ROLE_SYSTEM_CLOCK "clock" + ROLE_SYSTEM_SPLITBUTTON "split button" + ROLE_SYSTEM_IPADDRESS "IP address" + ROLE_SYSTEM_OUTLINEBUTTON "outline button" +} diff --git a/dlls/oleacc/tests/Makefile.in b/dlls/oleacc/tests/Makefile.in new file mode 100644 index 0000000..6e2bc8d --- /dev/null +++ b/dlls/oleacc/tests/Makefile.in @@ -0,0 +1,13 @@ +TOPSRCDIR = @top_srcdir@ +TOPOBJDIR = ../../.. +SRCDIR = @srcdir@ +VPATH = @srcdir@ +TESTDLL = oleacc.dll +IMPORTS = kernel32 oleacc + +CTESTS = \ + main.c + +(a)MAKE_TEST_RULES@ + +(a)DEPENDENCIES@ # everything below this line is overwritten by make depend diff --git a/dlls/oleacc/tests/main.c b/dlls/oleacc/tests/main.c new file mode 100644 index 0000000..66b25af --- /dev/null +++ b/dlls/oleacc/tests/main.c @@ -0,0 +1,121 @@ +/* + * oleacc tests + * + * Copyright 2008 Nikolay Sivov + * + * 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 <oleacc.h> +#include "wine/test.h" + +static void test_getroletext(void) +{ + INT ret, role; + CHAR buf[2], *buff, buff2[100]; + WCHAR bufW[2], *buffW, buff2W[100]; + + /* wrong role number */ + ret = GetRoleTextA(-1, NULL, 0); + ok(ret == 0, "GetRoleTextA doesn't return zero on wrong role number, got %d\n", ret); + buf[0] = '*'; + ret = GetRoleTextA(-1, buf, 2); + ok(ret == 0, "GetRoleTextA doesn't return zero on wrong role number, got %d\n", ret); + ok(buf[0] == '*', "GetRoleTextA modified buffer on wrong role number\n"); + buf[0] = '*'; + ret = GetRoleTextA(-1, buf, 0); + ok(ret == 0, "GetRoleTextA doesn't return zero on wrong role number, got %d\n", ret); + ok(buf[0] == '*', "GetRoleTextA modified buffer on wrong role number\n"); + + ret = GetRoleTextW(-1, NULL, 0); + ok(ret == 0, "GetRoleTextW doesn't return zero on wrong role number, got %d\n", ret); + bufW[0] = '*'; + ret = GetRoleTextW(-1, bufW, 2); + ok(ret == 0, "GetRoleTextW doesn't return zero on wrong role number, got %d\n", ret); + ok(bufW[0] == '\0', "GetRoleTextW doesn't return NULL char on wrong role number\n"); + bufW[0] = '*'; + ret = GetRoleTextW(-1, bufW, 0); + ok(ret == 0, "GetRoleTextW doesn't return zero on wrong role number, got %d\n", ret); + /* don't know why this char */ + todo_wine ok(bufW[0] == 0x1e90, "GetRoleTextW returned wrong char, got %u\n", bufW[0]); + + /* zero role number - not documented */ + ret = GetRoleTextA(0, NULL, 0); + ok(ret > 0, "GetRoleTextA doesn't return (>0) for zero role number, got %d\n", ret); + ret = GetRoleTextW(0, NULL, 0); + ok(ret > 0, "GetRoleTextW doesn't return (>0) for zero role number, got %d\n", ret); + + /* NULL buffer, return length */ + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, NULL, 0); + ok(ret > 0, "GetRoleTextA doesn't return length on NULL buffer, got %d\n", ret); + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, NULL, 1); + ok(ret > 0, "GetRoleTextA doesn't return length on NULL buffer, got %d\n", ret); + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, NULL, 0); + ok(ret > 0, "GetRoleTextW doesn't return length on NULL buffer, got %d\n", ret); + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, NULL, 1); + ok(ret > 0, "GetRoleTextW doesn't return length on NULL buffer, got %d\n", ret); + + /* use a smaller buffer */ + buf[0] = '*'; + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, buf, 1); + ok(ret == 0, "GetRoleTextA returned wrong length\n"); + ok(buf[0] == '\0', "GetRoleTextA returned not zero-length buffer\n"); + buf[1] = '*'; + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, buf, 2); + ok(ret == 1, "GetRoleTextA returned wrong length, got %d, expected 1\n", ret); + ok(buf[1] == '\0', "GetRoleTextA returned not zero-length buffer\n"); + + bufW[0] = '*'; + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, bufW, 1); + ok(ret == 0, "GetRoleTextW returned wrong length, got %d, expected 1\n", ret); + ok(bufW[0] == '\0', "GetRoleTextW returned not zero-length buffer\n"); + bufW[1] = '*'; + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, bufW, 2); + ok(ret == 1, "GetRoleTextW returned wrong length, got %d, expected 1\n", ret); + ok(bufW[1] == '\0', "GetRoleTextW returned not zero-length buffer\n"); + + /* use bigger buffer */ + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, NULL, 0); + buff = HeapAlloc(GetProcessHeap(), 0, 2*ret); + buff[2*ret-1] = '*'; + ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, buff, 2*ret); + ok(buff[2*ret-1] == '*', "GetRoleTextA shouldn't modify this part of buffer\n"); + HeapFree(GetProcessHeap(), 0, buff); + + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, NULL, 0); + buffW = HeapAlloc(GetProcessHeap(), 0, 2*ret*sizeof(WCHAR)); + buffW[2*ret-1] = '*'; + ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, buffW, 2*ret); + ok(buffW[2*ret-1] == '*', "GetRoleTextW shouldn't modify this part of buffer\n"); + HeapFree(GetProcessHeap(), 0, buffW); + + /* check returned length for all roles */ + for(role = 0; role <= ROLE_SYSTEM_OUTLINEBUTTON; role++){ + ret = GetRoleTextA(role, NULL, 0); + GetRoleTextA(role, buff2, sizeof(buff2)); + ok(ret == lstrlenA(buff2), + "GetRoleTextA: returned length doesn't match returned buffer for role %d\n", role); + + ret = GetRoleTextW(role, NULL, 0); + GetRoleTextW(role, buff2W, sizeof(buff2W)/sizeof(WCHAR)); + ok(ret == lstrlenW(buff2W), + "GetRoleTextW: returned length doesn't match returned buffer for role %d\n", role); + } +} + +START_TEST(main) +{ + test_getroletext(); +}
Something wrong with this? Please let me know if it's so.