1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #define private public
17 #include "print_job.h"
18 #undef private
19 #include "print_page_size.h"
20 #include "print_range.h"
21 #define private public
22 #include "print_margin.h"
23 #undef private
24 #define private public
25 #include "print_preview_attribute.h"
26 #undef private
27 #include "print_log.h"
28 #include "print_constant.h"
29
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Print {
34 class PrintJobTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void PrintJobTest::SetUpTestCase(void) {}
43
TearDownTestCase(void)44 void PrintJobTest::TearDownTestCase(void) {}
45
SetUp(void)46 void PrintJobTest::SetUp(void) {}
47
TearDown(void)48 void PrintJobTest::TearDown(void) {}
49
50 /**
51 * @tc.name: PrintJobTest_0002
52 * @tc.desc: Verify the PrintExtensionInfo function.
53 * @tc.type: FUNC
54 * @tc.require:
55 */
56 HWTEST_F(PrintJobTest, PrintJobTest_0002, TestSize.Level1)
57 {
58 PrintJob job;
59 OHOS::Print::PrintPreviewAttribute attr;
60 OHOS::Print::PrintMargin margin;
61
62 attr.SetResult(1);
63 EXPECT_EQ(attr.hasResult_, true);
64 EXPECT_EQ(attr.result_, 1);
65
66 job.SetPreview(attr);
67 EXPECT_EQ(job.hasPreview_, true);
68
69 margin.SetBottom(1);
70 EXPECT_EQ(margin.hasBottom_, true);
71 EXPECT_EQ(margin.bottom_, 1);
72
73 job.SetMargin(margin);
74 EXPECT_EQ(job.hasMargin_, true);
75
76 job.SetOption("option");
77 EXPECT_EQ(job.hasOption_, true);
78 EXPECT_EQ(job.option_, "option");
79
80 job.Dump();
81 }
82
83 /**
84 * @tc.name: PrintJobTest_0003
85 * @tc.desc: Verify the SetExtensionId function.
86 * @tc.type: FUNC
87 * @tc.require:
88 */
89 HWTEST_F(PrintJobTest, PrintJobTest_0003, TestSize.Level1)
90 {
91 PrintJob job;
92 std::vector<uint32_t> files = {1, 2, 3};
93 std::vector<uint32_t> getFiles;
94 job.SetFdList(files);
95 job.GetFdList(getFiles);
96 EXPECT_EQ(files.size(), getFiles.size());
97 for (size_t index = 0; index < files.size(); index++) {
98 EXPECT_EQ(files[index], getFiles[index]);
99 }
100 }
101
102 /**
103 * @tc.name: PrintJobTest_0004
104 * @tc.desc: Verify the SetVendorId function.
105 * @tc.type: FUNC
106 * @tc.require:
107 */
108 HWTEST_F(PrintJobTest, PrintJobTest_0004, TestSize.Level1)
109 {
110 PrintJob job;
111 job.SetJobId("jobid-1234");
112 EXPECT_EQ(job.GetJobId(), "jobid-1234");
113 }
114
115 /**
116 * @tc.name: PrintJobTest_0005
117 * @tc.desc: Verify the SetVendorIcon function.
118 * @tc.type: FUNC
119 * @tc.require:
120 */
121 HWTEST_F(PrintJobTest, PrintJobTest_0005, TestSize.Level1)
122 {
123 PrintJob job;
124 job.SetPrinterId("printid-1234");
125 EXPECT_EQ(job.GetPrinterId(), "printid-1234");
126 }
127
128 /**
129 * @tc.name: PrintJobTest_0006
130 * @tc.desc: Verify the SetVendorName function.
131 * @tc.type: FUNC
132 * @tc.require:
133 */
134 HWTEST_F(PrintJobTest, PrintJobTest_0006, TestSize.Level1)
135 {
136 PrintJob job;
137 job.SetJobState(PRINT_JOB_BLOCKED);
138 EXPECT_EQ(job.GetJobState(), PRINT_JOB_BLOCKED);
139 }
140
141 /**
142 * @tc.name: PrintJobTest_0007
143 * @tc.desc: Verify the SetVendorName function.
144 * @tc.type: FUNC
145 * @tc.require:
146 */
147 HWTEST_F(PrintJobTest, PrintJobTest_0007, TestSize.Level1)
148 {
149 PrintJob job;
150 job.SetJobState(PRINT_JOB_UNKNOWN + 1);
151 EXPECT_EQ(job.GetJobState(), PRINT_JOB_PREPARED);
152 }
153
154 /**
155 * @tc.name: PrintJobTest_0008
156 * @tc.desc: Verify the SetVendorName function.
157 * @tc.type: FUNC
158 * @tc.require:
159 */
160 HWTEST_F(PrintJobTest, PrintJobTest_0008, TestSize.Level1)
161 {
162 PrintJob job;
163 job.SetJobState(PRINT_JOB_COMPLETED);
164 job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
165 EXPECT_EQ(job.GetSubState(), PRINT_JOB_COMPLETED_FILE_CORRUPT);
166 }
167
168 /**
169 * @tc.name: PrintJobTest_0009
170 * @tc.desc: Verify the SetVendorName function.
171 * @tc.type: FUNC
172 * @tc.require:
173 */
174 HWTEST_F(PrintJobTest, PrintJobTest_0009, TestSize.Level1)
175 {
176 PrintJob job;
177 job.SetJobState(PRINT_JOB_COMPLETED);
178 job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
179 EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_UNKNOWN);
180 }
181
182 /**
183 * @tc.name: PrintJobTest_0010
184 * @tc.desc: Verify the SetVendorName function.
185 * @tc.type: FUNC
186 * @tc.require:
187 */
188 HWTEST_F(PrintJobTest, PrintJobTest_0010, TestSize.Level1)
189 {
190 PrintJob job;
191 job.SetJobState(PRINT_JOB_BLOCKED);
192 job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
193 EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_OFFLINE);
194 }
195
196 /**
197 * @tc.name: PrintJobTest_0011
198 * @tc.desc: Verify the SetVendorName function.
199 * @tc.type: FUNC
200 * @tc.require:
201 */
202 HWTEST_F(PrintJobTest, PrintJobTest_0011, TestSize.Level1)
203 {
204 PrintJob job;
205 job.SetJobState(PRINT_JOB_BLOCKED);
206 job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
207 EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_UNKNOWN);
208 }
209
210 /**
211 * @tc.name: PrintJobTest_0012
212 * @tc.desc: Verify the SetVendorName function.
213 * @tc.type: FUNC
214 * @tc.require:
215 */
216 HWTEST_F(PrintJobTest, PrintJobTest_0012, TestSize.Level1)
217 {
218 PrintJob job;
219 job.SetJobState(PRINT_JOB_RUNNING);
220 job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
221 EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_UNKNOWN);
222 }
223
224 /**
225 * @tc.name: PrintJobTest_0013
226 * @tc.desc: Verify the SetVendorName function.
227 * @tc.type: FUNC
228 * @tc.require:
229 */
230 HWTEST_F(PrintJobTest, PrintJobTest_0013, TestSize.Level1)
231 {
232 PrintJob job;
233 job.SetJobState(PRINT_JOB_RUNNING);
234 job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
235 EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_OFFLINE);
236 }
237
238 /**
239 * @tc.name: PrintJobTest_0014
240 * @tc.desc: Verify the SetVendorName function.
241 * @tc.type: FUNC
242 * @tc.require:
243 */
244 HWTEST_F(PrintJobTest, PrintJobTest_0014, TestSize.Level1)
245 {
246 PrintJob job;
247 job.SetCopyNumber(2);
248 EXPECT_EQ(job.GetCopyNumber(), 2);
249 }
250
251 /**
252 * @tc.name: PrintJobTest_0015
253 * @tc.desc: Verify the SetVendorName function.
254 * @tc.type: FUNC
255 * @tc.require:
256 */
257 HWTEST_F(PrintJobTest, PrintJobTest_0015, TestSize.Level1)
258 {
259 PrintJob job;
260 OHOS::Print::PrintRange range, getRange;
261 range.SetStartPage(1);
262 job.SetPageRange(range);
263 job.GetPageRange(getRange);
264 EXPECT_EQ(getRange.GetStartPage(), 1);
265 }
266
267 /**
268 * @tc.name: PrintJobTest_0016
269 * @tc.desc: Verify the SetVendorName function.
270 * @tc.type: FUNC
271 * @tc.require:
272 */
273 HWTEST_F(PrintJobTest, PrintJobTest_0016, TestSize.Level1)
274 {
275 PrintJob job;
276 job.SetIsSequential(true);
277 EXPECT_EQ(job.GetIsSequential(), true);
278 }
279
280 /**
281 * @tc.name: PrintJobTest_0017
282 * @tc.desc: Verify the SetVendorName function.
283 * @tc.type: FUNC
284 * @tc.require:
285 */
286 HWTEST_F(PrintJobTest, PrintJobTest_0017, TestSize.Level1)
287 {
288 PrintJob job;
289 OHOS::Print::PrintPageSize pageSize, getPageSize;
290 pageSize.SetId("pgid-1234");
291 job.SetPageSize(pageSize);
292 job.GetPageSize(getPageSize);
293 EXPECT_EQ(getPageSize.GetId(), "pgid-1234");
294 }
295
296 /**
297 * @tc.name: PrintJobTest_0018
298 * @tc.desc: Verify the SetVendorName function.
299 * @tc.type: FUNC
300 * @tc.require:
301 */
302 HWTEST_F(PrintJobTest, PrintJobTest_0018, TestSize.Level1)
303 {
304 PrintJob job;
305 job.SetIsLandscape(true);
306 EXPECT_EQ(job.GetIsLandscape(), true);
307 }
308
309 /**
310 * @tc.name: PrintJobTest_0019
311 * @tc.desc: Verify the SetVendorName function.
312 * @tc.type: FUNC
313 * @tc.require:
314 */
315 HWTEST_F(PrintJobTest, PrintJobTest_0019, TestSize.Level1)
316 {
317 PrintJob job;
318 job.SetColorMode(1);
319 EXPECT_EQ(job.GetColorMode(), 1);
320 }
321
322 /**
323 * @tc.name: PrintJobTest_0020
324 * @tc.desc: Verify the SetVendorName function.
325 * @tc.type: FUNC
326 * @tc.require:
327 */
328 HWTEST_F(PrintJobTest, PrintJobTest_0020, TestSize.Level1)
329 {
330 PrintJob job;
331 job.SetDuplexMode(1);
332 EXPECT_EQ(job.GetDuplexMode(), 1);
333 }
334
335 /**
336 * @tc.name: PrintJobTest_0021
337 * @tc.desc: Verify the SetVendorName function.
338 * @tc.type: FUNC
339 * @tc.require:
340 */
341 HWTEST_F(PrintJobTest, PrintJobTest_0021, TestSize.Level1)
342 {
343 PrintJob job, getJob;
344 OHOS::Print::PrintMargin margin, getMargin;
345 margin.SetBottom(1);
346 job.SetMargin(margin);
347 job.GetMargin(getMargin);
348 EXPECT_EQ(job.HasMargin(), true);
349 EXPECT_EQ(getMargin.GetBottom(), 1);
350 }
351
352 /**
353 * @tc.name: PrintJobTest_0022
354 * @tc.desc: Verify the SetVendorName function.
355 * @tc.type: FUNC
356 * @tc.require:
357 */
358 HWTEST_F(PrintJobTest, PrintJobTest_0022, TestSize.Level1)
359 {
360 PrintJob job;
361 job.SetOption("option-123");
362 EXPECT_EQ(job.HasOption(), true);
363 EXPECT_EQ(job.GetOption(), "option-123");
364 }
365
366 /**
367 * @tc.name: PrintJobTest_0023
368 * @tc.desc: Verify the SetVendorName function.
369 * @tc.type: FUNC
370 * @tc.require:
371 */
372 HWTEST_F(PrintJobTest, PrintJobTest_0023, TestSize.Level1)
373 {
374 PrintJob job, getJob;
375 OHOS::Print::PrintPreviewAttribute attr, getAttr;
376 attr.SetResult(1);
377 job.SetPreview(attr);
378 job.GetPreview(getAttr);
379 EXPECT_EQ(job.HasPreview(), true);
380 EXPECT_EQ(getAttr.GetResult(), 1);
381 }
382
383 /**
384 * @tc.name: PrintJobTest_0024
385 * @tc.desc: Verify the SetVendorName function.
386 * @tc.type: FUNC
387 * @tc.require:
388 */
389 HWTEST_F(PrintJobTest, PrintJobTest_0024, TestSize.Level1)
390 {
391 PrintJob job, updateJob;
392 job.SetColorMode(1);
393 job.SetCopyNumber(1);
394 job.SetIsLandscape(true);
395 job.SetIsSequential(true);
396 job.SetJobId("jobId-123");
397 updateJob.UpdateParams(job);
398 EXPECT_EQ(updateJob.GetColorMode(), 1);
399 }
400
401 /**
402 * @tc.name: PrintJobTest_0025
403 * @tc.desc: Verify the SetVendorName function.
404 * @tc.type: FUNC
405 * @tc.require:
406 */
407 HWTEST_F(PrintJobTest, PrintJobTest_0025, TestSize.Level1)
408 {
409 PrintJob job, jobInfo;
410 Parcel parcel;
411
412 job.SetIsSequential(true);
413 job.Marshalling(parcel);
414 }
415
416 /**
417 * @tc.name: PrintJobTest_0026
418 * @tc.desc: Verify the SetVendorName function.
419 * @tc.type: FUNC
420 * @tc.require:
421 */
422 HWTEST_F(PrintJobTest, PrintJobTest_0026, TestSize.Level1)
423 {
424 PrintJob job, jobInfo;
425 Parcel parcel;
426 OHOS::Print::PrintPreviewAttribute attr;
427 OHOS::Print::PrintMargin margin;
428
429 attr.SetResult(1);
430 job.SetPreview(attr);
431 margin.SetBottom(1);
432 job.SetMargin(margin);
433 job.SetOption("option");
434 job.Marshalling(parcel);
435 jobInfo.Unmarshalling(parcel);
436 EXPECT_EQ(jobInfo.GetIsSequential(), false);
437 }
438
439 /**
440 * @tc.name: PrintJobTest_0027
441 * @tc.desc: Verify the SetVendorName function.
442 * @tc.type: FUNC
443 * @tc.require:
444 */
445 HWTEST_F(PrintJobTest, PrintJobTest_0027, TestSize.Level1)
446 {
447 PrintJob job;
448 std::vector<uint32_t> files = {1, 2, 3};
449 OHOS::Print::PrintRange range;
450 OHOS::Print::PrintPageSize pageSize;
451
452 job.SetIsSequential(true);
453 PrintJob getJob(job);
454 EXPECT_EQ(getJob.GetIsSequential(), true);
455 }
456
457 /**
458 * @tc.name: PrintJobTest_0028
459 * @tc.desc: Verify the SetVendorName function.
460 * @tc.type: FUNC
461 * @tc.require:
462 */
463 HWTEST_F(PrintJobTest, PrintJobTest_0028, TestSize.Level1)
464 {
465 PrintJob job;
466 std::vector<uint32_t> files = {1, 2, 3};
467 OHOS::Print::PrintRange range;
468 OHOS::Print::PrintPageSize pageSize;
469
470 job.SetIsSequential(true);
471 PrintJob getJob = job;
472 EXPECT_EQ(getJob.GetIsSequential(), true);
473 }
474 } // namespace Print
475 } // namespace OHOS
476