[TWAIN_32_WINETEST]
[reactos.git] / rostests / winetests / twain_32 / dsm.c
1 /* Unit test suite for Twain DSM functions
2 *
3 * Copyright 2009 Jeremy White, CodeWeavers, Inc.
4 *
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.
9 *
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.
14 *
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
18 *
19 */
20 #include <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winerror.h"
26 #include "winuser.h"
27 #include "twain.h"
28
29 #include "wine/test.h"
30
31 static DSMENTRYPROC pDSM_Entry;
32
33 static BOOL dsm_RegisterWindowClasses(void)
34 {
35 WNDCLASSA cls;
36 BOOL rc;
37
38 cls.style = 0;
39 cls.lpfnWndProc = DefWindowProcA;
40 cls.cbClsExtra = 0;
41 cls.cbWndExtra = 0;
42 cls.hInstance = GetModuleHandleA(0);
43 cls.hIcon = 0;
44 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
45 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
46 cls.lpszMenuName = NULL;
47 cls.lpszClassName = "TWAIN_dsm_class";
48
49 rc = RegisterClassA(&cls);
50 ok(rc, "RegisterClassA failed: le=%u\n", GetLastError());
51 return rc;
52 }
53
54
55 static void get_condition_code(TW_IDENTITY *appid, TW_IDENTITY *source, TW_STATUS *status)
56 {
57 TW_UINT16 rc;
58 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_STATUS, MSG_GET, status);
59 ok(rc == TWRC_SUCCESS, "Condition code not available, rc %d\n", rc);
60 }
61
62 static BOOL get_onevalue(TW_HANDLE hcontainer, TW_UINT32 *ret, TW_UINT16 *type)
63 {
64 TW_ONEVALUE *onev;
65 onev = GlobalLock(hcontainer);
66 if (onev)
67 {
68 *ret = onev->Item;
69 if (type)
70 *type = onev->ItemType;
71 GlobalUnlock(hcontainer);
72 return TRUE;
73 }
74 return FALSE;
75 }
76
77 static TW_HANDLE alloc_and_set_onevalue(TW_UINT32 val, TW_UINT16 type)
78 {
79 TW_HANDLE hcontainer;
80 TW_ONEVALUE *onev;
81 hcontainer = GlobalAlloc(0, sizeof(*onev));
82 if (hcontainer)
83 {
84 onev = GlobalLock(hcontainer);
85 if (onev)
86 {
87 onev->ItemType = type;
88 onev->Item = val;
89 GlobalUnlock(hcontainer);
90 }
91 else
92 {
93 GlobalFree(hcontainer);
94 hcontainer = 0;
95 }
96 }
97 return hcontainer;
98 }
99
100 static void check_get(TW_CAPABILITY *pCapability, TW_INT32 actual_support,
101 TW_UINT32 orig_value, TW_UINT32 default_value, TW_UINT32 *suggested_set_value)
102 {
103 void *p;
104 if (suggested_set_value)
105 *suggested_set_value = orig_value + 1;
106 p = GlobalLock(pCapability->hContainer);
107 if (p)
108 {
109 if (pCapability->ConType == TWON_ONEVALUE)
110 {
111 TW_ONEVALUE *onev = p;
112 ok(onev->Item == orig_value || !(actual_support & TWQC_GETCURRENT), "MSG_GET of 0x%x returned 0x%x, expecting 0x%x\n",
113 pCapability->Cap, onev->Item, orig_value);
114 trace("MSG_GET of 0x%x returned val 0x%x, type %d\n", pCapability->Cap, onev->Item, onev->ItemType);
115 if (suggested_set_value)
116 *suggested_set_value = onev->Item;
117 }
118 else if (pCapability->ConType == TWON_ENUMERATION)
119 {
120 int i;
121 TW_UINT8 *p8;
122 TW_UINT16 *p16;
123 TW_UINT32 *p32;
124 TW_ENUMERATION *enumv = p;
125 p8 = enumv->ItemList;
126 p16 = (TW_UINT16 *) p8;
127 p32 = (TW_UINT32 *) p8;
128 trace("MSG_GET of 0x%x returned %d items:\n", pCapability->Cap, enumv->NumItems);
129 for (i = 0; i < enumv->NumItems; i++)
130 {
131 if (enumv->ItemType == TWTY_UINT8 || enumv->ItemType == TWTY_INT8)
132 trace(" %d: 0x%x\n", i, p8[i]);
133 if (enumv->ItemType == TWTY_UINT16 || enumv->ItemType == TWTY_INT16)
134 trace(" %d: 0x%x\n", i, p16[i]);
135 if (enumv->ItemType == TWTY_UINT32 || enumv->ItemType == TWTY_INT32)
136 trace(" %d: 0x%x\n", i, p32[i]);
137 }
138 if (enumv->ItemType == TWTY_UINT16 || enumv->ItemType == TWTY_INT16)
139 {
140 ok(p16[enumv->CurrentIndex] == orig_value,
141 "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETCURRENT (0x%x) do not match.\n",
142 pCapability->Cap, p16[enumv->CurrentIndex], orig_value);
143 ok(p16[enumv->DefaultIndex] == default_value,
144 "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETDEFAULT (0x%x) do not match.\n",
145 pCapability->Cap, p16[enumv->DefaultIndex], default_value);
146 if (suggested_set_value)
147 *suggested_set_value = p16[(enumv->CurrentIndex + 1) % enumv->NumItems];
148 }
149 if (enumv->ItemType == TWTY_UINT32 || enumv->ItemType == TWTY_INT32)
150 {
151 ok(p32[enumv->CurrentIndex] == orig_value,
152 "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETCURRENT (0x%x) do not match.\n",
153 pCapability->Cap, p32[enumv->CurrentIndex], orig_value);
154 ok(p32[enumv->DefaultIndex] == default_value,
155 "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETDEFAULT (0x%x) do not match.\n",
156 pCapability->Cap, p32[enumv->DefaultIndex], default_value);
157 if (suggested_set_value)
158 *suggested_set_value = p32[(enumv->CurrentIndex + 1) % enumv->NumItems];
159 }
160 }
161 else
162 trace("MSG_GET on type 0x%x returned type 0x%x, which we didn't check.\n", pCapability->Cap, pCapability->ConType);
163 GlobalUnlock(pCapability->hContainer);
164 }
165 }
166
167 static void test_onevalue_cap(TW_IDENTITY *appid, TW_IDENTITY *source, TW_UINT16 captype, TW_UINT16 type, TW_INT32 minimum_support)
168 {
169 TW_UINT16 rc;
170 TW_UINT16 rtype;
171 TW_STATUS status;
172 TW_CAPABILITY cap;
173 TW_UINT32 orig_value = 0;
174 TW_UINT32 new_value;
175 TW_UINT32 default_value = 0;
176 TW_INT32 actual_support;
177
178 memset(&cap, 0, sizeof(cap));
179 cap.Cap = captype;
180 cap.ConType = TWON_DONTCARE16;
181
182 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, &cap);
183 get_condition_code(appid, source, &status);
184 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
185 "Error [rc %d|cc %d] doing MSG_QUERYSUPPORT for type 0x%x\n", rc, status.ConditionCode, captype);
186 if (rc != TWRC_SUCCESS)
187 return;
188 ok(get_onevalue(cap.hContainer, (TW_UINT32 *) &actual_support, NULL), "Returned cap.hContainer invalid for QuerySupport on type 0x%x\n", captype);
189 ok((actual_support & minimum_support) == minimum_support,
190 "Error: minimum support 0x%x for type 0x%x, got 0x%x\n", minimum_support,
191 captype, actual_support);
192
193
194 if (actual_support & TWQC_GETCURRENT)
195 {
196 memset(&cap, 0, sizeof(cap));
197 cap.Cap = captype;
198 cap.ConType = TWON_DONTCARE16;
199
200 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETCURRENT, &cap);
201 get_condition_code(appid, source, &status);
202 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
203 "Error [rc %d|cc %d] doing MSG_GETCURRENT for type 0x%x\n", rc, status.ConditionCode, captype);
204 if (rc == TWRC_SUCCESS)
205 {
206 ok(get_onevalue(cap.hContainer, &orig_value, &rtype), "Returned cap.hContainer invalid for GETCURRENT on type 0x%x\n", captype);
207 ok(rtype == type, "Returned GETCURRENT type 0x%x for cap 0x%x is not expected 0x%x\n", rtype, captype, type);
208 GlobalFree(cap.hContainer);
209 }
210 }
211
212 if (actual_support & TWQC_GETDEFAULT)
213 {
214 memset(&cap, 0, sizeof(cap));
215 cap.Cap = captype;
216 cap.ConType = TWON_DONTCARE16;
217
218 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETDEFAULT, &cap);
219 get_condition_code(appid, source, &status);
220 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
221 "Error [rc %d|cc %d] doing MSG_GETDEFAULT for type 0x%x\n", rc, status.ConditionCode, captype);
222 if (rc == TWRC_SUCCESS)
223 {
224 ok(get_onevalue(cap.hContainer, &default_value, &rtype), "Returned cap.hContainer invalid for GETDEFAULT on type 0x%x\n", captype);
225 ok(rtype == type, "Returned GETDEFAULT type 0x%x for cap 0x%x is not expected 0x%x\n", rtype, captype, type);
226 GlobalFree(cap.hContainer);
227 }
228 }
229
230 new_value = orig_value;
231 if (actual_support & TWQC_GET)
232 {
233 memset(&cap, 0, sizeof(cap));
234 cap.Cap = captype;
235 cap.ConType = TWON_DONTCARE16;
236
237 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
238 get_condition_code(appid, source, &status);
239 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
240 "Error [rc %d|cc %d] doing MSG_GET for type 0x%x\n", rc, status.ConditionCode, captype);
241 check_get(&cap, actual_support, orig_value, default_value, &new_value);
242 if (rc == TWRC_SUCCESS)
243 GlobalFree(cap.hContainer);
244 }
245
246 if (actual_support & TWQC_SET)
247 {
248 memset(&cap, 0, sizeof(cap));
249 cap.Cap = captype;
250 cap.ConType = TWON_ONEVALUE;
251 cap.hContainer = alloc_and_set_onevalue(new_value, type);
252
253 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_SET, &cap);
254 get_condition_code(appid, source, &status);
255 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
256 "Error [rc %d|cc %d] doing MSG_SET for type 0x%x\n", rc, status.ConditionCode, captype);
257 GlobalFree(cap.hContainer);
258 }
259
260 if (actual_support & TWQC_RESET)
261 {
262 memset(&cap, 0, sizeof(cap));
263 cap.Cap = captype;
264 cap.ConType = TWON_DONTCARE16;
265
266 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_RESET, &cap);
267 get_condition_code(appid, source, &status);
268 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
269 "Error [rc %d|cc %d] doing MSG_RESET for type 0x%x\n", rc, status.ConditionCode, captype);
270 if (rc == TWRC_SUCCESS)
271 GlobalFree(cap.hContainer);
272 }
273 }
274
275 static void test_resolution(TW_IDENTITY *appid, TW_IDENTITY *source, TW_UINT16 captype, TW_INT32 minimum_support)
276 {
277 TW_UINT16 rc;
278 TW_STATUS status;
279 TW_CAPABILITY cap;
280 TW_UINT32 val;
281 TW_UINT16 type;
282 TW_INT32 actual_support;
283 TW_FIX32 orig_value = { 0, 0 };
284 TW_UINT32 new_value = 0;
285 TW_FIX32 default_value = { 0, 0 };
286
287 memset(&cap, 0, sizeof(cap));
288 cap.Cap = captype;
289 cap.ConType = TWON_DONTCARE16;
290
291 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, &cap);
292 get_condition_code(appid, source, &status);
293 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
294 "Error [rc %d|cc %d] doing MSG_QUERYSUPPORT for type 0x%x\n", rc, status.ConditionCode, captype);
295 if (rc != TWRC_SUCCESS)
296 return;
297 ok(get_onevalue(cap.hContainer, (TW_UINT32 *) &actual_support, NULL), "Returned cap.hContainer invalid for QuerySupport on type 0x%x\n", captype);
298 ok((actual_support & minimum_support) == minimum_support,
299 "Error: minimum support 0x%x for type 0x%x, got 0x%x\n", minimum_support,
300 captype, actual_support);
301
302
303 if (actual_support & TWQC_GETCURRENT)
304 {
305 memset(&cap, 0, sizeof(cap));
306 cap.Cap = captype;
307 cap.ConType = TWON_DONTCARE16;
308
309 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETCURRENT, &cap);
310 get_condition_code(appid, source, &status);
311 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
312 "Error [rc %d|cc %d] doing MSG_GETCURRENT for type 0x%x\n", rc, status.ConditionCode, captype);
313 if (rc == TWRC_SUCCESS)
314 {
315 get_onevalue(cap.hContainer, &val, &type);
316 ok(type == TWTY_FIX32, "GETCURRENT for RESOLUTION is not type FIX32, is type %d\n", type);
317 memcpy(&orig_value, &val, sizeof(orig_value));
318 GlobalFree(cap.hContainer);
319 }
320 }
321
322 if (actual_support & TWQC_GETDEFAULT)
323 {
324 memset(&cap, 0, sizeof(cap));
325 cap.Cap = captype;
326 cap.ConType = TWON_DONTCARE16;
327
328 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETDEFAULT, &cap);
329 get_condition_code(appid, source, &status);
330 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
331 "Error [rc %d|cc %d] doing MSG_GETDEFAULT for type 0x%x\n", rc, status.ConditionCode, captype);
332 if (rc == TWRC_SUCCESS)
333 {
334 get_onevalue(cap.hContainer, &val, &type);
335 ok(type == TWTY_FIX32, "GETDEFAULT for RESOLUTION is not type FIX32, is type %d\n", type);
336 memcpy(&default_value, &val, sizeof(default_value));
337 GlobalFree(cap.hContainer);
338 }
339 }
340
341 if (actual_support & TWQC_GET)
342 {
343 memset(&cap, 0, sizeof(cap));
344 cap.Cap = captype;
345 cap.ConType = TWON_DONTCARE16;
346
347 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
348 get_condition_code(appid, source, &status);
349 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
350 "Error [rc %d|cc %d] doing MSG_GET for type 0x%x\n", rc, status.ConditionCode, captype);
351 if (rc == TWRC_SUCCESS)
352 {
353 TW_RANGE *range;
354 ok(cap.ConType == TWON_RANGE, "MSG_GET for ICAP_[XY]RESOLUTION did not return TWON_RANGE, but %d\n", cap.ConType);
355 range = GlobalLock(cap.hContainer);
356 trace("MSG_GET of 0x%x returned [ItemType %d|MinValue %d|MaxValue %d|StepSize %d|DefaultValue %d|CurrentValue %d]:\n",
357 cap.Cap, range->ItemType, range->MinValue, range->MaxValue, range->StepSize,
358 range->DefaultValue, range->CurrentValue);
359 for (new_value = range->MinValue; new_value < range->MaxValue; new_value += range->StepSize)
360 if (new_value != range->CurrentValue)
361 break;
362 GlobalUnlock(cap.hContainer);
363 GlobalFree(cap.hContainer);
364 }
365 }
366
367 if (actual_support & TWQC_SET)
368 {
369 memset(&cap, 0, sizeof(cap));
370 cap.Cap = captype;
371 cap.ConType = TWON_ONEVALUE;
372 cap.hContainer = alloc_and_set_onevalue(new_value, TWTY_FIX32);
373
374 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_SET, &cap);
375 get_condition_code(appid, source, &status);
376 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
377 "Error [rc %d|cc %d] doing MSG_SET for type 0x%x\n", rc, status.ConditionCode, captype);
378 GlobalFree(cap.hContainer);
379
380 }
381
382 if (actual_support & TWQC_RESET)
383 {
384 memset(&cap, 0, sizeof(cap));
385 cap.Cap = captype;
386 cap.ConType = TWON_DONTCARE16;
387
388 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_RESET, &cap);
389 get_condition_code(appid, source, &status);
390 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
391 "Error [rc %d|cc %d] doing MSG_RESET for type 0x%x\n", rc, status.ConditionCode, captype);
392 if (rc == TWRC_SUCCESS)
393 GlobalFree(cap.hContainer);
394 }
395 }
396
397 static void test_physical(TW_IDENTITY *appid, TW_IDENTITY *source, TW_UINT16 captype, TW_INT32 minimum_support)
398 {
399 TW_UINT16 rc;
400 TW_STATUS status;
401 TW_CAPABILITY cap;
402 TW_UINT32 val;
403 TW_UINT16 type;
404 TW_INT32 actual_support;
405
406 memset(&cap, 0, sizeof(cap));
407 cap.Cap = captype;
408 cap.ConType = TWON_DONTCARE16;
409
410 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, &cap);
411 get_condition_code(appid, source, &status);
412 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
413 "Error [rc %d|cc %d] doing MSG_QUERYSUPPORT for type 0x%x\n", rc, status.ConditionCode, captype);
414 if (rc != TWRC_SUCCESS)
415 return;
416 ok(get_onevalue(cap.hContainer, (TW_UINT32 *) &actual_support, NULL), "Returned cap.hContainer invalid for QuerySupport on type 0x%x\n", captype);
417 ok((actual_support & minimum_support) == minimum_support,
418 "Error: minimum support 0x%x for type 0x%x, got 0x%x\n", minimum_support,
419 captype, actual_support);
420
421
422 if (actual_support & TWQC_GETCURRENT)
423 {
424 memset(&cap, 0, sizeof(cap));
425 cap.Cap = captype;
426 cap.ConType = TWON_DONTCARE16;
427
428 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETCURRENT, &cap);
429 get_condition_code(appid, source, &status);
430 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
431 "Error [rc %d|cc %d] doing MSG_GETCURRENT for type 0x%x\n", rc, status.ConditionCode, captype);
432 if (rc == TWRC_SUCCESS)
433 {
434 get_onevalue(cap.hContainer, &val, &type);
435 ok(type == TWTY_FIX32, "GETCURRENT for PHYSICALXXX is not type FIX32, is type %d\n", type);
436 GlobalFree(cap.hContainer);
437 }
438 }
439
440 if (actual_support & TWQC_GETDEFAULT)
441 {
442 memset(&cap, 0, sizeof(cap));
443 cap.Cap = captype;
444 cap.ConType = TWON_DONTCARE16;
445
446 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETDEFAULT, &cap);
447 get_condition_code(appid, source, &status);
448 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
449 "Error [rc %d|cc %d] doing MSG_GETDEFAULT for type 0x%x\n", rc, status.ConditionCode, captype);
450 if (rc == TWRC_SUCCESS)
451 {
452 get_onevalue(cap.hContainer, &val, &type);
453 ok(type == TWTY_FIX32, "GETDEFAULT for PHYSICALXXX is not type FIX32, is type %d\n", type);
454 GlobalFree(cap.hContainer);
455 }
456 }
457
458 if (actual_support & TWQC_GET)
459 {
460 memset(&cap, 0, sizeof(cap));
461 cap.Cap = captype;
462 cap.ConType = TWON_DONTCARE16;
463
464 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
465 get_condition_code(appid, source, &status);
466 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
467 "Error [rc %d|cc %d] doing MSG_GET for type 0x%x\n", rc, status.ConditionCode, captype);
468 if (rc == TWRC_SUCCESS)
469 {
470 get_onevalue(cap.hContainer, &val, &type);
471 ok(type == TWTY_FIX32, "GET for PHYSICALXXX is not type FIX32, is type %d\n", type);
472 trace("GET for Physical type 0x%x returns 0x%x\n", captype, val);
473 GlobalFree(cap.hContainer);
474 }
475 }
476
477 }
478
479 static void test_supported_sizes(TW_IDENTITY *appid, TW_IDENTITY *source, TW_INT32 minimum_support)
480 {
481 TW_UINT16 rc;
482 TW_STATUS status;
483 TW_CAPABILITY cap;
484 TW_UINT32 val;
485 TW_UINT16 type;
486 TW_INT32 actual_support;
487 TW_UINT32 orig_value = TWSS_NONE;
488 TW_UINT32 default_value = TWSS_NONE;
489 TW_UINT32 new_value = TWSS_NONE;
490
491
492 memset(&cap, 0, sizeof(cap));
493 cap.Cap = ICAP_SUPPORTEDSIZES;
494 cap.ConType = TWON_DONTCARE16;
495
496 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, &cap);
497 get_condition_code(appid, source, &status);
498 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
499 "Error [rc %d|cc %d] doing MSG_QUERYSUPPORT for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
500 if (rc != TWRC_SUCCESS)
501 return;
502 ok(get_onevalue(cap.hContainer, (TW_UINT32 *) &actual_support, NULL), "Returned cap.hContainer invalid for QuerySupport on ICAP_SUPPORTEDSIZES\n");
503 ok((actual_support & minimum_support) == minimum_support,
504 "Error: minimum support 0x%x for ICAP_SUPPORTEDSIZES, got 0x%x\n", minimum_support, actual_support);
505
506 if (actual_support & TWQC_GETCURRENT)
507 {
508 memset(&cap, 0, sizeof(cap));
509 cap.Cap = ICAP_SUPPORTEDSIZES;
510 cap.ConType = TWON_DONTCARE16;
511
512 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETCURRENT, &cap);
513 get_condition_code(appid, source, &status);
514 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
515 "Error [rc %d|cc %d] doing MSG_GETCURRENT for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
516 if (rc == TWRC_SUCCESS)
517 {
518 get_onevalue(cap.hContainer, &val, &type);
519 ok(type == TWTY_UINT16, "GETCURRENT for ICAP_SUPPORTEDSIZES is not type UINT16, is type %d\n", type);
520 trace("Current size is %d\n", val);
521 GlobalFree(cap.hContainer);
522 orig_value = val;
523 }
524 }
525
526 if (actual_support & TWQC_GETDEFAULT)
527 {
528 memset(&cap, 0, sizeof(cap));
529 cap.Cap = ICAP_SUPPORTEDSIZES;
530 cap.ConType = TWON_DONTCARE16;
531
532 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETDEFAULT, &cap);
533 get_condition_code(appid, source, &status);
534 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
535 "Error [rc %d|cc %d] doing MSG_GETDEFAULT for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
536 if (rc == TWRC_SUCCESS)
537 {
538 get_onevalue(cap.hContainer, &val, &type);
539 ok(type == TWTY_UINT16, "GETDEFAULT for PHYSICALXXX is not type TWTY_UINT16, is type %d\n", type);
540 trace("Default size is %d\n", val);
541 GlobalFree(cap.hContainer);
542 default_value = val;
543 }
544 }
545
546 if (actual_support & TWQC_GET)
547 {
548 memset(&cap, 0, sizeof(cap));
549 cap.Cap = ICAP_SUPPORTEDSIZES;
550 cap.ConType = TWON_DONTCARE16;
551
552 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
553 get_condition_code(appid, source, &status);
554 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
555 "Error [rc %d|cc %d] doing MSG_GET for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
556 check_get(&cap, actual_support, orig_value, default_value, &new_value);
557 }
558
559 if (actual_support & TWQC_SET)
560 {
561 memset(&cap, 0, sizeof(cap));
562 cap.Cap = ICAP_SUPPORTEDSIZES;
563 cap.ConType = TWON_ONEVALUE;
564 cap.hContainer = alloc_and_set_onevalue(new_value, TWTY_UINT16);
565
566 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_SET, &cap);
567 get_condition_code(appid, source, &status);
568 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
569 "Error [rc %d|cc %d] doing MSG_SET for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
570 GlobalFree(cap.hContainer);
571
572 }
573
574 if (actual_support & TWQC_RESET)
575 {
576 memset(&cap, 0, sizeof(cap));
577 cap.Cap = ICAP_SUPPORTEDSIZES;
578 cap.ConType = TWON_DONTCARE16;
579
580 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_RESET, &cap);
581 get_condition_code(appid, source, &status);
582 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
583 "Error [rc %d|cc %d] doing MSG_RESET for ICAP_SUPPORTEDSIZES\n", rc, status.ConditionCode);
584 if (rc == TWRC_SUCCESS)
585 GlobalFree(cap.hContainer);
586 }
587 }
588
589 static void test_imagelayout(TW_IDENTITY *appid, TW_IDENTITY *source)
590 {
591 TW_UINT16 rc;
592 TW_STATUS status;
593 TW_IMAGELAYOUT layout;
594
595 rc = pDSM_Entry(appid, source, DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET, &layout);
596 get_condition_code(appid, source, &status);
597 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
598 "Error [rc %d|cc %d] doing MSG_GET for DG_IMAGE/DAT_IMAGELAYOUT\n", rc, status.ConditionCode);
599 if (rc != TWRC_SUCCESS)
600 return;
601 trace("ImageLayout [Left %x.%x|Top %x.%x|Right %x.%x|Bottom %x.%x|Document %d|Page %d|Frame %d]\n",
602 layout.Frame.Left.Whole, layout.Frame.Left.Frac,
603 layout.Frame.Top.Whole, layout.Frame.Top.Frac,
604 layout.Frame.Right.Whole, layout.Frame.Right.Frac,
605 layout.Frame.Bottom.Whole, layout.Frame.Bottom.Frac,
606 layout.DocumentNumber, layout.PageNumber, layout.FrameNumber);
607
608 memset(&layout, 0, sizeof(layout));
609 layout.Frame.Left.Whole = 1;
610 layout.Frame.Right.Whole = 2;
611 layout.Frame.Top.Whole = 1;
612 layout.Frame.Bottom.Whole = 2;
613 rc = pDSM_Entry(appid, source, DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET, &layout);
614 get_condition_code(appid, source, &status);
615 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
616 "Error [rc %d|cc %d] doing MSG_SET for DG_IMAGE/DAT_IMAGELAYOUT\n", rc, status.ConditionCode);
617 if (rc != TWRC_SUCCESS)
618 return;
619
620 rc = pDSM_Entry(appid, source, DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET, &layout);
621 get_condition_code(appid, source, &status);
622 ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
623 "Error [rc %d|cc %d] doing MSG_GET for DG_IMAGE/DAT_IMAGELAYOUT\n", rc, status.ConditionCode);
624 if (rc != TWRC_SUCCESS)
625 return;
626 trace("ImageLayout after set [Left %x.%x|Top %x.%x|Right %x.%x|Bottom %x.%x|Document %d|Page %d|Frame %d]\n",
627 layout.Frame.Left.Whole, layout.Frame.Left.Frac,
628 layout.Frame.Top.Whole, layout.Frame.Top.Frac,
629 layout.Frame.Right.Whole, layout.Frame.Right.Frac,
630 layout.Frame.Bottom.Whole, layout.Frame.Bottom.Frac,
631 layout.DocumentNumber, layout.PageNumber, layout.FrameNumber);
632 }
633
634
635 static void test_single_source(TW_IDENTITY *appid, TW_IDENTITY *source)
636 {
637 TW_UINT16 rc;
638 TW_STATUS status;
639 TW_CAPABILITY cap;
640 UINT16 capabilities[CAP_CUSTOMBASE];
641
642 memset(&cap, 0, sizeof(cap));
643 cap.Cap = CAP_SUPPORTEDCAPS;
644 cap.ConType = TWON_DONTCARE16;
645
646 rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
647 get_condition_code(appid, source, &status);
648 ok(rc == TWRC_SUCCESS || status.ConditionCode == TWCC_SUCCESS,
649 "Error obtaining CAP_SUPPORTEDCAPS\n");
650
651 memset(capabilities, 0, sizeof(capabilities));
652 if (rc == TWRC_SUCCESS && cap.ConType == TWON_ARRAY)
653 {
654 TW_ARRAY *a;
655 a = GlobalLock(cap.hContainer);
656 if (a)
657 {
658 if (a->ItemType == TWTY_UINT16)
659 {
660 int i;
661 UINT16 *u = (UINT16 *) a->ItemList;
662 trace("%d Capabilities:\n", a->NumItems);
663 for (i = 0; i < a->NumItems; i++)
664 if (u[i] < sizeof(capabilities) / sizeof(capabilities[0]))
665 {
666 capabilities[u[i]] = 1;
667 trace(" %d: 0x%x\n", i, u[i]);
668 }
669 }
670 GlobalUnlock(cap.hContainer);
671 }
672 }
673
674 /* All sources must support: */
675 ok(capabilities[CAP_SUPPORTEDCAPS], "CAP_SUPPORTEDCAPS not supported\n");
676 ok(capabilities[CAP_XFERCOUNT], "CAP_XFERCOUNT not supported\n");
677 if (capabilities[CAP_XFERCOUNT])
678 test_onevalue_cap(appid, source, CAP_XFERCOUNT, TWTY_INT16,
679 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
680 ok(capabilities[CAP_UICONTROLLABLE], "CAP_UICONTROLLABLE not supported\n");
681 if (capabilities[CAP_UICONTROLLABLE])
682 test_onevalue_cap(appid, source, CAP_UICONTROLLABLE, TWTY_BOOL, TWQC_GET);
683
684 if (source->SupportedGroups & DG_IMAGE)
685 {
686 /*
687 Sources that supply image information must support DG_CONTROL / DAT_CAPABILITY /
688 MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT on:
689 */
690 ok(capabilities[ICAP_COMPRESSION], "ICAP_COMPRESSION not supported\n");
691 if (capabilities[ICAP_COMPRESSION])
692 test_onevalue_cap(appid, source, ICAP_COMPRESSION, TWTY_UINT16,
693 TWQC_GET | TWQC_GETDEFAULT | TWQC_GETCURRENT);
694 todo_wine
695 ok(capabilities[ICAP_PLANARCHUNKY], "ICAP_PLANARCHUNKY not supported\n");
696 ok(capabilities[ICAP_PHYSICALHEIGHT], "ICAP_PHYSICALHEIGHT not supported\n");
697 if (capabilities[ICAP_PHYSICALHEIGHT])
698 test_physical(appid, source, ICAP_PHYSICALHEIGHT,
699 TWQC_GET | TWQC_GETDEFAULT | TWQC_GETCURRENT);
700 ok(capabilities[ICAP_PHYSICALWIDTH], "ICAP_PHYSICALWIDTH not supported\n");
701 if (capabilities[ICAP_PHYSICALWIDTH])
702 test_physical(appid, source, ICAP_PHYSICALWIDTH,
703 TWQC_GET | TWQC_GETDEFAULT | TWQC_GETCURRENT);
704 ok(capabilities[ICAP_PIXELFLAVOR], "ICAP_PIXELFLAVOR not supported\n");
705 if (capabilities[ICAP_PIXELFLAVOR])
706 test_onevalue_cap(appid, source, ICAP_PIXELFLAVOR, TWTY_UINT16,
707 TWQC_GET | TWQC_GETDEFAULT | TWQC_GETCURRENT);
708
709 /*
710 Sources that supply image information must support DG_CONTROL / DAT_CAPABILITY /
711 MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_RESET and MSG_SET on:
712 */
713 ok(capabilities[ICAP_BITDEPTH], "ICAP_BITDEPTH not supported\n");
714 if (capabilities[ICAP_BITDEPTH])
715 test_onevalue_cap(appid, source, ICAP_BITDEPTH, TWTY_UINT16,
716 TWQC_GET | TWQC_GETDEFAULT | TWQC_GETCURRENT );
717 todo_wine
718 ok(capabilities[ICAP_BITORDER], "ICAP_BITORDER not supported\n");
719 ok(capabilities[ICAP_PIXELTYPE], "ICAP_PIXELTYPE not supported\n");
720 if (capabilities[ICAP_PIXELTYPE])
721 test_onevalue_cap(appid, source, ICAP_PIXELTYPE, TWTY_UINT16,
722 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
723 ok(capabilities[ICAP_UNITS], "ICAP_UNITS not supported\n");
724 if (capabilities[ICAP_UNITS])
725 test_onevalue_cap(appid, source, ICAP_UNITS, TWTY_UINT16,
726 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
727 ok(capabilities[ICAP_XFERMECH], "ICAP_XFERMECH not supported\n");
728 if (capabilities[ICAP_XFERMECH])
729 test_onevalue_cap(appid, source, ICAP_XFERMECH, TWTY_UINT16,
730 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
731 ok(capabilities[ICAP_XRESOLUTION], "ICAP_XRESOLUTION not supported\n");
732 if (capabilities[ICAP_XRESOLUTION])
733 test_resolution(appid, source, ICAP_XRESOLUTION,
734 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
735 ok(capabilities[ICAP_YRESOLUTION], "ICAP_YRESOLUTION not supported\n");
736 if (capabilities[ICAP_YRESOLUTION])
737 test_resolution(appid, source, ICAP_YRESOLUTION,
738 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
739
740 /* Optional capabilities */
741 if (capabilities[CAP_AUTOFEED])
742 test_onevalue_cap(appid, source, CAP_AUTOFEED, TWTY_BOOL,
743 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
744 if (capabilities[CAP_FEEDERENABLED])
745 test_onevalue_cap(appid, source, CAP_FEEDERENABLED, TWTY_BOOL,
746 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
747 if (capabilities[ICAP_SUPPORTEDSIZES])
748 test_supported_sizes(appid, source,
749 TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
750
751 /* Additional tests */
752 test_imagelayout(appid, source);
753
754 }
755 }
756
757 static void test_sources(TW_IDENTITY *appid)
758 {
759 TW_UINT16 rc;
760 TW_IDENTITY source;
761 TW_STATUS status;
762 int scannercount = 0;
763
764 memset(&source, 0, sizeof(source));
765 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &source);
766 get_condition_code(appid, NULL, &status);
767 ok( (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS) ||
768 (rc == TWRC_FAILURE && status.ConditionCode == TWCC_NODS),
769 "Get first invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
770
771 while (rc == TWRC_SUCCESS)
772 {
773 scannercount++;
774 trace("[Scanner %d|Version %d.%d(%s)|Protocol %d.%d|SupportedGroups 0x%x|Manufacturer %s|Family %s|ProductName %s]\n",
775 scannercount,
776 source.Version.MajorNum, source.Version.MinorNum, source.Version.Info,
777 source.ProtocolMajor, source.ProtocolMinor, source.SupportedGroups,
778 source.Manufacturer, source.ProductFamily, source.ProductName);
779 memset(&source, 0, sizeof(source));
780 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &source);
781 get_condition_code(appid, NULL, &status);
782 ok(rc == TWRC_SUCCESS || rc == TWRC_ENDOFLIST, "Get next source failed, rc %d, cc %d\n", rc, status.ConditionCode);
783 }
784
785 memset(&source, 0, sizeof(source));
786 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &source);
787 get_condition_code(appid, NULL, &status);
788 ok( (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS) ||
789 (rc == TWRC_FAILURE && status.ConditionCode == TWCC_NODS),
790 "Get default invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
791
792 /* A DS might display a Popup during MSG_OPENDS, when the scanner is not connected */
793 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS && winetest_interactive)
794 {
795 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &source);
796 get_condition_code(appid, NULL, &status);
797
798 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
799 {
800 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &source);
801 get_condition_code(appid, NULL, &status);
802 ok(rc == TWRC_SUCCESS, "Close DS Failed, rc %d, cc %d\n", rc, status.ConditionCode);
803 }
804 }
805
806 if (winetest_interactive)
807 {
808 trace("Interactive, so trying userselect\n");
809 memset(&source, 0, sizeof(source));
810 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &source);
811 get_condition_code(appid, NULL, &status);
812 ok(rc == TWRC_SUCCESS || rc == TWRC_CANCEL, "Userselect failed, rc %d, cc %d\n", rc, status.ConditionCode);
813
814 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
815 {
816 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &source);
817 get_condition_code(appid, NULL, &status);
818 if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
819 {
820 test_single_source(appid, &source);
821 rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &source);
822 get_condition_code(appid, NULL, &status);
823 ok(rc == TWRC_SUCCESS, "Close DS Failed, rc %d, cc %d\n", rc, status.ConditionCode);
824 }
825 }
826 }
827
828 }
829
830 START_TEST(dsm)
831 {
832 TW_IDENTITY appid;
833 TW_UINT16 rc;
834 HANDLE hwnd;
835 HMODULE htwain;
836
837 if (!dsm_RegisterWindowClasses())
838 {
839 skip("Could not register the test class, skipping tests\n");
840 return;
841 }
842
843 htwain = LoadLibraryA("twain_32.dll");
844 if (! htwain)
845 {
846 win_skip("twain_32.dll not available, skipping tests\n");
847 return;
848 }
849 pDSM_Entry = (void*)GetProcAddress(htwain, "DSM_Entry");
850 ok(pDSM_Entry != NULL, "Unable to GetProcAddress DSM_Entry\n");
851 if (! pDSM_Entry)
852 {
853 win_skip("DSM_Entry not available, skipping tests\n");
854 return;
855 }
856
857 memset(&appid, 0, sizeof(appid));
858 appid.Version.Language = TWLG_ENGLISH_USA;
859 appid.Version.Country = TWCY_USA;
860 appid.ProtocolMajor = TWON_PROTOCOLMAJOR;
861 appid.ProtocolMinor = TWON_PROTOCOLMINOR;
862 appid.SupportedGroups = DG_CONTROL | DG_IMAGE;
863
864 hwnd = CreateWindowA("TWAIN_dsm_class", "Twain Test", 0, CW_USEDEFAULT, CW_USEDEFAULT,
865 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandleA(NULL), NULL);
866
867 rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &hwnd);
868 ok(rc == TWRC_SUCCESS, "MSG_OPENDSM returned %d\n", rc);
869
870 test_sources(&appid);
871
872 rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF) &hwnd);
873 ok(rc == TWRC_SUCCESS, "MSG_CLOSEDSM returned %d\n", rc);
874
875 DestroyWindow(hwnd);
876 FreeLibrary(htwain);
877 }