add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / EnumPrinters.c
1 /******************************************************************
2  * SPOOLSS regression testing code for Samba print servers
3  *
4  *****************************************************************/
5
6 #include <windows.h>
7 #include <stdio.h>
8 #include "printlib.h"
9
10
11 void TestEnumPrinters (LPTSTR servername, DWORD flags)
12 {
13         DWORD   needed, returned, i;
14         PPRINTER_INFO_1 buffer1 = NULL;
15         PPRINTER_INFO_2 buffer2 = NULL;
16         PPRINTER_INFO_5 buffer5 = NULL;
17
18         /* INFO LEVEL 1 */
19         needed = returned = 0;
20         EnumPrinters(flags, servername, 1, (LPBYTE)buffer1, 0, &needed, &returned);
21         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
22         {
23                 if (needed != 0)
24                         fprintf (stderr, "Error EnumPrinters Info Level 1 for [%s] using NULL buffer.\n", servername);
25                 else
26                         printf ("Info level 1 returned no information\n");
27         }
28         else
29         {
30                 if ((buffer1 = (PPRINTER_INFO_1)malloc(needed)) == NULL)
31                 {
32                         fprintf (stderr, "Unable to malloc memory for buffer!\n");
33                         return;
34                 }
35                 if (!EnumPrinters(flags, servername, 1, (LPBYTE)buffer1, needed, &needed, &returned))
36                 {
37                         fprintf (stderr, "Error enumerating printers Info Level 1 for [%s].\nSize of buffer = %d\n",
38                                         servername, needed);
39                 }
40
41                 printf ("Printer Info Level 1:\n");
42                 for (i=0; i<returned; i++)
43                 {
44                         print_printer_info_1 (&buffer1[i]);
45                         printf ("\n");
46                 }
47                 free (buffer1);
48         }
49
50         /* the following flags are only valid for info level 1 */
51         if ((flags == PRINTER_ENUM_REMOTE) || (flags == PRINTER_ENUM_NETWORK))
52                 return;
53
54         /* INFO LEVEL 2 */
55         needed = returned = 0;
56         EnumPrinters(flags, servername, 2, (LPBYTE)buffer2, 0, &needed, &returned);
57         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
58         {
59                 if (needed != 0)
60                         fprintf (stderr, "Error EnumPrinters Info Level 2 for [%s] using NULL buffer.\n", servername);
61                 else
62                         printf ("Info level 2 returned no information\n");
63         }
64         else
65         {
66                 if ((buffer2 = (PPRINTER_INFO_2)malloc(needed)) == NULL)
67                 {
68                         fprintf (stderr, "Unable to malloc memory for buffer!\n");
69                         return;
70                 }
71                 if (!EnumPrinters(flags, servername, 2, (LPBYTE)buffer2, needed, &needed, &returned))
72                 {
73                         fprintf (stderr, "Error enumerating printers Info Level 2 for [%s].\nSize of buffer = %d\n",
74                                         servername, needed);
75                 }
76
77                 printf ("Printer Info Level 2:\n");
78                 for (i=0; i<returned; i++)
79                 {
80                         print_printer_info_2 (&buffer2[i]);
81                         printf ("\n");
82                 }
83                 free (buffer2);
84         }
85
86         /* INFO LEVEL 5 */
87         needed = returned = 0;
88         EnumPrinters(flags, servername, 5, (LPBYTE)buffer5, 0, &needed, &returned);
89         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
90         {
91                 if (needed != 0)
92                         fprintf (stderr, "Error EnumPrinters Info Level 5 for [%s] using NULL buffer.\n", servername);
93                 else
94                         printf ("Info level 5 returned no information\n");
95         }
96         else
97         {
98                 if ((buffer5 = (PPRINTER_INFO_5)malloc(needed)) == NULL)
99                 {
100                         fprintf (stderr, "Unable to malloc memory for buffer!\n");
101                         return;
102                 }
103                 if (!EnumPrinters(flags, servername, 5, (LPBYTE)buffer5, needed, &needed, &returned))
104                 {
105                         fprintf (stderr, "Error enumerating printers Info Level 5 for [%s].\nSize of buffer = %d\n",
106                                         servername, needed);
107                 }
108
109                 printf ("Printer Info Level 5:\n");
110                 for (i=0; i<returned; i++)
111                 {
112                         print_printer_info_5 (&buffer5[i]);
113                         printf ("\n");
114                 }
115                 free (buffer5);
116         }
117
118 }
119
120
121 int main (int argc, char* argv[])
122 {
123
124         if (argc < 2)
125         {
126                 fprintf (stderr, "useage: %s <servername>\n", argv[0]);
127                 exit (-1);
128         }
129 #if 0
130         printf ("\n\nFlags = PRINTER_ENUM_NAME\n");
131         TestEnumPrinters (argv[1], PRINTER_ENUM_NAME);
132         printf ("\n");
133
134         printf ("\n\nFlags = PRINTER_ENUM_NAME | PRINTER_ENUM_SHARED\n");
135         TestEnumPrinters (argv[1], PRINTER_ENUM_NAME | PRINTER_ENUM_SHARED);
136         printf ("\n");
137 #endif
138
139         printf ("\n\nFlags = PRINTER_ENUM_CONNECTIONS\n");
140         TestEnumPrinters (argv[1], PRINTER_ENUM_CONNECTIONS);
141         printf ("\n");
142
143         printf ("\n\nFlags = PRINTER_ENUM_NETWORK\n");
144         TestEnumPrinters (NULL, PRINTER_ENUM_NETWORK);
145         printf ("\n");
146
147         printf ("\n\nFlags = PRINTER_ENUM_REMOTE\n");
148         TestEnumPrinters (NULL, PRINTER_ENUM_REMOTE);
149         printf ("\n");
150
151
152         return 0;
153
154 }