add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / EnumPrinterDrivers.c
1 /******************************************************************
2  * SPOOLSS regression testing code for Samba print servers
3  *
4  *****************************************************************/
5
6 #include <windows.h>
7 #include <stdio.h>
8
9 #define NUM_ARCH        5
10 const LPTSTR arch [NUM_ARCH] = {        "Windows 4.0",
11                                                         "Windows NT x86",
12                                                         "Windows NT R4000",
13                                                         "Windows NT PowerPC",
14                                                         "Windows NT Alpha_AXP"  };
15
16 int main (int argc, char* argv[])
17 {
18         DWORD   needed, returned, i, j;
19         PDRIVER_INFO_1  buffer1 = NULL;
20         PDRIVER_INFO_2  buffer2 = NULL;
21         PDRIVER_INFO_3  buffer3 = NULL;
22
23         if (argc < 2)
24         {
25                 fprintf (stderr, "useage: %s <servername>\n", argv[0]);
26                 exit (-1);
27         }
28
29         for (i=0; i<NUM_ARCH; i++)
30         {
31                 printf ("\n\n[%s]\n", arch[i]);
32
33                 /* INFO LEVEL 1 */
34                 needed = returned = 0;
35                 EnumPrinterDrivers(argv[1], arch[i], 1, (LPBYTE)buffer1, 0, &needed, &returned);
36                 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
37                 {
38                         if (needed != 0)
39                                 fprintf (stderr, "Error EnumPrinterDrivers Info Level 1 for [%s] using NULL buffer.\n", argv[1]);
40                         else
41                                 printf ("Info level 1 returned no information\n");
42                 }
43                 else
44                 {
45                         if ((buffer1 = (PDRIVER_INFO_1)malloc(needed)) == NULL)
46                         {
47                                 fprintf (stderr, "Unable to malloc memory for buffer!\n");
48                                 exit (-1);
49                         }
50                         if (!EnumPrinterDrivers(argv[1], arch[i], 1, (LPBYTE)buffer1, needed, &needed, &returned))
51                         {
52                                 fprintf (stderr, "Error enumerating printer drivers Info Level 1 for [%s].\nSize of buffer = %d\n",
53                                                 argv[1], needed);
54                         }
55
56                         printf ("Driver Info Level 1\n");
57                         for (j=0; j<returned; j++)
58                         {
59                                 printf ("\tDriver Name\t= %s\n\n", buffer1[j].pName);
60                                 printf ("\n");
61                         }
62                         free (buffer1);
63                 }
64
65                 /* INFO LEVEL 2 */
66                 needed = returned = 0;
67                 EnumPrinterDrivers(argv[1], arch[i], 2, (LPBYTE)buffer2, 0, &needed, &returned);
68                 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
69                 {
70                         if (needed != 0)
71                                 fprintf (stderr, "Error EnumPrinterDrivers Info Level 2 for [%s] using NULL buffer.\n", argv[1]);
72                         else
73                                 printf ("Info level 2 returned no information\n");
74                 }
75                 else
76                 {
77                         if ((buffer2 = (PDRIVER_INFO_2)malloc(needed)) == NULL)
78                         {
79                                 fprintf (stderr, "Unable to malloc memory for buffer!\n");
80                                 exit (-1);
81                         }
82                         if (!EnumPrinterDrivers(argv[1], arch[i], 2, (LPBYTE)buffer2, needed, &needed, &returned))
83                         {
84                                 fprintf (stderr, "Error enumerating printer drivers Info Level 2 for [%s].\nSize of buffer = %d\n",
85                                                 argv[1], needed);
86                         }
87
88                         printf ("\nDriver Info Level 2\n");
89                         for (j=0; j<returned; j++)
90                         {
91                                 printf ("\tDriver Name\t= %s\n",        buffer2[j].pName);
92                                 printf ("\tEnvironment\t= %s\n",        buffer2[j].pEnvironment);
93                                 printf ("\tVersion\t\t= %d\n",          buffer2[j].cVersion);
94                                 printf ("\tDriver Path\t= %s\n",        buffer2[j].pDriverPath);
95                                 printf ("\tData File\t= %s\n",          buffer2[j].pDataFile);
96                                 printf ("\tConfig File\t= %s\n\n",      buffer2[j].pConfigFile);
97                                 printf ("\n");
98                         }
99                         free (buffer2);
100                 }
101
102                 /* INFO LEVEL 3 */
103                 needed = returned = 0;
104                 EnumPrinterDrivers(argv[1], arch[i], 3, (LPBYTE)buffer3, 0, &needed, &returned);
105                 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
106                 {
107                         if (needed != 0)
108                                 fprintf (stderr, "Error EnumPrinterDrivers Info Level 3 for [%s] using NULL buffer.\n", argv[1]);
109                         else
110                                 printf ("Info level 3 returned no information\n");
111                 }
112                 else
113                 {
114                         if ((buffer3 = (PDRIVER_INFO_3)malloc(needed)) == NULL)
115                         {
116                                 fprintf (stderr, "Unable to malloc memory for buffer!\n");
117                                 exit (-1);
118                         }
119                         if (!EnumPrinterDrivers(argv[1], arch[i], 3, (LPBYTE)buffer3, needed, &needed, &returned))
120                         {
121                                 fprintf (stderr, "Error enumerating printer drivers Info Level 3 for [%s].\nSize of buffer = %d\n",
122                                                 argv[1], needed);
123                         }
124
125                         printf ("\nDriver Info Level 3\n");
126                         for (j=0; j<returned; j++)
127                         {
128                                 char*   ptr;
129
130                                 printf ("\tDriver Name\t= %s\n",        buffer3[j].pName);
131                                 printf ("\tEnvironment\t= %s\n",        buffer3[j].pEnvironment);
132                                 printf ("\tVersion\t\t= %d\n",          buffer3[j].cVersion);
133                                 printf ("\tDriver Path\t= %s\n",        buffer3[j].pDriverPath);
134                                 printf ("\tData File\t= %s\n",          buffer3[j].pDataFile);
135                                 printf ("\tConfig File\t= %s\n",        buffer3[j].pConfigFile);
136                                 printf ("\tHelp Path\t= %s\n",          buffer3[j].pHelpFile);
137                                 printf ("\tMonitor Name\t= %s\n",       buffer3[j].pMonitorName);
138                                 printf ("\tData Type\t= %s\n",          buffer3[j].pDefaultDataType);
139                                 ptr = (char*)buffer3->pDependentFiles;
140                                 while (*ptr != '\0')
141                                 {
142                                         printf ("\tDependent Files\t= %s\n", ptr);
143                                         for (;*ptr != '\0'; ptr++)
144                                                 /* printf ("%s\n", ptr); */
145                                                 ;
146                                         ptr++;
147                                 }
148
149                                 printf ("\n");
150                         }
151                         free (buffer3);
152                 }
153
154         }
155
156
157         return 0;
158
159 }