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 ****************************************************************************/
28 /****************************************************************************
29 ****************************************************************************/
31 static BOOL
test_OpenPrinter(struct torture_context
*tctx
,
33 LPPRINTER_DEFAULTS defaults
,
36 torture_comment(tctx
, "Testing OpenPrinter(%s)", printername
);
38 if (!OpenPrinter(printername
, handle
, defaults
)) {
40 sprintf(tmp
, "failed to open printer %s, error was: 0x%08x\n",
41 printername
, GetLastError());
42 torture_fail(tctx
, tmp
);
48 /****************************************************************************
49 ****************************************************************************/
51 static BOOL
test_ClosePrinter(struct torture_context
*tctx
,
54 torture_comment(tctx
, "Testing ClosePrinter");
56 if (!ClosePrinter(handle
)) {
58 sprintf(tmp
, "failed to close printer, error was: %s\n",
59 errstr(GetLastError()));
60 torture_fail(tctx
, tmp
);
67 /****************************************************************************
68 ****************************************************************************/
70 static BOOL
test_EnumPrinters(struct torture_context
*tctx
,
73 DWORD levels
[] = { 1, 2, 5 };
74 DWORD success
[] = { 1, 1, 1 };
76 DWORD flags
= PRINTER_ENUM_NAME
;
79 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
86 torture_comment(tctx
, "Testing EnumPrinters level %d", levels
[i
]);
88 EnumPrinters(flags
, servername
, levels
[i
], NULL
, 0, &needed
, &returned
);
90 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
92 buffer
= malloc(needed
);
93 torture_assert(tctx
, buffer
, "malloc failed");
94 if (!EnumPrinters(flags
, servername
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
99 sprintf(tmp
, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
100 levels
[i
], servername
, needed
, errstr(err
));
102 torture_fail(tctx
, tmp
);
104 torture_warning(tctx
, tmp
);
109 print_printer_info_bylevel(levels
[i
], buffer
, returned
);
119 /****************************************************************************
120 ****************************************************************************/
122 static BOOL
test_EnumDrivers(struct torture_context
*tctx
,
126 DWORD levels
[] = { 1, 2, 3, 4, 5, 6 };
127 DWORD success
[] = { 1, 1, 1, 1, 1, 1 };
129 LPBYTE buffer
= NULL
;
131 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
138 torture_comment(tctx
, "Testing EnumPrinterDrivers level %d", levels
[i
]);
140 EnumPrinterDrivers(servername
, architecture
, levels
[i
], NULL
, 0, &needed
, &returned
);
141 err
= GetLastError();
142 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
144 buffer
= malloc(needed
);
145 torture_assert(tctx
, buffer
, "malloc failed");
146 if (!EnumPrinterDrivers(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
147 err
= GetLastError();
151 sprintf(tmp
, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
152 levels
[i
], servername
, needed
, errstr(err
));
154 torture_fail(tctx
, tmp
);
156 torture_warning(tctx
, tmp
);
161 print_driver_info_bylevel(levels
[i
], buffer
, returned
);
171 /****************************************************************************
172 ****************************************************************************/
174 static BOOL
test_GetForm(struct torture_context
*tctx
,
179 DWORD levels
[] = { 1, 2 };
180 DWORD success
[] = { 1, 0 };
182 LPBYTE buffer
= NULL
;
184 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
190 torture_comment(tctx
, "Testing GetForm(%s) level %d", formname
, levels
[i
]);
192 GetForm(handle
, formname
, levels
[i
], NULL
, 0, &needed
);
193 err
= GetLastError();
194 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
196 buffer
= malloc(needed
);
197 torture_assert(tctx
, buffer
, "malloc failed");
198 if (!GetForm(handle
, formname
, levels
[i
], buffer
, needed
, &needed
)) {
199 err
= GetLastError();
203 sprintf(tmp
, "GetForm failed level %d on [%s] (buffer size = %d), error: %s\n",
204 levels
[i
], servername
, needed
, errstr(err
));
206 torture_fail(tctx
, tmp
);
208 torture_warning(tctx
, tmp
);
213 print_form_info_bylevel(levels
[i
], buffer
, 1);
223 /****************************************************************************
224 ****************************************************************************/
226 static BOOL
test_EnumForms(struct torture_context
*tctx
,
230 DWORD levels
[] = { 1, 2 };
231 DWORD success
[] = { 1, 1 };
233 LPBYTE buffer
= NULL
;
235 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
242 torture_comment(tctx
, "Testing EnumForms level %d", levels
[i
]);
244 if (tctx
->samba3
&& levels
[i
] == 2) {
245 torture_comment(tctx
, "skipping level %d enum against samba\n", levels
[i
]);
249 EnumForms(handle
, levels
[i
], NULL
, 0, &needed
, &returned
);
250 err
= GetLastError();
251 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
253 buffer
= malloc(needed
);
254 torture_assert(tctx
, buffer
, "malloc failed");
255 if (!EnumForms(handle
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
256 err
= GetLastError();
260 sprintf(tmp
, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
261 levels
[i
], servername
, needed
, errstr(err
));
263 torture_fail(tctx
, tmp
);
265 torture_warning(tctx
, tmp
);
270 print_form_info_bylevel(levels
[i
], buffer
, returned
);
280 /****************************************************************************
281 ****************************************************************************/
283 static BOOL
test_EnumPorts(struct torture_context
*tctx
,
286 DWORD levels
[] = { 1, 2 };
287 DWORD success
[] = { 1, 1 };
289 LPBYTE buffer
= NULL
;
291 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
298 torture_comment(tctx
, "Testing EnumPorts level %d", levels
[i
]);
300 EnumPorts(servername
, levels
[i
], NULL
, 0, &needed
, &returned
);
301 err
= GetLastError();
302 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
304 buffer
= malloc(needed
);
305 torture_assert(tctx
, buffer
, "malloc failed");
306 if (!EnumPorts(servername
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
307 err
= GetLastError();
311 sprintf(tmp
, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
312 levels
[i
], servername
, needed
, errstr(err
));
314 torture_fail(tctx
, tmp
);
316 torture_warning(tctx
, tmp
);
321 print_port_info_bylevel(levels
[i
], buffer
, returned
);
331 /****************************************************************************
332 ****************************************************************************/
334 static BOOL
test_EnumMonitors(struct torture_context
*tctx
,
337 DWORD levels
[] = { 1, 2 };
338 DWORD success
[] = { 1, 1 };
340 LPBYTE buffer
= NULL
;
342 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
349 torture_comment(tctx
, "Testing EnumMonitors level %d", levels
[i
]);
351 EnumMonitors(servername
, levels
[i
], NULL
, 0, &needed
, &returned
);
352 err
= GetLastError();
353 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
355 buffer
= malloc(needed
);
356 torture_assert(tctx
, buffer
, "malloc failed");
357 if (!EnumMonitors(servername
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
358 err
= GetLastError();
362 sprintf(tmp
, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
363 levels
[i
], servername
, needed
, errstr(err
));
365 torture_fail(tctx
, tmp
);
367 torture_warning(tctx
, tmp
);
372 print_monitor_info_bylevel(levels
[i
], buffer
, returned
);
382 /****************************************************************************
383 ****************************************************************************/
385 static BOOL
test_EnumPrintProcessors(struct torture_context
*tctx
,
389 DWORD levels
[] = { 1 };
390 DWORD success
[] = { 1 };
392 LPBYTE buffer
= NULL
;
394 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
401 torture_comment(tctx
, "Testing EnumPrintProcessors level %d", levels
[i
]);
403 EnumPrintProcessors(servername
, architecture
, levels
[i
], NULL
, 0, &needed
, &returned
);
404 err
= GetLastError();
405 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
407 buffer
= malloc(needed
);
408 torture_assert(tctx
, buffer
, "malloc failed");
409 if (!EnumPrintProcessors(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
410 err
= GetLastError();
414 sprintf(tmp
, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
415 levels
[i
], servername
, needed
, errstr(err
));
417 torture_fail(tctx
, tmp
);
419 torture_warning(tctx
, tmp
);
424 print_printprocessor_info_bylevel(levels
[i
], buffer
, returned
);
434 /****************************************************************************
435 ****************************************************************************/
437 static BOOL
test_EnumPrintProcessorDatatypes(struct torture_context
*tctx
,
440 DWORD levels
[] = { 1 };
441 DWORD success
[] = { 1 };
443 LPBYTE buffer
= NULL
;
445 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
452 torture_comment(tctx
, "Testing EnumPrintProcessorDatatypes level %d", levels
[i
]);
454 EnumPrintProcessorDatatypes(servername
, "winprint", levels
[i
], NULL
, 0, &needed
, &returned
);
455 err
= GetLastError();
456 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
458 buffer
= malloc(needed
);
459 torture_assert(tctx
, buffer
, "malloc failed");
460 if (!EnumPrintProcessorDatatypes(servername
, "winprint", levels
[i
], buffer
, needed
, &needed
, &returned
)) {
461 err
= GetLastError();
465 sprintf(tmp
, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
466 levels
[i
], servername
, needed
, errstr(err
));
468 torture_fail(tctx
, tmp
);
470 torture_warning(tctx
, tmp
);
475 print_datatypes_info_bylevel(levels
[i
], buffer
, returned
);
485 /****************************************************************************
486 ****************************************************************************/
488 static BOOL
test_EnumPrinterKey(struct torture_context
*tctx
,
498 torture_comment(tctx
, "Testing EnumPrinterKey(%s)", key
);
500 err
= EnumPrinterKey(handle
, key
, NULL
, 0, &needed
);
501 if (err
== ERROR_MORE_DATA
) {
502 buffer
= (LPTSTR
)malloc(needed
);
503 torture_assert(tctx
, buffer
, "malloc failed");
504 err
= EnumPrinterKey(handle
, key
, buffer
, needed
, &needed
);
507 sprintf(tmp
, "EnumPrinterKey(%s) failed on [%s] (buffer size = %d), error: %s\n",
508 key
, servername
, needed
, errstr(err
));
509 torture_fail(tctx
, tmp
);
513 print_printer_keys(buffer
);
521 /****************************************************************************
522 ****************************************************************************/
524 static BOOL
test_GetPrinter(struct torture_context
*tctx
,
528 DWORD levels
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
529 DWORD success
[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
531 LPBYTE buffer
= NULL
;
533 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
539 torture_comment(tctx
, "Testing GetPrinter level %d", levels
[i
]);
541 GetPrinter(handle
, levels
[i
], NULL
, 0, &needed
);
542 err
= GetLastError();
543 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
545 buffer
= malloc(needed
);
546 torture_assert(tctx
, buffer
, "malloc failed");
547 if (!GetPrinter(handle
, levels
[i
], buffer
, needed
, &needed
)) {
548 err
= GetLastError();
552 sprintf(tmp
, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
553 levels
[i
], printername
, needed
, errstr(err
));
555 torture_fail(tctx
, tmp
);
557 torture_warning(tctx
, tmp
);
562 print_printer_info_bylevel(levels
[i
], buffer
, 1);
572 /****************************************************************************
573 ****************************************************************************/
575 static BOOL
test_GetPrinterDriver(struct torture_context
*tctx
,
580 DWORD levels
[] = { 1, 2, 3, 4, 5, 6, 8 };
581 DWORD success
[] = { 1, 1, 1, 1, 1, 1, 1 };
583 LPBYTE buffer
= NULL
;
585 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
591 torture_comment(tctx
, "Testing GetPrinterDriver level %d", levels
[i
]);
593 GetPrinterDriver(handle
, architecture
, levels
[i
], NULL
, 0, &needed
);
594 err
= GetLastError();
595 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
597 buffer
= malloc(needed
);
598 torture_assert(tctx
, buffer
, "malloc failed");
599 if (!GetPrinterDriver(handle
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
600 err
= GetLastError();
604 sprintf(tmp
, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
605 levels
[i
], printername
, needed
, errstr(err
));
607 torture_fail(tctx
, tmp
);
609 torture_warning(tctx
, tmp
);
614 print_driver_info_bylevel(levels
[i
], buffer
, 1);
625 /****************************************************************************
626 ****************************************************************************/
628 static BOOL
test_EnumJobs(struct torture_context
*tctx
,
632 DWORD levels
[] = { 1, 2, 3, 4 };
633 DWORD success
[] = { 1, 1, 1, 1 };
635 LPBYTE buffer
= NULL
;
637 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
644 torture_comment(tctx
, "Testing EnumJobs level %d", levels
[i
]);
646 if (tctx
->samba3
&& levels
[i
] == 4) {
647 torture_comment(tctx
, "skipping level %d enum against samba\n", levels
[i
]);
651 EnumJobs(handle
, 0, 100, levels
[i
], NULL
, 0, &needed
, &returned
);
652 err
= GetLastError();
653 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
655 buffer
= malloc(needed
);
656 torture_assert(tctx
, buffer
, "malloc failed");
657 if (!EnumJobs(handle
, 0, 100, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
658 err
= GetLastError();
662 sprintf(tmp
, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
663 levels
[i
], printername
, needed
, errstr(err
));
665 torture_fail(tctx
, tmp
);
667 torture_warning(tctx
, tmp
);
672 print_job_info_bylevel(levels
[i
], buffer
, returned
);
682 /****************************************************************************
683 ****************************************************************************/
685 static BOOL
test_EnumPrinterDataEx(struct torture_context
*tctx
,
692 LPBYTE buffer
= NULL
;
698 torture_comment(tctx
, "Testing EnumPrinterDataEx(%s)", keyname
);
700 err
= EnumPrinterDataEx(handle
, keyname
, NULL
, 0, &needed
, &returned
);
701 if (err
== ERROR_MORE_DATA
) {
702 buffer
= malloc(needed
);
703 torture_assert(tctx
, buffer
, "malloc failed");
704 err
= EnumPrinterDataEx(handle
, keyname
, buffer
, needed
, &needed
, &returned
);
707 sprintf(tmp
, "EnumPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n",
708 keyname
, servername
, needed
, errstr(err
));
709 torture_fail(tctx
, tmp
);
714 LPPRINTER_ENUM_VALUES v
= (LPPRINTER_ENUM_VALUES
)buffer
;
715 for (i
=0; i
< returned
; i
++) {
716 print_printer_enum_values(&v
[i
]);
721 *returned_p
= returned
;
733 /****************************************************************************
734 ****************************************************************************/
736 static BOOL
test_devicemode_equal(struct torture_context
*tctx
,
745 torture_comment(tctx
, "%s\n", __location__
);
749 torture_assert_str_equal(tctx
, (const char *)d1
->dmDeviceName
, (const char *)d2
->dmDeviceName
, "dmDeviceName mismatch");
750 torture_assert_int_equal(tctx
, d1
->dmSpecVersion
, d2
->dmSpecVersion
, "dmSpecVersion mismatch");
751 torture_assert_int_equal(tctx
, d1
->dmDriverVersion
, d2
->dmDriverVersion
, "dmDriverVersion mismatch");
752 torture_assert_int_equal(tctx
, d1
->dmSize
, d2
->dmSize
, "size mismatch");
753 torture_assert_int_equal(tctx
, d1
->dmDriverExtra
, d2
->dmDriverExtra
, "dmDriverExtra mismatch");
754 torture_assert_int_equal(tctx
, d1
->dmFields
, d2
->dmFields
, "dmFields mismatch");
756 torture_assert_int_equal(tctx
, d1
->dmOrientation
, d2
->dmOrientation
, "dmOrientation mismatch");
757 torture_assert_int_equal(tctx
, d1
->dmPaperSize
, d2
->dmPaperSize
, "dmPaperSize mismatch");
758 torture_assert_int_equal(tctx
, d1
->dmPaperLength
, d2
->dmPaperLength
, "dmPaperLength mismatch");
759 torture_assert_int_equal(tctx
, d1
->dmPaperWidth
, d2
->dmPaperWidth
, "dmPaperWidth mismatch");
760 torture_assert_int_equal(tctx
, d1
->dmScale
, d2
->dmScale
, "dmScale mismatch");
761 torture_assert_int_equal(tctx
, d1
->dmCopies
, d2
->dmCopies
, "dmCopies mismatch");
762 torture_assert_int_equal(tctx
, d1
->dmDefaultSource
, d2
->dmDefaultSource
, "dmDefaultSource mismatch");
763 torture_assert_int_equal(tctx
, d1
->dmPrintQuality
, d2
->dmPrintQuality
, "dmPrintQuality mismatch");
765 torture_assert_int_equal(tctx
, d1
->dmColor
, d2
->dmColor
, "dmColor mismatch");
766 torture_assert_int_equal(tctx
, d1
->dmDuplex
, d2
->dmDuplex
, "dmDuplex mismatch");
767 torture_assert_int_equal(tctx
, d1
->dmYResolution
, d2
->dmYResolution
, "dmYResolution mismatch");
768 torture_assert_int_equal(tctx
, d1
->dmTTOption
, d2
->dmTTOption
, "dmTTOption mismatch");
769 torture_assert_int_equal(tctx
, d1
->dmCollate
, d2
->dmCollate
, "dmCollate mismatch");
770 torture_assert_str_equal(tctx
, (const char *)d1
->dmFormName
, (const char *)d2
->dmFormName
, "dmFormName mismatch");
771 torture_assert_int_equal(tctx
, d1
->dmLogPixels
, d2
->dmLogPixels
, "dmLogPixels mismatch");
772 torture_assert_int_equal(tctx
, d1
->dmBitsPerPel
, d2
->dmBitsPerPel
, "dmBitsPerPel mismatch");
773 torture_assert_int_equal(tctx
, d1
->dmPelsWidth
, d2
->dmPelsWidth
, "dmPelsWidth mismatch");
774 torture_assert_int_equal(tctx
, d1
->dmPelsHeight
, d2
->dmPelsHeight
, "dmPelsHeight mismatch");
776 torture_assert_int_equal(tctx
, d1
->dmDisplayFlags
, d2
->dmDisplayFlags
, "dmDisplayFlags mismatch");
778 torture_assert_int_equal(tctx
, d1
->dmDisplayFrequency
, d2
->dmDisplayFrequency
, "dmDisplayFrequency mismatch");
780 torture_assert_int_equal(tctx
, d1
->dmICMMethod
, d2
->dmICMMethod
, "dmICMMethod mismatch");
781 torture_assert_int_equal(tctx
, d1
->dmICMIntent
, d2
->dmICMIntent
, "dmICMIntent mismatch");
782 torture_assert_int_equal(tctx
, d1
->dmMediaType
, d2
->dmMediaType
, "dmMediaType mismatch");
783 torture_assert_int_equal(tctx
, d1
->dmDitherType
, d2
->dmDitherType
, "dmDitherType mismatch");
784 torture_assert_int_equal(tctx
, d1
->dmReserved1
, d2
->dmReserved1
, "dmReserved1 mismatch");
785 torture_assert_int_equal(tctx
, d1
->dmReserved2
, d2
->dmReserved2
, "reserved2 mismatch");
787 torture_assert_int_equal(tctx
, d1
->dmPanningWidth
, d2
->dmPanningWidth
, "dmPanningWidth mismatch");
788 torture_assert_int_equal(tctx
, d1
->dmPanningHeight
, d2
->dmPanningHeight
, "dmPanningHeight mismatch");
790 /* torture_assert_mem_equal(tctx, d1 + d1->dmSize, d2 + d2->dmSize, d1->dmDriverExtra, "private extra data mismatch"); */
795 static BOOL
test_DeviceModes(struct torture_context
*tctx
,
799 PPRINTER_INFO_2 info2
= NULL
;
800 PPRINTER_INFO_8 info8
= NULL
;
805 torture_comment(tctx
, "Testing DeviceModes");
807 torture_comment(tctx
, "Testing GetPrinter level %d", 2);
809 GetPrinter(handle
, 2, NULL
, 0, &needed
);
810 err
= GetLastError();
811 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
813 info2
= (PPRINTER_INFO_2
)malloc(needed
);
814 torture_assert(tctx
, (LPBYTE
)info2
, "malloc failed");
815 if (!GetPrinter(handle
, 2, (LPBYTE
)info2
, needed
, &needed
)) {
816 err
= GetLastError();
820 sprintf(tmp
, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
821 2, printername
, needed
, errstr(err
));
822 torture_fail(tctx
, tmp
);
826 print_printer_info_2(info2
);
829 torture_comment(tctx
, "Testing GetPrinter level %d", 8);
831 GetPrinter(handle
, 8, NULL
, 0, &needed
);
832 err
= GetLastError();
833 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
835 info8
= (PPRINTER_INFO_8
)malloc(needed
);
836 torture_assert(tctx
, (LPBYTE
)info8
, "malloc failed");
837 if (!GetPrinter(handle
, 8, (LPBYTE
)info8
, needed
, &needed
)) {
838 err
= GetLastError();
842 sprintf(tmp
, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
843 8, printername
, needed
, errstr(err
));
844 torture_fail(tctx
, tmp
);
848 print_printer_info_8(info8
);
851 torture_assert(tctx
, test_devicemode_equal(tctx
, info2
->pDevMode
, info8
->pDevMode
), "");
859 /****************************************************************************
860 ****************************************************************************/
862 static BOOL
test_GetJob(struct torture_context
*tctx
,
867 DWORD levels
[] = { 1, 2, 3, 4 };
868 DWORD success
[] = { 1, 1, 1, 1 };
870 LPBYTE buffer
= NULL
;
872 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
878 torture_comment(tctx
, "Testing GetJob(%d) level %d", job_id
, levels
[i
]);
880 if (tctx
->samba3
&& (levels
[i
] == 4) || (levels
[i
] == 3)) {
881 torture_comment(tctx
, "skipping level %d getjob against samba\n", levels
[i
]);
885 GetJob(handle
, job_id
, levels
[i
], NULL
, 0, &needed
);
886 err
= GetLastError();
887 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
889 buffer
= malloc(needed
);
890 torture_assert(tctx
, buffer
, "malloc failed");
891 if (!GetJob(handle
, job_id
, levels
[i
], buffer
, needed
, &needed
)) {
892 err
= GetLastError();
896 sprintf(tmp
, "GetJob failed level %d on [%s] (buffer size = %d), error: %s\n",
897 levels
[i
], printername
, needed
, errstr(err
));
899 torture_fail(tctx
, tmp
);
901 torture_warning(tctx
, tmp
);
906 print_job_info_bylevel(levels
[i
], buffer
, 1);
916 /****************************************************************************
917 ****************************************************************************/
919 static BOOL
test_EachJob(struct torture_context
*tctx
,
924 PJOB_INFO_1 buffer
= NULL
;
932 torture_comment(tctx
, "Testing Each PrintJob %d");
934 EnumJobs(handle
, 0, 100, level
, NULL
, 0, &needed
, &returned
);
935 err
= GetLastError();
936 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
938 buffer
= (PJOB_INFO_1
)malloc(needed
);
939 torture_assert(tctx
, buffer
, "malloc failed");
940 if (!EnumJobs(handle
, 0, 100, level
, (LPBYTE
)buffer
, needed
, &needed
, &returned
)) {
941 err
= GetLastError();
945 sprintf(tmp
, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
946 level
, printername
, needed
, errstr(err
));
947 torture_fail(tctx
, tmp
);
951 print_job_info_bylevel(level
, (LPBYTE
)buffer
, returned
);
954 for (i
=0; i
< returned
; i
++) {
955 ret
= test_GetJob(tctx
, printername
, handle
, buffer
[i
].JobId
);
964 /****************************************************************************
965 ****************************************************************************/
967 static BOOL
test_OnePrinter(struct torture_context
*tctx
,
970 LPPRINTER_DEFAULTS defaults
)
975 torture_comment(tctx
, "Testing Printer %s", printername
);
977 ret
&= test_OpenPrinter(tctx
, printername
, defaults
, &handle
);
978 ret
&= test_GetPrinter(tctx
, printername
, handle
);
979 ret
&= test_GetPrinterDriver(tctx
, printername
, architecture
, handle
);
980 ret
&= test_EnumForms(tctx
, printername
, handle
);
981 ret
&= test_EnumJobs(tctx
, printername
, handle
);
982 ret
&= test_EachJob(tctx
, printername
, handle
);
983 ret
&= test_EnumPrinterKey(tctx
, printername
, handle
, "");
984 ret
&= test_EnumPrinterKey(tctx
, printername
, handle
, "PrinterDriverData");
985 ret
&= test_EnumPrinterDataEx(tctx
, printername
, "PrinterDriverData", handle
, NULL
, NULL
);
986 ret
&= test_DeviceModes(tctx
, printername
, handle
);
987 ret
&= test_ClosePrinter(tctx
, handle
);
992 /****************************************************************************
993 ****************************************************************************/
995 static BOOL
test_EachPrinter(struct torture_context
*tctx
,
998 LPPRINTER_DEFAULTS defaults
)
1005 DWORD flags
= PRINTER_ENUM_NAME
;
1006 PPRINTER_INFO_1 buffer
= NULL
;
1009 torture_comment(tctx
, "Testing EnumPrinters level %d", 1);
1011 EnumPrinters(flags
, servername
, 1, NULL
, 0, &needed
, &returned
);
1012 err
= GetLastError();
1013 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
1015 buffer
= (PPRINTER_INFO_1
)malloc(needed
);
1016 torture_assert(tctx
, buffer
, "malloc failed");
1017 if (!EnumPrinters(flags
, servername
, 1, (LPBYTE
)buffer
, needed
, &needed
, &returned
)) {
1018 err
= GetLastError();
1022 sprintf(tmp
, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
1023 1, servername
, needed
, errstr(err
));
1024 torture_fail(tctx
, tmp
);
1027 for (i
=0; i
< returned
; i
++) {
1028 ret
&= test_OnePrinter(tctx
, buffer
[i
].pName
, architecture
, defaults
);
1036 /****************************************************************************
1037 ****************************************************************************/
1039 static BOOL
test_GetPrintProcessorDirectory(struct torture_context
*tctx
,
1043 DWORD levels
[] = { 1 };
1044 DWORD success
[] = { 1 };
1046 LPBYTE buffer
= NULL
;
1048 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
1054 torture_comment(tctx
, "Testing GetPrintProcessorDirectory level %d", levels
[i
]);
1056 GetPrintProcessorDirectory(servername
, architecture
, levels
[i
], NULL
, 0, &needed
);
1057 err
= GetLastError();
1058 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
1060 buffer
= malloc(needed
);
1061 torture_assert(tctx
, buffer
, "malloc failed");
1062 if (!GetPrintProcessorDirectory(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
1063 err
= GetLastError();
1067 sprintf(tmp
, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
1068 levels
[i
], servername
, needed
, errstr(err
));
1070 torture_fail(tctx
, tmp
);
1072 torture_warning(tctx
, tmp
);
1077 printf("\tPrint Processor Directory\t= %s\n\n", (LPSTR
)buffer
);
1087 /****************************************************************************
1088 ****************************************************************************/
1090 static BOOL
test_GetPrinterDriverDirectory(struct torture_context
*tctx
,
1094 DWORD levels
[] = { 1 };
1095 DWORD success
[] = { 1 };
1097 LPBYTE buffer
= NULL
;
1099 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
1105 torture_comment(tctx
, "Testing GetPrinterDriverDirectory level %d", levels
[i
]);
1107 GetPrinterDriverDirectory(servername
, architecture
, levels
[i
], NULL
, 0, &needed
);
1108 err
= GetLastError();
1109 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
1111 buffer
= malloc(needed
);
1112 torture_assert(tctx
, buffer
, "malloc failed");
1113 if (!GetPrinterDriverDirectory(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
1114 err
= GetLastError();
1118 sprintf(tmp
, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
1119 levels
[i
], servername
, needed
, errstr(err
));
1121 torture_fail(tctx
, tmp
);
1123 torture_warning(tctx
, tmp
);
1128 printf("\tPrinter Driver Directory\t= %s\n\n", (LPSTR
)buffer
);
1138 /****************************************************************************
1139 ****************************************************************************/
1141 static BOOL
test_GetPrinterData(struct torture_context
*tctx
,
1149 LPBYTE buffer
= NULL
;
1155 torture_comment(tctx
, "Testing GetPrinterData(%s)", valuename
);
1157 err
= GetPrinterData(handle
, valuename
, &type
, NULL
, 0, &needed
);
1158 if (err
== ERROR_MORE_DATA
) {
1159 buffer
= (LPBYTE
)malloc(needed
);
1160 torture_assert(tctx
, buffer
, "malloc failed");
1161 err
= GetPrinterData(handle
, valuename
, &type
, buffer
, needed
, &needed
);
1164 sprintf(tmp
, "GetPrinterData(%s) failed on [%s] (buffer size = %d), error: %s\n",
1165 valuename
, servername
, needed
, errstr(err
));
1166 torture_fail(tctx
, tmp
);
1170 print_printer_data("PrinterDriverData", valuename
, needed
, buffer
, type
);
1190 /****************************************************************************
1191 ****************************************************************************/
1193 static BOOL
test_GetPrinterDataEx(struct torture_context
*tctx
,
1202 LPBYTE buffer
= NULL
;
1208 torture_comment(tctx
, "Testing GetPrinterDataEx(%s - %s)", keyname
, valuename
);
1210 err
= GetPrinterDataEx(handle
, keyname
, valuename
, &type
, NULL
, 0, &needed
);
1211 if (err
== ERROR_MORE_DATA
) {
1212 buffer
= (LPBYTE
)malloc(needed
);
1213 torture_assert(tctx
, buffer
, "malloc failed");
1214 err
= GetPrinterDataEx(handle
, keyname
, valuename
, &type
, buffer
, needed
, &needed
);
1217 sprintf(tmp
, "GetPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n",
1218 valuename
, servername
, needed
, errstr(err
));
1219 torture_fail(tctx
, tmp
);
1223 print_printer_data(keyname
, valuename
, needed
, buffer
, type
);
1243 /****************************************************************************
1244 ****************************************************************************/
1246 static BOOL
test_DeletePrinterDataEx(struct torture_context
*tctx
,
1255 torture_comment(tctx
, "Testing DeletePrinterDataEx(%s - %s)", keyname
, valuename
);
1257 err
= DeletePrinterDataEx(handle
, keyname
, valuename
);
1259 sprintf(tmp
, "DeletePrinterDataEx(%s - %s) failed on [%s], error: %s\n",
1260 keyname
, valuename
, servername
, errstr(err
));
1261 torture_fail(tctx
, tmp
);
1267 /****************************************************************************
1268 ****************************************************************************/
1270 static BOOL
test_DeletePrinterKey(struct torture_context
*tctx
,
1278 torture_comment(tctx
, "Testing DeletePrinterKey(%s)", keyname
);
1280 err
= DeletePrinterKey(handle
, keyname
);
1282 sprintf(tmp
, "DeletePrinterKey(%s) failed on [%s], error: %s\n",
1283 keyname
, servername
, errstr(err
));
1284 torture_fail(tctx
, tmp
);
1290 /****************************************************************************
1291 ****************************************************************************/
1293 static BOOL
test_PrinterData(struct torture_context
*tctx
,
1299 DWORD type
, type_ex
;
1300 LPBYTE buffer
, buffer_ex
;
1301 DWORD size
, size_ex
;
1302 LPSTR valuenames
[] = {
1303 SPLREG_DEFAULT_SPOOL_DIRECTORY
,
1304 SPLREG_MAJOR_VERSION
,
1305 SPLREG_MINOR_VERSION
,
1307 SPLREG_DNS_MACHINE_NAME
,
1308 SPLREG_ARCHITECTURE
,
1312 for (i
=0; i
< ARRAY_SIZE(valuenames
); i
++) {
1313 ret
&= test_GetPrinterData(tctx
, servername
, valuenames
[i
], handle
, &type
, &buffer
, &size
);
1314 ret
&= test_GetPrinterDataEx(tctx
, servername
, "random", valuenames
[i
], handle
, &type_ex
, &buffer_ex
, &size_ex
);
1315 torture_assert_int_equal(tctx
, type
, type_ex
, "type mismatch");
1316 torture_assert_int_equal(tctx
, size
, size_ex
, "size mismatch");
1317 torture_assert_mem_equal(tctx
, buffer
, buffer_ex
, size
, "buffer mismatch");
1325 /****************************************************************************
1326 ****************************************************************************/
1328 const char *get_string_param(const char *str
)
1332 p
= strchr(str
, '=');
1340 /****************************************************************************
1341 ****************************************************************************/
1343 int main(int argc
, char *argv
[])
1347 LPSTR architecture
= "Windows NT x86";
1348 HANDLE server_handle
;
1349 PRINTER_DEFAULTS defaults_admin
, defaults_use
;
1350 struct torture_context
*tctx
;
1354 fprintf(stderr
, "usage: %s <servername> [print] [samba3] [architecture=ARCHITECTURE]\n", argv
[0]);
1358 tctx
= malloc(sizeof(struct torture_context
));
1360 fprintf(stderr
, "out of memory\n");
1363 memset(tctx
, '\0', sizeof(*tctx
));
1365 servername
= argv
[1];
1367 for (i
=1; i
< argc
; i
++) {
1368 if (strcmp(argv
[i
], "print") == 0) {
1371 if (strcmp(argv
[i
], "samba3") == 0) {
1372 tctx
->samba3
= TRUE
;
1374 if (strncmp(argv
[i
], "architecture", strlen("architecture")) == 0) {
1375 architecture
= get_string_param(argv
[i
]);
1379 printf("Running testsuite with architecture: %s\n", architecture
);
1381 defaults_admin
.pDatatype
= NULL
;
1382 defaults_admin
.pDevMode
= NULL
;
1383 defaults_admin
.DesiredAccess
= PRINTER_ACCESS_ADMINISTER
;
1385 defaults_use
.pDatatype
= NULL
;
1386 defaults_use
.pDevMode
= NULL
;
1387 defaults_use
.DesiredAccess
= PRINTER_ACCESS_USE
;
1389 if ((servername
[0] == '\\') && (servername
[1] == '\\')) {
1390 LPSTR p
= servername
+2;
1392 if ((p2
= strchr(p
, '\\')) != NULL
) {
1393 ret
= test_OnePrinter(tctx
, servername
, architecture
, NULL
);
1398 ret
&= test_EnumPrinters(tctx
, servername
);
1399 ret
&= test_EnumDrivers(tctx
, servername
, architecture
);
1400 ret
&= test_OpenPrinter(tctx
, servername
, NULL
, &server_handle
);
1401 /* ret &= test_EnumPrinterKey(tctx, servername, server_handle, ""); */
1402 ret
&= test_PrinterData(tctx
, servername
, server_handle
);
1403 ret
&= test_EnumForms(tctx
, servername
, server_handle
);
1404 ret
&= test_ClosePrinter(tctx
, server_handle
);
1405 ret
&= test_EnumPorts(tctx
, servername
);
1406 ret
&= test_EnumMonitors(tctx
, servername
);
1407 ret
&= test_EnumPrintProcessors(tctx
, servername
, architecture
);
1408 ret
&= test_EnumPrintProcessorDatatypes(tctx
, servername
);
1409 ret
&= test_GetPrintProcessorDirectory(tctx
, servername
, architecture
);
1410 ret
&= test_GetPrinterDriverDirectory(tctx
, servername
, architecture
);
1411 ret
&= test_EachPrinter(tctx
, servername
, architecture
, NULL
);
1415 if (tctx
->last_reason
) {
1416 fprintf(stderr
, "failed: %s\n", tctx
->last_reason
);
1422 printf("%s run successfully\n", argv
[0]);