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