c550b99923aa2f6bc10a3b80e053235f3b365b15
[ira/wip.git] / testprogs / win32 / spoolss / spoolss.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for spoolss rpc operations
4
5    Copyright (C) Guenther Deschner 2009-2010
6
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.
11
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.
16
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/>.
19 */
20
21 /****************************************************************************
22 ****************************************************************************/
23
24 #include "spoolss.h"
25 #include "string.h"
26 #include "torture.h"
27
28 /****************************************************************************
29 ****************************************************************************/
30
31 static BOOL test_OpenPrinter(struct torture_context *tctx,
32                              LPSTR printername,
33                              HANDLE handle)
34 {
35         torture_comment(tctx, "Testing OpenPrinter(%s)", printername);
36
37         if (!OpenPrinter(printername, handle, NULL)) {
38                 char tmp[1024];
39                 sprintf(tmp, "failed to open printer %s, error was: 0x%08x\n",
40                         printername, GetLastError());
41                 torture_fail(tctx, tmp);
42         }
43
44         return TRUE;
45 }
46
47 /****************************************************************************
48 ****************************************************************************/
49
50 static BOOL test_ClosePrinter(struct torture_context *tctx,
51                               HANDLE handle)
52 {
53         torture_comment(tctx, "Testing ClosePrinter");
54
55         if (!ClosePrinter(handle)) {
56                 char tmp[1024];
57                 sprintf(tmp, "failed to close printer, error was: %s\n",
58                         errstr(GetLastError()));
59                 torture_fail(tctx, tmp);
60         }
61
62         return TRUE;
63 }
64
65
66 /****************************************************************************
67 ****************************************************************************/
68
69 static BOOL test_EnumPrinters(struct torture_context *tctx,
70                               LPSTR servername)
71 {
72         DWORD levels[]  = { 1, 2, 5 };
73         DWORD success[] = { 1, 1, 1 };
74         DWORD i;
75         DWORD flags = PRINTER_ENUM_NAME;
76         LPBYTE buffer = NULL;
77
78         for (i=0; i < ARRAY_SIZE(levels); i++) {
79
80                 DWORD needed = 0;
81                 DWORD returned = 0;
82                 DWORD err = 0;
83                 char tmp[1024];
84
85                 torture_comment(tctx, "Testing EnumPrinters level %d", levels[i]);
86
87                 EnumPrinters(flags, servername, levels[i], NULL, 0, &needed, &returned);
88                 err = GetLastError();
89                 if (err == ERROR_INSUFFICIENT_BUFFER) {
90                         err = 0;
91                         buffer = malloc(needed);
92                         torture_assert(tctx, buffer, "malloc failed");
93                         if (!EnumPrinters(flags, servername, levels[i], buffer, needed, &needed, &returned)) {
94                                 err = GetLastError();
95                         }
96                 }
97                 if (err) {
98                         sprintf(tmp, "EnumPrinters failed level %d on [%s] (buffer size = %d), error: %s\n",
99                                 levels[i], servername, needed, errstr(err));
100                         if (success[i]) {
101                                 torture_fail(tctx, tmp);
102                         } else {
103                                 torture_warning(tctx, tmp);
104                         }
105                 }
106
107                 if (tctx->print) {
108                         print_printer_info_bylevel(levels[i], buffer, returned);
109                 }
110
111                 free(buffer);
112                 buffer = NULL;
113         }
114
115         return TRUE;
116 }
117
118 /****************************************************************************
119 ****************************************************************************/
120
121 static BOOL test_EnumDrivers(struct torture_context *tctx,
122                              LPSTR servername,
123                              LPSTR architecture)
124 {
125         DWORD levels[]  = { 1, 2, 3, 4, 5, 6, 8 };
126         DWORD success[] = { 1, 1, 1, 1, 1, 1, 1 };
127         DWORD i;
128         LPBYTE buffer = NULL;
129
130         for (i=0; i < ARRAY_SIZE(levels); i++) {
131
132                 DWORD needed = 0;
133                 DWORD returned = 0;
134                 DWORD err = 0;
135                 char tmp[1024];
136
137                 torture_comment(tctx, "Testing EnumPrinterDrivers level %d", levels[i]);
138
139                 EnumPrinterDrivers(servername, architecture, levels[i], NULL, 0, &needed, &returned);
140                 err = GetLastError();
141                 if (err == ERROR_INSUFFICIENT_BUFFER) {
142                         err = 0;
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();
147                         }
148                 }
149                 if (err) {
150                         sprintf(tmp, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
151                                 levels[i], servername, needed, errstr(err));
152                         if (success[i]) {
153                                 torture_fail(tctx, tmp);
154                         } else {
155                                 torture_warning(tctx, tmp);
156                         }
157                 }
158
159                 free(buffer);
160                 buffer = NULL;
161         }
162
163         return TRUE;
164 }
165
166 /****************************************************************************
167 ****************************************************************************/
168
169 static BOOL test_EnumForms(struct torture_context *tctx,
170                            LPSTR servername,
171                            HANDLE handle)
172 {
173         DWORD levels[]  = { 1, 2 };
174         DWORD success[] = { 1, 0 };
175         DWORD i;
176         LPBYTE buffer = NULL;
177
178         for (i=0; i < ARRAY_SIZE(levels); i++) {
179
180                 DWORD needed = 0;
181                 DWORD returned = 0;
182                 DWORD err = 0;
183                 char tmp[1024];
184
185                 torture_comment(tctx, "Testing EnumForms level %d", levels[i]);
186
187                 EnumForms(handle, levels[i], NULL, 0, &needed, &returned);
188                 err = GetLastError();
189                 if (err == ERROR_INSUFFICIENT_BUFFER) {
190                         err = 0;
191                         buffer = malloc(needed);
192                         torture_assert(tctx, buffer, "malloc failed");
193                         if (!EnumForms(handle, levels[i], buffer, needed, &needed, &returned)) {
194                                 err = GetLastError();
195                         }
196                 }
197                 if (err) {
198                         sprintf(tmp, "EnumForms failed level %d on [%s] (buffer size = %d), error: %s\n",
199                                 levels[i], servername, needed, errstr(err));
200                         if (success[i]) {
201                                 torture_fail(tctx, tmp);
202                         } else {
203                                 torture_warning(tctx, tmp);
204                         }
205                 }
206
207                 free(buffer);
208                 buffer = NULL;
209         }
210
211         return TRUE;
212 }
213
214 /****************************************************************************
215 ****************************************************************************/
216
217 static BOOL test_EnumPorts(struct torture_context *tctx,
218                            LPSTR servername)
219 {
220         DWORD levels[]  = { 1, 2 };
221         DWORD success[] = { 1, 1 };
222         DWORD i;
223         LPBYTE buffer = NULL;
224
225         for (i=0; i < ARRAY_SIZE(levels); i++) {
226
227                 DWORD needed = 0;
228                 DWORD returned = 0;
229                 DWORD err = 0;
230                 char tmp[1024];
231
232                 torture_comment(tctx, "Testing EnumPorts level %d", levels[i]);
233
234                 EnumPorts(servername, levels[i], NULL, 0, &needed, &returned);
235                 err = GetLastError();
236                 if (err == ERROR_INSUFFICIENT_BUFFER) {
237                         err = 0;
238                         buffer = malloc(needed);
239                         torture_assert(tctx, buffer, "malloc failed");
240                         if (!EnumPorts(servername, levels[i], buffer, needed, &needed, &returned)) {
241                                 err = GetLastError();
242                         }
243                 }
244                 if (err) {
245                         sprintf(tmp, "EnumPorts failed level %d on [%s] (buffer size = %d), error: %s\n",
246                                 levels[i], servername, needed, errstr(err));
247                         if (success[i]) {
248                                 torture_fail(tctx, tmp);
249                         } else {
250                                 torture_warning(tctx, tmp);
251                         }
252                 }
253
254                 free(buffer);
255                 buffer = NULL;
256         }
257
258         return TRUE;
259 }
260
261 /****************************************************************************
262 ****************************************************************************/
263
264 static BOOL test_EnumMonitors(struct torture_context *tctx,
265                               LPSTR servername)
266 {
267         DWORD levels[]  = { 1, 2 };
268         DWORD success[] = { 1, 1 };
269         DWORD i;
270         LPBYTE buffer = NULL;
271
272         for (i=0; i < ARRAY_SIZE(levels); i++) {
273
274                 DWORD needed = 0;
275                 DWORD returned = 0;
276                 DWORD err = 0;
277                 char tmp[1024];
278
279                 torture_comment(tctx, "Testing EnumMonitors level %d", levels[i]);
280
281                 EnumMonitors(servername, levels[i], NULL, 0, &needed, &returned);
282                 err = GetLastError();
283                 if (err == ERROR_INSUFFICIENT_BUFFER) {
284                         err = 0;
285                         buffer = malloc(needed);
286                         torture_assert(tctx, buffer, "malloc failed");
287                         if (!EnumMonitors(servername, levels[i], buffer, needed, &needed, &returned)) {
288                                 err = GetLastError();
289                         }
290                 }
291                 if (err) {
292                         sprintf(tmp, "EnumMonitors failed level %d on [%s] (buffer size = %d), error: %s\n",
293                                 levels[i], servername, needed, errstr(err));
294                         if (success[i]) {
295                                 torture_fail(tctx, tmp);
296                         } else {
297                                 torture_warning(tctx, tmp);
298                         }
299                 }
300
301                 free(buffer);
302                 buffer = NULL;
303         }
304
305         return TRUE;
306 }
307
308 /****************************************************************************
309 ****************************************************************************/
310
311 static BOOL test_EnumPrintProcessors(struct torture_context *tctx,
312                                      LPSTR servername,
313                                      LPSTR architecture)
314 {
315         DWORD levels[]  = { 1 };
316         DWORD success[] = { 1 };
317         DWORD i;
318         LPBYTE buffer = NULL;
319
320         for (i=0; i < ARRAY_SIZE(levels); i++) {
321
322                 DWORD needed = 0;
323                 DWORD returned = 0;
324                 DWORD err = 0;
325                 char tmp[1024];
326
327                 torture_comment(tctx, "Testing EnumPrintProcessors level %d", levels[i]);
328
329                 EnumPrintProcessors(servername, architecture, levels[i], NULL, 0, &needed, &returned);
330                 err = GetLastError();
331                 if (err == ERROR_INSUFFICIENT_BUFFER) {
332                         err = 0;
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();
337                         }
338                 }
339                 if (err) {
340                         sprintf(tmp, "EnumPrintProcessors failed level %d on [%s] (buffer size = %d), error: %s\n",
341                                 levels[i], servername, needed, errstr(err));
342                         if (success[i]) {
343                                 torture_fail(tctx, tmp);
344                         } else {
345                                 torture_warning(tctx, tmp);
346                         }
347                 }
348
349                 free(buffer);
350                 buffer = NULL;
351         }
352
353         return TRUE;
354 }
355
356 /****************************************************************************
357 ****************************************************************************/
358
359 static BOOL test_EnumPrintProcessorDatatypes(struct torture_context *tctx,
360                                              LPSTR servername,
361                                              LPSTR architecture)
362 {
363         DWORD levels[]  = { 1 };
364         DWORD success[] = { 1 };
365         DWORD i;
366         LPBYTE buffer = NULL;
367
368         for (i=0; i < ARRAY_SIZE(levels); i++) {
369
370                 DWORD needed = 0;
371                 DWORD returned = 0;
372                 DWORD err = 0;
373                 char tmp[1024];
374
375                 torture_comment(tctx, "Testing EnumPrintProcessorDatatypes level %d", levels[i]);
376
377                 EnumPrintProcessorDatatypes(servername, architecture, levels[i], NULL, 0, &needed, &returned);
378                 err = GetLastError();
379                 if (err == ERROR_INSUFFICIENT_BUFFER) {
380                         err = 0;
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();
385                         }
386                 }
387                 if (err) {
388                         sprintf(tmp, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
389                                 levels[i], servername, needed, errstr(err));
390                         if (success[i]) {
391                                 torture_fail(tctx, tmp);
392                         } else {
393                                 torture_warning(tctx, tmp);
394                         }
395                 }
396
397                 free(buffer);
398                 buffer = NULL;
399         }
400
401         return TRUE;
402 }
403
404 /****************************************************************************
405 ****************************************************************************/
406
407 static BOOL test_GetPrinter(struct torture_context *tctx,
408                             LPSTR printername,
409                             HANDLE handle)
410 {
411         DWORD levels[]  = { 1, 2, 3, 4, 5, 6, 7, 8 };
412         DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
413         DWORD i;
414         LPBYTE buffer = NULL;
415
416         for (i=0; i < ARRAY_SIZE(levels); i++) {
417
418                 DWORD needed = 0;
419                 DWORD err = 0;
420                 char tmp[1024];
421
422                 torture_comment(tctx, "Testing GetPrinter level %d", levels[i]);
423
424                 GetPrinter(handle, levels[i], NULL, 0, &needed);
425                 err = GetLastError();
426                 if (err == ERROR_INSUFFICIENT_BUFFER) {
427                         err = 0;
428                         buffer = malloc(needed);
429                         torture_assert(tctx, buffer, "malloc failed");
430                         if (!GetPrinter(handle, levels[i], buffer, needed, &needed)) {
431                                 err = GetLastError();
432                         }
433                 }
434                 if (err) {
435                         sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
436                                 levels[i], printername, needed, errstr(err));
437                         if (success[i]) {
438                                 torture_fail(tctx, tmp);
439                         } else {
440                                 torture_warning(tctx, tmp);
441                         }
442                 }
443
444                 free(buffer);
445                 buffer = NULL;
446         }
447
448         return TRUE;
449 }
450
451 /****************************************************************************
452 ****************************************************************************/
453
454 static BOOL test_GetPrinterDriver(struct torture_context *tctx,
455                                   LPSTR printername,
456                                   LPSTR architecture,
457                                   HANDLE handle)
458 {
459         DWORD levels[]  = { 1, 2, 3, 4, 5, 6, 8, 101};
460         DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
461         DWORD i;
462         LPBYTE buffer = NULL;
463
464         for (i=0; i < ARRAY_SIZE(levels); i++) {
465
466                 DWORD needed = 0;
467                 DWORD err = 0;
468                 char tmp[1024];
469
470                 torture_comment(tctx, "Testing GetPrinterDriver level %d", levels[i]);
471
472                 GetPrinterDriver(handle, architecture, levels[i], NULL, 0, &needed);
473                 err = GetLastError();
474                 if (err == ERROR_INSUFFICIENT_BUFFER) {
475                         err = 0;
476                         buffer = malloc(needed);
477                         torture_assert(tctx, buffer, "malloc failed");
478                         if (!GetPrinterDriver(handle, architecture, levels[i], buffer, needed, &needed)) {
479                                 err = GetLastError();
480                         }
481                 }
482                 if (err) {
483                         sprintf(tmp, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
484                                 levels[i], printername, needed, errstr(err));
485                         if (success[i]) {
486                                 torture_fail(tctx, tmp);
487                         } else {
488                                 torture_warning(tctx, tmp);
489                         }
490                 }
491
492                 free(buffer);
493                 buffer = NULL;
494         }
495
496         return TRUE;
497 }
498
499
500 /****************************************************************************
501 ****************************************************************************/
502
503 static BOOL test_EnumJobs(struct torture_context *tctx,
504                           LPSTR printername,
505                           HANDLE handle)
506 {
507         DWORD levels[]  = { 1, 2, 3, 4 };
508         DWORD success[] = { 1, 1, 1, 1 };
509         DWORD i;
510         LPBYTE buffer = NULL;
511
512         for (i=0; i < ARRAY_SIZE(levels); i++) {
513
514                 DWORD needed = 0;
515                 DWORD returned = 0;
516                 DWORD err = 0;
517                 char tmp[1024];
518
519                 torture_comment(tctx, "Testing EnumJobs level %d", levels[i]);
520
521                 EnumJobs(handle, 0, 100, levels[i], NULL, 0, &needed, &returned);
522                 err = GetLastError();
523                 if (err == ERROR_INSUFFICIENT_BUFFER) {
524                         err = 0;
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();
529                         }
530                 }
531                 if (err) {
532                         sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
533                                 levels[i], printername, needed, errstr(err));
534                         if (success[i]) {
535                                 torture_fail(tctx, tmp);
536                         } else {
537                                 torture_warning(tctx, tmp);
538                         }
539                 }
540
541                 free(buffer);
542                 buffer = NULL;
543         }
544
545         return TRUE;
546 }
547
548 /****************************************************************************
549 ****************************************************************************/
550
551 static BOOL test_OnePrinter(struct torture_context *tctx,
552                             LPSTR printername,
553                             LPSTR architecture)
554 {
555         HANDLE handle;
556         BOOL ret = TRUE;
557
558         torture_comment(tctx, "Testing Printer %s", printername);
559
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);
566
567         return ret;
568 }
569
570 /****************************************************************************
571 ****************************************************************************/
572
573 static BOOL test_OneDriver(struct torture_context *tctx,
574                            LPSTR printername,
575                            LPSTR drivername)
576 {
577         return TRUE;
578 }
579
580 /****************************************************************************
581 ****************************************************************************/
582
583 static BOOL test_EachDriver(struct torture_context *tctx,
584                             LPSTR servername)
585 {
586         return TRUE;
587 }
588
589 /****************************************************************************
590 ****************************************************************************/
591
592 static BOOL test_EachPrinter(struct torture_context *tctx,
593                              LPSTR servername,
594                              LPSTR architecture)
595 {
596         DWORD needed = 0;
597         DWORD returned = 0;
598         DWORD err = 0;
599         char tmp[1024];
600         DWORD i;
601         DWORD flags = PRINTER_ENUM_NAME;
602         PPRINTER_INFO_1 buffer = NULL;
603
604         torture_comment(tctx, "Testing EnumPrinters level %d", 1);
605
606         EnumPrinters(flags, servername, 1, NULL, 0, &needed, &returned);
607         err = GetLastError();
608         if (err == ERROR_INSUFFICIENT_BUFFER) {
609                 err = 0;
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();
614                 }
615         }
616         if (err) {
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);
620         }
621
622         for (i=0; i < returned; i++) {
623                 torture_assert(tctx, test_OnePrinter(tctx, buffer[i].pName, architecture),
624                         "failed to test one printer");
625         }
626
627         free(buffer);
628
629         return TRUE;
630 }
631
632 /****************************************************************************
633 ****************************************************************************/
634
635 static BOOL test_GetPrintProcessorDirectory(struct torture_context *tctx,
636                                             LPSTR servername,
637                                             LPSTR architecture)
638 {
639         DWORD levels[]  = { 1 };
640         DWORD success[] = { 1 };
641         DWORD i;
642         LPBYTE buffer = NULL;
643
644         for (i=0; i < ARRAY_SIZE(levels); i++) {
645
646                 DWORD needed = 0;
647                 DWORD err = 0;
648                 char tmp[1024];
649
650                 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %d", levels[i]);
651
652                 GetPrintProcessorDirectory(servername, architecture, levels[i], NULL, 0, &needed);
653                 err = GetLastError();
654                 if (err == ERROR_INSUFFICIENT_BUFFER) {
655                         err = 0;
656                         buffer = malloc(needed);
657                         torture_assert(tctx, buffer, "malloc failed");
658                         if (!GetPrintProcessorDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
659                                 err = GetLastError();
660                         }
661                 }
662                 if (err) {
663                         sprintf(tmp, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
664                                 levels[i], servername, needed, errstr(err));
665                         if (success[i]) {
666                                 torture_fail(tctx, tmp);
667                         } else {
668                                 torture_warning(tctx, tmp);
669                         }
670                 }
671
672                 free(buffer);
673                 buffer = NULL;
674         }
675
676         return TRUE;
677 }
678
679 /****************************************************************************
680 ****************************************************************************/
681
682 static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
683                                            LPSTR servername,
684                                            LPSTR architecture)
685 {
686         DWORD levels[]  = { 1 };
687         DWORD success[] = { 1 };
688         DWORD i;
689         LPBYTE buffer = NULL;
690
691         for (i=0; i < ARRAY_SIZE(levels); i++) {
692
693                 DWORD needed = 0;
694                 DWORD err = 0;
695                 char tmp[1024];
696
697                 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %d", levels[i]);
698
699                 GetPrinterDriverDirectory(servername, architecture, levels[i], NULL, 0, &needed);
700                 err = GetLastError();
701                 if (err == ERROR_INSUFFICIENT_BUFFER) {
702                         err = 0;
703                         buffer = malloc(needed);
704                         torture_assert(tctx, buffer, "malloc failed");
705                         if (!GetPrinterDriverDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
706                                 err = GetLastError();
707                         }
708                 }
709                 if (err) {
710                         sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
711                                 levels[i], servername, needed, errstr(err));
712                         if (success[i]) {
713                                 torture_fail(tctx, tmp);
714                         } else {
715                                 torture_warning(tctx, tmp);
716                         }
717                 }
718
719                 free(buffer);
720                 buffer = NULL;
721         }
722
723         return TRUE;
724 }
725
726
727 /****************************************************************************
728 ****************************************************************************/
729
730 int main(int argc, char *argv[])
731 {
732         BOOL ret = FALSE;
733         LPSTR servername;
734         LPSTR architecture = "Windows NT x86";
735         HANDLE handle;
736         struct torture_context *tctx;
737
738         if (argc < 2) {
739                 fprintf(stderr, "usage: %s <servername> [print]\n", argv[0]);
740                 exit(-1);
741         }
742
743         tctx = malloc(sizeof(struct torture_context));
744         if (!tctx) {
745                 fprintf(stderr, "out of memory\n");
746                 exit(-1);
747         }
748         memset(tctx, '\0', sizeof(*tctx));
749
750         servername = argv[1];
751
752         if (argc >= 3) {
753                 if (strcmp(argv[2], "print") == 0) {
754                         tctx->print = TRUE;
755                 }
756         }
757
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);
771
772         if (!ret) {
773                 if (tctx->last_reason) {
774                         fprintf(stderr, "failed: %s\n", tctx->last_reason);
775                 }
776                 free(tctx);
777                 return -1;
778         }
779
780         printf("%s run successfully\n", argv[0]);
781
782         free(tctx);
783         return 0;
784 }