testprogs: fix driver levels in spoolss test.
[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 };
126         DWORD success[] = { 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 {
362         DWORD levels[]  = { 1 };
363         DWORD success[] = { 1 };
364         DWORD i;
365         LPBYTE buffer = NULL;
366
367         for (i=0; i < ARRAY_SIZE(levels); i++) {
368
369                 DWORD needed = 0;
370                 DWORD returned = 0;
371                 DWORD err = 0;
372                 char tmp[1024];
373
374                 torture_comment(tctx, "Testing EnumPrintProcessorDatatypes level %d", levels[i]);
375
376                 EnumPrintProcessorDatatypes(servername, "winprint", levels[i], NULL, 0, &needed, &returned);
377                 err = GetLastError();
378                 if (err == ERROR_INSUFFICIENT_BUFFER) {
379                         err = 0;
380                         buffer = malloc(needed);
381                         torture_assert(tctx, buffer, "malloc failed");
382                         if (!EnumPrintProcessorDatatypes(servername, "winprint", levels[i], buffer, needed, &needed, &returned)) {
383                                 err = GetLastError();
384                         }
385                 }
386                 if (err) {
387                         sprintf(tmp, "EnumPrintProcessorDatatypes failed level %d on [%s] (buffer size = %d), error: %s\n",
388                                 levels[i], servername, needed, errstr(err));
389                         if (success[i]) {
390                                 torture_fail(tctx, tmp);
391                         } else {
392                                 torture_warning(tctx, tmp);
393                         }
394                 }
395
396                 free(buffer);
397                 buffer = NULL;
398         }
399
400         return TRUE;
401 }
402
403 /****************************************************************************
404 ****************************************************************************/
405
406 static BOOL test_GetPrinter(struct torture_context *tctx,
407                             LPSTR printername,
408                             HANDLE handle)
409 {
410         DWORD levels[]  = { 1, 2, 3, 4, 5, 6, 7, 8 };
411         DWORD success[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
412         DWORD i;
413         LPBYTE buffer = NULL;
414
415         for (i=0; i < ARRAY_SIZE(levels); i++) {
416
417                 DWORD needed = 0;
418                 DWORD err = 0;
419                 char tmp[1024];
420
421                 torture_comment(tctx, "Testing GetPrinter level %d", levels[i]);
422
423                 GetPrinter(handle, levels[i], NULL, 0, &needed);
424                 err = GetLastError();
425                 if (err == ERROR_INSUFFICIENT_BUFFER) {
426                         err = 0;
427                         buffer = malloc(needed);
428                         torture_assert(tctx, buffer, "malloc failed");
429                         if (!GetPrinter(handle, levels[i], buffer, needed, &needed)) {
430                                 err = GetLastError();
431                         }
432                 }
433                 if (err) {
434                         sprintf(tmp, "GetPrinter failed level %d on [%s] (buffer size = %d), error: %s\n",
435                                 levels[i], printername, needed, errstr(err));
436                         if (success[i]) {
437                                 torture_fail(tctx, tmp);
438                         } else {
439                                 torture_warning(tctx, tmp);
440                         }
441                 }
442
443                 free(buffer);
444                 buffer = NULL;
445         }
446
447         return TRUE;
448 }
449
450 /****************************************************************************
451 ****************************************************************************/
452
453 static BOOL test_GetPrinterDriver(struct torture_context *tctx,
454                                   LPSTR printername,
455                                   LPSTR architecture,
456                                   HANDLE handle)
457 {
458         DWORD levels[]  = { 1, 2, 3, 4, 5, 6, 8 };
459         DWORD success[] = { 1, 1, 1, 1, 1, 1, 1 };
460         DWORD i;
461         LPBYTE buffer = NULL;
462
463         for (i=0; i < ARRAY_SIZE(levels); i++) {
464
465                 DWORD needed = 0;
466                 DWORD err = 0;
467                 char tmp[1024];
468
469                 torture_comment(tctx, "Testing GetPrinterDriver level %d", levels[i]);
470
471                 GetPrinterDriver(handle, architecture, levels[i], NULL, 0, &needed);
472                 err = GetLastError();
473                 if (err == ERROR_INSUFFICIENT_BUFFER) {
474                         err = 0;
475                         buffer = malloc(needed);
476                         torture_assert(tctx, buffer, "malloc failed");
477                         if (!GetPrinterDriver(handle, architecture, levels[i], buffer, needed, &needed)) {
478                                 err = GetLastError();
479                         }
480                 }
481                 if (err) {
482                         sprintf(tmp, "GetPrinterDriver failed level %d on [%s] (buffer size = %d), error: %s\n",
483                                 levels[i], printername, needed, errstr(err));
484                         if (success[i]) {
485                                 torture_fail(tctx, tmp);
486                         } else {
487                                 torture_warning(tctx, tmp);
488                         }
489                 }
490
491                 free(buffer);
492                 buffer = NULL;
493         }
494
495         return TRUE;
496 }
497
498
499 /****************************************************************************
500 ****************************************************************************/
501
502 static BOOL test_EnumJobs(struct torture_context *tctx,
503                           LPSTR printername,
504                           HANDLE handle)
505 {
506         DWORD levels[]  = { 1, 2, 3, 4 };
507         DWORD success[] = { 1, 1, 1, 1 };
508         DWORD i;
509         LPBYTE buffer = NULL;
510
511         for (i=0; i < ARRAY_SIZE(levels); i++) {
512
513                 DWORD needed = 0;
514                 DWORD returned = 0;
515                 DWORD err = 0;
516                 char tmp[1024];
517
518                 torture_comment(tctx, "Testing EnumJobs level %d", levels[i]);
519
520                 EnumJobs(handle, 0, 100, levels[i], NULL, 0, &needed, &returned);
521                 err = GetLastError();
522                 if (err == ERROR_INSUFFICIENT_BUFFER) {
523                         err = 0;
524                         buffer = malloc(needed);
525                         torture_assert(tctx, buffer, "malloc failed");
526                         if (!EnumJobs(handle, 0, 100, levels[i], buffer, needed, &needed, &returned)) {
527                                 err = GetLastError();
528                         }
529                 }
530                 if (err) {
531                         sprintf(tmp, "EnumJobs failed level %d on [%s] (buffer size = %d), error: %s\n",
532                                 levels[i], printername, needed, errstr(err));
533                         if (success[i]) {
534                                 torture_fail(tctx, tmp);
535                         } else {
536                                 torture_warning(tctx, tmp);
537                         }
538                 }
539
540                 free(buffer);
541                 buffer = NULL;
542         }
543
544         return TRUE;
545 }
546
547 /****************************************************************************
548 ****************************************************************************/
549
550 static BOOL test_OnePrinter(struct torture_context *tctx,
551                             LPSTR printername,
552                             LPSTR architecture)
553 {
554         HANDLE handle;
555         BOOL ret = TRUE;
556
557         torture_comment(tctx, "Testing Printer %s", printername);
558
559         ret &= test_OpenPrinter(tctx, printername, &handle);
560         ret &= test_GetPrinter(tctx, printername, handle);
561         ret &= test_GetPrinterDriver(tctx, printername, architecture, handle);
562         ret &= test_EnumForms(tctx, printername, handle);
563         ret &= test_EnumJobs(tctx, printername, handle);
564         ret &= test_ClosePrinter(tctx, handle);
565
566         return ret;
567 }
568
569 /****************************************************************************
570 ****************************************************************************/
571
572 static BOOL test_OneDriver(struct torture_context *tctx,
573                            LPSTR printername,
574                            LPSTR drivername)
575 {
576         return TRUE;
577 }
578
579 /****************************************************************************
580 ****************************************************************************/
581
582 static BOOL test_EachDriver(struct torture_context *tctx,
583                             LPSTR servername)
584 {
585         return TRUE;
586 }
587
588 /****************************************************************************
589 ****************************************************************************/
590
591 static BOOL test_EachPrinter(struct torture_context *tctx,
592                              LPSTR servername,
593                              LPSTR architecture)
594 {
595         DWORD needed = 0;
596         DWORD returned = 0;
597         DWORD err = 0;
598         char tmp[1024];
599         DWORD i;
600         DWORD flags = PRINTER_ENUM_NAME;
601         PPRINTER_INFO_1 buffer = NULL;
602         BOOL ret = TRUE;
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                 ret &= test_OnePrinter(tctx, buffer[i].pName, architecture);
624         }
625
626         free(buffer);
627
628         return ret;
629 }
630
631 /****************************************************************************
632 ****************************************************************************/
633
634 static BOOL test_GetPrintProcessorDirectory(struct torture_context *tctx,
635                                             LPSTR servername,
636                                             LPSTR architecture)
637 {
638         DWORD levels[]  = { 1 };
639         DWORD success[] = { 1 };
640         DWORD i;
641         LPBYTE buffer = NULL;
642
643         for (i=0; i < ARRAY_SIZE(levels); i++) {
644
645                 DWORD needed = 0;
646                 DWORD err = 0;
647                 char tmp[1024];
648
649                 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %d", levels[i]);
650
651                 GetPrintProcessorDirectory(servername, architecture, levels[i], NULL, 0, &needed);
652                 err = GetLastError();
653                 if (err == ERROR_INSUFFICIENT_BUFFER) {
654                         err = 0;
655                         buffer = malloc(needed);
656                         torture_assert(tctx, buffer, "malloc failed");
657                         if (!GetPrintProcessorDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
658                                 err = GetLastError();
659                         }
660                 }
661                 if (err) {
662                         sprintf(tmp, "GetPrintProcessorDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
663                                 levels[i], servername, needed, errstr(err));
664                         if (success[i]) {
665                                 torture_fail(tctx, tmp);
666                         } else {
667                                 torture_warning(tctx, tmp);
668                         }
669                 }
670
671                 free(buffer);
672                 buffer = NULL;
673         }
674
675         return TRUE;
676 }
677
678 /****************************************************************************
679 ****************************************************************************/
680
681 static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
682                                            LPSTR servername,
683                                            LPSTR architecture)
684 {
685         DWORD levels[]  = { 1 };
686         DWORD success[] = { 1 };
687         DWORD i;
688         LPBYTE buffer = NULL;
689
690         for (i=0; i < ARRAY_SIZE(levels); i++) {
691
692                 DWORD needed = 0;
693                 DWORD err = 0;
694                 char tmp[1024];
695
696                 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %d", levels[i]);
697
698                 GetPrinterDriverDirectory(servername, architecture, levels[i], NULL, 0, &needed);
699                 err = GetLastError();
700                 if (err == ERROR_INSUFFICIENT_BUFFER) {
701                         err = 0;
702                         buffer = malloc(needed);
703                         torture_assert(tctx, buffer, "malloc failed");
704                         if (!GetPrinterDriverDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
705                                 err = GetLastError();
706                         }
707                 }
708                 if (err) {
709                         sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
710                                 levels[i], servername, needed, errstr(err));
711                         if (success[i]) {
712                                 torture_fail(tctx, tmp);
713                         } else {
714                                 torture_warning(tctx, tmp);
715                         }
716                 }
717
718                 free(buffer);
719                 buffer = NULL;
720         }
721
722         return TRUE;
723 }
724
725
726 /****************************************************************************
727 ****************************************************************************/
728
729 int main(int argc, char *argv[])
730 {
731         BOOL ret = FALSE;
732         LPSTR servername;
733         LPSTR architecture = "Windows NT x86";
734         HANDLE handle;
735         struct torture_context *tctx;
736
737         if (argc < 2) {
738                 fprintf(stderr, "usage: %s <servername> [print]\n", argv[0]);
739                 exit(-1);
740         }
741
742         tctx = malloc(sizeof(struct torture_context));
743         if (!tctx) {
744                 fprintf(stderr, "out of memory\n");
745                 exit(-1);
746         }
747         memset(tctx, '\0', sizeof(*tctx));
748
749         servername = argv[1];
750
751         if (argc >= 3) {
752                 if (strcmp(argv[2], "print") == 0) {
753                         tctx->print = TRUE;
754                 }
755         }
756
757         ret &= test_EnumPrinters(tctx, servername);
758         ret &= test_EnumDrivers(tctx, servername, architecture);
759         ret &= test_OpenPrinter(tctx, servername, &handle);
760         ret &= test_EnumForms(tctx, servername, handle);
761         ret &= test_ClosePrinter(tctx, handle);
762         ret &= test_EnumPorts(tctx, servername);
763         ret &= test_EnumMonitors(tctx, servername);
764         ret &= test_EnumPrintProcessors(tctx, servername, architecture);
765         ret &= test_EnumPrintProcessorDatatypes(tctx, servername);
766         ret &= test_GetPrintProcessorDirectory(tctx, servername, architecture);
767         ret &= test_GetPrinterDriverDirectory(tctx, servername, architecture);
768         ret &= test_EachPrinter(tctx, servername, architecture);
769         ret &= test_EachDriver(tctx, servername);
770
771         if (!ret) {
772                 if (tctx->last_reason) {
773                         fprintf(stderr, "failed: %s\n", tctx->last_reason);
774                 }
775                 free(tctx);
776                 return -1;
777         }
778
779         printf("%s run successfully\n", argv[0]);
780
781         free(tctx);
782         return 0;
783 }