add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / PagePrinter.c
1 /******************************************************************
2  * SPOOLSS regression testing code for Samba print servers
3  *
4  *****************************************************************/
5
6 #include <windows.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <io.h>
10 #include <string.h>
11 #include "printlib.h"
12
13
14 int main (int argc, char* argv[])
15 {
16
17         HANDLE                          printer;
18         int                                     fd;
19         BYTE                            buffer[256];
20         DWORD                           bytes, wrote;
21         DOC_INFO_1                      buffer1;
22         PRINTER_DEFAULTS        print_defaults;
23
24         if (argc < 3)
25         {
26                 fprintf (stderr, "useage: %s <printername> <filename>\n", argv[0]);
27                 exit (-1);
28         }
29
30         printf ("This test program exercises the following win32 functions:\n");
31         printf ("\tResetPrinter()\n");
32         printf ("\tStartDocPrinter()\n");
33         printf ("\tEndDocPrinter()\n");
34         printf ("\tStartPagePrinter()\n");
35         printf ("\tEndPagePrinter()\n");
36         printf ("\tWritePrinter()\n");
37         printf ("\n\n");
38
39         printf ("This test program exercises both the StartPagePrinter()\n");
40         printf ("and EndPagePrinter() Win32 functions.\n\n");
41
42         if (!OpenPrinter (argv[1], &printer, NULL))
43         {
44                 fprintf (stderr, "Unable to open %s!\n", argv[1]);
45                 exit (-1);
46         }
47         else
48         {
49                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
50         }
51
52         /* set the printer defaults */
53         print_defaults.pDatatype                = _strdup ("RAW");
54         print_defaults.DesiredAccess            = 0;
55         print_defaults.pDevMode                 = NULL;
56         if (ResetPrinter(printer, &print_defaults))
57                 printf ("ResetPrinter call succeeded\n");
58         else
59                 PrintLastError();
60         printf ("\n");
61
62         /* StartDocPrinter */
63         buffer1.pDocName        = _strdup("Testing Printer");
64         buffer1.pDatatype       = _strdup("RAW");
65         buffer1.pOutputFile     = NULL;
66
67         printf ("Attempting to call StartDocPrinter() using DOC_INFO_1 :\n");
68         print_doc_info_1 (&buffer1);
69         printf ("\n");
70
71         if (StartDocPrinter (printer, 1, (LPBYTE)&buffer1))
72                 printf ("StartDocPrinter called successfully\n");
73         else
74                 PrintLastError();
75         printf ("\n");
76
77
78         if (StartPagePrinter(printer))
79         {
80                 printf ("StartPagePrinter returned success.\n");
81
82                 if ((fd=_open(argv[2], _O_RDONLY)) == -1)
83                 {
84                         fprintf (stderr, "ERROR: Unable to open [%s] for read access!\n", argv[2]);
85                         ClosePrinter (printer);
86                         exit (-1);
87                 }
88
89                 while ((bytes=_read(fd, buffer, 256)) != 0)
90                 {
91                         if (!WritePrinter(printer, (LPVOID)buffer, bytes, &wrote))
92                         {
93                                 fprintf (stderr, "ERROR: WritePrinter failed for [%d] bytes!\n", bytes);
94                                 PrintLastError();
95                         }
96                         else
97                                 printf ("Successfully wrote [%d] bytes to the printer\n", bytes);
98                 }
99                 _close (fd);
100
101                 if (EndPagePrinter (printer))
102                         printf ("EndPagePrinter returned success.\n");
103                 else
104                         PrintLastError();
105         }
106         else
107                 PrintLastError();
108         printf ("\n");
109
110         printf ("Attempting to call EndDocPrinter\n");
111         if (EndDocPrinter (printer))
112                 printf ("EndDocPrinter called successfully\n");
113         else
114                 PrintLastError();
115         printf ("\n");
116
117
118
119         if (!ClosePrinter(printer))
120         {
121                 fprintf (stderr, "Error closing printer!\n");
122                 exit (-1);
123         }
124         else
125         {
126                 printf ("Printer [%s] closed successfully.\n", argv[1]);
127         }
128
129         return 0;
130
131 }