winedbg: Don't dereference possibly NULL thread pointer.
[wine/zf.git] / dlls / wintab32 / tests / context.c
bloba88e4bb845d21736f67d39ca128285deb4b4d9fb
1 /*
2 * tests for Wintab context behavior
4 * Copyright 2009 John Klehm
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.
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.
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
21 #include <assert.h>
22 #include <windows.h>
23 #include <wintab.h>
25 #include "wine/test.h"
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;
35 static LOGCONTEXTA glogContext;
37 static HCTX (WINAPI *pWTOpenA)(HWND, LPLOGCONTEXTA, BOOL);
38 static BOOL (WINAPI *pWTClose)(HCTX);
39 static UINT (WINAPI *pWTInfoA)(UINT, UINT, void*);
41 static HMODULE load_functions(void)
43 #define GET_PROC(func) \
44 (p ## func = (void *)GetProcAddress(hWintab, #func))
46 HMODULE hWintab = LoadLibraryA(wintab32Dll);
48 if (!hWintab)
50 trace("LoadLibraryA(%s) failed\n",
51 wintab32Dll);
52 return NULL;
55 if (GET_PROC(WTOpenA) &&
56 GET_PROC(WTInfoA) &&
57 GET_PROC(WTClose) )
59 return hWintab;
61 else
63 FreeLibrary(hWintab);
64 trace("Library loaded but failed to load function pointers\n");
65 return NULL;
68 #undef GET_PROC
71 static LRESULT CALLBACK wintabTestWndProc(HWND hwnd, UINT msg, WPARAM wParam,
72 LPARAM lParam)
74 return DefWindowProcA(hwnd, msg, wParam, lParam);
77 static void wintab_create_window(HWND* pHwnd)
79 WNDCLASSA testWindowClass;
81 if (!pHwnd) return;
83 *pHwnd = NULL;
85 ZeroMemory(&testWindowClass, sizeof(testWindowClass));
87 testWindowClass.lpfnWndProc = wintabTestWndProc;
88 testWindowClass.hInstance = NULL;
89 testWindowClass.hIcon = NULL;
90 testWindowClass.hCursor = NULL;
91 testWindowClass.hbrBackground = NULL;
92 testWindowClass.lpszMenuName = NULL;
93 testWindowClass.lpszClassName = wintabTestWindowClassName;
95 assert(RegisterClassA(&testWindowClass));
97 *pHwnd = CreateWindowA(wintabTestWindowClassName, NULL,
98 WS_OVERLAPPED, X, Y, WIDTH, HEIGHT, NULL, NULL,
99 NULL, NULL);
101 assert(*pHwnd != NULL);
104 static void wintab_destroy_window(HWND hwnd)
106 DestroyWindow(hwnd);
107 UnregisterClassA(wintabTestWindowClassName, NULL);
110 /* test how a logcontext is validated by wtopen */
111 static void test_WTOpenContextValidation(void)
113 HWND defaultWindow = NULL;
114 HCTX hCtx = NULL;
115 LOGCONTEXTA testLogCtx;
116 LOGCONTEXTA refLogCtx;
117 int memdiff;
119 wintab_create_window(&defaultWindow);
121 ZeroMemory(&testLogCtx, sizeof(testLogCtx));
122 strcpy(testLogCtx.lcName, contextName);
124 ZeroMemory(&refLogCtx, sizeof(refLogCtx));
125 strcpy(refLogCtx.lcName, contextName);
127 /* a zeroed out context has values which makes WTOpen return null
128 * on wacom tablets but not on uclogic tablets */
129 hCtx = pWTOpenA(defaultWindow, &testLogCtx, TRUE);
131 /* check if the context gets updated */
132 memdiff = memcmp(&testLogCtx, &refLogCtx, sizeof(LOGCONTEXTA));
133 ok(0 == memdiff, "Expected 0 == memcmp(testLogCtx, refLogCtx), got %i\n",
134 memdiff);
136 if (hCtx)
137 pWTClose(hCtx);
139 wintab_destroy_window(defaultWindow);
142 static void test_WTInfoA(void)
144 char name[LCNAMELEN];
145 UINT ret;
146 AXIS value;
147 AXIS orientation[3];
149 glogContext.lcOptions |= CXO_SYSTEM;
151 ret = pWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
152 if(!ret)
154 skip("No tablet connected\n");
155 return;
157 ok(ret == sizeof( LOGCONTEXTA ), "incorrect size\n" );
158 ok(glogContext.lcOptions & CXO_SYSTEM, "Wrong options 0x%08x\n", glogContext.lcOptions);
160 ret = pWTInfoA( WTI_DEVICES, DVC_NAME, name );
161 trace("DVC_NAME %s\n", name);
163 ret = pWTInfoA( WTI_DEVICES, DVC_HARDWARE, name );
164 trace("DVC_HARDWARE %s\n", name);
166 ret = pWTInfoA( WTI_DEVICES, DVC_X, &value );
167 ok(ret == sizeof( AXIS ), "Wrong DVC_X size %d\n", ret);
168 trace("DVC_X %d, %d, %d\n", value.axMin, value.axMax, value.axUnits);
170 ret = pWTInfoA( WTI_DEVICES, DVC_Y, &value );
171 ok(ret == sizeof( AXIS ), "Wrong DVC_Y size %d\n", ret);
172 trace("DVC_Y %d, %d, %d\n", value.axMin, value.axMax, value.axUnits);
174 ret = pWTInfoA( WTI_DEVICES, DVC_Z, &value );
175 if(ret)
176 trace("DVC_Z %d, %d, %d\n", value.axMin, value.axMax, value.axUnits);
177 else
178 trace("DVC_Z not supported\n");
180 ret = pWTInfoA( WTI_DEVICES, DVC_NPRESSURE, &value );
181 ok(ret == sizeof( AXIS ), "Wrong DVC_NPRESSURE, size %d\n", ret);
182 trace("DVC_NPRESSURE %d, %d, %d\n", value.axMin, value.axMax, value.axUnits);
184 ret = pWTInfoA( WTI_DEVICES, DVC_TPRESSURE, &value );
185 if(ret)
186 trace("DVC_TPRESSURE %d, %d, %d\n", value.axMin, value.axMax, value.axUnits);
187 else
188 trace("DVC_TPRESSURE not supported\n");
190 ret = pWTInfoA( WTI_DEVICES, DVC_ORIENTATION, &orientation );
191 ok(ret == sizeof( AXIS )*3, "Wrong DVC_ORIENTATION, size %d\n", ret);
192 trace("DVC_ORIENTATION0 %d, %d, %d\n", orientation[0].axMin, orientation[0].axMax, orientation[0].axUnits);
193 trace("DVC_ORIENTATION1 %d, %d, %d\n", orientation[1].axMin, orientation[1].axMax, orientation[1].axUnits);
194 trace("DVC_ORIENTATION2 %d, %d, %d\n", orientation[2].axMin, orientation[2].axMax, orientation[2].axUnits);
196 ret = pWTInfoA( WTI_DEVICES, DVC_ROTATION, &orientation );
197 if(ret)
199 trace("DVC_ROTATION0 %d, %d, %d\n", orientation[0].axMin, orientation[0].axMax, orientation[0].axUnits);
200 trace("DVC_ROTATION1 %d, %d, %d\n", orientation[1].axMin, orientation[1].axMax, orientation[1].axUnits);
201 trace("DVC_ROTATION2 %d, %d, %d\n", orientation[2].axMin, orientation[2].axMax, orientation[2].axUnits);
203 else
204 trace("DVC_ROTATION not supported\n");
208 START_TEST(context)
210 HMODULE hWintab = load_functions();
212 if (!hWintab)
214 skip("Wintab32.dll not available\n");
215 return;
218 test_WTOpenContextValidation();
219 test_WTInfoA();
221 FreeLibrary(hWintab);