wintab32: Add a test showing WTOpen does not modify or open an invalid context
John Klehm
xixsimplicityxix at gmail.com
Fri Jul 31 14:57:42 CDT 2009
Enjoy.
--John Klehm
-------------- next part --------------
From d876944df851abae6b2433f30d066c128cd4d8cd Mon Sep 17 00:00:00 2001
From: John Klehm <xixsimplicityxix at gmail.com>
Date: Fri, 31 Jul 2009 14:50:29 -0500
Subject: wintab32: Add a test showing WTOpen does not modify or open an invalid
context
---
dlls/wintab32/tests/Makefile.in | 13 ++++
dlls/wintab32/tests/context.c | 152 +++++++++++++++++++++++++++++++++++++++
2 files changed, 165 insertions(+), 0 deletions(-)
create mode 100644 dlls/wintab32/tests/Makefile.in
create mode 100644 dlls/wintab32/tests/context.c
diff --git a/dlls/wintab32/tests/Makefile.in b/dlls/wintab32/tests/Makefile.in
new file mode 100644
index 0000000..07c2961
--- /dev/null
+++ b/dlls/wintab32/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = wintab32.dll
+IMPORTS = kernel32 user32
+
+CTESTS = \
+ context.c
+
+ at MAKE_TEST_RULES@
+
+ at DEPENDENCIES@ # everything below this line is overwritten by make depend
diff --git a/dlls/wintab32/tests/context.c b/dlls/wintab32/tests/context.c
new file mode 100644
index 0000000..9bbf352
--- /dev/null
+++ b/dlls/wintab32/tests/context.c
@@ -0,0 +1,152 @@
+/*
+ * tests for Wintab context behavior
+ *
+ * Copyright 2009 John Klehm
+ *
+ * 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 <windows.h>
+#include <wintab.h>
+
+#include "wine/test.h"
+
+static const CHAR wintab32Dll[] = "Wintab32.dll";
+static const CHAR defaultWindowName[] = "Wintab Test";
+static const CHAR wintabTestWindowClassName[] = "WintabTestWnd";
+static const CHAR contextName[] = "TestContext";
+static const UINT X = 0;
+static const UINT Y = 0;
+static const UINT WIDTH = 200;
+static const UINT HEIGHT = 200;
+
+static HCTX (WINAPI *pWTOpenA)(HWND, LPLOGCONTEXTA, BOOL);
+static BOOL (WINAPI *pWTClose)(HCTX);
+
+static HMODULE load_functions(void)
+{
+#define GET_PROC(func) \
+ (p ## func = (void *)GetProcAddress(hWintab, #func))
+
+ HMODULE hWintab = LoadLibraryA(wintab32Dll);
+
+ if (!hWintab)
+ {
+ trace("LoadLibraryA(%s) failed\n",
+ wintab32Dll);
+ return NULL;
+ }
+
+ if (GET_PROC(WTOpenA) &&
+ GET_PROC(WTClose) )
+ {
+ return hWintab;
+ }
+ else
+ {
+ FreeLibrary(hWintab);
+ trace("Library loaded but failed to load function pointers\n");
+ return NULL;
+ }
+
+#undef GET_PROC
+}
+
+static LRESULT CALLBACK wintabTestWndProc(HWND hwnd, UINT msg, WPARAM wParam,
+ LPARAM lParam)
+{
+ return DefWindowProcA(hwnd, msg, wParam, lParam);
+}
+
+static BOOL wintab_create_window(HWND* pHwnd)
+{
+ WNDCLASSA testWindowClass;
+
+ if (!pHwnd) return FALSE;
+
+ *pHwnd = NULL;
+
+ ZeroMemory(&testWindowClass, sizeof(testWindowClass));
+
+ testWindowClass.lpfnWndProc = (WNDPROC)wintabTestWndProc;
+ testWindowClass.hInstance = NULL;
+ testWindowClass.hIcon = NULL;
+ testWindowClass.hCursor = NULL;
+ testWindowClass.hbrBackground = NULL;
+ testWindowClass.lpszMenuName = NULL;
+ testWindowClass.lpszClassName = wintabTestWindowClassName;
+
+ if (!RegisterClassA( &testWindowClass))
+ return FALSE;
+
+ *pHwnd = CreateWindowA(wintabTestWindowClassName, NULL,
+ WS_OVERLAPPED, X, Y, WIDTH, HEIGHT, NULL, NULL,
+ NULL, NULL);
+
+ return (*pHwnd)? TRUE:FALSE;
+}
+
+static void wintab_destroy_window(HWND hwnd)
+{
+ DestroyWindow(hwnd);
+ UnregisterClassA(wintabTestWindowClassName, NULL);
+}
+
+/* test if empty logcontext is modified by wtopen */
+static void test_WTOpenContextUnchanged(void)
+{
+ HWND defaultWindow = NULL;
+ HCTX hCtx = NULL;
+ LOGCONTEXTA testLogCtx;
+ LOGCONTEXTA refLogCtx;
+ int memdiff;
+
+ wintab_create_window(&defaultWindow);
+
+ ZeroMemory(&testLogCtx, sizeof(testLogCtx));
+ strcpy(testLogCtx.lcName, contextName);
+
+ ZeroMemory(&refLogCtx, sizeof(refLogCtx));
+ strcpy(refLogCtx.lcName, contextName);
+
+ /* a zero'd out context has invalid values which makes WTOpen fail */
+ hCtx = pWTOpenA(defaultWindow, &testLogCtx, TRUE);
+ todo_wine ok(NULL == hCtx, "Expected NULL, got %p\n", hCtx);
+
+ /* even though the values are invalid they are not corrected in anyway */
+ memdiff = memcmp(&testLogCtx, &refLogCtx, sizeof(LOGCONTEXTA));
+ ok(0 == memdiff, "Expected 0 == memcmp(testLogCtx, refLogCtx), got %i\n",
+ memdiff);
+
+ if (hCtx)
+ pWTClose(hCtx);
+
+ wintab_destroy_window(defaultWindow);
+}
+
+START_TEST(context)
+{
+ HMODULE hWintab = load_functions();
+
+ if (!hWintab)
+ {
+ skip("Wintab32.dll not available\n");
+ return;
+ }
+
+ test_WTOpenContextUnchanged();
+
+ FreeLibrary(hWintab);
+}
--
1.6.3.3
More information about the wine-patches
mailing list