ldb: bump version to 2.6.0 for Samba 4.17.x releases
[Samba.git] / testprogs / win32 / spoolss / testspoolss.c
blob794e545e1866fc2ea9f3db69941a2978a8b62e81
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Guenther Deschner 2009-2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /****************************************************************************
22 ****************************************************************************/
24 #include "testspoolss.h"
25 #include "string.h"
26 #include "torture.h"
28 /****************************************************************************
29 ****************************************************************************/
31 static BOOL test_OpenPrinter(struct torture_context *tctx,
32 LPSTR printername,
33 LPPRINTER_DEFAULTS defaults,
34 LPHANDLE handle)
36 torture_comment(tctx, "Testing OpenPrinter(%s)", printername);
38 if (!OpenPrinter(printername, handle, defaults)) {
39 char tmp[1024];
40 sprintf(tmp, "failed to open printer %s, error was: 0x%08x\n",
41 printername, GetLastError());
42 torture_fail(tctx, tmp);
45 return TRUE;
48 /****************************************************************************
49 ****************************************************************************/
51 static BOOL test_ClosePrinter(struct torture_context *tctx,
52 HANDLE handle)
54 torture_comment(tctx, "Testing ClosePrinter");
56 if (!ClosePrinter(handle)) {
57 char tmp[1024];
58 sprintf(tmp, "failed to close printer, error was: %s\n",
59 errstr(GetLastError()));
60 torture_fail(tctx, tmp);
63 return TRUE;
67 /****************************************************************************
68 ****************************************************************************/
70 static BOOL test_EnumPrinters(struct torture_context *tctx,
71 LPSTR servername)
73 DWORD levels[] = { 1, 2, 5 };
74 DWORD success[] = { 1, 1, 1 };
75 DWORD i;
76 DWORD flags = PRINTER_ENUM_NAME;
77 LPBYTE buffer = NULL;
79 for (i=0; i < ARRAY_SIZE(levels); i++) {
81 DWORD needed = 0;
82 DWORD returned = 0;
83 DWORD err = 0;
84 char tmp[1024];
86 torture_comment(tctx, "Testing EnumPrinters level %d", levels[i]);
88 EnumPrinters(flags, servername, levels[i], NULL, 0, &needed, &returned);
89 err = GetLastError();
90 if (err == ERROR_INSUFFICIENT_BUFFER) {
91 err = 0;
92 buffer = malloc(needed);
93 torture_assert(tctx, buffer, "malloc failed");
94 if (!EnumPrinters(flags, servername, levels[i], buffer, needed, &needed, &returned)) {
95 err = GetLastError();
98 if (err) {
99 sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
100 levels[i], servername, needed, errstr(err));
101 if (success[i]) {
102 torture_fail(tctx, tmp);
103 } else {
104 torture_warning(tctx, tmp);
108 if (tctx->print) {
109 print_printer_info_bylevel(levels[i], buffer, returned);
112 free(buffer);
113 buffer = NULL;
116 return TRUE;
119 /****************************************************************************
120 ****************************************************************************/
122 static BOOL test_EnumDrivers(struct torture_context *tctx,
123 LPSTR servername,
124 LPSTR architecture)
126 DWORD levels[] = { 1, 2, 3, 4, 5, 6 };
127 DWORD success[] = { 1, 1, 1, 1, 1, 1 };
128 DWORD i;
129 LPBYTE buffer = NULL;
131 for (i=0; i < ARRAY_SIZE(levels); i++) {
133 DWORD needed = 0;
134 DWORD returned = 0;
135 DWORD err = 0;
136 char tmp[1024];
138 torture_comment(tctx, "Testing EnumPrinterDrivers(%s) level %d",
139 architecture, levels[i]);
141 EnumPrinterDrivers(servername, architecture, levels[i], NULL, 0, &needed, &returned);
142 err = GetLastError();
143 if (err == ERROR_INSUFFICIENT_BUFFER) {
144 err = 0;
145 buffer = malloc(needed);
146 torture_assert(tctx, buffer, "malloc failed");
147 if (!EnumPrinterDrivers(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
148 err = GetLastError();
151 if (err) {
152 sprintf(tmp, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
153 levels[i], servername, needed, errstr(err));
154 if (success[i]) {
155 torture_fail(tctx, tmp);
156 } else {
157 torture_warning(tctx, tmp);
161 if (tctx->print) {
162 print_driver_info_bylevel(levels[i], buffer, returned);
165 free(buffer);
166 buffer = NULL;
169 return TRUE;
172 /****************************************************************************
173 ****************************************************************************/
175 static BOOL test_GetForm(struct torture_context *tctx,
176 LPSTR servername,
177 HANDLE handle,
178 LPSTR formname)
180 DWORD levels[] = { 1, 2 };
181 DWORD success[] = { 1, 0 };
182 DWORD i;
183 LPBYTE buffer = NULL;
185 for (i=0; i < ARRAY_SIZE(levels); i++) {
187 DWORD needed = 0;
188 DWORD err = 0;
189 char tmp[1024];
191 torture_comment(tctx, "Testing GetForm(%s) level %d", formname, levels[i]);
193 GetForm(handle, formname, levels[i], NULL, 0, &needed);
194 err = GetLastError();
195 if (err == ERROR_INSUFFICIENT_BUFFER) {
196 err = 0;
197 buffer = malloc(needed);
198 torture_assert(tctx, buffer, "malloc failed");
199 if (!GetForm(handle, formname, levels[i], buffer, needed, &needed)) {
200 err = GetLastError();
203 if (err) {
204 sprintf(tmp, "GetForm failed level %d on [%s] (buffer size = %d), error: %s\n",
205 levels[i], servername, needed, errstr(err));
206 if (success[i]) {
207 torture_fail(tctx, tmp);
208 } else {
209 torture_warning(tctx, tmp);
213 if (tctx->print) {
214 print_form_info_bylevel(levels[i], buffer, 1);
217 free(buffer);
218 buffer = NULL;
221 return TRUE;
224 /****************************************************************************
225 ****************************************************************************/
227 static BOOL test_EnumForms(struct torture_context *tctx,
228 LPSTR servername,
229 HANDLE handle)
231 DWORD levels[] = { 1, 2 };
232 DWORD success[] = { 1, 1 };
233 DWORD i;
234 LPBYTE buffer = NULL;
236 for (i=0; i < ARRAY_SIZE(levels); i++) {
238 DWORD needed = 0;
239 DWORD returned = 0;
240 DWORD err = 0;
241 char tmp[1024];
243 torture_comment(tctx, "Testing EnumForms level %d", levels[i]);
245 if (tctx->samba3 && levels[i] == 2) {
246 torture_comment(tctx, "skipping level %d enum against samba\n", levels[i]);
247 continue;
250 EnumForms(handle, levels[i], NULL, 0, &needed, &returned);
251 err = GetLastError();
252 if (err == ERROR_INSUFFICIENT_BUFFER) {
253 err = 0;
254 buffer = malloc(needed);
255 torture_assert(tctx, buffer, "malloc failed");
256 if (!EnumForms(handle, levels[i], buffer, needed, &needed, &returned)) {
257 err = GetLastError();
260 if (err) {
261 sprintf(tmp, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
262 levels[i], servername, needed, errstr(err));
263 if (success[i]) {
264 torture_fail(tctx, tmp);
265 } else {
266 torture_warning(tctx, tmp);
270 if (tctx->print) {
271 print_form_info_bylevel(levels[i], buffer, returned);
274 free(buffer);
275 buffer = NULL;
278 return TRUE;
281 /****************************************************************************
282 ****************************************************************************/
284 static BOOL test_EnumPorts(struct torture_context *tctx,
285 LPSTR servername)
287 DWORD levels[] = { 1, 2 };
288 DWORD success[] = { 1, 1 };
289 DWORD i;
290 LPBYTE buffer = NULL;
292 for (i=0; i < ARRAY_SIZE(levels); i++) {
294 DWORD needed = 0;
295 DWORD returned = 0;
296 DWORD err = 0;
297 char tmp[1024];
299 torture_comment(tctx, "Testing EnumPorts level %d", levels[i]);
301 EnumPorts(servername, levels[i], NULL, 0, &needed, &returned);
302 err = GetLastError();
303 if (err == ERROR_INSUFFICIENT_BUFFER) {
304 err = 0;
305 buffer = malloc(needed);
306 torture_assert(tctx, buffer, "malloc failed");
307 if (!EnumPorts(servername, levels[i], buffer, needed, &needed, &returned)) {
308 err = GetLastError();
311 if (err) {
312 sprintf(tmp, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
313 levels[i], servername, needed, errstr(err));
314 if (success[i]) {
315 torture_fail(tctx, tmp);
316 } else {
317 torture_warning(tctx, tmp);
321 if (tctx->print) {
322 print_port_info_bylevel(levels[i], buffer, returned);
325 free(buffer);
326 buffer = NULL;
329 return TRUE;
332 /****************************************************************************
333 ****************************************************************************/
335 static BOOL test_EnumMonitors(struct torture_context *tctx,
336 LPSTR servername)
338 DWORD levels[] = { 1, 2 };
339 DWORD success[] = { 1, 1 };
340 DWORD i;
341 LPBYTE buffer = NULL;
343 for (i=0; i < ARRAY_SIZE(levels); i++) {
345 DWORD needed = 0;
346 DWORD returned = 0;
347 DWORD err = 0;
348 char tmp[1024];
350 torture_comment(tctx, "Testing EnumMonitors level %d", levels[i]);
352 EnumMonitors(servername, levels[i], NULL, 0, &needed, &returned);
353 err = GetLastError();
354 if (err == ERROR_INSUFFICIENT_BUFFER) {
355 err = 0;
356 buffer = malloc(needed);
357 torture_assert(tctx, buffer, "malloc failed");
358 if (!EnumMonitors(servername, levels[i], buffer, needed, &needed, &returned)) {
359 err = GetLastError();
362 if (err) {
363 sprintf(tmp, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
364 levels[i], servername, needed, errstr(err));
365 if (success[i]) {
366 torture_fail(tctx, tmp);
367 } else {
368 torture_warning(tctx, tmp);
372 if (tctx->print) {
373 print_monitor_info_bylevel(levels[i], buffer, returned);
376 free(buffer);
377 buffer = NULL;
380 return TRUE;
383 /****************************************************************************
384 ****************************************************************************/
386 static BOOL test_EnumPrintProcessors(struct torture_context *tctx,
387 LPSTR servername,
388 LPSTR architecture)
390 DWORD levels[] = { 1 };
391 DWORD success[] = { 1 };
392 DWORD i;
393 LPBYTE buffer = NULL;
395 for (i=0; i < ARRAY_SIZE(levels); i++) {
397 DWORD needed = 0;
398 DWORD returned = 0;
399 DWORD err = 0;
400 char tmp[1024];
402 torture_comment(tctx, "Testing EnumPrintProcessors(%s) level %d", architecture, levels[i]);
404 EnumPrintProcessors(servername, architecture, levels[i], NULL, 0, &needed, &returned);
405 err = GetLastError();
406 if (err == ERROR_INSUFFICIENT_BUFFER) {
407 err = 0;
408 buffer = malloc(needed);
409 torture_assert(tctx, buffer, "malloc failed");
410 if (!EnumPrintProcessors(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
411 err = GetLastError();
414 if (err) {
415 sprintf(tmp, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
416 levels[i], servername, needed, errstr(err));
417 if (success[i]) {
418 torture_fail(tctx, tmp);
419 } else {
420 torture_warning(tctx, tmp);
424 if (tctx->print) {
425 print_printprocessor_info_bylevel(levels[i], buffer, returned);
428 free(buffer);
429 buffer = NULL;
432 return TRUE;
435 /****************************************************************************
436 ****************************************************************************/
438 static BOOL test_EnumPrintProcessorDatatypes(struct torture_context *tctx,
439 LPSTR servername)
441 DWORD levels[] = { 1 };
442 DWORD success[] = { 1 };
443 DWORD i;
444 LPBYTE buffer = NULL;
446 for (i=0; i < ARRAY_SIZE(levels); i++) {
448 DWORD needed = 0;
449 DWORD returned = 0;
450 DWORD err = 0;
451 char tmp[1024];
453 torture_comment(tctx, "Testing EnumPrintProcessorDatatypes level %d", levels[i]);
455 EnumPrintProcessorDatatypes(servername, "winprint", levels[i], NULL, 0, &needed, &returned);
456 err = GetLastError();
457 if (err == ERROR_INSUFFICIENT_BUFFER) {
458 err = 0;
459 buffer = malloc(needed);
460 torture_assert(tctx, buffer, "malloc failed");
461 if (!EnumPrintProcessorDatatypes(servername, "winprint", levels[i], buffer, needed, &needed, &returned)) {
462 err = GetLastError();
465 if (err) {
466 sprintf(tmp, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
467 levels[i], servername, needed, errstr(err));
468 if (success[i]) {
469 torture_fail(tctx, tmp);
470 } else {
471 torture_warning(tctx, tmp);
475 if (tctx->print) {
476 print_datatypes_info_bylevel(levels[i], buffer, returned);
479 free(buffer);
480 buffer = NULL;
483 return TRUE;
486 /****************************************************************************
487 ****************************************************************************/
489 static BOOL test_EnumPrinterKey(struct torture_context *tctx,
490 LPSTR servername,
491 HANDLE handle,
492 LPCSTR key)
494 LPSTR buffer = NULL;
495 DWORD needed = 0;
496 DWORD err = 0;
497 char tmp[1024];
499 torture_comment(tctx, "Testing EnumPrinterKey(%s)", key);
501 err = EnumPrinterKey(handle, key, NULL, 0, &needed);
502 if (err == ERROR_MORE_DATA) {
503 buffer = (LPTSTR)malloc(needed);
504 torture_assert(tctx, buffer, "malloc failed");
505 err = EnumPrinterKey(handle, key, buffer, needed, &needed);
507 if (err) {
508 sprintf(tmp, "EnumPrinterKey(%s) failed on [%s] (buffer size = %d), error: %s\n",
509 key, servername, needed, errstr(err));
510 torture_fail(tctx, tmp);
513 if (tctx->print) {
514 print_printer_keys(buffer);
517 free(buffer);
519 return TRUE;
522 /****************************************************************************
523 ****************************************************************************/
525 static BOOL test_GetPrinter(struct torture_context *tctx,
526 LPSTR printername,
527 HANDLE handle)
529 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
530 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
531 DWORD i;
532 LPBYTE buffer = NULL;
534 for (i=0; i < ARRAY_SIZE(levels); i++) {
536 DWORD needed = 0;
537 DWORD err = 0;
538 char tmp[1024];
540 torture_comment(tctx, "Testing GetPrinter level %d", levels[i]);
542 GetPrinter(handle, levels[i], NULL, 0, &needed);
543 err = GetLastError();
544 if (err == ERROR_INSUFFICIENT_BUFFER) {
545 err = 0;
546 buffer = malloc(needed);
547 torture_assert(tctx, buffer, "malloc failed");
548 if (!GetPrinter(handle, levels[i], buffer, needed, &needed)) {
549 err = GetLastError();
552 if (err) {
553 sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
554 levels[i], printername, needed, errstr(err));
555 if (success[i]) {
556 torture_fail(tctx, tmp);
557 } else {
558 torture_warning(tctx, tmp);
562 if (tctx->print) {
563 print_printer_info_bylevel(levels[i], buffer, 1);
566 free(buffer);
567 buffer = NULL;
570 return TRUE;
573 /****************************************************************************
574 ****************************************************************************/
576 static BOOL test_GetPrinterDriver(struct torture_context *tctx,
577 LPSTR printername,
578 LPSTR architecture,
579 HANDLE handle)
581 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 8 };
582 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1 };
583 DWORD i;
584 LPBYTE buffer = NULL;
586 for (i=0; i < ARRAY_SIZE(levels); i++) {
588 DWORD needed = 0;
589 DWORD err = 0;
590 char tmp[1024];
592 torture_comment(tctx, "Testing GetPrinterDriver(%s) level %d",
593 architecture, levels[i]);
595 GetPrinterDriver(handle, architecture, levels[i], NULL, 0, &needed);
596 err = GetLastError();
597 if (err == ERROR_INSUFFICIENT_BUFFER) {
598 err = 0;
599 buffer = malloc(needed);
600 torture_assert(tctx, buffer, "malloc failed");
601 if (!GetPrinterDriver(handle, architecture, levels[i], buffer, needed, &needed)) {
602 err = GetLastError();
605 if (err) {
606 sprintf(tmp, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
607 levels[i], printername, needed, errstr(err));
608 if (success[i]) {
609 torture_fail(tctx, tmp);
610 } else {
611 torture_warning(tctx, tmp);
615 if (tctx->print) {
616 print_driver_info_bylevel(levels[i], buffer, 1);
619 free(buffer);
620 buffer = NULL;
623 return TRUE;
627 /****************************************************************************
628 ****************************************************************************/
630 static BOOL test_EnumJobs(struct torture_context *tctx,
631 LPSTR printername,
632 HANDLE handle)
634 DWORD levels[] = { 1, 2, 3, 4 };
635 DWORD success[] = { 1, 1, 1, 1 };
636 DWORD i;
637 LPBYTE buffer = NULL;
639 for (i=0; i < ARRAY_SIZE(levels); i++) {
641 DWORD needed = 0;
642 DWORD returned = 0;
643 DWORD err = 0;
644 char tmp[1024];
646 torture_comment(tctx, "Testing EnumJobs level %d", levels[i]);
648 if (tctx->samba3 && levels[i] == 4) {
649 torture_comment(tctx, "skipping level %d enum against samba\n", levels[i]);
650 continue;
653 EnumJobs(handle, 0, 100, levels[i], NULL, 0, &needed, &returned);
654 err = GetLastError();
655 if (err == ERROR_INSUFFICIENT_BUFFER) {
656 err = 0;
657 buffer = malloc(needed);
658 torture_assert(tctx, buffer, "malloc failed");
659 if (!EnumJobs(handle, 0, 100, levels[i], buffer, needed, &needed, &returned)) {
660 err = GetLastError();
663 if (err) {
664 sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
665 levels[i], printername, needed, errstr(err));
666 if (success[i]) {
667 torture_fail(tctx, tmp);
668 } else {
669 torture_warning(tctx, tmp);
673 if (tctx->print) {
674 print_job_info_bylevel(levels[i], buffer, returned);
677 free(buffer);
678 buffer = NULL;
681 return TRUE;
684 /****************************************************************************
685 ****************************************************************************/
687 static BOOL test_EnumPrinterData(struct torture_context *tctx,
688 LPSTR servername,
689 HANDLE handle)
691 DWORD err = 0;
692 LPTSTR value_name;
693 LPBYTE data;
694 DWORD index = 0;
695 DWORD type;
696 DWORD value_offered = 0, value_needed;
697 DWORD data_offered = 0, data_needed;
698 char tmp[1024];
700 torture_comment(tctx, "Testing EnumPrinterData(%d) (value offered: %d, data_offered: %d)\n",
701 index, value_offered, data_offered);
703 err = EnumPrinterData(handle, 0, NULL, 0, &value_needed, NULL, NULL, 0, &data_needed);
704 if (err) {
705 sprintf(tmp, "EnumPrinterData(%d) failed on [%s] (value size = %d, data size = %d), error: %s\n",
706 index, servername, value_offered, data_offered, errstr(err));
707 torture_fail(tctx, tmp);
710 value_name = malloc(value_needed);
711 torture_assert(tctx, value_name, "malloc failed");
712 data = malloc(data_needed);
713 torture_assert(tctx, data, "malloc failed");
715 value_offered = value_needed;
716 data_offered = data_needed;
718 do {
720 value_needed = 0;
721 data_needed = 0;
723 torture_comment(tctx, "Testing EnumPrinterData(%d) (value offered: %d, data_offered: %d)\n",
724 index, value_offered, data_offered);
726 err = EnumPrinterData(handle, index++, value_name, value_offered, &value_needed, &type, data, data_offered, &data_needed);
727 if (err == ERROR_NO_MORE_ITEMS) {
728 break;
730 if (err) {
731 sprintf(tmp, "EnumPrinterData(%d) failed on [%s] (value size = %d, data size = %d), error: %s\n",
732 index, servername, value_offered, data_offered, errstr(err));
733 torture_fail(tctx, tmp);
736 if (tctx->print) {
737 print_printer_data(NULL, value_name, data_needed, data, type);
740 } while (err != ERROR_NO_MORE_ITEMS);
742 free(value_name);
743 free(data);
745 return TRUE;
748 /****************************************************************************
749 ****************************************************************************/
751 static BOOL test_EnumPrinterDataEx(struct torture_context *tctx,
752 LPSTR servername,
753 LPSTR keyname,
754 HANDLE handle,
755 LPBYTE *buffer_p,
756 DWORD *returned_p)
758 LPBYTE buffer = NULL;
759 DWORD needed = 0;
760 DWORD returned = 0;
761 DWORD err = 0;
762 char tmp[1024];
764 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)", keyname);
766 err = EnumPrinterDataEx(handle, keyname, NULL, 0, &needed, &returned);
767 if (err == ERROR_MORE_DATA) {
768 buffer = malloc(needed);
769 torture_assert(tctx, buffer, "malloc failed");
770 err = EnumPrinterDataEx(handle, keyname, buffer, needed, &needed, &returned);
772 if (err) {
773 sprintf(tmp, "EnumPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n",
774 keyname, servername, needed, errstr(err));
775 torture_fail(tctx, tmp);
778 if (tctx->print) {
779 DWORD i;
780 LPPRINTER_ENUM_VALUES v = (LPPRINTER_ENUM_VALUES)buffer;
781 for (i=0; i < returned; i++) {
782 print_printer_enum_values(&v[i]);
786 if (returned_p) {
787 *returned_p = returned;
790 if (buffer_p) {
791 *buffer_p = buffer;
792 } else {
793 free(buffer);
796 return TRUE;
799 /****************************************************************************
800 ****************************************************************************/
802 static BOOL test_devicemode_equal(struct torture_context *tctx,
803 const DEVMODE *d1,
804 const DEVMODE *d2)
806 if (d1 == d2) {
807 return TRUE;
810 if (!d1 || !d2) {
811 torture_comment(tctx, "%s\n", __location__);
812 return FALSE;
815 torture_assert_str_equal(tctx, (const char *)d1->dmDeviceName, (const char *)d2->dmDeviceName, "dmDeviceName mismatch");
816 torture_assert_int_equal(tctx, d1->dmSpecVersion, d2->dmSpecVersion, "dmSpecVersion mismatch");
817 torture_assert_int_equal(tctx, d1->dmDriverVersion, d2->dmDriverVersion, "dmDriverVersion mismatch");
818 torture_assert_int_equal(tctx, d1->dmSize, d2->dmSize, "size mismatch");
819 torture_assert_int_equal(tctx, d1->dmDriverExtra, d2->dmDriverExtra, "dmDriverExtra mismatch");
820 torture_assert_int_equal(tctx, d1->dmFields, d2->dmFields, "dmFields mismatch");
822 torture_assert_int_equal(tctx, d1->dmOrientation, d2->dmOrientation, "dmOrientation mismatch");
823 torture_assert_int_equal(tctx, d1->dmPaperSize, d2->dmPaperSize, "dmPaperSize mismatch");
824 torture_assert_int_equal(tctx, d1->dmPaperLength, d2->dmPaperLength, "dmPaperLength mismatch");
825 torture_assert_int_equal(tctx, d1->dmPaperWidth, d2->dmPaperWidth, "dmPaperWidth mismatch");
826 torture_assert_int_equal(tctx, d1->dmScale, d2->dmScale, "dmScale mismatch");
827 torture_assert_int_equal(tctx, d1->dmCopies, d2->dmCopies, "dmCopies mismatch");
828 torture_assert_int_equal(tctx, d1->dmDefaultSource, d2->dmDefaultSource, "dmDefaultSource mismatch");
829 torture_assert_int_equal(tctx, d1->dmPrintQuality, d2->dmPrintQuality, "dmPrintQuality mismatch");
831 torture_assert_int_equal(tctx, d1->dmColor, d2->dmColor, "dmColor mismatch");
832 torture_assert_int_equal(tctx, d1->dmDuplex, d2->dmDuplex, "dmDuplex mismatch");
833 torture_assert_int_equal(tctx, d1->dmYResolution, d2->dmYResolution, "dmYResolution mismatch");
834 torture_assert_int_equal(tctx, d1->dmTTOption, d2->dmTTOption, "dmTTOption mismatch");
835 torture_assert_int_equal(tctx, d1->dmCollate, d2->dmCollate, "dmCollate mismatch");
836 torture_assert_str_equal(tctx, (const char *)d1->dmFormName, (const char *)d2->dmFormName, "dmFormName mismatch");
837 torture_assert_int_equal(tctx, d1->dmLogPixels, d2->dmLogPixels, "dmLogPixels mismatch");
838 torture_assert_int_equal(tctx, d1->dmBitsPerPel, d2->dmBitsPerPel, "dmBitsPerPel mismatch");
839 torture_assert_int_equal(tctx, d1->dmPelsWidth, d2->dmPelsWidth, "dmPelsWidth mismatch");
840 torture_assert_int_equal(tctx, d1->dmPelsHeight, d2->dmPelsHeight, "dmPelsHeight mismatch");
842 torture_assert_int_equal(tctx, d1->dmDisplayFlags, d2->dmDisplayFlags, "dmDisplayFlags mismatch");
843 /* or dmNup ? */
844 torture_assert_int_equal(tctx, d1->dmDisplayFrequency, d2->dmDisplayFrequency, "dmDisplayFrequency mismatch");
846 torture_assert_int_equal(tctx, d1->dmICMMethod, d2->dmICMMethod, "dmICMMethod mismatch");
847 torture_assert_int_equal(tctx, d1->dmICMIntent, d2->dmICMIntent, "dmICMIntent mismatch");
848 torture_assert_int_equal(tctx, d1->dmMediaType, d2->dmMediaType, "dmMediaType mismatch");
849 torture_assert_int_equal(tctx, d1->dmDitherType, d2->dmDitherType, "dmDitherType mismatch");
850 torture_assert_int_equal(tctx, d1->dmReserved1, d2->dmReserved1, "dmReserved1 mismatch");
851 torture_assert_int_equal(tctx, d1->dmReserved2, d2->dmReserved2, "reserved2 mismatch");
853 torture_assert_int_equal(tctx, d1->dmPanningWidth, d2->dmPanningWidth, "dmPanningWidth mismatch");
854 torture_assert_int_equal(tctx, d1->dmPanningHeight, d2->dmPanningHeight, "dmPanningHeight mismatch");
856 /* torture_assert_mem_equal(tctx, d1 + d1->dmSize, d2 + d2->dmSize, d1->dmDriverExtra, "private extra data mismatch"); */
858 return TRUE;
861 /****************************************************************************
862 ****************************************************************************/
864 static BOOL test_DeviceModes(struct torture_context *tctx,
865 LPSTR printername,
866 HANDLE handle)
868 PPRINTER_INFO_2 info2 = NULL;
869 PPRINTER_INFO_8 info8 = NULL;
870 DWORD needed = 0;
871 DWORD err = 0;
872 char tmp[1024];
874 torture_comment(tctx, "Testing DeviceModes");
876 torture_comment(tctx, "Testing GetPrinter level %d", 2);
878 GetPrinter(handle, 2, NULL, 0, &needed);
879 err = GetLastError();
880 if (err == ERROR_INSUFFICIENT_BUFFER) {
881 err = 0;
882 info2 = (PPRINTER_INFO_2)malloc(needed);
883 torture_assert(tctx, (LPBYTE)info2, "malloc failed");
884 if (!GetPrinter(handle, 2, (LPBYTE)info2, needed, &needed)) {
885 err = GetLastError();
888 if (err) {
889 sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
890 2, printername, needed, errstr(err));
891 torture_fail(tctx, tmp);
894 if (tctx->print) {
895 print_printer_info_2(info2);
898 torture_comment(tctx, "Testing GetPrinter level %d", 8);
900 GetPrinter(handle, 8, NULL, 0, &needed);
901 err = GetLastError();
902 if (err == ERROR_INSUFFICIENT_BUFFER) {
903 err = 0;
904 info8 = (PPRINTER_INFO_8)malloc(needed);
905 torture_assert(tctx, (LPBYTE)info8, "malloc failed");
906 if (!GetPrinter(handle, 8, (LPBYTE)info8, needed, &needed)) {
907 err = GetLastError();
910 if (err) {
911 sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
912 8, printername, needed, errstr(err));
913 torture_fail(tctx, tmp);
916 if (tctx->print) {
917 print_printer_info_8(info8);
920 torture_assert(tctx, test_devicemode_equal(tctx, info2->pDevMode, info8->pDevMode), "");
922 free(info2);
923 free(info8);
925 return TRUE;
928 /****************************************************************************
929 ****************************************************************************/
931 static BOOL test_GetJob(struct torture_context *tctx,
932 LPSTR printername,
933 HANDLE handle,
934 DWORD job_id)
936 DWORD levels[] = { 1, 2, 3, 4 };
937 DWORD success[] = { 1, 1, 1, 1 };
938 DWORD i;
939 LPBYTE buffer = NULL;
941 for (i=0; i < ARRAY_SIZE(levels); i++) {
943 DWORD needed = 0;
944 DWORD err = 0;
945 char tmp[1024];
947 torture_comment(tctx, "Testing GetJob(%d) level %d", job_id, levels[i]);
949 if (tctx->samba3 && (levels[i] == 4) || (levels[i] == 3)) {
950 torture_comment(tctx, "skipping level %d getjob against samba\n", levels[i]);
951 continue;
954 GetJob(handle, job_id, levels[i], NULL, 0, &needed);
955 err = GetLastError();
956 if (err == ERROR_INSUFFICIENT_BUFFER) {
957 err = 0;
958 buffer = malloc(needed);
959 torture_assert(tctx, buffer, "malloc failed");
960 if (!GetJob(handle, job_id, levels[i], buffer, needed, &needed)) {
961 err = GetLastError();
964 if (err) {
965 sprintf(tmp, "GetJob failed level %d on [%s] (buffer size = %d), error: %s\n",
966 levels[i], printername, needed, errstr(err));
967 if (success[i]) {
968 torture_fail(tctx, tmp);
969 } else {
970 torture_warning(tctx, tmp);
974 if (tctx->print) {
975 print_job_info_bylevel(levels[i], buffer, 1);
978 free(buffer);
979 buffer = NULL;
982 return TRUE;
985 /****************************************************************************
986 ****************************************************************************/
988 static BOOL test_EachJob(struct torture_context *tctx,
989 LPSTR printername,
990 HANDLE handle)
992 DWORD i;
993 PJOB_INFO_1 buffer = NULL;
994 DWORD needed = 0;
995 DWORD returned = 0;
996 DWORD err = 0;
997 DWORD level = 1;
998 char tmp[1024];
999 BOOL ret = TRUE;
1001 torture_comment(tctx, "Testing Each PrintJob %d");
1003 EnumJobs(handle, 0, 100, level, NULL, 0, &needed, &returned);
1004 err = GetLastError();
1005 if (err == ERROR_INSUFFICIENT_BUFFER) {
1006 err = 0;
1007 buffer = (PJOB_INFO_1)malloc(needed);
1008 torture_assert(tctx, buffer, "malloc failed");
1009 if (!EnumJobs(handle, 0, 100, level, (LPBYTE)buffer, needed, &needed, &returned)) {
1010 err = GetLastError();
1013 if (err) {
1014 sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
1015 level, printername, needed, errstr(err));
1016 torture_fail(tctx, tmp);
1019 if (tctx->print) {
1020 print_job_info_bylevel(level, (LPBYTE)buffer, returned);
1023 for (i=0; i < returned; i++) {
1024 ret = test_GetJob(tctx, printername, handle, buffer[i].JobId);
1027 free(buffer);
1029 return ret;
1033 /****************************************************************************
1034 ****************************************************************************/
1036 static BOOL test_OnePrinter(struct torture_context *tctx,
1037 LPSTR printername,
1038 LPSTR architecture,
1039 LPPRINTER_DEFAULTS defaults)
1041 HANDLE handle;
1042 BOOL ret = TRUE;
1044 torture_comment(tctx, "Testing Printer %s", printername);
1046 ret &= test_OpenPrinter(tctx, printername, defaults, &handle);
1047 ret &= test_GetPrinter(tctx, printername, handle);
1048 ret &= test_GetPrinterDriver(tctx, printername, architecture, handle);
1049 ret &= test_EnumForms(tctx, printername, handle);
1050 ret &= test_EnumJobs(tctx, printername, handle);
1051 ret &= test_EachJob(tctx, printername, handle);
1052 ret &= test_EnumPrinterKey(tctx, printername, handle, "");
1053 ret &= test_EnumPrinterKey(tctx, printername, handle, "PrinterDriverData");
1054 ret &= test_EnumPrinterData(tctx, printername, handle);
1055 ret &= test_EnumPrinterDataEx(tctx, printername, "PrinterDriverData", handle, NULL, NULL);
1056 ret &= test_DeviceModes(tctx, printername, handle);
1057 #if 0
1058 /* don't run these at the moment, behaviour is PrinterData API calls (not
1059 * dcerpc calls) is almost unpredictable - gd */
1060 ret &= test_PrinterData(tctx, printername, handle);
1061 ret &= test_PrinterDataW(tctx, printername, handle);
1062 #endif
1063 ret &= test_ClosePrinter(tctx, handle);
1065 return ret;
1068 /****************************************************************************
1069 ****************************************************************************/
1071 static BOOL test_EachPrinter(struct torture_context *tctx,
1072 LPSTR servername,
1073 LPSTR architecture,
1074 LPPRINTER_DEFAULTS defaults)
1076 DWORD needed = 0;
1077 DWORD returned = 0;
1078 DWORD err = 0;
1079 char tmp[1024];
1080 DWORD i;
1081 DWORD flags = PRINTER_ENUM_NAME;
1082 PPRINTER_INFO_1 buffer = NULL;
1083 BOOL ret = TRUE;
1085 torture_comment(tctx, "Testing EnumPrinters level %d", 1);
1087 EnumPrinters(flags, servername, 1, NULL, 0, &needed, &returned);
1088 err = GetLastError();
1089 if (err == ERROR_INSUFFICIENT_BUFFER) {
1090 err = 0;
1091 buffer = (PPRINTER_INFO_1)malloc(needed);
1092 torture_assert(tctx, buffer, "malloc failed");
1093 if (!EnumPrinters(flags, servername, 1, (LPBYTE)buffer, needed, &needed, &returned)) {
1094 err = GetLastError();
1097 if (err) {
1098 sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
1099 1, servername, needed, errstr(err));
1100 torture_fail(tctx, tmp);
1103 for (i=0; i < returned; i++) {
1104 ret &= test_OnePrinter(tctx, buffer[i].pName, architecture, defaults);
1107 free(buffer);
1109 return ret;
1112 /****************************************************************************
1113 ****************************************************************************/
1115 static BOOL test_GetPrintProcessorDirectory(struct torture_context *tctx,
1116 LPSTR servername,
1117 LPSTR architecture)
1119 DWORD levels[] = { 1 };
1120 DWORD success[] = { 1 };
1121 DWORD i;
1122 LPBYTE buffer = NULL;
1124 for (i=0; i < ARRAY_SIZE(levels); i++) {
1126 DWORD needed = 0;
1127 DWORD err = 0;
1128 char tmp[1024];
1130 torture_comment(tctx, "Testing GetPrintProcessorDirectory(%s) level %d",
1131 architecture, levels[i]);
1133 GetPrintProcessorDirectory(servername, architecture, levels[i], NULL, 0, &needed);
1134 err = GetLastError();
1135 if (err == ERROR_INSUFFICIENT_BUFFER) {
1136 err = 0;
1137 buffer = malloc(needed);
1138 torture_assert(tctx, buffer, "malloc failed");
1139 if (!GetPrintProcessorDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
1140 err = GetLastError();
1143 if (err) {
1144 sprintf(tmp, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
1145 levels[i], servername, needed, errstr(err));
1146 if (success[i]) {
1147 torture_fail(tctx, tmp);
1148 } else {
1149 torture_warning(tctx, tmp);
1153 if (tctx->print) {
1154 printf("\tPrint Processor Directory\t= %s\n\n", (LPSTR)buffer);
1157 free(buffer);
1158 buffer = NULL;
1161 return TRUE;
1164 /****************************************************************************
1165 ****************************************************************************/
1167 static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
1168 LPSTR servername,
1169 LPSTR architecture)
1171 DWORD levels[] = { 1 };
1172 DWORD success[] = { 1 };
1173 DWORD i;
1174 LPBYTE buffer = NULL;
1176 for (i=0; i < ARRAY_SIZE(levels); i++) {
1178 DWORD needed = 0;
1179 DWORD err = 0;
1180 char tmp[1024];
1182 torture_comment(tctx, "Testing GetPrinterDriverDirectory(%s) level %d",
1183 architecture, levels[i]);
1185 GetPrinterDriverDirectory(servername, architecture, levels[i], NULL, 0, &needed);
1186 err = GetLastError();
1187 if (err == ERROR_INSUFFICIENT_BUFFER) {
1188 err = 0;
1189 buffer = malloc(needed);
1190 torture_assert(tctx, buffer, "malloc failed");
1191 if (!GetPrinterDriverDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
1192 err = GetLastError();
1195 if (err) {
1196 sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
1197 levels[i], servername, needed, errstr(err));
1198 if (success[i]) {
1199 torture_fail(tctx, tmp);
1200 } else {
1201 torture_warning(tctx, tmp);
1205 if (tctx->print) {
1206 printf("\tPrinter Driver Directory\t= %s\n\n", (LPSTR)buffer);
1209 free(buffer);
1210 buffer = NULL;
1213 return TRUE;
1216 /****************************************************************************
1217 ****************************************************************************/
1219 static BOOL test_GetPrinterData(struct torture_context *tctx,
1220 LPSTR servername,
1221 LPSTR valuename,
1222 HANDLE handle,
1223 DWORD *type_p,
1224 LPBYTE *buffer_p,
1225 DWORD *size_p)
1227 LPBYTE buffer = NULL;
1228 DWORD needed = 0;
1229 DWORD type;
1230 DWORD err = 0;
1231 char tmp[1024];
1233 torture_comment(tctx, "Testing GetPrinterData(%s)", valuename);
1235 err = GetPrinterData(handle, valuename, &type, NULL, 0, &needed);
1236 if (err == ERROR_MORE_DATA) {
1237 buffer = (LPBYTE)malloc(needed);
1238 torture_assert(tctx, buffer, "malloc failed");
1239 err = GetPrinterData(handle, valuename, &type, buffer, needed, &needed);
1241 if (err) {
1242 sprintf(tmp, "GetPrinterData(%s) failed on [%s] (buffer size = %d), error: %s\n",
1243 valuename, servername, needed, errstr(err));
1244 torture_fail(tctx, tmp);
1247 if (tctx->print) {
1248 print_printer_data("PrinterDriverData", valuename, needed, buffer, type);
1251 if (type_p) {
1252 *type_p = type;
1255 if (size_p) {
1256 *size_p = needed;
1259 if (buffer_p) {
1260 *buffer_p = buffer;
1261 } else {
1262 free(buffer);
1265 return TRUE;
1268 /****************************************************************************
1269 ****************************************************************************/
1271 static BOOL test_GetPrinterDataEx(struct torture_context *tctx,
1272 LPSTR servername,
1273 LPSTR keyname,
1274 LPSTR valuename,
1275 HANDLE handle,
1276 DWORD *type_p,
1277 LPBYTE *buffer_p,
1278 DWORD *size_p)
1280 LPBYTE buffer = NULL;
1281 DWORD needed = 0;
1282 DWORD type;
1283 DWORD err = 0;
1284 char tmp[1024];
1286 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)", keyname, valuename);
1288 err = GetPrinterDataEx(handle, keyname, valuename, &type, NULL, 0, &needed);
1289 if (err == ERROR_MORE_DATA) {
1290 buffer = (LPBYTE)malloc(needed);
1291 torture_assert(tctx, buffer, "malloc failed");
1292 err = GetPrinterDataEx(handle, keyname, valuename, &type, buffer, needed, &needed);
1294 if (err) {
1295 sprintf(tmp, "GetPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n",
1296 valuename, servername, needed, errstr(err));
1297 torture_fail(tctx, tmp);
1300 if (tctx->print) {
1301 print_printer_data(keyname, valuename, needed, buffer, type);
1304 if (type_p) {
1305 *type_p = type;
1308 if (size_p) {
1309 *size_p = needed;
1312 if (buffer_p) {
1313 *buffer_p = buffer;
1314 } else {
1315 free(buffer);
1318 return TRUE;
1321 /****************************************************************************
1322 ****************************************************************************/
1324 static BOOL test_GetPrinterDataExW(struct torture_context *tctx,
1325 LPSTR servername,
1326 LPCWSTR keyname,
1327 LPCWSTR valuename,
1328 HANDLE handle,
1329 DWORD *type_p,
1330 LPBYTE *buffer_p,
1331 DWORD *size_p)
1333 LPBYTE buffer = NULL;
1334 DWORD needed = 0;
1335 DWORD type;
1336 DWORD err = 0;
1337 char tmp[1024];
1339 torture_comment(tctx, "Testing GetPrinterDataExW(%ls - %ls)", keyname, valuename);
1341 err = GetPrinterDataExW(handle, keyname, valuename, &type, NULL, 0, &needed);
1342 if (err == ERROR_MORE_DATA) {
1343 buffer = (LPBYTE)malloc(needed);
1344 torture_assert(tctx, buffer, "malloc failed");
1345 err = GetPrinterDataExW(handle, keyname, valuename, &type, buffer, needed, &needed);
1347 if (err) {
1348 sprintf(tmp, "GetPrinterDataExW(%ls) failed on [%s] (buffer size = %d), error: %s\n",
1349 valuename, servername, needed, errstr(err));
1350 torture_fail(tctx, tmp);
1353 if (tctx->print) {
1354 print_printer_dataw(keyname, valuename, needed, buffer, type);
1357 if (type_p) {
1358 *type_p = type;
1361 if (size_p) {
1362 *size_p = needed;
1365 if (buffer_p) {
1366 *buffer_p = buffer;
1367 } else {
1368 free(buffer);
1371 return TRUE;
1375 /****************************************************************************
1376 ****************************************************************************/
1378 static BOOL test_DeletePrinterDataEx(struct torture_context *tctx,
1379 LPSTR servername,
1380 LPSTR keyname,
1381 LPSTR valuename,
1382 HANDLE handle)
1384 DWORD err = 0;
1385 char tmp[1024];
1387 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)", keyname, valuename);
1389 err = DeletePrinterDataEx(handle, keyname, valuename);
1390 if (err) {
1391 sprintf(tmp, "DeletePrinterDataEx(%s - %s) failed on [%s], error: %s\n",
1392 keyname, valuename, servername, errstr(err));
1393 torture_fail(tctx, tmp);
1396 return TRUE;
1399 /****************************************************************************
1400 ****************************************************************************/
1402 static BOOL test_DeletePrinterDataExW(struct torture_context *tctx,
1403 LPSTR servername,
1404 LPCWSTR keyname,
1405 LPCWSTR valuename,
1406 HANDLE handle)
1408 DWORD err = 0;
1409 char tmp[1024];
1411 torture_comment(tctx, "Testing DeletePrinterDataExW(%ls - %ls)", keyname, valuename);
1413 err = DeletePrinterDataExW(handle, keyname, valuename);
1414 if (err) {
1415 sprintf(tmp, "DeletePrinterDataExW(%ls - %ls) failed on [%s], error: %s\n",
1416 keyname, valuename, servername, errstr(err));
1417 torture_fail(tctx, tmp);
1420 return TRUE;
1424 /****************************************************************************
1425 ****************************************************************************/
1427 static BOOL test_DeletePrinterKey(struct torture_context *tctx,
1428 LPSTR servername,
1429 LPSTR keyname,
1430 HANDLE handle)
1432 DWORD err = 0;
1433 char tmp[1024];
1435 torture_comment(tctx, "Testing DeletePrinterKey(%s)", keyname);
1437 err = DeletePrinterKey(handle, keyname);
1438 if (err) {
1439 sprintf(tmp, "DeletePrinterKey(%s) failed on [%s], error: %s\n",
1440 keyname, servername, errstr(err));
1441 torture_fail(tctx, tmp);
1444 return TRUE;
1447 /****************************************************************************
1448 ****************************************************************************/
1450 static BOOL test_DeletePrinterKeyW(struct torture_context *tctx,
1451 LPSTR servername,
1452 LPCWSTR keyname,
1453 HANDLE handle)
1455 DWORD err = 0;
1456 char tmp[1024];
1458 torture_comment(tctx, "Testing DeletePrinterKeyW(%ls)", keyname);
1460 err = DeletePrinterKeyW(handle, keyname);
1461 if (err) {
1462 sprintf(tmp, "DeletePrinterKeyW(%ls) failed on [%s], error: %s\n",
1463 keyname, servername, errstr(err));
1464 torture_fail(tctx, tmp);
1467 return TRUE;
1470 /****************************************************************************
1471 ****************************************************************************/
1473 static BOOL test_SetPrinterDataEx(struct torture_context *tctx,
1474 LPSTR servername,
1475 LPSTR keyname,
1476 LPSTR valuename,
1477 HANDLE handle,
1478 DWORD type,
1479 LPBYTE buffer,
1480 DWORD offered)
1482 DWORD err = 0;
1483 char tmp[1024];
1485 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s)", keyname, valuename);
1487 err = SetPrinterDataEx(handle, keyname, valuename, type, buffer, offered);
1488 if (err) {
1489 sprintf(tmp, "SetPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n",
1490 valuename, servername, offered, errstr(err));
1491 torture_fail(tctx, tmp);
1494 return TRUE;
1497 /****************************************************************************
1498 ****************************************************************************/
1500 static BOOL test_SetPrinterDataExW(struct torture_context *tctx,
1501 LPCSTR servername,
1502 LPCWSTR keyname,
1503 LPCWSTR valuename,
1504 HANDLE handle,
1505 DWORD type,
1506 LPBYTE buffer,
1507 DWORD offered)
1509 DWORD err = 0;
1510 char tmp[1024];
1512 torture_comment(tctx, "Testing SetPrinterDataExW(%ls - %ls)", keyname, valuename);
1514 err = SetPrinterDataExW(handle, keyname, valuename, type, buffer, offered);
1515 if (err) {
1516 sprintf(tmp, "SetPrinterDataExW(%ls) failed on [%s] (buffer size = %d), error: %s\n",
1517 valuename, servername, offered, errstr(err));
1518 torture_fail(tctx, tmp);
1521 return TRUE;
1525 /****************************************************************************
1526 ****************************************************************************/
1528 static BOOL test_PrinterData_Server(struct torture_context *tctx,
1529 LPSTR servername,
1530 HANDLE handle)
1532 BOOL ret = TRUE;
1533 DWORD i;
1534 DWORD type, type_ex;
1535 LPBYTE buffer, buffer_ex;
1536 DWORD size, size_ex;
1537 LPSTR valuenames[] = {
1538 SPLREG_DEFAULT_SPOOL_DIRECTORY,
1539 SPLREG_MAJOR_VERSION,
1540 SPLREG_MINOR_VERSION,
1541 SPLREG_DS_PRESENT,
1542 SPLREG_DNS_MACHINE_NAME,
1543 SPLREG_ARCHITECTURE,
1544 SPLREG_OS_VERSION
1547 for (i=0; i < ARRAY_SIZE(valuenames); i++) {
1548 ret &= test_GetPrinterData(tctx, servername, valuenames[i], handle, &type, &buffer, &size);
1549 ret &= test_GetPrinterDataEx(tctx, servername, "random", valuenames[i], handle, &type_ex, &buffer_ex, &size_ex);
1550 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
1551 torture_assert_int_equal(tctx, size, size_ex, "size mismatch");
1552 torture_assert_mem_equal(tctx, buffer, buffer_ex, size, "buffer mismatch");
1553 free(buffer);
1554 free(buffer_ex);
1557 return ret;
1560 /****************************************************************************
1561 ****************************************************************************/
1563 static BOOL PrinterDataEqual(struct torture_context *tctx,
1564 DWORD type1, DWORD type2,
1565 DWORD size1, DWORD size2,
1566 LPBYTE buffer1, LPBYTE buffer2)
1568 torture_assert_int_equal(tctx, type1, type2, "type mismatch");
1569 torture_assert_int_equal(tctx, size1, size2, "size mismatch");
1570 torture_assert_mem_equal(tctx, buffer1, buffer2, size1, "buffer mismatch");
1572 return TRUE;
1575 /****************************************************************************
1576 ****************************************************************************/
1578 static BOOL test_PrinterData(struct torture_context *tctx,
1579 LPSTR printername,
1580 HANDLE handle)
1582 char tmp[1024];
1583 LPSTR keyname = "torture_key";
1584 LPSTR valuename = "torture_value";
1585 BOOL ret = TRUE;
1586 DWORD types[] = {
1587 REG_SZ,
1588 REG_DWORD,
1589 REG_BINARY
1591 DWORD value = 12345678;
1592 LPSTR str = "abcdefghijklmnopqrstuvwxzy";
1593 DWORD t, s;
1595 for (t=0; t < ARRAY_SIZE(types); t++) {
1596 for (s=0; s < strlen(str); s++) {
1598 DWORD type, type_ex;
1599 LPBYTE buffer, buffer_ex;
1600 DWORD size, size_ex;
1602 if (types[t] == REG_DWORD) {
1603 s = 0xffff;
1606 switch (types[t]) {
1607 case REG_BINARY:
1608 buffer = malloc(s);
1609 memcpy(buffer, str, s);
1610 size = s;
1611 break;
1612 case REG_DWORD:
1613 buffer = malloc(4);
1614 memcpy(buffer, &value, 4);
1615 size = 4;
1616 break;
1617 case REG_SZ:
1618 buffer = malloc(s);
1619 memcpy(buffer, str, s);
1620 size = s;
1621 break;
1622 default:
1623 sprintf(tmp, "type %d untested\n", types[t]);
1624 torture_fail(tctx, tmp);
1625 break;
1628 type = types[t];
1630 torture_comment(tctx, "Testing PrinterData (type: %s, size: 0x%08x)", reg_type_str(type), size);
1632 torture_assert(tctx,
1633 test_SetPrinterDataEx(tctx, printername, keyname, valuename, handle, type, buffer, size),
1634 "failed to call SetPrinterDataEx");
1635 torture_assert(tctx,
1636 test_GetPrinterDataEx(tctx, printername, keyname, valuename, handle, &type_ex, &buffer_ex, &size_ex),
1637 "failed to call GetPrinterDataEx");
1639 if (!PrinterDataEqual(tctx, type_ex, type, size_ex, size, buffer_ex, buffer)) {
1640 torture_warning(tctx, "GetPrinterDataEx does not return the same info as we set with SetPrinterDataEx");
1641 ret = FALSE;
1643 ret &= test_DeletePrinterDataEx(tctx, printername, keyname, valuename, handle);
1644 ret &= test_DeletePrinterKey(tctx, printername, keyname, handle);
1646 free(buffer);
1647 free(buffer_ex);
1651 return ret;
1654 /****************************************************************************
1655 ****************************************************************************/
1657 static BOOL test_PrinterDataW(struct torture_context *tctx,
1658 LPSTR printername,
1659 HANDLE handle)
1661 char tmp[1024];
1662 LPCWSTR keyname = L"torture_key";
1663 LPCWSTR valuename = L"torture_value";
1664 BOOL ret = TRUE;
1665 DWORD types[] = {
1666 REG_SZ,
1667 REG_DWORD,
1668 REG_BINARY
1670 DWORD value = 12345678;
1671 LPSTR str = "abcdefghijklmnopqrstuvwxzy";
1672 DWORD t, s;
1674 for (t=0; t < ARRAY_SIZE(types); t++) {
1675 for (s=0; s < strlen(str); s++) {
1677 DWORD type, type_ex;
1678 LPBYTE buffer, buffer_ex;
1679 DWORD size, size_ex;
1681 if (types[t] == REG_DWORD) {
1682 s = 0xffff;
1685 switch (types[t]) {
1686 case REG_BINARY:
1687 buffer = malloc(s);
1688 memcpy(buffer, str, s);
1689 size = s;
1690 break;
1691 case REG_DWORD:
1692 buffer = malloc(4);
1693 memcpy(buffer, &value, 4);
1694 size = 4;
1695 break;
1696 case REG_SZ:
1697 buffer = malloc(s);
1698 memcpy(buffer, str, s);
1699 size = s;
1700 break;
1701 default:
1702 sprintf(tmp, "type %d untested\n", types[t]);
1703 torture_fail(tctx, tmp);
1704 break;
1707 type = types[t];
1709 torture_comment(tctx, "Testing PrinterDataW (type: %s, size: 0x%08x)", reg_type_str(type), size);
1711 torture_assert(tctx,
1712 test_SetPrinterDataExW(tctx, printername, keyname, valuename, handle, type, buffer, size),
1713 "failed to call SetPrinterDataExW");
1714 torture_assert(tctx,
1715 test_GetPrinterDataExW(tctx, printername, keyname, valuename, handle, &type_ex, &buffer_ex, &size_ex),
1716 "failed to call GetPrinterDataExW");
1718 if (!PrinterDataEqual(tctx, type_ex, type, size_ex, size, buffer_ex, buffer)) {
1719 torture_warning(tctx, "GetPrinterDataExW does not return the same info as we set with SetPrinterDataExW");
1720 ret = FALSE;
1722 ret &= test_DeletePrinterDataExW(tctx, printername, keyname, valuename, handle);
1723 ret &= test_DeletePrinterKeyW(tctx, printername, keyname, handle);
1725 free(buffer);
1726 free(buffer_ex);
1730 return ret;
1733 /****************************************************************************
1734 ****************************************************************************/
1736 const char *get_string_param(const char *str)
1738 const char *p;
1740 p = strchr(str, '=');
1741 if (!p) {
1742 return NULL;
1745 return (p+1);
1748 /****************************************************************************
1749 ****************************************************************************/
1751 int main(int argc, char *argv[])
1753 BOOL ret = FALSE;
1754 LPSTR servername;
1755 LPSTR architecture = "Windows NT x86";
1756 HANDLE server_handle;
1757 PRINTER_DEFAULTS defaults_admin, defaults_use;
1758 struct torture_context *tctx;
1759 int i;
1761 if (argc < 2) {
1762 fprintf(stderr, "usage: %s <name> [print] [samba3] [architecture=ARCHITECTURE]\n\n", argv[0]);
1763 fprintf(stderr, "\t<name> can be a server or printer name URI\n");
1764 fprintf(stderr, "\t[print] will print all data that has been retrieved\n");
1765 fprintf(stderr, "\t from the printserver\n");
1766 fprintf(stderr, "\t[samba3] will skip some tests samba servers are known\n");
1767 fprintf(stderr, "\t not to have implemented\n");
1768 fprintf(stderr, "\t[architecture=X] allows one to define a specific\n");
1769 fprintf(stderr, "\t architecture to test with. choose between:\n");
1770 fprintf(stderr, "\t \"Windows NT x86\" or \"Windows x64\"\n");
1771 exit(-1);
1774 tctx = malloc(sizeof(struct torture_context));
1775 if (!tctx) {
1776 fprintf(stderr, "out of memory\n");
1777 exit(-1);
1779 memset(tctx, '\0', sizeof(*tctx));
1781 servername = argv[1];
1783 for (i=1; i < argc; i++) {
1784 if (strcmp(argv[i], "print") == 0) {
1785 tctx->print = TRUE;
1787 if (strcmp(argv[i], "samba3") == 0) {
1788 tctx->samba3 = TRUE;
1790 if (strncmp(argv[i], "architecture", strlen("architecture")) == 0) {
1791 architecture = get_string_param(argv[i]);
1795 printf("Running testsuite with architecture: %s\n", architecture);
1797 defaults_admin.pDatatype = NULL;
1798 defaults_admin.pDevMode = NULL;
1799 defaults_admin.DesiredAccess = PRINTER_ACCESS_ADMINISTER;
1801 defaults_use.pDatatype = NULL;
1802 defaults_use.pDevMode = NULL;
1803 defaults_use.DesiredAccess = PRINTER_ACCESS_USE;
1805 if ((servername[0] == '\\') && (servername[1] == '\\')) {
1806 LPSTR p = servername+2;
1807 LPSTR p2;
1808 if ((p2 = strchr(p, '\\')) != NULL) {
1809 ret = test_OnePrinter(tctx, servername, architecture, &defaults_admin);
1810 goto done;
1814 ret &= test_EnumPrinters(tctx, servername);
1815 ret &= test_EnumDrivers(tctx, servername, architecture);
1816 ret &= test_OpenPrinter(tctx, servername, NULL, &server_handle);
1817 /* ret &= test_EnumPrinterKey(tctx, servername, server_handle, ""); */
1818 ret &= test_PrinterData_Server(tctx, servername, server_handle);
1819 ret &= test_EnumForms(tctx, servername, server_handle);
1820 ret &= test_ClosePrinter(tctx, server_handle);
1821 ret &= test_EnumPorts(tctx, servername);
1822 ret &= test_EnumMonitors(tctx, servername);
1823 ret &= test_EnumPrintProcessors(tctx, servername, architecture);
1824 ret &= test_EnumPrintProcessorDatatypes(tctx, servername);
1825 ret &= test_GetPrintProcessorDirectory(tctx, servername, architecture);
1826 ret &= test_GetPrinterDriverDirectory(tctx, servername, architecture);
1827 ret &= test_EachPrinter(tctx, servername, architecture, &defaults_admin);
1829 done:
1830 if (!ret) {
1831 if (tctx->last_reason) {
1832 fprintf(stderr, "failed: %s\n", tctx->last_reason);
1834 free(tctx);
1835 return -1;
1838 printf("%s run successfully\n", argv[0]);
1840 free(tctx);
1841 return 0;