Release 1.5.29.
[wine] / dlls / wintab32 / tests / context.c
1 /*
2  * tests for Wintab context behavior
3  *
4  * Copyright 2009 John Klehm
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 #include <assert.h>
22 #include <windows.h>
23 #include <wintab.h>
24
25 #include "wine/test.h"
26
27 static const CHAR wintab32Dll[] = "Wintab32.dll";
28 static const CHAR wintabTestWindowClassName[] = "WintabTestWnd";
29 static const CHAR contextName[] = "TestContext";
30 static const UINT X = 0;
31 static const UINT Y = 0;
32 static const UINT WIDTH = 200;
33 static const UINT HEIGHT = 200;
34
35 static HCTX (WINAPI *pWTOpenA)(HWND, LPLOGCONTEXTA, BOOL);
36 static BOOL (WINAPI *pWTClose)(HCTX);
37
38 static HMODULE load_functions(void)
39 {
40 #define GET_PROC(func) \
41     (p ## func = (void *)GetProcAddress(hWintab, #func))
42
43     HMODULE hWintab = LoadLibraryA(wintab32Dll);
44
45     if (!hWintab)
46     {
47         trace("LoadLibraryA(%s) failed\n",
48             wintab32Dll);
49         return NULL;
50     }
51
52     if (GET_PROC(WTOpenA) &&
53         GET_PROC(WTClose) )
54     {
55         return hWintab;
56     }
57     else
58     {
59         FreeLibrary(hWintab);
60         trace("Library loaded but failed to load function pointers\n");
61         return NULL;
62     }
63
64 #undef GET_PROC
65 }
66
67 static LRESULT CALLBACK wintabTestWndProc(HWND hwnd, UINT msg, WPARAM wParam,
68                 LPARAM lParam)
69 {
70     return DefWindowProcA(hwnd, msg, wParam, lParam);
71 }
72
73 static void wintab_create_window(HWND* pHwnd)
74 {
75     WNDCLASSA testWindowClass;
76
77     if (!pHwnd) return;
78
79     *pHwnd = NULL;
80
81     ZeroMemory(&testWindowClass, sizeof(testWindowClass));
82
83     testWindowClass.lpfnWndProc   = wintabTestWndProc;
84     testWindowClass.hInstance     = NULL;
85     testWindowClass.hIcon         = NULL;
86     testWindowClass.hCursor       = NULL;
87     testWindowClass.hbrBackground = NULL;
88     testWindowClass.lpszMenuName  = NULL;
89     testWindowClass.lpszClassName = wintabTestWindowClassName;
90
91     assert(RegisterClassA(&testWindowClass));
92
93     *pHwnd = CreateWindowA(wintabTestWindowClassName, NULL,
94                             WS_OVERLAPPED, X, Y, WIDTH, HEIGHT, NULL, NULL,
95                             NULL, NULL);
96
97     assert(*pHwnd != NULL);
98 }
99
100 static void wintab_destroy_window(HWND hwnd)
101 {
102     DestroyWindow(hwnd);
103     UnregisterClassA(wintabTestWindowClassName, NULL);
104 }
105
106 /* test how a logcontext is validated by wtopen */
107 static void test_WTOpenContextValidation(void)
108 {
109     HWND defaultWindow = NULL;
110     HCTX hCtx = NULL;
111     LOGCONTEXTA testLogCtx;
112     LOGCONTEXTA refLogCtx;
113     int memdiff;
114
115     wintab_create_window(&defaultWindow);
116
117     ZeroMemory(&testLogCtx, sizeof(testLogCtx));
118     strcpy(testLogCtx.lcName, contextName);
119
120     ZeroMemory(&refLogCtx, sizeof(refLogCtx));
121     strcpy(refLogCtx.lcName, contextName);
122
123     /* a zeroed out context has values which makes WTOpen return null
124      * on wacom tablets but not on uclogic tablets */
125     hCtx = pWTOpenA(defaultWindow, &testLogCtx, TRUE);
126
127     /* check if the context gets updated */
128     memdiff = memcmp(&testLogCtx, &refLogCtx, sizeof(LOGCONTEXTA));
129     ok(0 == memdiff, "Expected 0 == memcmp(testLogCtx, refLogCtx), got %i\n",
130         memdiff);
131
132     if (hCtx)
133         pWTClose(hCtx);
134
135     wintab_destroy_window(defaultWindow);
136 }
137
138 START_TEST(context)
139 {
140     HMODULE hWintab = load_functions();
141
142     if (!hWintab)
143     {
144         skip("Wintab32.dll not available\n");
145         return;
146     }
147
148     test_WTOpenContextValidation();
149
150     FreeLibrary(hWintab);
151 }