s4-smbtorture: add test_netprintjob() to RAP-PRINTING.
[samba.git] / source4 / torture / rap / printing.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for SMB printing operations
4
5    Copyright (C) Guenther Deschner 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 #include "includes.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/libcli.h"
24 #include "torture/torture.h"
25 #include "torture/util.h"
26 #include "system/filesys.h"
27
28 #include "torture/smbtorture.h"
29 #include "torture/util.h"
30 #include "../librpc/gen_ndr/rap.h"
31 #include "torture/rap/proto.h"
32 #include "param/param.h"
33
34
35 #define TORTURE_PRINT_FILE "torture_print_file"
36
37 static bool test_raw_print(struct torture_context *tctx,
38                            struct smbcli_state *cli)
39 {
40         int fnum;
41         DATA_BLOB data;
42         ssize_t size_written;
43         const char *str;
44
45         fnum = smbcli_open(cli->tree, TORTURE_PRINT_FILE, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
46         if (fnum == -1) {
47                 torture_fail(tctx, "failed to open file");
48         }
49
50         str = talloc_asprintf(tctx, "TortureTestPage: %d\nData\n",0);
51
52         data = data_blob_string_const(str);
53
54         size_written = smbcli_write(cli->tree, fnum, 0, data.data, 0, data.length);
55         if (size_written != data.length) {
56                 torture_fail(tctx, "failed to write file");
57         }
58
59         torture_assert_ntstatus_ok(tctx,
60                 smbcli_close(cli->tree, fnum),
61                 "failed to close file");
62
63         return true;
64 }
65
66 static bool test_netprintqenum(struct torture_context *tctx,
67                                struct smbcli_state *cli)
68 {
69         struct rap_NetPrintQEnum r;
70         int i, q;
71         uint16_t levels[] = { 0, 1, 3, 5 };
72         NTSTATUS status;
73
74         for (i=0; i < ARRAY_SIZE(levels); i++) {
75
76                 r.in.level = levels[i];
77                 r.in.bufsize = 8192;
78
79                 torture_comment(tctx,
80                         "Testing rap_NetPrintQEnum level %d\n", r.in.level);
81
82                 status = smbcli_rap_netprintqenum(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r);
83                 if (!NT_STATUS_IS_OK(status)) {
84                         torture_warning(tctx, "smbcli_rap_netprintqenum failed with %s\n", nt_errstr(status));
85                         continue;
86                 }
87
88                 for (q=0; q<r.out.count; q++) {
89                         switch (r.in.level) {
90                         case 0:
91                                 printf("%s\n", r.out.info[q].info0.PrintQName);
92                                 break;
93                         }
94                 }
95         }
96
97         return true;
98 }
99
100 static bool test_netprintqgetinfo(struct torture_context *tctx,
101                                   struct smbcli_state *cli)
102 {
103         struct rap_NetPrintQGetInfo r;
104         struct rap_NetPrintQEnum r_enum;
105         int i, p;
106         uint16_t levels[] = { 0, 1, 3, 5 };
107         NTSTATUS status;
108
109         r_enum.in.level = 5;
110         r_enum.in.bufsize = 8192;
111
112         torture_assert_ntstatus_ok(tctx,
113                 smbcli_rap_netprintqenum(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r_enum),
114                 "failed to enum printq");
115
116         for (p=0; p < r_enum.out.count; p++) {
117
118                 for (i=0; i < ARRAY_SIZE(levels); i++) {
119
120                         r.in.level = levels[i];
121                         r.in.bufsize = 8192;
122                         r.in.PrintQueueName = r_enum.out.info[p].info5.PrintQueueName;
123
124                         torture_comment(tctx, "Testing rap_NetPrintQGetInfo(%s) level %d\n",
125                                 r.in.PrintQueueName, r.in.level);
126
127                         status = smbcli_rap_netprintqgetinfo(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r);
128                         if (!NT_STATUS_IS_OK(status)) {
129                                 torture_warning(tctx, "smbcli_rap_netprintqgetinfo failed with %s\n", nt_errstr(status));
130                                 continue;
131                         }
132
133                         switch (r.in.level) {
134                         case 0:
135                                 printf("%s\n", r.out.info.info0.PrintQName);
136                                 break;
137                         }
138                 }
139         }
140
141         return true;
142 }
143
144 static bool test_netprintjob_pause(struct torture_context *tctx,
145                                    struct smbcli_state *cli,
146                                    uint16_t job_id)
147 {
148         struct rap_NetPrintJobPause r;
149
150         r.in.JobID = job_id;
151
152         torture_comment(tctx, "Testing rap_NetPrintJobPause(%d)\n", r.in.JobID);
153
154         torture_assert_ntstatus_ok(tctx,
155                 smbcli_rap_netprintjobpause(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
156                 "smbcli_rap_netprintjobpause failed");
157
158         return true;
159 }
160
161 static bool test_netprintjob_continue(struct torture_context *tctx,
162                                       struct smbcli_state *cli,
163                                       uint16_t job_id)
164 {
165         struct rap_NetPrintJobContinue r;
166
167         r.in.JobID = job_id;
168
169         torture_comment(tctx, "Testing rap_NetPrintJobContinue(%d)\n", r.in.JobID);
170
171         torture_assert_ntstatus_ok(tctx,
172                 smbcli_rap_netprintjobcontinue(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
173                 "smbcli_rap_netprintjobcontinue failed");
174
175         return true;
176 }
177
178 static bool test_netprintjob_delete(struct torture_context *tctx,
179                                     struct smbcli_state *cli,
180                                     uint16_t job_id)
181 {
182         struct rap_NetPrintJobDelete r;
183
184         r.in.JobID = job_id;
185
186         torture_comment(tctx, "Testing rap_NetPrintJobDelete(%d)\n", r.in.JobID);
187
188         torture_assert_ntstatus_ok(tctx,
189                 smbcli_rap_netprintjobdelete(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
190                 "smbcli_rap_netprintjobdelete failed");
191
192         return true;
193 }
194
195 static bool test_netprintjob(struct torture_context *tctx,
196                              struct smbcli_state *cli)
197 {
198         uint16_t job_id = 400;
199
200         torture_assert(tctx,
201                 test_netprintjob_pause(tctx, cli, job_id),
202                 "failed to pause job");
203         torture_assert(tctx,
204                 test_netprintjob_continue(tctx, cli, job_id),
205                 "failed to continue job");
206         torture_assert(tctx,
207                 test_netprintjob_delete(tctx, cli, job_id),
208                 "failed to delete job");
209
210         return true;
211 }
212
213 static bool test_rap_print(struct torture_context *tctx,
214                            struct smbcli_state *cli)
215 {
216         /*
217         pause printer
218         print printfile
219         enumjobs printer
220         delete job
221         start printer
222         */
223
224         return true;
225 }
226
227 struct torture_suite *torture_rap_printing(TALLOC_CTX *mem_ctx)
228 {
229         struct torture_suite *suite = torture_suite_create(mem_ctx, "PRINTING");
230
231         torture_suite_add_1smb_test(suite, "raw_print", test_raw_print);
232         torture_suite_add_1smb_test(suite, "rap_print", test_rap_print);
233         torture_suite_add_1smb_test(suite, "rap_printq_enum", test_netprintqenum);
234         torture_suite_add_1smb_test(suite, "rap_printq_getinfo", test_netprintqgetinfo);
235         torture_suite_add_1smb_test(suite, "rap_printjob", test_netprintjob);
236
237         return suite;
238 }