twain_32: Add an initial test framework for twain_32.dll.
[wine/multimedia.git] / dlls / twain_32 / tests / dsm.c
bloba915b536e830f0a4fbc75484f4ec7c488c224c6c
1 /* Unit test suite for Twain DSM functions
3 * Copyright 2009 Jeremy White, CodeWeavers, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include <assert.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winerror.h"
26 #include "winuser.h"
27 #include "twain.h"
29 #include "wine/test.h"
31 static DSMENTRYPROC pDSM_Entry;
33 static BOOL dsm_RegisterWindowClasses(void)
35 WNDCLASSA cls;
37 cls.style = 0;
38 cls.lpfnWndProc = DefWindowProc;
39 cls.cbClsExtra = 0;
40 cls.cbWndExtra = 0;
41 cls.hInstance = GetModuleHandleA(0);
42 cls.hIcon = 0;
43 cls.hCursor = LoadCursorA(0, IDC_ARROW);
44 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
45 cls.lpszMenuName = NULL;
46 cls.lpszClassName = "TWAIN_dsm_class";
47 if (!RegisterClassA(&cls)) return FALSE;
49 return TRUE;
53 static void get_condition_code(TW_IDENTITY *appid, TW_STATUS *status)
55 TW_UINT16 rc;
56 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_STATUS, MSG_GET, status);
57 ok(rc == TWRC_SUCCESS, "Condition code not available, rc %d\n", rc);
60 static void test_sources(TW_IDENTITY *appid)
62 TW_UINT16 rc;
63 TW_IDENTITY source;
64 TW_STATUS status;
66 memset(&source, 0, sizeof(source));
67 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &source);
68 get_condition_code(appid, &status);
69 todo_wine
70 ok(rc == TWRC_SUCCESS || rc == TWRC_FAILURE, "Get first error code, rc %d, cc %d\n", rc, status.ConditionCode);
71 if (rc == TWRC_SUCCESS)
72 ok(status.ConditionCode == TWCC_SUCCESS,"Get first invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
73 if (rc == TWRC_FAILURE)
74 ok(status.ConditionCode == TWCC_NODS,"Get first invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
76 while (rc == TWRC_SUCCESS)
78 trace("Got scanner %s\n", source.ProductName);
79 memset(&source, 0, sizeof(source));
80 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &source);
81 get_condition_code(appid, &status);
82 ok(rc == TWRC_SUCCESS || rc == TWRC_ENDOFLIST, "Get next source failed, rc %d, cc %d\n", rc, status.ConditionCode);
85 memset(&source, 0, sizeof(source));
86 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &source);
87 get_condition_code(appid, &status);
88 ok(rc == TWRC_SUCCESS || rc == TWRC_FAILURE, "Get default error code, rc %d, cc %d\n", rc, status.ConditionCode);
89 if (rc == TWRC_SUCCESS)
91 todo_wine
92 ok(status.ConditionCode == TWCC_SUCCESS,"Get default invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
95 if (rc == TWRC_FAILURE)
96 ok(status.ConditionCode == TWCC_NODS,"Get default invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
98 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
100 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &source);
101 get_condition_code(appid, &status);
103 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
105 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &source);
106 get_condition_code(appid, &status);
107 ok(rc == TWRC_SUCCESS, "Close DS Failed, rc %d, cc %d\n", rc, status.ConditionCode);
111 if (winetest_interactive)
113 trace("Interactive, so trying userselect\n");
114 memset(&source, 0, sizeof(source));
115 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &source);
116 get_condition_code(appid, &status);
117 ok(rc == TWRC_SUCCESS || rc == TWRC_CANCEL, "Userselect failed, rc %d, cc %d\n", rc, status.ConditionCode);
122 START_TEST(dsm)
124 TW_IDENTITY appid;
125 TW_UINT16 rc;
126 HANDLE hwnd;
127 HMODULE htwain;
129 if (!dsm_RegisterWindowClasses()) assert(0);
131 htwain = LoadLibraryA("twain_32.dll");
132 if (! htwain)
134 skip("twain_32.dll not available, skipping tests\n");
135 return;
137 pDSM_Entry = (void*)GetProcAddress(htwain, "DSM_Entry");
138 ok(pDSM_Entry != NULL, "Unable to GetProcAddress DSM_Entry\n");
139 if (! pDSM_Entry)
141 skip("DSM_Entry not available, skipping tests\n");
142 return;
145 memset(&appid, 0, sizeof(appid));
146 appid.Version.Language = TWLG_ENGLISH_USA;
147 appid.Version.Country = TWCY_USA;
148 appid.ProtocolMajor = TWON_PROTOCOLMAJOR;
149 appid.ProtocolMinor = TWON_PROTOCOLMINOR;
150 appid.SupportedGroups = DG_CONTROL | DG_IMAGE;
152 hwnd = CreateWindow("TWAIN_dsm_class", "Twain Test", 0,
153 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
154 NULL, NULL, GetModuleHandleA(0), NULL);
156 rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &hwnd);
157 ok(rc == TWRC_SUCCESS, "MSG_OPENDSM returned %d", rc);
159 test_sources(&appid);
161 rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF) &hwnd);
162 ok(rc == TWRC_SUCCESS, "MSG_CLOSEDSM returned %d", rc);
164 DestroyWindow(hwnd);
165 FreeLibrary(htwain);