2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Guenther Deschner 2009
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);
114 /****************************************************************************
115 ****************************************************************************/
117 static BOOL test_EnumDrivers(struct torture_context *tctx,
120 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 8 };
121 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1 };
123 LPBYTE buffer = NULL;
125 for (i=0; i < ARRAY_SIZE(levels); i++) {
132 torture_comment(tctx, "Testing EnumPrinterDrivers level %d", levels[i]);
134 EnumPrinterDrivers(servername, "Windows NT x86", levels[i], NULL, 0, &needed, &returned);
135 err = GetLastError();
136 if (err == ERROR_INSUFFICIENT_BUFFER) {
138 buffer = malloc(needed);
139 torture_assert(tctx, buffer, "malloc failed");
140 if (!EnumPrinterDrivers(servername, "Windows NT x86", levels[i], buffer, needed, &needed, &returned)) {
141 err = GetLastError();
145 sprintf(tmp, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
146 levels[i], servername, needed, errstr(err));
148 torture_fail(tctx, tmp);
150 torture_warning(tctx, tmp);
161 /****************************************************************************
162 ****************************************************************************/
164 static BOOL test_EnumForms(struct torture_context *tctx,
168 DWORD levels[] = { 1, 2 };
169 DWORD success[] = { 1, 0 };
171 LPBYTE buffer = NULL;
173 for (i=0; i < ARRAY_SIZE(levels); i++) {
180 torture_comment(tctx, "Testing EnumForms level %d", levels[i]);
182 EnumForms(handle, levels[i], NULL, 0, &needed, &returned);
183 err = GetLastError();
184 if (err == ERROR_INSUFFICIENT_BUFFER) {
186 buffer = malloc(needed);
187 torture_assert(tctx, buffer, "malloc failed");
188 if (!EnumForms(handle, levels[i], buffer, needed, &needed, &returned)) {
189 err = GetLastError();
193 sprintf(tmp, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
194 levels[i], servername, needed, errstr(err));
196 torture_fail(tctx, tmp);
198 torture_warning(tctx, tmp);
209 /****************************************************************************
210 ****************************************************************************/
212 static BOOL test_EnumPorts(struct torture_context *tctx,
215 DWORD levels[] = { 1, 2 };
216 DWORD success[] = { 1, 1 };
218 LPBYTE buffer = NULL;
220 for (i=0; i < ARRAY_SIZE(levels); i++) {
227 torture_comment(tctx, "Testing EnumPorts level %d", levels[i]);
229 EnumPorts(servername, levels[i], NULL, 0, &needed, &returned);
230 err = GetLastError();
231 if (err == ERROR_INSUFFICIENT_BUFFER) {
233 buffer = malloc(needed);
234 torture_assert(tctx, buffer, "malloc failed");
235 if (!EnumPorts(servername, levels[i], buffer, needed, &needed, &returned)) {
236 err = GetLastError();
240 sprintf(tmp, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
241 levels[i], servername, needed, errstr(err));
243 torture_fail(tctx, tmp);
245 torture_warning(tctx, tmp);
256 /****************************************************************************
257 ****************************************************************************/
259 static BOOL test_EnumMonitors(struct torture_context *tctx,
262 DWORD levels[] = { 1, 2 };
263 DWORD success[] = { 1, 1 };
265 LPBYTE buffer = NULL;
267 for (i=0; i < ARRAY_SIZE(levels); i++) {
274 torture_comment(tctx, "Testing EnumMonitors level %d", levels[i]);
276 EnumMonitors(servername, levels[i], NULL, 0, &needed, &returned);
277 err = GetLastError();
278 if (err == ERROR_INSUFFICIENT_BUFFER) {
280 buffer = malloc(needed);
281 torture_assert(tctx, buffer, "malloc failed");
282 if (!EnumMonitors(servername, levels[i], buffer, needed, &needed, &returned)) {
283 err = GetLastError();
287 sprintf(tmp, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
288 levels[i], servername, needed, errstr(err));
290 torture_fail(tctx, tmp);
292 torture_warning(tctx, tmp);
303 /****************************************************************************
304 ****************************************************************************/
306 static BOOL test_EnumPrintProcessors(struct torture_context *tctx,
309 DWORD levels[] = { 1 };
310 DWORD success[] = { 1 };
312 LPBYTE buffer = NULL;
314 for (i=0; i < ARRAY_SIZE(levels); i++) {
321 torture_comment(tctx, "Testing EnumPrintProcessors level %d", levels[i]);
323 EnumPrintProcessors(servername, "Windows NT x86", levels[i], NULL, 0, &needed, &returned);
324 err = GetLastError();
325 if (err == ERROR_INSUFFICIENT_BUFFER) {
327 buffer = malloc(needed);
328 torture_assert(tctx, buffer, "malloc failed");
329 if (!EnumPrintProcessors(servername, "Windows NT x86", levels[i], buffer, needed, &needed, &returned)) {
330 err = GetLastError();
334 sprintf(tmp, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
335 levels[i], servername, needed, errstr(err));
337 torture_fail(tctx, tmp);
339 torture_warning(tctx, tmp);
350 /****************************************************************************
351 ****************************************************************************/
353 static BOOL test_EnumPrintProcessorDatatypes(struct torture_context *tctx,
356 DWORD levels[] = { 1 };
357 DWORD success[] = { 1 };
359 LPBYTE buffer = NULL;
361 for (i=0; i < ARRAY_SIZE(levels); i++) {
368 torture_comment(tctx, "Testing EnumPrintProcessorDatatypes level %d", levels[i]);
370 EnumPrintProcessorDatatypes(servername, "Windows NT x86", levels[i], NULL, 0, &needed, &returned);
371 err = GetLastError();
372 if (err == ERROR_INSUFFICIENT_BUFFER) {
374 buffer = malloc(needed);
375 torture_assert(tctx, buffer, "malloc failed");
376 if (!EnumPrintProcessorDatatypes(servername, "Windows NT x86", levels[i], buffer, needed, &needed, &returned)) {
377 err = GetLastError();
381 sprintf(tmp, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
382 levels[i], servername, needed, errstr(err));
384 torture_fail(tctx, tmp);
386 torture_warning(tctx, tmp);
397 /****************************************************************************
398 ****************************************************************************/
400 static BOOL test_GetPrinter(struct torture_context *tctx,
404 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
405 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
407 LPBYTE buffer = NULL;
409 for (i=0; i < ARRAY_SIZE(levels); i++) {
415 torture_comment(tctx, "Testing GetPrinter level %d", levels[i]);
417 GetPrinter(handle, levels[i], NULL, 0, &needed);
418 err = GetLastError();
419 if (err == ERROR_INSUFFICIENT_BUFFER) {
421 buffer = malloc(needed);
422 torture_assert(tctx, buffer, "malloc failed");
423 if (!GetPrinter(handle, levels[i], buffer, needed, &needed)) {
424 err = GetLastError();
428 sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
429 levels[i], printername, needed, errstr(err));
431 torture_fail(tctx, tmp);
433 torture_warning(tctx, tmp);
444 /****************************************************************************
445 ****************************************************************************/
447 static BOOL test_GetPrinterDriver(struct torture_context *tctx,
451 DWORD levels[] = { 1, 2, 3, 4, 5, 6, 8, 101};
452 DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
454 LPBYTE buffer = NULL;
456 for (i=0; i < ARRAY_SIZE(levels); i++) {
462 torture_comment(tctx, "Testing GetPrinterDriver level %d", levels[i]);
464 GetPrinterDriver(handle, "Windows NT x86", levels[i], NULL, 0, &needed);
465 err = GetLastError();
466 if (err == ERROR_INSUFFICIENT_BUFFER) {
468 buffer = malloc(needed);
469 torture_assert(tctx, buffer, "malloc failed");
470 if (!GetPrinterDriver(handle, "Windows NT x86", levels[i], buffer, needed, &needed)) {
471 err = GetLastError();
475 sprintf(tmp, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
476 levels[i], printername, needed, errstr(err));
478 torture_fail(tctx, tmp);
480 torture_warning(tctx, tmp);
492 /****************************************************************************
493 ****************************************************************************/
495 static BOOL test_EnumJobs(struct torture_context *tctx,
499 DWORD levels[] = { 1, 2, 3, 4 };
500 DWORD success[] = { 1, 1, 1, 1 };
502 LPBYTE buffer = NULL;
504 for (i=0; i < ARRAY_SIZE(levels); i++) {
511 torture_comment(tctx, "Testing EnumJobs level %d", levels[i]);
513 EnumJobs(handle, 0, 100, levels[i], NULL, 0, &needed, &returned);
514 err = GetLastError();
515 if (err == ERROR_INSUFFICIENT_BUFFER) {
517 buffer = malloc(needed);
518 torture_assert(tctx, buffer, "malloc failed");
519 if (!EnumJobs(handle, 0, 100, levels[i], buffer, needed, &needed, &returned)) {
520 err = GetLastError();
524 sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
525 levels[i], printername, needed, errstr(err));
527 torture_fail(tctx, tmp);
529 torture_warning(tctx, tmp);
540 /****************************************************************************
541 ****************************************************************************/
543 static BOOL test_OnePrinter(struct torture_context *tctx,
549 torture_comment(tctx, "Testing Printer %s", printername);
551 ret &= test_OpenPrinter(tctx, printername, &handle);
552 ret &= test_GetPrinter(tctx, printername, handle);
553 ret &= test_GetPrinterDriver(tctx, printername, handle);
554 ret &= test_EnumForms(tctx, printername, handle);
555 ret &= test_EnumJobs(tctx, printername, handle);
556 ret &= test_ClosePrinter(tctx, handle);
561 /****************************************************************************
562 ****************************************************************************/
564 static BOOL test_OneDriver(struct torture_context *tctx,
571 /****************************************************************************
572 ****************************************************************************/
574 static BOOL test_EachDriver(struct torture_context *tctx,
580 /****************************************************************************
581 ****************************************************************************/
583 static BOOL test_EachPrinter(struct torture_context *tctx,
591 DWORD flags = PRINTER_ENUM_NAME;
592 PPRINTER_INFO_1 buffer = NULL;
594 torture_comment(tctx, "Testing EnumPrinters level %d", 1);
596 EnumPrinters(flags, servername, 1, NULL, 0, &needed, &returned);
597 err = GetLastError();
598 if (err == ERROR_INSUFFICIENT_BUFFER) {
600 buffer = (PPRINTER_INFO_1)malloc(needed);
601 torture_assert(tctx, buffer, "malloc failed");
602 if (!EnumPrinters(flags, servername, 1, (LPBYTE)buffer, needed, &needed, &returned)) {
603 err = GetLastError();
607 sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
608 1, servername, needed, errstr(err));
609 torture_fail(tctx, tmp);
612 for (i=0; i < returned; i++) {
613 torture_assert(tctx, test_OnePrinter(tctx, buffer[i].pName),
614 "failed to test one printer");
622 /****************************************************************************
623 ****************************************************************************/
625 static BOOL test_GetPrintProcessorDirectory(struct torture_context *tctx,
628 DWORD levels[] = { 1 };
629 DWORD success[] = { 1 };
631 LPBYTE buffer = NULL;
633 for (i=0; i < ARRAY_SIZE(levels); i++) {
639 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %d", levels[i]);
641 GetPrintProcessorDirectory(servername, "Windows NT x86", levels[i], NULL, 0, &needed);
642 err = GetLastError();
643 if (err == ERROR_INSUFFICIENT_BUFFER) {
645 buffer = malloc(needed);
646 torture_assert(tctx, buffer, "malloc failed");
647 if (!GetPrintProcessorDirectory(servername, "Windows NT x86", levels[i], buffer, needed, &needed)) {
648 err = GetLastError();
652 sprintf(tmp, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
653 levels[i], servername, needed, errstr(err));
655 torture_fail(tctx, tmp);
657 torture_warning(tctx, tmp);
668 /****************************************************************************
669 ****************************************************************************/
671 static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
674 DWORD levels[] = { 1 };
675 DWORD success[] = { 1 };
677 LPBYTE buffer = NULL;
679 for (i=0; i < ARRAY_SIZE(levels); i++) {
685 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %d", levels[i]);
687 GetPrinterDriverDirectory(servername, "Windows NT x86", levels[i], NULL, 0, &needed);
688 err = GetLastError();
689 if (err == ERROR_INSUFFICIENT_BUFFER) {
691 buffer = malloc(needed);
692 torture_assert(tctx, buffer, "malloc failed");
693 if (!GetPrinterDriverDirectory(servername, "Windows NT x86", levels[i], buffer, needed, &needed)) {
694 err = GetLastError();
698 sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
699 levels[i], servername, needed, errstr(err));
701 torture_fail(tctx, tmp);
703 torture_warning(tctx, tmp);
715 /****************************************************************************
716 ****************************************************************************/
718 int main(int argc, char *argv[])
723 struct torture_context *tctx;
726 fprintf(stderr, "usage: %s <servername> [print]\n", argv[0]);
730 tctx = malloc(sizeof(struct torture_context));
732 fprintf(stderr, "out of memory\n");
735 memset(tctx, '\0', sizeof(*tctx));
737 servername = argv[1];
740 if (strcmp(argv[2], "print") == 0) {
745 ret &= test_EnumPrinters(tctx, servername);
746 ret &= test_EnumDrivers(tctx, servername);
747 ret &= test_OpenPrinter(tctx, servername, &handle);
748 ret &= test_EnumForms(tctx, servername, handle);
749 ret &= test_ClosePrinter(tctx, handle);
750 ret &= test_EnumPorts(tctx, servername);
751 ret &= test_EnumMonitors(tctx, servername);
752 ret &= test_EnumPrintProcessors(tctx, servername);
753 ret &= test_EnumPrintProcessorDatatypes(tctx, servername);
754 ret &= test_GetPrintProcessorDirectory(tctx, servername);
755 ret &= test_GetPrinterDriverDirectory(tctx, servername);
756 ret &= test_EachPrinter(tctx, servername);
757 ret &= test_EachDriver(tctx, servername);
760 if (tctx->last_reason) {
761 fprintf(stderr, "failed: %s\n", tctx->last_reason);
767 printf("%s run successfully\n", argv[0]);