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
);
167 /****************************************************************************
168 ****************************************************************************/
170 static BOOL
test_GetForm(struct torture_context
*tctx
,
175 DWORD levels
[] = { 1, 2 };
176 DWORD success
[] = { 1, 0 };
178 LPBYTE buffer
= NULL
;
180 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
186 torture_comment(tctx
, "Testing GetForm(%s) level %d", formname
, levels
[i
]);
188 GetForm(handle
, formname
, levels
[i
], NULL
, 0, &needed
);
189 err
= GetLastError();
190 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
192 buffer
= malloc(needed
);
193 torture_assert(tctx
, buffer
, "malloc failed");
194 if (!GetForm(handle
, formname
, levels
[i
], buffer
, needed
, &needed
)) {
195 err
= GetLastError();
199 sprintf(tmp
, "GetForm failed level %d on [%s] (buffer size = %d), error: %s\n",
200 levels
[i
], servername
, needed
, errstr(err
));
202 torture_fail(tctx
, tmp
);
204 torture_warning(tctx
, tmp
);
215 /****************************************************************************
216 ****************************************************************************/
218 static BOOL
test_EnumForms(struct torture_context
*tctx
,
222 DWORD levels
[] = { 1, 2 };
223 DWORD success
[] = { 1, 0 };
225 LPBYTE buffer
= NULL
;
227 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
234 torture_comment(tctx
, "Testing EnumForms level %d", levels
[i
]);
236 EnumForms(handle
, levels
[i
], NULL
, 0, &needed
, &returned
);
237 err
= GetLastError();
238 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
240 buffer
= malloc(needed
);
241 torture_assert(tctx
, buffer
, "malloc failed");
242 if (!EnumForms(handle
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
243 err
= GetLastError();
247 sprintf(tmp
, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
248 levels
[i
], servername
, needed
, errstr(err
));
250 torture_fail(tctx
, tmp
);
252 torture_warning(tctx
, tmp
);
263 /****************************************************************************
264 ****************************************************************************/
266 static BOOL
test_EnumPorts(struct torture_context
*tctx
,
269 DWORD levels
[] = { 1, 2 };
270 DWORD success
[] = { 1, 1 };
272 LPBYTE buffer
= NULL
;
274 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
281 torture_comment(tctx
, "Testing EnumPorts level %d", levels
[i
]);
283 EnumPorts(servername
, levels
[i
], NULL
, 0, &needed
, &returned
);
284 err
= GetLastError();
285 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
287 buffer
= malloc(needed
);
288 torture_assert(tctx
, buffer
, "malloc failed");
289 if (!EnumPorts(servername
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
290 err
= GetLastError();
294 sprintf(tmp
, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
295 levels
[i
], servername
, needed
, errstr(err
));
297 torture_fail(tctx
, tmp
);
299 torture_warning(tctx
, tmp
);
310 /****************************************************************************
311 ****************************************************************************/
313 static BOOL
test_EnumMonitors(struct torture_context
*tctx
,
316 DWORD levels
[] = { 1, 2 };
317 DWORD success
[] = { 1, 1 };
319 LPBYTE buffer
= NULL
;
321 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
328 torture_comment(tctx
, "Testing EnumMonitors level %d", levels
[i
]);
330 EnumMonitors(servername
, levels
[i
], NULL
, 0, &needed
, &returned
);
331 err
= GetLastError();
332 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
334 buffer
= malloc(needed
);
335 torture_assert(tctx
, buffer
, "malloc failed");
336 if (!EnumMonitors(servername
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
337 err
= GetLastError();
341 sprintf(tmp
, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
342 levels
[i
], servername
, needed
, errstr(err
));
344 torture_fail(tctx
, tmp
);
346 torture_warning(tctx
, tmp
);
357 /****************************************************************************
358 ****************************************************************************/
360 static BOOL
test_EnumPrintProcessors(struct torture_context
*tctx
,
364 DWORD levels
[] = { 1 };
365 DWORD success
[] = { 1 };
367 LPBYTE buffer
= NULL
;
369 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
376 torture_comment(tctx
, "Testing EnumPrintProcessors level %d", levels
[i
]);
378 EnumPrintProcessors(servername
, architecture
, levels
[i
], NULL
, 0, &needed
, &returned
);
379 err
= GetLastError();
380 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
382 buffer
= malloc(needed
);
383 torture_assert(tctx
, buffer
, "malloc failed");
384 if (!EnumPrintProcessors(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
385 err
= GetLastError();
389 sprintf(tmp
, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
390 levels
[i
], servername
, needed
, errstr(err
));
392 torture_fail(tctx
, tmp
);
394 torture_warning(tctx
, tmp
);
405 /****************************************************************************
406 ****************************************************************************/
408 static BOOL
test_EnumPrintProcessorDatatypes(struct torture_context
*tctx
,
411 DWORD levels
[] = { 1 };
412 DWORD success
[] = { 1 };
414 LPBYTE buffer
= NULL
;
416 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
423 torture_comment(tctx
, "Testing EnumPrintProcessorDatatypes level %d", levels
[i
]);
425 EnumPrintProcessorDatatypes(servername
, "winprint", levels
[i
], NULL
, 0, &needed
, &returned
);
426 err
= GetLastError();
427 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
429 buffer
= malloc(needed
);
430 torture_assert(tctx
, buffer
, "malloc failed");
431 if (!EnumPrintProcessorDatatypes(servername
, "winprint", levels
[i
], buffer
, needed
, &needed
, &returned
)) {
432 err
= GetLastError();
436 sprintf(tmp
, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
437 levels
[i
], servername
, needed
, errstr(err
));
439 torture_fail(tctx
, tmp
);
441 torture_warning(tctx
, tmp
);
452 /****************************************************************************
453 ****************************************************************************/
455 static BOOL
test_EnumPrinterKey(struct torture_context
*tctx
,
465 torture_comment(tctx
, "Testing EnumPrinterKey(%s)", key
);
467 err
= EnumPrinterKey(handle
, key
, NULL
, 0, &needed
);
468 if (err
== ERROR_MORE_DATA
) {
469 buffer
= (LPTSTR
)malloc(needed
);
470 torture_assert(tctx
, buffer
, "malloc failed");
471 err
= EnumPrinterKey(handle
, key
, buffer
, needed
, &needed
);
474 sprintf(tmp
, "EnumPrinterKey(%s) failed on [%s] (buffer size = %d), error: %s\n",
475 key
, servername
, needed
, errstr(err
));
476 torture_fail(tctx
, tmp
);
480 print_printer_keys(buffer
);
488 /****************************************************************************
489 ****************************************************************************/
491 static BOOL
test_GetPrinter(struct torture_context
*tctx
,
495 DWORD levels
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
496 DWORD success
[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
498 LPBYTE buffer
= NULL
;
500 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
506 torture_comment(tctx
, "Testing GetPrinter level %d", levels
[i
]);
508 GetPrinter(handle
, levels
[i
], NULL
, 0, &needed
);
509 err
= GetLastError();
510 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
512 buffer
= malloc(needed
);
513 torture_assert(tctx
, buffer
, "malloc failed");
514 if (!GetPrinter(handle
, levels
[i
], buffer
, needed
, &needed
)) {
515 err
= GetLastError();
519 sprintf(tmp
, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
520 levels
[i
], printername
, needed
, errstr(err
));
522 torture_fail(tctx
, tmp
);
524 torture_warning(tctx
, tmp
);
535 /****************************************************************************
536 ****************************************************************************/
538 static BOOL
test_GetPrinterDriver(struct torture_context
*tctx
,
543 DWORD levels
[] = { 1, 2, 3, 4, 5, 6, 8 };
544 DWORD success
[] = { 1, 1, 1, 1, 1, 1, 1 };
546 LPBYTE buffer
= NULL
;
548 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
554 torture_comment(tctx
, "Testing GetPrinterDriver level %d", levels
[i
]);
556 GetPrinterDriver(handle
, architecture
, levels
[i
], NULL
, 0, &needed
);
557 err
= GetLastError();
558 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
560 buffer
= malloc(needed
);
561 torture_assert(tctx
, buffer
, "malloc failed");
562 if (!GetPrinterDriver(handle
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
563 err
= GetLastError();
567 sprintf(tmp
, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
568 levels
[i
], printername
, needed
, errstr(err
));
570 torture_fail(tctx
, tmp
);
572 torture_warning(tctx
, tmp
);
584 /****************************************************************************
585 ****************************************************************************/
587 static BOOL
test_EnumJobs(struct torture_context
*tctx
,
591 DWORD levels
[] = { 1, 2, 3, 4 };
592 DWORD success
[] = { 1, 1, 1, 1 };
594 LPBYTE buffer
= NULL
;
596 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
603 torture_comment(tctx
, "Testing EnumJobs level %d", levels
[i
]);
605 EnumJobs(handle
, 0, 100, levels
[i
], NULL
, 0, &needed
, &returned
);
606 err
= GetLastError();
607 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
609 buffer
= malloc(needed
);
610 torture_assert(tctx
, buffer
, "malloc failed");
611 if (!EnumJobs(handle
, 0, 100, levels
[i
], buffer
, needed
, &needed
, &returned
)) {
612 err
= GetLastError();
616 sprintf(tmp
, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
617 levels
[i
], printername
, needed
, errstr(err
));
619 torture_fail(tctx
, tmp
);
621 torture_warning(tctx
, tmp
);
632 /****************************************************************************
633 ****************************************************************************/
635 static BOOL
test_OnePrinter(struct torture_context
*tctx
,
638 LPPRINTER_DEFAULTS defaults
)
643 torture_comment(tctx
, "Testing Printer %s", printername
);
645 ret
&= test_OpenPrinter(tctx
, printername
, defaults
, &handle
);
646 ret
&= test_GetPrinter(tctx
, printername
, handle
);
647 ret
&= test_GetPrinterDriver(tctx
, printername
, architecture
, handle
);
648 ret
&= test_EnumForms(tctx
, printername
, handle
);
649 ret
&= test_EnumJobs(tctx
, printername
, handle
);
650 ret
&= test_EnumPrinterKey(tctx
, printername
, handle
, "");
651 ret
&= test_EnumPrinterKey(tctx
, printername
, handle
, "PrinterDriverData");
652 ret
&= test_ClosePrinter(tctx
, handle
);
657 /****************************************************************************
658 ****************************************************************************/
660 static BOOL
test_EachPrinter(struct torture_context
*tctx
,
663 LPPRINTER_DEFAULTS defaults
)
670 DWORD flags
= PRINTER_ENUM_NAME
;
671 PPRINTER_INFO_1 buffer
= NULL
;
674 torture_comment(tctx
, "Testing EnumPrinters level %d", 1);
676 EnumPrinters(flags
, servername
, 1, NULL
, 0, &needed
, &returned
);
677 err
= GetLastError();
678 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
680 buffer
= (PPRINTER_INFO_1
)malloc(needed
);
681 torture_assert(tctx
, buffer
, "malloc failed");
682 if (!EnumPrinters(flags
, servername
, 1, (LPBYTE
)buffer
, needed
, &needed
, &returned
)) {
683 err
= GetLastError();
687 sprintf(tmp
, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
688 1, servername
, needed
, errstr(err
));
689 torture_fail(tctx
, tmp
);
692 for (i
=0; i
< returned
; i
++) {
693 ret
&= test_OnePrinter(tctx
, buffer
[i
].pName
, architecture
, defaults
);
701 /****************************************************************************
702 ****************************************************************************/
704 static BOOL
test_GetPrintProcessorDirectory(struct torture_context
*tctx
,
708 DWORD levels
[] = { 1 };
709 DWORD success
[] = { 1 };
711 LPBYTE buffer
= NULL
;
713 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
719 torture_comment(tctx
, "Testing GetPrintProcessorDirectory level %d", levels
[i
]);
721 GetPrintProcessorDirectory(servername
, architecture
, levels
[i
], NULL
, 0, &needed
);
722 err
= GetLastError();
723 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
725 buffer
= malloc(needed
);
726 torture_assert(tctx
, buffer
, "malloc failed");
727 if (!GetPrintProcessorDirectory(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
728 err
= GetLastError();
732 sprintf(tmp
, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
733 levels
[i
], servername
, needed
, errstr(err
));
735 torture_fail(tctx
, tmp
);
737 torture_warning(tctx
, tmp
);
748 /****************************************************************************
749 ****************************************************************************/
751 static BOOL
test_GetPrinterDriverDirectory(struct torture_context
*tctx
,
755 DWORD levels
[] = { 1 };
756 DWORD success
[] = { 1 };
758 LPBYTE buffer
= NULL
;
760 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
766 torture_comment(tctx
, "Testing GetPrinterDriverDirectory level %d", levels
[i
]);
768 GetPrinterDriverDirectory(servername
, architecture
, levels
[i
], NULL
, 0, &needed
);
769 err
= GetLastError();
770 if (err
== ERROR_INSUFFICIENT_BUFFER
) {
772 buffer
= malloc(needed
);
773 torture_assert(tctx
, buffer
, "malloc failed");
774 if (!GetPrinterDriverDirectory(servername
, architecture
, levels
[i
], buffer
, needed
, &needed
)) {
775 err
= GetLastError();
779 sprintf(tmp
, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
780 levels
[i
], servername
, needed
, errstr(err
));
782 torture_fail(tctx
, tmp
);
784 torture_warning(tctx
, tmp
);
796 /****************************************************************************
797 ****************************************************************************/
799 int main(int argc
, char *argv
[])
803 LPSTR architecture
= "Windows NT x86";
804 HANDLE server_handle
;
805 PRINTER_DEFAULTS defaults_admin
, defaults_use
;
806 struct torture_context
*tctx
;
809 fprintf(stderr
, "usage: %s <servername> [print]\n", argv
[0]);
813 tctx
= malloc(sizeof(struct torture_context
));
815 fprintf(stderr
, "out of memory\n");
818 memset(tctx
, '\0', sizeof(*tctx
));
820 servername
= argv
[1];
823 if (strcmp(argv
[2], "print") == 0) {
828 defaults_admin
.pDatatype
= NULL
;
829 defaults_admin
.pDevMode
= NULL
;
830 defaults_admin
.DesiredAccess
= PRINTER_ACCESS_ADMINISTER
;
832 defaults_use
.pDatatype
= NULL
;
833 defaults_use
.pDevMode
= NULL
;
834 defaults_use
.DesiredAccess
= PRINTER_ACCESS_USE
;
836 ret
&= test_EnumPrinters(tctx
, servername
);
837 ret
&= test_EnumDrivers(tctx
, servername
, architecture
);
838 ret
&= test_OpenPrinter(tctx
, servername
, NULL
, &server_handle
);
839 /* ret &= test_EnumPrinterKey(tctx, servername, server_handle, ""); */
840 ret
&= test_EnumForms(tctx
, servername
, server_handle
);
841 ret
&= test_ClosePrinter(tctx
, server_handle
);
842 ret
&= test_EnumPorts(tctx
, servername
);
843 ret
&= test_EnumMonitors(tctx
, servername
);
844 ret
&= test_EnumPrintProcessors(tctx
, servername
, architecture
);
845 ret
&= test_EnumPrintProcessorDatatypes(tctx
, servername
);
846 ret
&= test_GetPrintProcessorDirectory(tctx
, servername
, architecture
);
847 ret
&= test_GetPrinterDriverDirectory(tctx
, servername
, architecture
);
848 ret
&= test_EachPrinter(tctx
, servername
, architecture
, NULL
);
851 if (tctx
->last_reason
) {
852 fprintf(stderr
, "failed: %s\n", tctx
->last_reason
);
858 printf("%s run successfully\n", argv
[0]);