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