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,
35 torture_comment(tctx, "Testing OpenPrinter(%s)", printername);
37 if (!OpenPrinter(printername, handle, NULL)) {
39 sprintf(tmp, "failed to open printer %s, error was: 0x%08x\n",
40 printername, GetLastError());
41 torture_fail(tctx, tmp);
47 /****************************************************************************
48 ****************************************************************************/
50 static BOOL test_ClosePrinter(struct torture_context *tctx,
53 torture_comment(tctx, "Testing ClosePrinter");
55 if (!ClosePrinter(handle)) {
57 sprintf(tmp, "failed to close printer, error was: %s\n",
58 errstr(GetLastError()));
59 torture_fail(tctx, tmp);
66 /****************************************************************************
67 ****************************************************************************/
69 static BOOL test_EnumPrinters(struct torture_context *tctx,
72 DWORD levels[] = { 1, 2, 5 };
73 DWORD success[] = { 1, 1, 1 };
75 DWORD flags = PRINTER_ENUM_NAME;
78 for (i=0; i < ARRAY_SIZE(levels); i++) {
85 torture_comment(tctx, "Testing EnumPrinters level %d", levels[i]);
87 EnumPrinters(flags, servername, levels[i], NULL, 0, &needed, &returned);
89 if (err == ERROR_INSUFFICIENT_BUFFER) {
91 buffer = malloc(needed);
92 torture_assert(tctx, buffer, "malloc failed");
93 if (!EnumPrinters(flags, servername, levels[i], buffer, needed, &needed, &returned)) {
98 sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
99 levels[i], servername, needed, errstr(err));
101 torture_fail(tctx, tmp);
103 torture_warning(tctx, tmp);
108 print_printer_info_bylevel(levels[i], buffer, returned);
118 /****************************************************************************
119 ****************************************************************************/
121 static BOOL test_EnumDrivers(struct torture_context *tctx,
125 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 8 };
126 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1 };
128 LPBYTE buffer = NULL;
130 for (i=0; i < ARRAY_SIZE(levels); i++) {
137 torture_comment(tctx, "Testing EnumPrinterDrivers level %d", levels[i]);
139 EnumPrinterDrivers(servername, architecture, levels[i], NULL, 0, &needed, &returned);
140 err = GetLastError();
141 if (err == ERROR_INSUFFICIENT_BUFFER) {
143 buffer = malloc(needed);
144 torture_assert(tctx, buffer, "malloc failed");
145 if (!EnumPrinterDrivers(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
146 err = GetLastError();
150 sprintf(tmp, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
151 levels[i], servername, needed, errstr(err));
153 torture_fail(tctx, tmp);
155 torture_warning(tctx, tmp);
166 /****************************************************************************
167 ****************************************************************************/
169 static BOOL test_EnumForms(struct torture_context *tctx,
173 DWORD levels[] = { 1, 2 };
174 DWORD success[] = { 1, 0 };
176 LPBYTE buffer = NULL;
178 for (i=0; i < ARRAY_SIZE(levels); i++) {
185 torture_comment(tctx, "Testing EnumForms level %d", levels[i]);
187 EnumForms(handle, levels[i], NULL, 0, &needed, &returned);
188 err = GetLastError();
189 if (err == ERROR_INSUFFICIENT_BUFFER) {
191 buffer = malloc(needed);
192 torture_assert(tctx, buffer, "malloc failed");
193 if (!EnumForms(handle, levels[i], buffer, needed, &needed, &returned)) {
194 err = GetLastError();
198 sprintf(tmp, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
199 levels[i], servername, needed, errstr(err));
201 torture_fail(tctx, tmp);
203 torture_warning(tctx, tmp);
214 /****************************************************************************
215 ****************************************************************************/
217 static BOOL test_EnumPorts(struct torture_context *tctx,
220 DWORD levels[] = { 1, 2 };
221 DWORD success[] = { 1, 1 };
223 LPBYTE buffer = NULL;
225 for (i=0; i < ARRAY_SIZE(levels); i++) {
232 torture_comment(tctx, "Testing EnumPorts level %d", levels[i]);
234 EnumPorts(servername, levels[i], NULL, 0, &needed, &returned);
235 err = GetLastError();
236 if (err == ERROR_INSUFFICIENT_BUFFER) {
238 buffer = malloc(needed);
239 torture_assert(tctx, buffer, "malloc failed");
240 if (!EnumPorts(servername, levels[i], buffer, needed, &needed, &returned)) {
241 err = GetLastError();
245 sprintf(tmp, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
246 levels[i], servername, needed, errstr(err));
248 torture_fail(tctx, tmp);
250 torture_warning(tctx, tmp);
261 /****************************************************************************
262 ****************************************************************************/
264 static BOOL test_EnumMonitors(struct torture_context *tctx,
267 DWORD levels[] = { 1, 2 };
268 DWORD success[] = { 1, 1 };
270 LPBYTE buffer = NULL;
272 for (i=0; i < ARRAY_SIZE(levels); i++) {
279 torture_comment(tctx, "Testing EnumMonitors level %d", levels[i]);
281 EnumMonitors(servername, levels[i], NULL, 0, &needed, &returned);
282 err = GetLastError();
283 if (err == ERROR_INSUFFICIENT_BUFFER) {
285 buffer = malloc(needed);
286 torture_assert(tctx, buffer, "malloc failed");
287 if (!EnumMonitors(servername, levels[i], buffer, needed, &needed, &returned)) {
288 err = GetLastError();
292 sprintf(tmp, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
293 levels[i], servername, needed, errstr(err));
295 torture_fail(tctx, tmp);
297 torture_warning(tctx, tmp);
308 /****************************************************************************
309 ****************************************************************************/
311 static BOOL test_EnumPrintProcessors(struct torture_context *tctx,
315 DWORD levels[] = { 1 };
316 DWORD success[] = { 1 };
318 LPBYTE buffer = NULL;
320 for (i=0; i < ARRAY_SIZE(levels); i++) {
327 torture_comment(tctx, "Testing EnumPrintProcessors level %d", levels[i]);
329 EnumPrintProcessors(servername, architecture, levels[i], NULL, 0, &needed, &returned);
330 err = GetLastError();
331 if (err == ERROR_INSUFFICIENT_BUFFER) {
333 buffer = malloc(needed);
334 torture_assert(tctx, buffer, "malloc failed");
335 if (!EnumPrintProcessors(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
336 err = GetLastError();
340 sprintf(tmp, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
341 levels[i], servername, needed, errstr(err));
343 torture_fail(tctx, tmp);
345 torture_warning(tctx, tmp);
356 /****************************************************************************
357 ****************************************************************************/
359 static BOOL test_EnumPrintProcessorDatatypes(struct torture_context *tctx,
363 DWORD levels[] = { 1 };
364 DWORD success[] = { 1 };
366 LPBYTE buffer = NULL;
368 for (i=0; i < ARRAY_SIZE(levels); i++) {
375 torture_comment(tctx, "Testing EnumPrintProcessorDatatypes level %d", levels[i]);
377 EnumPrintProcessorDatatypes(servername, architecture, levels[i], NULL, 0, &needed, &returned);
378 err = GetLastError();
379 if (err == ERROR_INSUFFICIENT_BUFFER) {
381 buffer = malloc(needed);
382 torture_assert(tctx, buffer, "malloc failed");
383 if (!EnumPrintProcessorDatatypes(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
384 err = GetLastError();
388 sprintf(tmp, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
389 levels[i], servername, needed, errstr(err));
391 torture_fail(tctx, tmp);
393 torture_warning(tctx, tmp);
404 /****************************************************************************
405 ****************************************************************************/
407 static BOOL test_GetPrinter(struct torture_context *tctx,
411 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
412 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
414 LPBYTE buffer = NULL;
416 for (i=0; i < ARRAY_SIZE(levels); i++) {
422 torture_comment(tctx, "Testing GetPrinter level %d", levels[i]);
424 GetPrinter(handle, levels[i], NULL, 0, &needed);
425 err = GetLastError();
426 if (err == ERROR_INSUFFICIENT_BUFFER) {
428 buffer = malloc(needed);
429 torture_assert(tctx, buffer, "malloc failed");
430 if (!GetPrinter(handle, levels[i], buffer, needed, &needed)) {
431 err = GetLastError();
435 sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
436 levels[i], printername, needed, errstr(err));
438 torture_fail(tctx, tmp);
440 torture_warning(tctx, tmp);
451 /****************************************************************************
452 ****************************************************************************/
454 static BOOL test_GetPrinterDriver(struct torture_context *tctx,
459 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 8, 101};
460 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
462 LPBYTE buffer = NULL;
464 for (i=0; i < ARRAY_SIZE(levels); i++) {
470 torture_comment(tctx, "Testing GetPrinterDriver level %d", levels[i]);
472 GetPrinterDriver(handle, architecture, levels[i], NULL, 0, &needed);
473 err = GetLastError();
474 if (err == ERROR_INSUFFICIENT_BUFFER) {
476 buffer = malloc(needed);
477 torture_assert(tctx, buffer, "malloc failed");
478 if (!GetPrinterDriver(handle, architecture, levels[i], buffer, needed, &needed)) {
479 err = GetLastError();
483 sprintf(tmp, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
484 levels[i], printername, needed, errstr(err));
486 torture_fail(tctx, tmp);
488 torture_warning(tctx, tmp);
500 /****************************************************************************
501 ****************************************************************************/
503 static BOOL test_EnumJobs(struct torture_context *tctx,
507 DWORD levels[] = { 1, 2, 3, 4 };
508 DWORD success[] = { 1, 1, 1, 1 };
510 LPBYTE buffer = NULL;
512 for (i=0; i < ARRAY_SIZE(levels); i++) {
519 torture_comment(tctx, "Testing EnumJobs level %d", levels[i]);
521 EnumJobs(handle, 0, 100, levels[i], NULL, 0, &needed, &returned);
522 err = GetLastError();
523 if (err == ERROR_INSUFFICIENT_BUFFER) {
525 buffer = malloc(needed);
526 torture_assert(tctx, buffer, "malloc failed");
527 if (!EnumJobs(handle, 0, 100, levels[i], buffer, needed, &needed, &returned)) {
528 err = GetLastError();
532 sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
533 levels[i], printername, needed, errstr(err));
535 torture_fail(tctx, tmp);
537 torture_warning(tctx, tmp);
548 /****************************************************************************
549 ****************************************************************************/
551 static BOOL test_OnePrinter(struct torture_context *tctx,
558 torture_comment(tctx, "Testing Printer %s", printername);
560 ret &= test_OpenPrinter(tctx, printername, &handle);
561 ret &= test_GetPrinter(tctx, printername, handle);
562 ret &= test_GetPrinterDriver(tctx, printername, architecture, handle);
563 ret &= test_EnumForms(tctx, printername, handle);
564 ret &= test_EnumJobs(tctx, printername, handle);
565 ret &= test_ClosePrinter(tctx, handle);
570 /****************************************************************************
571 ****************************************************************************/
573 static BOOL test_OneDriver(struct torture_context *tctx,
580 /****************************************************************************
581 ****************************************************************************/
583 static BOOL test_EachDriver(struct torture_context *tctx,
589 /****************************************************************************
590 ****************************************************************************/
592 static BOOL test_EachPrinter(struct torture_context *tctx,
601 DWORD flags = PRINTER_ENUM_NAME;
602 PPRINTER_INFO_1 buffer = NULL;
604 torture_comment(tctx, "Testing EnumPrinters level %d", 1);
606 EnumPrinters(flags, servername, 1, NULL, 0, &needed, &returned);
607 err = GetLastError();
608 if (err == ERROR_INSUFFICIENT_BUFFER) {
610 buffer = (PPRINTER_INFO_1)malloc(needed);
611 torture_assert(tctx, buffer, "malloc failed");
612 if (!EnumPrinters(flags, servername, 1, (LPBYTE)buffer, needed, &needed, &returned)) {
613 err = GetLastError();
617 sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
618 1, servername, needed, errstr(err));
619 torture_fail(tctx, tmp);
622 for (i=0; i < returned; i++) {
623 torture_assert(tctx, test_OnePrinter(tctx, buffer[i].pName, architecture),
624 "failed to test one printer");
632 /****************************************************************************
633 ****************************************************************************/
635 static BOOL test_GetPrintProcessorDirectory(struct torture_context *tctx,
639 DWORD levels[] = { 1 };
640 DWORD success[] = { 1 };
642 LPBYTE buffer = NULL;
644 for (i=0; i < ARRAY_SIZE(levels); i++) {
650 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %d", levels[i]);
652 GetPrintProcessorDirectory(servername, architecture, levels[i], NULL, 0, &needed);
653 err = GetLastError();
654 if (err == ERROR_INSUFFICIENT_BUFFER) {
656 buffer = malloc(needed);
657 torture_assert(tctx, buffer, "malloc failed");
658 if (!GetPrintProcessorDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
659 err = GetLastError();
663 sprintf(tmp, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
664 levels[i], servername, needed, errstr(err));
666 torture_fail(tctx, tmp);
668 torture_warning(tctx, tmp);
679 /****************************************************************************
680 ****************************************************************************/
682 static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
686 DWORD levels[] = { 1 };
687 DWORD success[] = { 1 };
689 LPBYTE buffer = NULL;
691 for (i=0; i < ARRAY_SIZE(levels); i++) {
697 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %d", levels[i]);
699 GetPrinterDriverDirectory(servername, architecture, levels[i], NULL, 0, &needed);
700 err = GetLastError();
701 if (err == ERROR_INSUFFICIENT_BUFFER) {
703 buffer = malloc(needed);
704 torture_assert(tctx, buffer, "malloc failed");
705 if (!GetPrinterDriverDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
706 err = GetLastError();
710 sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
711 levels[i], servername, needed, errstr(err));
713 torture_fail(tctx, tmp);
715 torture_warning(tctx, tmp);
727 /****************************************************************************
728 ****************************************************************************/
730 int main(int argc, char *argv[])
734 LPSTR architecture = "Windows NT x86";
736 struct torture_context *tctx;
739 fprintf(stderr, "usage: %s <servername> [print]\n", argv[0]);
743 tctx = malloc(sizeof(struct torture_context));
745 fprintf(stderr, "out of memory\n");
748 memset(tctx, '\0', sizeof(*tctx));
750 servername = argv[1];
753 if (strcmp(argv[2], "print") == 0) {
758 ret &= test_EnumPrinters(tctx, servername);
759 ret &= test_EnumDrivers(tctx, servername, architecture);
760 ret &= test_OpenPrinter(tctx, servername, &handle);
761 ret &= test_EnumForms(tctx, servername, handle);
762 ret &= test_ClosePrinter(tctx, handle);
763 ret &= test_EnumPorts(tctx, servername);
764 ret &= test_EnumMonitors(tctx, servername);
765 ret &= test_EnumPrintProcessors(tctx, servername, architecture);
766 ret &= test_EnumPrintProcessorDatatypes(tctx, servername, architecture);
767 ret &= test_GetPrintProcessorDirectory(tctx, servername, architecture);
768 ret &= test_GetPrinterDriverDirectory(tctx, servername, architecture);
769 ret &= test_EachPrinter(tctx, servername, architecture);
770 ret &= test_EachDriver(tctx, servername);
773 if (tctx->last_reason) {
774 fprintf(stderr, "failed: %s\n", tctx->last_reason);
780 printf("%s run successfully\n", argv[0]);