• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NeedRename
52  * @tc.desc: Verify the PrintExtensionInfo function.
53  * @tc.type: FUNC
54  * @tc.require:
55  */
56 HWTEST_F(PrintJobTest, PrintJobTest_0002_NeedRename, 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_NeedRename
85  * @tc.desc: Verify the SetExtensionId function.
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(PrintJobTest, PrintJobTest_0003_NeedRename, 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: DupFdlist_ShouldReturnSameFd
104  * @tc.desc: Verify the DupFdlist function.
105  * @tc.type: FUNC
106  * @tc.require:
107  */
108 HWTEST_F(PrintJobTest, DupFdlist_WhenBadfd_ShouldReturnSameFd, TestSize.Level1)
109 {
110     PrintJob job;
111     std::vector<uint32_t> fdList = { 997, 998, 999 };
112     std::vector<uint32_t> dupFdList;
113     job.SetFdList(fdList);
114     job.DupFdList(dupFdList);
115     EXPECT_EQ(fdList.size(), dupFdList.size());
116     for (size_t index = 0; index < fdList.size(); index++) {
117         EXPECT_EQ(fdList[index], dupFdList[index]);
118     }
119 }
120 
121 /**
122  * @tc.name: PrintJobTest_0004_NeedRename
123  * @tc.desc: Verify the SetVendorId function.
124  * @tc.type: FUNC
125  * @tc.require:
126  */
127 HWTEST_F(PrintJobTest, PrintJobTest_0004_NeedRename, TestSize.Level1)
128 {
129     PrintJob job;
130     job.SetJobId("jobid-1234");
131     EXPECT_EQ(job.GetJobId(), "jobid-1234");
132 }
133 
134 /**
135  * @tc.name: PrintJobTest_0005_NeedRename
136  * @tc.desc: Verify the SetVendorIcon function.
137  * @tc.type: FUNC
138  * @tc.require:
139  */
140 HWTEST_F(PrintJobTest, PrintJobTest_0005_NeedRename, TestSize.Level1)
141 {
142     PrintJob job;
143     job.SetPrinterId("printid-1234");
144     EXPECT_EQ(job.GetPrinterId(), "printid-1234");
145 }
146 
147 /**
148  * @tc.name: PrintJobTest_0006_NeedRename
149  * @tc.desc: Verify the SetVendorName function.
150  * @tc.type: FUNC
151  * @tc.require:
152  */
153 HWTEST_F(PrintJobTest, PrintJobTest_0006_NeedRename, TestSize.Level1)
154 {
155     PrintJob job;
156     job.SetJobState(PRINT_JOB_BLOCKED);
157     EXPECT_EQ(job.GetJobState(), PRINT_JOB_BLOCKED);
158 }
159 
160 /**
161  * @tc.name: PrintJobTest_0007_NeedRename
162  * @tc.desc: Verify the SetVendorName function.
163  * @tc.type: FUNC
164  * @tc.require:
165  */
166 HWTEST_F(PrintJobTest, PrintJobTest_0007_NeedRename, TestSize.Level1)
167 {
168     PrintJob job;
169     job.SetJobState(PRINT_JOB_UNKNOWN + 1);
170     EXPECT_EQ(job.GetJobState(), PRINT_JOB_PREPARED);
171 }
172 
173 /**
174  * @tc.name: PrintJobTest_0008_NeedRename
175  * @tc.desc: Verify the SetVendorName function.
176  * @tc.type: FUNC
177  * @tc.require:
178  */
179 HWTEST_F(PrintJobTest, PrintJobTest_0008_NeedRename, TestSize.Level1)
180 {
181     PrintJob job;
182     job.SetJobState(PRINT_JOB_COMPLETED);
183     job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
184     EXPECT_EQ(job.GetSubState(), PRINT_JOB_COMPLETED_FILE_CORRUPT);
185 }
186 
187 /**
188  * @tc.name: PrintJobTest_0009_NeedRename
189  * @tc.desc: Verify the SetVendorName function.
190  * @tc.type: FUNC
191  * @tc.require:
192  */
193 HWTEST_F(PrintJobTest, PrintJobTest_0009_NeedRename, TestSize.Level1)
194 {
195     PrintJob job;
196     job.SetJobState(PRINT_JOB_COMPLETED);
197     job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
198     EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_OFFLINE);
199 }
200 
201 /**
202  * @tc.name: PrintJobTest_0010_NeedRename
203  * @tc.desc: Verify the SetVendorName function.
204  * @tc.type: FUNC
205  * @tc.require:
206  */
207 HWTEST_F(PrintJobTest, PrintJobTest_0010_NeedRename, TestSize.Level1)
208 {
209     PrintJob job;
210     job.SetJobState(PRINT_JOB_BLOCKED);
211     job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
212     EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_OFFLINE);
213 }
214 
215 /**
216  * @tc.name: PrintJobTest_0011_NeedRename
217  * @tc.desc: Verify the SetVendorName function.
218  * @tc.type: FUNC
219  * @tc.require:
220  */
221 HWTEST_F(PrintJobTest, PrintJobTest_0011_NeedRename, TestSize.Level1)
222 {
223     PrintJob job;
224     job.SetJobState(PRINT_JOB_BLOCKED);
225     job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
226     EXPECT_EQ(job.GetSubState(), PRINT_JOB_COMPLETED_FILE_CORRUPT);
227 }
228 
229 /**
230  * @tc.name: PrintJobTest_0012_NeedRename
231  * @tc.desc: Verify the SetVendorName function.
232  * @tc.type: FUNC
233  * @tc.require:
234  */
235 HWTEST_F(PrintJobTest, PrintJobTest_0012_NeedRename, TestSize.Level1)
236 {
237     PrintJob job;
238     job.SetJobState(PRINT_JOB_RUNNING);
239     job.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
240     EXPECT_EQ(job.GetSubState(), PRINT_JOB_COMPLETED_FILE_CORRUPT);
241 }
242 
243 /**
244  * @tc.name: PrintJobTest_0013_NeedRename
245  * @tc.desc: Verify the SetVendorName function.
246  * @tc.type: FUNC
247  * @tc.require:
248  */
249 HWTEST_F(PrintJobTest, PrintJobTest_0013_NeedRename, TestSize.Level1)
250 {
251     PrintJob job;
252     job.SetJobState(PRINT_JOB_RUNNING);
253     job.SetSubState(PRINT_JOB_BLOCKED_OFFLINE);
254     EXPECT_EQ(job.GetSubState(), PRINT_JOB_BLOCKED_OFFLINE);
255 }
256 
257 /**
258  * @tc.name: PrintJobTest_0014_NeedRename
259  * @tc.desc: Verify the SetVendorName function.
260  * @tc.type: FUNC
261  * @tc.require:
262  */
263 HWTEST_F(PrintJobTest, PrintJobTest_0014_NeedRename, TestSize.Level1)
264 {
265     PrintJob job;
266     job.SetCopyNumber(2);
267     EXPECT_EQ(job.GetCopyNumber(), 2);
268 }
269 
270 /**
271  * @tc.name: PrintJobTest_0015_NeedRename
272  * @tc.desc: Verify the SetVendorName function.
273  * @tc.type: FUNC
274  * @tc.require:
275  */
276 HWTEST_F(PrintJobTest, PrintJobTest_0015_NeedRename, TestSize.Level1)
277 {
278     PrintJob job;
279     OHOS::Print::PrintRange range, getRange;
280     range.SetStartPage(1);
281     job.SetPageRange(range);
282     job.GetPageRange(getRange);
283     EXPECT_EQ(getRange.GetStartPage(), 1);
284 }
285 
286 /**
287  * @tc.name: PrintJobTest_0016_NeedRename
288  * @tc.desc: Verify the SetVendorName function.
289  * @tc.type: FUNC
290  * @tc.require:
291  */
292 HWTEST_F(PrintJobTest, PrintJobTest_0016_NeedRename, TestSize.Level1)
293 {
294     PrintJob job;
295     job.SetIsSequential(true);
296     EXPECT_EQ(job.GetIsSequential(), true);
297 }
298 
299 /**
300  * @tc.name: PrintJobTest_0017_NeedRename
301  * @tc.desc: Verify the SetVendorName function.
302  * @tc.type: FUNC
303  * @tc.require:
304  */
305 HWTEST_F(PrintJobTest, PrintJobTest_0017_NeedRename, TestSize.Level1)
306 {
307     PrintJob job;
308     OHOS::Print::PrintPageSize pageSize, getPageSize;
309     pageSize.SetId("pgid-1234");
310     job.SetPageSize(pageSize);
311     job.GetPageSize(getPageSize);
312     EXPECT_EQ(getPageSize.GetId(), "pgid-1234");
313 }
314 
315 /**
316  * @tc.name: PrintJobTest_0018_NeedRename
317  * @tc.desc: Verify the SetVendorName function.
318  * @tc.type: FUNC
319  * @tc.require:
320  */
321 HWTEST_F(PrintJobTest, PrintJobTest_0018_NeedRename, TestSize.Level1)
322 {
323     PrintJob job;
324     job.SetIsLandscape(true);
325     EXPECT_EQ(job.GetIsLandscape(), true);
326 }
327 
328 /**
329  * @tc.name: PrintJobTest_0019_NeedRename
330  * @tc.desc: Verify the SetVendorName function.
331  * @tc.type: FUNC
332  * @tc.require:
333  */
334 HWTEST_F(PrintJobTest, PrintJobTest_0019_NeedRename, TestSize.Level1)
335 {
336     PrintJob job;
337     job.SetColorMode(1);
338     EXPECT_EQ(job.GetColorMode(), 1);
339 }
340 
341 /**
342  * @tc.name: PrintJobTest_0020_NeedRename
343  * @tc.desc: Verify the SetVendorName function.
344  * @tc.type: FUNC
345  * @tc.require:
346  */
347 HWTEST_F(PrintJobTest, PrintJobTest_0020_NeedRename, TestSize.Level1)
348 {
349     PrintJob job;
350     job.SetDuplexMode(1);
351     EXPECT_EQ(job.GetDuplexMode(), 1);
352 }
353 
354 /**
355  * @tc.name: PrintJobTest_0021_NeedRename
356  * @tc.desc: Verify the SetVendorName function.
357  * @tc.type: FUNC
358  * @tc.require:
359  */
360 HWTEST_F(PrintJobTest, PrintJobTest_0021_NeedRename, TestSize.Level1)
361 {
362     PrintJob job, getJob;
363     OHOS::Print::PrintMargin margin, getMargin;
364     margin.SetBottom(1);
365     job.SetMargin(margin);
366     job.GetMargin(getMargin);
367     EXPECT_EQ(job.HasMargin(), true);
368     EXPECT_EQ(getMargin.GetBottom(), 1);
369 }
370 
371 /**
372  * @tc.name: PrintJobTest_0022_NeedRename
373  * @tc.desc: Verify the SetVendorName function.
374  * @tc.type: FUNC
375  * @tc.require:
376  */
377 HWTEST_F(PrintJobTest, PrintJobTest_0022_NeedRename, TestSize.Level1)
378 {
379     PrintJob job;
380     job.SetOption("option-123");
381     EXPECT_EQ(job.HasOption(), true);
382     EXPECT_EQ(job.GetOption(), "option-123");
383 }
384 
385 /**
386  * @tc.name: PrintJobTest_0023_NeedRename
387  * @tc.desc: Verify the SetVendorName function.
388  * @tc.type: FUNC
389  * @tc.require:
390  */
391 HWTEST_F(PrintJobTest, PrintJobTest_0023_NeedRename, TestSize.Level1)
392 {
393     PrintJob job, getJob;
394     OHOS::Print::PrintPreviewAttribute attr, getAttr;
395     attr.SetResult(1);
396     job.SetPreview(attr);
397     job.GetPreview(getAttr);
398     EXPECT_EQ(job.HasPreview(), true);
399     EXPECT_EQ(getAttr.GetResult(), 1);
400 }
401 
402 /**
403  * @tc.name: PrintJobTest_0024_NeedRename
404  * @tc.desc: Verify the SetVendorName function.
405  * @tc.type: FUNC
406  * @tc.require:
407  */
408 HWTEST_F(PrintJobTest, PrintJobTest_0024_NeedRename, TestSize.Level1)
409 {
410     PrintJob job, updateJob;
411     job.SetColorMode(1);
412     job.SetCopyNumber(1);
413     job.SetIsLandscape(true);
414     job.SetIsSequential(true);
415     job.SetJobId("jobId-123");
416     updateJob.UpdateParams(job);
417     EXPECT_EQ(updateJob.GetColorMode(), 1);
418 }
419 
420 /**
421  * @tc.name: PrintJobTest_0025_NeedRename
422  * @tc.desc: Verify the SetVendorName function.
423  * @tc.type: FUNC
424  * @tc.require:
425  */
426 HWTEST_F(PrintJobTest, PrintJobTest_0025_NeedRename, TestSize.Level1)
427 {
428     PrintJob job, jobInfo;
429     Parcel parcel;
430 
431     job.SetIsSequential(true);
432     job.Marshalling(parcel);
433     EXPECT_EQ(job.GetIsSequential(), true);
434 }
435 
436 /**
437  * @tc.name: PrintJobTest_0026_NeedRename
438  * @tc.desc: Verify the SetVendorName function.
439  * @tc.type: FUNC
440  * @tc.require:
441  */
442 HWTEST_F(PrintJobTest, PrintJobTest_0026_NeedRename, TestSize.Level1)
443 {
444     PrintJob job, jobInfo;
445     Parcel parcel;
446     OHOS::Print::PrintPreviewAttribute attr;
447     OHOS::Print::PrintMargin margin;
448 
449     attr.SetResult(1);
450     job.SetPreview(attr);
451     margin.SetBottom(1);
452     job.SetMargin(margin);
453     job.SetOption("option");
454     job.Marshalling(parcel);
455     jobInfo.Unmarshalling(parcel);
456     EXPECT_EQ(jobInfo.GetIsSequential(), false);
457 }
458 
459 /**
460  * @tc.name: PrintJobTest_0027_NeedRename
461  * @tc.desc: Verify the SetVendorName function.
462  * @tc.type: FUNC
463  * @tc.require:
464  */
465 HWTEST_F(PrintJobTest, PrintJobTest_0027_NeedRename, TestSize.Level1)
466 {
467     PrintJob job;
468     std::vector<uint32_t> files = {1, 2, 3};
469     OHOS::Print::PrintRange range;
470     OHOS::Print::PrintPageSize pageSize;
471 
472     job.SetIsSequential(true);
473     PrintJob getJob(job);
474     EXPECT_EQ(getJob.GetIsSequential(), true);
475 }
476 
477 /**
478  * @tc.name: PrintJobTest_0028_NeedRename
479  * @tc.desc: Verify the SetVendorName function.
480  * @tc.type: FUNC
481  * @tc.require:
482  */
483 HWTEST_F(PrintJobTest, PrintJobTest_0028_NeedRename, TestSize.Level1)
484 {
485     PrintJob job;
486     std::vector<uint32_t> files = {1, 2, 3};
487     OHOS::Print::PrintRange range;
488     OHOS::Print::PrintPageSize pageSize;
489 
490     job.SetIsSequential(true);
491     PrintJob getJob = job;
492     EXPECT_EQ(getJob.GetIsSequential(), true);
493 }
494 } // namespace Print
495 } // namespace OHOS
496