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