add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / SetJob.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 int main (int argc, char* argv[])
12 {
13
14         HANDLE                  printer;
15         DWORD                   dwJobId = 0;
16 #if 0
17         DOCINFO                 docinfo;
18 #endif
19         LPVOID                  lpMsgBuf;
20
21
22         if (argc < 3)
23         {
24                 fprintf (stderr, "useage: %s <printername> <Job ID>\n", argv[0]);
25                 exit (-1);
26         }
27
28         /* open the printer */
29         if (!OpenPrinter (argv[1], &printer, NULL))
30         {
31                 fprintf (stderr, "Unable to open %s!\n", argv[1]);
32                 exit (-1);
33         }
34         else
35         {
36                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
37         }
38
39 #if 0
40         docinfo.lpszDocName = _strdup (argv[2]);
41         docinfo.lpszOutput  = NULL;
42         docinfo.lpszDatatype = _strdup ("RAW");
43         docinfo.fwType = 0;
44         docinfo.cbSize = sizeof (docinfo);
45
46         dwJobId = StartDoc (NULL, &docinfo);
47         printf ("JobId = %d\n", dwJobId);
48         if (dwJobId < 1)
49         {
50                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
51                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
52                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
53                         (LPTSTR) &lpMsgBuf, 0, NULL);
54                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
55                 LocalFree (lpMsgBuf);
56         }
57         else
58         {
59                 printf ("StartDoc called successfully.  Job ID = %d\n", dwJobId);
60         }
61 #endif
62
63         dwJobId = atoi (argv[2]);
64
65         printf ("command = JOB_CONTROL_PAUSE\n");
66         if (SetJob(printer, dwJobId, 0, NULL, JOB_CONTROL_PAUSE))
67         {
68                 printf ("Job Id [%d] paused successfully\n", dwJobId);
69         }
70         else
71         {
72                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
73                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
74                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
75                         (LPTSTR) &lpMsgBuf, 0, NULL);
76                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
77                 LocalFree (lpMsgBuf);
78         }
79         printf ("\n");
80
81         printf ("command = JOB_CONTROL_RESUME\n");
82         if (SetJob(printer, dwJobId, 0, NULL, JOB_CONTROL_RESUME))
83         {
84                 printf ("Job Id [%d] resumed successfully\n", dwJobId);
85         }
86         else
87         {
88                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
89                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
90                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
91                         (LPTSTR) &lpMsgBuf, 0, NULL);
92                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
93                 LocalFree (lpMsgBuf);
94         }
95         printf ("\n");
96
97         printf ("command = JOB_CONTROL_RESTART\n");
98         if (SetJob(printer, dwJobId, 0, NULL, JOB_CONTROL_RESTART))
99         {
100                 printf ("Job Id [%d] restarted successfully\n", dwJobId);
101         }
102         else
103         {
104                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
105                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
106                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
107                         (LPTSTR) &lpMsgBuf, 0, NULL);
108                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
109                 LocalFree (lpMsgBuf);
110         }
111         printf ("\n");
112
113
114         printf ("command = JOB_CONTROL_DELETE\n");
115         if (SetJob(printer, dwJobId, 0, NULL, JOB_CONTROL_DELETE))
116         {
117                 printf ("Job Id [%d] deleted successfully\n", dwJobId);
118         }
119         else
120         {
121                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
122                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
123                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
124                         (LPTSTR) &lpMsgBuf, 0, NULL);
125                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
126                 LocalFree (lpMsgBuf);
127         }
128         printf ("\n");
129
130         /* close the printer */
131         if (!ClosePrinter(printer))
132         {
133                 fprintf (stderr, "Error closing printer!\n");
134                 exit (-1);
135         }
136         else
137         {
138                 printf ("Printer [%s] closed successfully.\n", argv[1]);
139         }
140
141         return 0;
142
143 }