1 /*
2 * Copyright (c) 2023 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
16 #include <thread>
17 #include <gtest/gtest.h>
18 #define private public
19 #include "print_cups_client.h"
20 #undef private
21 #include "print_constant.h"
22 #include "print_log.h"
23 #include "fstream"
24 #define private public
25 #include "print_service_ability.h"
26 #undef private
27
28 using namespace testing::ext;
29 using json = nlohmann::json;
30
31 namespace OHOS {
32 namespace Print {
33 static constexpr const char *JOB_OPTIONS =
34 "{\"jobName\":\"xx\",\"jobNum\":1,\"mediaType\":\"stationery\",\"documentCategory\":0,\"printQuality\":\"4\","
35 "\"printerName\":\"printer1\",\"printerUri\":\"ipp://192.168.0.1:111/ipp/print\",\"borderless\":true,"
36 "\"documentFormat\":\"application/pdf\",\"files\":[\"/data/1.pdf\"],\"isAutoRotate\":true}";
37
38 const uint32_t DIR_MODE = 0771;
39
40 static const std::string PRINTER_STATE_NONE = "none";
41 static const std::string PRINTER_STATE_MEDIA_EMPTY = "media-empty";
42 static const std::string PRINTER_STATE_MEDIA_JAM = "media-jam";
43 static const std::string PRINTER_STATE_PAUSED = "paused";
44 static const std::string PRINTER_STATE_TONER_LOW = "toner-low";
45 static const std::string PRINTER_STATE_TONER_EMPTY = "toner-empty";
46 static const std::string PRINTER_STATE_DOOR_EMPTY = "door-open";
47 static const std::string PRINTER_STATE_MEDIA_NEEDED = "media-needed";
48 static const std::string PRINTER_STATE_MARKER_LOW = "marker-supply-low";
49 static const std::string PRINTER_STATE_MARKER_EMPTY = "marker-supply-empty";
50 static const std::string PRINTER_STATE_INK_EMPTY = "marker-ink-almost-empty";
51 static const std::string PRINTER_STATE_COVER_OPEN = "cover-open";
52 static const std::string PRINTER_STATE_OFFLINE = "offline";
53
54 class PrintCupsClientTest : public testing::Test {
55 public:
56 static void SetUpTestCase(void);
57 static void TearDownTestCase(void);
58 void SetUp();
59 void TearDown();
60 std::string GetDefaultJobId();
61 };
62
SetUpTestCase(void)63 void PrintCupsClientTest::SetUpTestCase(void)
64 {}
65
TearDownTestCase(void)66 void PrintCupsClientTest::TearDownTestCase(void)
67 {}
68
SetUp(void)69 void PrintCupsClientTest::SetUp(void)
70 {
71 static int32_t testNo = 0;
72 PRINT_HILOGI("PrintCupsClientTest_%{public}d", ++testNo);
73 }
74
TearDown(void)75 void PrintCupsClientTest::TearDown(void)
76 {}
77
GetDefaultJobId()78 std::string PrintCupsClientTest::GetDefaultJobId()
79 {
80 return std::to_string(0);
81 }
82
83 /**
84 * @tc.name: PrintCupsClientTest_0001
85 * @tc.desc: StartCupsdService
86 * @tc.type: FUNC
87 * @tc.require:
88 */
89 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0001, TestSize.Level1)
90 {
91 OHOS::Print::PrintCupsClient printCupsClient;
92 int32_t ret = printCupsClient.StartCupsdService();
93 EXPECT_EQ(ret, E_PRINT_NONE);
94 }
95
96 /**
97 * @tc.name: PrintCupsClientTest_0002
98 * @tc.desc: ChangeFilterPermission
99 * @tc.type: FUNC
100 * @tc.require:
101 */
102 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0002, TestSize.Level1)
103 {
104 OHOS::Print::PrintCupsClient printCupsClient;
105 std::string path = "";
106 mode_t mode = 16;
107 EXPECT_EQ(printCupsClient.ChangeFilterPermission(path, mode), false);
108 }
109
110 /**
111 * @tc.name: PrintCupsClientTest_0003
112 * @tc.desc: SymlinkDirectory
113 * @tc.type: FUNC
114 * @tc.require:
115 */
116 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0003, TestSize.Level1)
117 {
118 OHOS::Print::PrintCupsClient printCupsClient;
119 const char *srcDir = "./PrintCupsClientTest_0003_srcDir";
120 const char *destDir = "./PrintCupsClientTest_0003_destDir";
121
122 if (access(srcDir, F_OK) != 0) {
123 mkdir(srcDir, DIR_MODE);
124 }
125 if (access(destDir, F_OK) != 0) {
126 mkdir (destDir, DIR_MODE);
127 }
128
129 std::string srcFilePath = "./PrintCupsClientTest_0003_srcDir/PrintCupsClientTestFileName";
130 std::ofstream testSrcFile(srcFilePath.c_str(), std::ios::out);
131 EXPECT_EQ(testSrcFile.is_open(), true);
132 testSrcFile.close();
133
134 printCupsClient.SymlinkDirectory(srcDir, destDir);
135
136 struct stat destDirstat = {};
137 EXPECT_EQ(lstat((std::string(destDir)
138 + "/PrintCupsClientTestFileName").c_str(), &destDirstat), 0);
139 EXPECT_EQ(S_ISLNK(destDirstat.st_mode), true);
140
141 EXPECT_GE(std::filesystem::remove_all(std::filesystem::current_path() / srcDir), 0);
142 EXPECT_GE(std::filesystem::remove_all(std::filesystem::current_path() / destDir), 0);
143 }
144
145 /**
146 * @tc.name: PrintCupsClientTest_0004
147 * @tc.desc: CopyDirectory
148 * @tc.type: FUNC
149 * @tc.require:
150 */
151 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0004, TestSize.Level1)
152 {
153 OHOS::Print::PrintCupsClient printCupsClient;
154 const char *srcDir = "./PrintCupsClientTest_0004_srcDir";
155 const char *destDir = "./PrintCupsClientTest_0004_destDir";
156 const char *subSrcDir = "PrintCupsClientTest_0004_srcDir/PrintCupsClientTest";
157
158 if (access(srcDir, F_OK) != 0) {
159 mkdir(srcDir, DIR_MODE);
160 }
161
162 if (access(destDir, F_OK) != 0) {
163 mkdir(destDir, DIR_MODE);
164 }
165
166 if (access(subSrcDir, F_OK) != 0) {
167 mkdir(subSrcDir, DIR_MODE);
168 }
169
170 std::string srcFilePath = std::string(subSrcDir) + "/PrintCupsClientTestFileName";
171 std::ofstream testSrcFile(srcFilePath.c_str(), std::ios::out);
172 EXPECT_EQ(testSrcFile.is_open(), true);
173 testSrcFile.close();
174
175 printCupsClient.CopyDirectory(srcDir, destDir);
176
177 EXPECT_EQ(std::filesystem::is_regular_file(
178 std::string(destDir) + "/PrintCupsClientTest/PrintCupsClientTestFileName"),
179 true);
180 EXPECT_GE(std::filesystem::remove_all(std::filesystem::current_path() / srcDir), 0);
181 EXPECT_GE(std::filesystem::remove_all(std::filesystem::current_path() / destDir), 0);
182 }
183
184 /**
185 * @tc.name: PrintCupsClientTest_0005
186 * @tc.desc: InitCupsResources
187 * @tc.type: FUNC
188 * @tc.require:
189 */
190 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0005, TestSize.Level1)
191 {
192 OHOS::Print::PrintCupsClient printCupsClient;
193 int32_t ret = printCupsClient.InitCupsResources();
194 EXPECT_EQ(ret, E_PRINT_NONE);
195 }
196
197 /**
198 * @tc.name: PrintCupsClientTest_0006
199 * @tc.desc: StopCupsdService
200 * @tc.type: FUNC
201 * @tc.require:
202 */
203 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0006, TestSize.Level1)
204 {
205 OHOS::Print::PrintCupsClient printCupsClient;
206 int32_t ret = printCupsClient.StartCupsdService();
207 EXPECT_EQ(ret, E_PRINT_NONE);
208 printCupsClient.StopCupsdService();
209 }
210
211 /**
212 * @tc.name: PrintCupsClientTest_0008
213 * @tc.desc: SetDefaultPrinter
214 * @tc.type: FUNC
215 * @tc.require:
216 */
217 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0008, TestSize.Level1)
218 {
219 OHOS::Print::PrintCupsClient printCupsClient;
220 std::string printerName = "DIRECT-PixLab_V1-0105";
221 printCupsClient.SetDefaultPrinter(printerName);
222 printCupsClient.StartCupsdService();
223 printCupsClient.SetDefaultPrinter(printerName);
224 }
225
226 /**
227 * @tc.name: PrintCupsClientTest_0009
228 * @tc.desc: QueryPrinterInfoByPrinterId
229 * @tc.type: FUNC
230 * @tc.require:
231 */
232 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0009, TestSize.Level1)
233 {
234 OHOS::Print::PrintCupsClient printCupsClient;
235 std::string printerName = "DIRECT-PixLab_V1-0105";
236 std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-0105";
237 PrinterInfo info;
238 info.SetPrinterName(printerName);
239 printCupsClient.QueryPrinterInfoByPrinterId(printerId, info);
240 }
241
242 /**
243 * @tc.name: PrintCupsClientTest_0012
244 * @tc.desc: QueryPrinterCapabilityByUri
245 * @tc.type: FUNC
246 * @tc.require:
247 */
248 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0012, TestSize.Level1)
249 {
250 OHOS::Print::PrintCupsClient printCupsClient;
251 std::string printerUri = "ipp://192.168.186.1:631/ipp/print";
252 std::string printerId = "1";
253 PrinterCapability printerCaps;
254 int32_t ret = printCupsClient.QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps);
255 EXPECT_EQ(ret, E_PRINT_SERVER_FAILURE);
256 }
257
258 /**
259 * @tc.name: PrintCupsClientTest_0013
260 * @tc.desc: AddCupsPrintJob
261 * @tc.type: FUNC
262 * @tc.require:
263 */
264 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0013, TestSize.Level1)
265 {
266 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
267 PrintJob testJob;
268 printCupsClient->AddCupsPrintJob(testJob);
269 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
270 }
271
272 /**
273 * @tc.name: PrintCupsClientTest_0014
274 * @tc.desc: AddCupsPrintJob
275 * @tc.type: FUNC
276 * @tc.require:
277 */
278 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0014, TestSize.Level1)
279 {
280 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
281 PrintJob testJob;
282 testJob.SetJobId(GetDefaultJobId());
283 std::vector<uint32_t> files = {1};
284 testJob.SetFdList(files);
285 testJob.SetColorMode(1);
286 testJob.SetCopyNumber(1);
287 testJob.SetDuplexMode(0);
288 OHOS::Print::PrintPageSize pageSize;
289 pageSize.SetId("pgid-1234");
290 testJob.SetPageSize(pageSize);
291 testJob.SetPrinterId("printid-1234");
292 testJob.SetOption(JOB_OPTIONS);
293 printCupsClient->AddCupsPrintJob(testJob);
294 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
295 }
296
297 /**
298 * @tc.name: PrintCupsClientTest_0015
299 * @tc.desc: StartNextJob
300 * @tc.type: FUNC
301 * @tc.require:
302 */
303 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0015, TestSize.Level1)
304 {
305 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
306 printCupsClient->toCups_ = false;
307 printCupsClient->StartNextJob();
308 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
309 }
310
311 /**
312 * @tc.name: PrintCupsClientTest_0016
313 * @tc.desc: StartNextJob
314 * @tc.type: FUNC
315 * @tc.require:
316 */
317 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0016, TestSize.Level1)
318 {
319 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
320 PrintJob testJob;
321 testJob.SetJobId(GetDefaultJobId());
322 std::vector<uint32_t> files = {1};
323 testJob.SetFdList(files);
324 OHOS::Print::PrintPageSize pageSize;
325 pageSize.SetId("pgid-1234");
326 testJob.SetPageSize(pageSize);
327 testJob.SetPrinterId("printid-1234");
328 testJob.SetOption(JOB_OPTIONS);
329 JobParameters *jobParams = printCupsClient->BuildJobParameters(testJob);
330 printCupsClient->jobQueue_.push_back(jobParams);
331 printCupsClient->toCups_ = false;
332 printCupsClient->StartNextJob();
333 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
334 delete jobParams;
335 }
336
337 /**
338 * @tc.name: PrintCupsClientTest_0018
339 * @tc.desc: StartNextJob
340 * @tc.type: FUNC
341 * @tc.require:
342 */
343 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0018, TestSize.Level1)
344 {
345 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
346 JobParameters *jobParams = nullptr;
347 printCupsClient->jobQueue_.push_back(jobParams);
348 printCupsClient->toCups_ = false;
349 printCupsClient->StartNextJob();
350 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
351 delete jobParams;
352 }
353
354 /**
355 * @tc.name: PrintCupsClientTest_0019
356 * @tc.desc: JobCompleteCallback
357 * @tc.type: FUNC
358 * @tc.require:
359 */
360 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0019, TestSize.Level1)
361 {
362 auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
363 printCupsClient->JobCompleteCallback();
364 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
365 }
366
367 /**
368 * @tc.name: PrintCupsClientTest_0021
369 * @tc.desc: FillBorderlessOptions
370 * @tc.type: FUNC
371 * @tc.require:
372 */
373 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0021, TestSize.Level1)
374 {
375 OHOS::Print::PrintCupsClient printCupsClient;
376 PrintJob testJob;
377 testJob.SetJobId(GetDefaultJobId());
378 std::vector<uint32_t> files = {1};
379 testJob.SetFdList(files);
380 OHOS::Print::PrintPageSize pageSize;
381 pageSize.SetId("pgid-1234");
382 testJob.SetPageSize(pageSize);
383 testJob.SetPrinterId("printid-1234");
384 testJob.SetOption(JOB_OPTIONS);
385 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
386 jobParams->borderless = 1;
387 jobParams->mediaSize = "";
388 jobParams->mediaType = "";
389 int numOptions = 0;
390 cups_option_t *options = nullptr;
391 printCupsClient.FillBorderlessOptions(jobParams, numOptions, &options);
392 EXPECT_EQ(numOptions, 0);
393 delete jobParams;
394 delete options;
395 }
396
397 /**
398 * @tc.name: PrintCupsClientTest_0022
399 * @tc.desc: FillBorderlessOptions
400 * @tc.type: FUNC
401 * @tc.require:
402 */
403 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0022, TestSize.Level1)
404 {
405 OHOS::Print::PrintCupsClient printCupsClient;
406 PrintJob testJob;
407 testJob.SetJobId(GetDefaultJobId());
408 std::vector<uint32_t> files = {1};
409 testJob.SetFdList(files);
410 OHOS::Print::PrintPageSize pageSize;
411 pageSize.SetId("pgid-1234");
412 testJob.SetPageSize(pageSize);
413 testJob.SetPrinterId("printid-1234");
414 testJob.SetOption(JOB_OPTIONS);
415 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
416 jobParams->mediaSize = "testMediaSize";
417 jobParams->mediaType = "testMediaType";
418 int numOptions = 0;
419 cups_option_t *options = nullptr;
420 printCupsClient.FillBorderlessOptions(jobParams, numOptions, &options);
421 EXPECT_EQ(numOptions, 0);
422 delete jobParams;
423 delete options;
424 }
425
426 /**
427 * @tc.name: PrintCupsClientTest_0023
428 * @tc.desc: FillBorderlessOptions
429 * @tc.type: FUNC
430 * @tc.require:
431 */
432 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0023, TestSize.Level1)
433 {
434 OHOS::Print::PrintCupsClient printCupsClient;
435 PrintJob testJob;
436 testJob.SetJobId(GetDefaultJobId());
437 std::vector<uint32_t> files = {1};
438 testJob.SetFdList(files);
439 OHOS::Print::PrintPageSize pageSize;
440 pageSize.SetId("pgid-1234");
441 testJob.SetPageSize(pageSize);
442 testJob.SetPrinterId("printid-1234");
443 testJob.SetOption(JOB_OPTIONS);
444 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
445 jobParams->borderless = 0;
446 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
447 int numOptions = 0;
448 cups_option_t *options = nullptr;
449 int ret = printCupsClient.FillBorderlessOptions(jobParams, numOptions, &options);
450 EXPECT_EQ(ret, 2);
451 delete jobParams;
452 delete options;
453 }
454
455 /**
456 * @tc.name: PrintCupsClientTest_0024
457 * @tc.desc: FillBorderlessOptions
458 * @tc.type: FUNC
459 * @tc.require:
460 */
461 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0024, TestSize.Level1)
462 {
463 OHOS::Print::PrintCupsClient printCupsClient;
464 PrintJob testJob;
465 testJob.SetJobId(GetDefaultJobId());
466 std::vector<uint32_t> files = {1};
467 testJob.SetFdList(files);
468 OHOS::Print::PrintPageSize pageSize;
469 pageSize.SetId("pgid-1234");
470 testJob.SetPageSize(pageSize);
471 testJob.SetPrinterId("printid-1234");
472 testJob.SetOption(JOB_OPTIONS);
473 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
474 jobParams->borderless = 1;
475 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
476 jobParams->mediaSize = CUPS_MEDIA_4X6;
477 int numOptions = 0;
478 cups_option_t *options = nullptr;
479 int ret = printCupsClient.FillBorderlessOptions(jobParams, numOptions, &options);
480 EXPECT_EQ(ret, 2);
481 delete jobParams;
482 delete options;
483 }
484
485 /**
486 * @tc.name: PrintCupsClientTest_0025
487 * @tc.desc: FillJobOptions
488 * @tc.type: FUNC
489 * @tc.require:
490 */
491 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0025, TestSize.Level1)
492 {
493 int num = 0;
494 cups_option_t *options = nullptr;
495 OHOS::Print::PrintCupsClient printCupsClient;
496 PrintJob jobInfo;
497 jobInfo.SetCopyNumber(2);
498 jobInfo.SetDuplexMode(1);
499 jobInfo.SetColorMode(0);
500 jobInfo.SetOption(JOB_OPTIONS);
501 JobParameters *jobParams = printCupsClient.BuildJobParameters(jobInfo);
502 jobParams->printerId = "1";
503 jobParams->numCopies = 2;
504 jobParams->duplex = "";
505 jobParams->printQuality = "";
506 jobParams->color = "";
507 jobParams->isAutoRotate = true;
508 int ret = printCupsClient.FillJobOptions(jobParams, num, &options);
509 EXPECT_EQ(ret, 7);
510 delete jobParams;
511 delete options;
512 }
513
514 /**
515 * @tc.name: PrintCupsClientTest_0026
516 * @tc.desc: FillJobOptions
517 * @tc.type: FUNC
518 * @tc.require:
519 */
520 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0026, TestSize.Level1)
521 {
522 int num = 0;
523 cups_option_t *options = nullptr;
524 OHOS::Print::PrintCupsClient printCupsClient;
525 PrintJob jobInfo;
526 jobInfo.SetCopyNumber(2);
527 jobInfo.SetDuplexMode(1);
528 jobInfo.SetColorMode(0);
529 jobInfo.SetOption(JOB_OPTIONS);
530 JobParameters *jobParams = printCupsClient.BuildJobParameters(jobInfo);
531 jobParams->printerId = "1";
532 jobParams->numCopies = 0;
533 jobParams->duplex = "test_duplex";
534 jobParams->printQuality = "test_printQuality";
535 jobParams->color = "test_color";
536 jobParams->borderless = 1;
537 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
538 jobParams->mediaSize = CUPS_MEDIA_4X6;
539 int ret = printCupsClient.FillJobOptions(jobParams, num, &options);
540 EXPECT_EQ(ret, 7);
541 delete jobParams;
542 delete options;
543 }
544
545 /**
546 * @tc.name: PrintCupsClientTest_0027
547 * @tc.desc: QueryAddedPrinterList
548 * @tc.type: FUNC
549 * @tc.require:
550 */
551 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0027, TestSize.Level1)
552 {
553 OHOS::Print::PrintCupsClient printCupsClient;
554 std::vector<std::string> printerNameList;
555 printerNameList.push_back("testPrinterName");
556 printCupsClient.StopCupsdService();
557 printCupsClient.QueryAddedPrinterList(printerNameList);
558 }
559
560 /**
561 * @tc.name: PrintCupsClientTest_0028
562 * @tc.desc: QueryAddedPrinterList
563 * @tc.type: FUNC
564 * @tc.require:
565 */
566 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0028, TestSize.Level1)
567 {
568 OHOS::Print::PrintCupsClient printCupsClient;
569 std::vector<std::string> printerNameList;
570 printerNameList.push_back("testPrinterName");
571 printCupsClient.StartCupsdService();
572 printCupsClient.QueryAddedPrinterList(printerNameList);
573 }
574
575 /**
576 * @tc.name: PrintCupsClientTest_0030
577 * @tc.desc: GetPPDFile
578 * @tc.type: FUNC
579 * @tc.require:
580 */
581 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0030, TestSize.Level1)
582 {
583 OHOS::Print::PrintCupsClient printCupsClient;
584 std::string printerName = "testPrinterName";
585 printCupsClient.StopCupsdService();
586 ppd_file_t *ppd = printCupsClient.GetPPDFile(printerName);
587 EXPECT_EQ(ppd, nullptr);
588 }
589
590 /**
591 * @tc.name: PrintCupsClientTest_0031
592 * @tc.desc: GetPPDFile
593 * @tc.type: FUNC
594 * @tc.require:
595 */
596 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0031, TestSize.Level1)
597 {
598 OHOS::Print::PrintCupsClient printCupsClient;
599 std::string printerName = "testPrinterName";
600 printCupsClient.StartCupsdService();
601 printCupsClient.GetPPDFile(printerName);
602 }
603
604 /**
605 * @tc.name: PrintCupsClientTest_0032
606 * @tc.desc: QueryPrinterAttrList
607 * @tc.type: FUNC
608 * @tc.require:
609 */
610 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0032, TestSize.Level1)
611 {
612 OHOS::Print::PrintCupsClient printCupsClient;
613 std::string printerName = "testPrinterName";
614 std::vector<std::string> keyList;
615 std::vector<std::string> valueList;
616 printCupsClient.QueryPrinterAttrList(printerName, keyList, valueList);
617 }
618
619 /**
620 * @tc.name: PrintCupsClientTest_0033
621 * @tc.desc: QueryPrinterInfoByPrinterId
622 * @tc.type: FUNC
623 * @tc.require:
624 */
625 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0033, TestSize.Level1)
626 {
627 OHOS::Print::PrintCupsClient printCupsClient;
628 std::string printerId = "testPrinterId";
629 PrinterInfo info;
630 info.SetPrinterName("testPrinterName");
631 printCupsClient.QueryPrinterInfoByPrinterId(printerId, info);
632 }
633
634 /**
635 * @tc.name: PrintCupsClientTest_0034
636 * @tc.desc: CheckPrinterMakeModel
637 * @tc.type: FUNC
638 * @tc.require:
639 */
640 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0034, TestSize.Level1)
641 {
642 OHOS::Print::PrintCupsClient printCupsClient;
643 JobParameters *jobParams = nullptr;
644 bool ret = printCupsClient.CheckPrinterMakeModel(jobParams);
645 EXPECT_EQ(ret, false);
646 }
647
648 /**
649 * @tc.name: PrintCupsClientTest_0036
650 * @tc.desc: VerifyPrintJob
651 * @tc.type: FUNC
652 * @tc.require:
653 */
654 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0036, TestSize.Level1)
655 {
656 OHOS::Print::PrintCupsClient printCupsClient;
657 JobParameters *jobParams = nullptr;
658 int num = 0;
659 uint32_t jobId = 1;
660 cups_option_t *options = nullptr;
661 http_t *http = nullptr;
662 bool ret = printCupsClient.VerifyPrintJob(jobParams, num, jobId, options, http);
663 EXPECT_EQ(ret, false);
664 delete jobParams;
665 delete options;
666 delete http;
667 }
668
669 /**
670 * @tc.name: PrintCupsClientTest_0039
671 * @tc.desc: UpdatePrintJobStateInJobParams
672 * @tc.type: FUNC
673 * @tc.require:
674 */
675 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0039, TestSize.Level1)
676 {
677 OHOS::Print::PrintCupsClient printCupsClient;
678 PrintJob testJob;
679 testJob.SetJobId(GetDefaultJobId());
680 std::vector<uint32_t> files = {1};
681 testJob.SetFdList(files);
682 OHOS::Print::PrintPageSize pageSize;
683 pageSize.SetId("pgid-1234");
684 testJob.SetPageSize(pageSize);
685 testJob.SetPrinterId("printid-1234");
686 testJob.SetOption(JOB_OPTIONS);
687 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
688 EXPECT_NE(jobParams, nullptr);
689 EXPECT_NE(jobParams->serviceAbility, nullptr);
690
691 uint32_t state = PRINT_JOB_BLOCKED;
692 uint32_t subState = PRINT_JOB_BLOCKED_UNKNOWN;
693 printCupsClient.UpdatePrintJobStateInJobParams(jobParams, state, subState);
694
695 auto jobId = jobParams->serviceJobId;
696 auto userData = jobParams->serviceAbility->GetUserDataByJobId(jobId);
697 EXPECT_EQ(userData, nullptr);
698 delete jobParams;
699 }
700
701 /**
702 * @tc.name: PrintCupsClientTest_0042
703 * @tc.desc: UpdateJobStatus
704 * @tc.type: FUNC
705 * @tc.require:
706 */
707 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0042, TestSize.Level1)
708 {
709 OHOS::Print::PrintCupsClient printCupsClient;
710 JobStatus *prevousJobStatus = nullptr;
711 JobStatus *jobStatus = nullptr;
712
713 printCupsClient.UpdateJobStatus(prevousJobStatus, jobStatus);
714
715 EXPECT_EQ(prevousJobStatus, nullptr);
716 EXPECT_EQ(jobStatus, nullptr);
717
718 JobStatus *prevousJobStatus2 = new (std::nothrow) JobStatus{{'1', '\0'}, (ipp_jstate_t)0, {'1', '\0'}};
719 JobStatus *savePrevousJobStatus2 = new (std::nothrow) JobStatus{{'1', '\0'}, (ipp_jstate_t)0, {'1', '\0'}};
720
721 printCupsClient.UpdateJobStatus(prevousJobStatus2, jobStatus);
722
723 EXPECT_EQ(prevousJobStatus2->job_state, savePrevousJobStatus2->job_state);
724 EXPECT_EQ(std::string(
725 prevousJobStatus2->printer_state_reasons),
726 std::string(savePrevousJobStatus2->printer_state_reasons));
727
728 delete prevousJobStatus;
729 delete jobStatus;
730 delete prevousJobStatus2;
731 delete savePrevousJobStatus2;
732 }
733
734 /**
735 * @tc.name: PrintCupsClientTest_0043
736 * @tc.desc: UpdateJobStatus
737 * @tc.type: FUNC
738 * @tc.require:
739 */
740 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0043, TestSize.Level1)
741 {
742 OHOS::Print::PrintCupsClient printCupsClient;
743 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
744 JobStatus *prevousJobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
745 printCupsClient.UpdateJobStatus(prevousJobStatus, jobStatus);
746
747 EXPECT_EQ(prevousJobStatus->job_state, jobStatus->job_state);
748 EXPECT_EQ(std::string(prevousJobStatus->printer_state_reasons), std::string(jobStatus->printer_state_reasons));
749 delete prevousJobStatus;
750 delete jobStatus;
751 }
752
753 /**
754 * @tc.name: PrintCupsClientTest_0044
755 * @tc.desc: JobStatusCallback
756 * @tc.type: FUNC
757 * @tc.require:
758 */
759 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0044, TestSize.Level1)
760 {
761 OHOS::Print::PrintCupsClient printCupsClient;
762 PrintJob testJob;
763 testJob.SetJobId(GetDefaultJobId());
764 std::vector<uint32_t> files = {1};
765 testJob.SetFdList(files);
766 OHOS::Print::PrintPageSize pageSize;
767 pageSize.SetId("pgid-1234");
768 testJob.SetPageSize(pageSize);
769 testJob.SetPrinterId("printid-1234");
770 testJob.SetOption(JOB_OPTIONS);
771 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
772 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
773 bool isOffline = true;
774 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
775 jobParams->serviceJobId,
776 1,
777 "ipp://192.168.186.1:631/ipp/print",
778 "DIRECT-PixLab_V1-0105"};
779 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
780 delete jobParams;
781 delete jobStatus;
782 delete param;
783 }
784
785 /**
786 * @tc.name: PrintCupsClientTest_0045
787 * @tc.desc: JobStatusCallback
788 * @tc.type: FUNC
789 * @tc.require:
790 */
791 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0045, TestSize.Level1)
792 {
793 OHOS::Print::PrintCupsClient printCupsClient;
794 PrintJob testJob;
795 testJob.SetJobId(GetDefaultJobId());
796 std::vector<uint32_t> files = {1};
797 testJob.SetFdList(files);
798 OHOS::Print::PrintPageSize pageSize;
799 pageSize.SetId("pgid-1234");
800 testJob.SetPageSize(pageSize);
801 testJob.SetPrinterId("printid-1234");
802 testJob.SetOption(JOB_OPTIONS);
803 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
804 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
805 bool isOffline = false;
806 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
807 jobParams->serviceJobId,
808 1,
809 "ipp://192.168.186.1:631/ipp/print",
810 "DIRECT-PixLab_V1-0105"};
811 jobStatus->job_state = IPP_JOB_COMPLETED;
812 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
813 delete jobParams;
814 delete jobStatus;
815 delete param;
816 }
817
818 /**
819 * @tc.name: PrintCupsClientTest_0046
820 * @tc.desc: JobStatusCallback
821 * @tc.type: FUNC
822 * @tc.require:
823 */
824 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0046, TestSize.Level1)
825 {
826 OHOS::Print::PrintCupsClient printCupsClient;
827 PrintJob testJob;
828 testJob.SetJobId(GetDefaultJobId());
829 std::vector<uint32_t> files = {1};
830 testJob.SetFdList(files);
831 OHOS::Print::PrintPageSize pageSize;
832 pageSize.SetId("pgid-1234");
833 testJob.SetPageSize(pageSize);
834 testJob.SetPrinterId("printid-1234");
835 testJob.SetOption(JOB_OPTIONS);
836 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
837 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
838 bool isOffline = false;
839 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
840 jobParams->serviceJobId,
841 1,
842 "ipp://192.168.186.1:631/ipp/print",
843 "DIRECT-PixLab_V1-0105"};
844 jobStatus->job_state = IPP_JOB_PROCESSING;
845 int ret = memcpy_s(jobStatus->printer_state_reasons,
846 sizeof(jobStatus->printer_state_reasons),
847 PRINTER_STATE_NONE.c_str(),
848 strlen(PRINTER_STATE_NONE.c_str()));
849 if (ret != 0) {
850 delete jobParams;
851 delete jobStatus;
852 delete param;
853 return;
854 }
855 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
856 delete jobParams;
857 delete jobStatus;
858 delete param;
859 }
860
861 /**
862 * @tc.name: PrintCupsClientTest_0047
863 * @tc.desc: JobStatusCallback
864 * @tc.type: FUNC
865 * @tc.require:
866 */
867 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0047, TestSize.Level1)
868 {
869 OHOS::Print::PrintCupsClient printCupsClient;
870 PrintJob testJob;
871 testJob.SetJobId(GetDefaultJobId());
872 std::vector<uint32_t> files = {1};
873 testJob.SetFdList(files);
874 OHOS::Print::PrintPageSize pageSize;
875 pageSize.SetId("pgid-1234");
876 testJob.SetPageSize(pageSize);
877 testJob.SetPrinterId("printid-1234");
878 testJob.SetOption(JOB_OPTIONS);
879 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
880 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
881 bool isOffline = false;
882 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
883 jobParams->serviceJobId,
884 1,
885 "ipp://192.168.186.1:631/ipp/print",
886 "DIRECT-PixLab_V1-0105"};
887 jobStatus->job_state = IPP_JOB_PROCESSING;
888 int ret = memcpy_s(jobStatus->printer_state_reasons,
889 sizeof(jobStatus->printer_state_reasons),
890 PRINTER_STATE_MEDIA_EMPTY.c_str(),
891 strlen(PRINTER_STATE_MEDIA_EMPTY.c_str()));
892 if (ret != 0) {
893 delete jobParams;
894 delete jobStatus;
895 delete param;
896 return;
897 }
898 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
899 delete jobParams;
900 delete jobStatus;
901 delete param;
902 }
903
904 /**
905 * @tc.name: PrintCupsClientTest_0048
906 * @tc.desc: JobStatusCallback
907 * @tc.type: FUNC
908 * @tc.require:
909 */
910 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0048, TestSize.Level1)
911 {
912 OHOS::Print::PrintCupsClient printCupsClient;
913 PrintJob testJob;
914 testJob.SetJobId(GetDefaultJobId());
915 std::vector<uint32_t> files = {1};
916 testJob.SetFdList(files);
917 OHOS::Print::PrintPageSize pageSize;
918 pageSize.SetId("pgid-1234");
919 testJob.SetPageSize(pageSize);
920 testJob.SetPrinterId("printid-1234");
921 testJob.SetOption(JOB_OPTIONS);
922 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
923 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
924 bool isOffline = false;
925 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
926 jobParams->serviceJobId,
927 1,
928 "ipp://192.168.186.1:631/ipp/print",
929 "DIRECT-PixLab_V1-0105"};
930 jobStatus->job_state = IPP_JOB_CANCELED;
931 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
932 delete jobParams;
933 delete jobStatus;
934 delete param;
935 }
936
937 /**
938 * @tc.name: PrintCupsClientTest_0049
939 * @tc.desc: JobStatusCallback
940 * @tc.type: FUNC
941 * @tc.require:
942 */
943 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0049, TestSize.Level1)
944 {
945 OHOS::Print::PrintCupsClient printCupsClient;
946 PrintJob testJob;
947 testJob.SetJobId(GetDefaultJobId());
948 std::vector<uint32_t> files = {1};
949 testJob.SetFdList(files);
950 OHOS::Print::PrintPageSize pageSize;
951 pageSize.SetId("pgid-1234");
952 testJob.SetPageSize(pageSize);
953 testJob.SetPrinterId("printid-1234");
954 testJob.SetOption(JOB_OPTIONS);
955 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
956 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
957 bool isOffline = false;
958 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
959 jobParams->serviceJobId,
960 1,
961 "ipp://192.168.186.1:631/ipp/print",
962 "DIRECT-PixLab_V1-0105"};
963 jobStatus->job_state = IPP_JOB_ABORTED;
964 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
965 delete jobParams;
966 delete jobStatus;
967 delete param;
968 }
969
970 /**
971 * @tc.name: PrintCupsClientTest_0050
972 * @tc.desc: JobStatusCallback
973 * @tc.type: FUNC
974 * @tc.require:
975 */
976 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0050, TestSize.Level1)
977 {
978 OHOS::Print::PrintCupsClient printCupsClient;
979 PrintJob testJob;
980 testJob.SetJobId(GetDefaultJobId());
981 std::vector<uint32_t> files = {1};
982 testJob.SetFdList(files);
983 OHOS::Print::PrintPageSize pageSize;
984 pageSize.SetId("pgid-1234");
985 testJob.SetPageSize(pageSize);
986 testJob.SetPrinterId("printid-1234");
987 testJob.SetOption(JOB_OPTIONS);
988 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
989 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
990 bool isOffline = false;
991 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
992 jobParams->serviceJobId,
993 1,
994 "ipp://192.168.186.1:631/ipp/print",
995 "DIRECT-PixLab_V1-0105"};
996 jobStatus->job_state = IPP_JOB_PENDING;
997 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
998 delete jobParams;
999 delete jobStatus;
1000 delete param;
1001 }
1002
1003 /**
1004 * @tc.name: PrintCupsClientTest_0051
1005 * @tc.desc: JobStatusCallback
1006 * @tc.type: FUNC
1007 * @tc.require:
1008 */
1009 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0051, TestSize.Level1)
1010 {
1011 OHOS::Print::PrintCupsClient printCupsClient;
1012 PrintJob testJob;
1013 testJob.SetJobId(GetDefaultJobId());
1014 std::vector<uint32_t> files = {1};
1015 testJob.SetFdList(files);
1016 OHOS::Print::PrintPageSize pageSize;
1017 pageSize.SetId("pgid-1234");
1018 testJob.SetPageSize(pageSize);
1019 testJob.SetPrinterId("printid-1234");
1020 testJob.SetOption(JOB_OPTIONS);
1021 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1022 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1023 bool isOffline = false;
1024 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1025 jobParams->serviceJobId,
1026 1,
1027 "ipp://192.168.186.1:631/ipp/print",
1028 "DIRECT-PixLab_V1-0105"};
1029 jobStatus->job_state = IPP_JOB_HELD;
1030 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
1031 delete jobParams;
1032 delete jobStatus;
1033 delete param;
1034 }
1035
1036 /**
1037 * @tc.name: PrintCupsClientTest_0052
1038 * @tc.desc: JobStatusCallback
1039 * @tc.type: FUNC
1040 * @tc.require:
1041 */
1042 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0052, TestSize.Level1)
1043 {
1044 OHOS::Print::PrintCupsClient printCupsClient;
1045 PrintJob testJob;
1046 testJob.SetJobId(GetDefaultJobId());
1047 std::vector<uint32_t> files = {1};
1048 testJob.SetFdList(files);
1049 OHOS::Print::PrintPageSize pageSize;
1050 pageSize.SetId("pgid-1234");
1051 testJob.SetPageSize(pageSize);
1052 testJob.SetPrinterId("printid-1234");
1053 testJob.SetOption(JOB_OPTIONS);
1054 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1055 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1056 bool isOffline = false;
1057 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1058 jobParams->serviceJobId,
1059 1,
1060 "ipp://192.168.186.1:631/ipp/print",
1061 "DIRECT-PixLab_V1-0105"};
1062 jobStatus->job_state = IPP_JOB_STOPPED;
1063 printCupsClient.JobStatusCallback(param, jobStatus, isOffline);
1064 delete jobParams;
1065 delete jobStatus;
1066 delete param;
1067 }
1068
1069 /**
1070 * @tc.name: PrintCupsClientTest_0053
1071 * @tc.desc: ReportBlockedReason
1072 * @tc.type: FUNC
1073 * @tc.require:
1074 */
1075 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0053, TestSize.Level1)
1076 {
1077 OHOS::Print::PrintCupsClient printCupsClient;
1078 JobStatus *jobStatus = nullptr;
1079 JobMonitorParam *param = nullptr;
1080 printCupsClient.ReportBlockedReason(param, jobStatus);
1081 delete jobStatus;
1082 delete param;
1083 }
1084
1085 /**
1086 * @tc.name: PrintCupsClientTest_0054
1087 * @tc.desc: ReportBlockedReason
1088 * @tc.type: FUNC
1089 * @tc.require:
1090 */
1091 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0054, TestSize.Level1)
1092 {
1093 OHOS::Print::PrintCupsClient printCupsClient;
1094 PrintJob testJob;
1095 testJob.SetJobId(GetDefaultJobId());
1096 std::vector<uint32_t> files = {1};
1097 testJob.SetFdList(files);
1098 OHOS::Print::PrintPageSize pageSize;
1099 pageSize.SetId("pgid-1234");
1100 testJob.SetPageSize(pageSize);
1101 testJob.SetPrinterId("printid-1234");
1102 testJob.SetOption(JOB_OPTIONS);
1103 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1104 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1105 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility = nullptr,
1106 jobParams->serviceJobId,
1107 1,
1108 "ipp://192.168.186.1:631/ipp/print",
1109 "DIRECT-PixLab_V1-0105"};
1110 printCupsClient.ReportBlockedReason(param, jobStatus);
1111 delete jobParams;
1112 delete jobStatus;
1113 delete param;
1114 }
1115
1116 /**
1117 * @tc.name: PrintCupsClientTest_0055
1118 * @tc.desc: ReportBlockedReason
1119 * @tc.type: FUNC
1120 * @tc.require:
1121 */
1122 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0055, TestSize.Level1)
1123 {
1124 OHOS::Print::PrintCupsClient printCupsClient;
1125 PrintJob testJob;
1126 testJob.SetJobId(GetDefaultJobId());
1127 std::vector<uint32_t> files = {1};
1128 testJob.SetFdList(files);
1129 OHOS::Print::PrintPageSize pageSize;
1130 pageSize.SetId("pgid-1234");
1131 testJob.SetPageSize(pageSize);
1132 testJob.SetPrinterId("printid-1234");
1133 testJob.SetOption(JOB_OPTIONS);
1134 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1135 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1136 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1137 jobParams->serviceJobId,
1138 1,
1139 "ipp://192.168.186.1:631/ipp/print",
1140 "DIRECT-PixLab_V1-0105"};
1141 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1142 PRINTER_STATE_MEDIA_EMPTY.c_str(), strlen(PRINTER_STATE_MEDIA_EMPTY.c_str()));
1143 printCupsClient.ReportBlockedReason(param, jobStatus);
1144 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1145 PRINTER_STATE_MEDIA_JAM.c_str(), strlen(PRINTER_STATE_MEDIA_JAM.c_str()));
1146 printCupsClient.ReportBlockedReason(param, jobStatus);
1147 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1148 PRINTER_STATE_PAUSED.c_str(), strlen(PRINTER_STATE_PAUSED.c_str()));
1149 printCupsClient.ReportBlockedReason(param, jobStatus);
1150 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1151 PRINTER_STATE_TONER_LOW.c_str(), strlen(PRINTER_STATE_TONER_LOW.c_str()));
1152 printCupsClient.ReportBlockedReason(param, jobStatus);
1153 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1154 PRINTER_STATE_TONER_EMPTY.c_str(), strlen(PRINTER_STATE_TONER_EMPTY.c_str()));
1155 printCupsClient.ReportBlockedReason(param, jobStatus);
1156 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1157 PRINTER_STATE_DOOR_EMPTY.c_str(), strlen(PRINTER_STATE_DOOR_EMPTY.c_str()));
1158 printCupsClient.ReportBlockedReason(param, jobStatus);
1159 delete jobParams;
1160 delete jobStatus;
1161 delete param;
1162 }
1163
1164 /**
1165 * @tc.name: PrintCupsClientTest_0056
1166 * @tc.desc: QueryJobState
1167 * @tc.type: FUNC
1168 * @tc.require:
1169 */
1170 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0056, TestSize.Level1)
1171 {
1172 OHOS::Print::PrintCupsClient printCupsClient;
1173 PrintJob testJob;
1174 testJob.SetJobId(GetDefaultJobId());
1175 std::vector<uint32_t> files = {1};
1176 testJob.SetFdList(files);
1177 OHOS::Print::PrintPageSize pageSize;
1178 pageSize.SetId("pgid-1234");
1179 testJob.SetPageSize(pageSize);
1180 testJob.SetPrinterId("printid-1234");
1181 testJob.SetOption(JOB_OPTIONS);
1182 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1183 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1184 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1185 jobParams->serviceJobId,
1186 1,
1187 "ipp://192.168.186.1:631/ipp/print",
1188 "DIRECT-PixLab_V1-0105"};
1189 http_t *http = nullptr;
1190 printCupsClient.QueryJobState(http, param, jobStatus);
1191 delete jobParams;
1192 delete jobStatus;
1193 delete param;
1194 delete http;
1195 }
1196
1197 /**
1198 * @tc.name: PrintCupsClientTest_0057
1199 * @tc.desc: QueryJobState
1200 * @tc.type: FUNC
1201 * @tc.require:
1202 */
1203 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0057, TestSize.Level1)
1204 {
1205 OHOS::Print::PrintCupsClient printCupsClient;
1206 PrintJob testJob;
1207 testJob.SetJobId(GetDefaultJobId());
1208 std::vector<uint32_t> files = {1};
1209 testJob.SetFdList(files);
1210 OHOS::Print::PrintPageSize pageSize;
1211 pageSize.SetId("pgid-1234");
1212 testJob.SetPageSize(pageSize);
1213 testJob.SetPrinterId("printid-1234");
1214 testJob.SetOption(JOB_OPTIONS);
1215 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1216 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1217 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1218 jobParams->serviceJobId,
1219 0,
1220 "ipp://192.168.186.1:631/ipp/print",
1221 "DIRECT-PixLab_V1-0105"};
1222 http_t *http = nullptr;
1223 printCupsClient.QueryJobState(http, param, jobStatus);
1224 delete jobParams;
1225 delete jobStatus;
1226 delete param;
1227 delete http;
1228 }
1229
1230 /**
1231 * @tc.name: PrintCupsClientTest_0059
1232 * @tc.desc: CancelCupsJob
1233 * @tc.type: FUNC
1234 * @tc.require:
1235 */
1236 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0059, TestSize.Level1)
1237 {
1238 OHOS::Print::PrintCupsClient printCupsClient;
1239 printCupsClient.CancelCupsJob(GetDefaultJobId());
1240 }
1241
1242 /**
1243 * @tc.name: PrintCupsClientTest_0060
1244 * @tc.desc: CancelCupsJob
1245 * @tc.type: FUNC
1246 * @tc.require:
1247 */
1248 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0060, TestSize.Level1)
1249 {
1250 OHOS::Print::PrintCupsClient printCupsClient;
1251 std::string serviceJobId = "0";
1252 PrintJob testJob;
1253 testJob.SetJobId(GetDefaultJobId());
1254 std::vector<uint32_t> files = {1};
1255 testJob.SetFdList(files);
1256 OHOS::Print::PrintPageSize pageSize;
1257 pageSize.SetId("pgid-1234");
1258 testJob.SetPageSize(pageSize);
1259 testJob.SetPrinterId("printid-1234");
1260 testJob.SetOption(JOB_OPTIONS);
1261 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1262 printCupsClient.jobQueue_.push_back(jobParams);
1263 PRINT_HILOGI("CancelCupsJob(): printCupsClient.jobQueue_.size(): %{public}u", printCupsClient.jobQueue_.size());
1264 printCupsClient.CancelCupsJob(serviceJobId);
1265 }
1266
1267 /**
1268 * @tc.name: PrintCupsClientTest_0061
1269 * @tc.desc: CancelCupsJob
1270 * @tc.type: FUNC
1271 * @tc.require:
1272 */
1273 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0061, TestSize.Level1)
1274 {
1275 OHOS::Print::PrintCupsClient printCupsClient;
1276 std::string serviceJobId = "1";
1277 PrintJob testJob;
1278 testJob.SetJobId(GetDefaultJobId());
1279 std::vector<uint32_t> files = {1};
1280 testJob.SetFdList(files);
1281 OHOS::Print::PrintPageSize pageSize;
1282 pageSize.SetId("pgid-1234");
1283 testJob.SetPageSize(pageSize);
1284 testJob.SetPrinterId("printid-1234");
1285 testJob.SetOption(JOB_OPTIONS);
1286 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1287 printCupsClient.jobQueue_.push_back(jobParams);
1288 printCupsClient.currentJob_ = jobParams;
1289 printCupsClient.CancelCupsJob(serviceJobId);
1290 delete jobParams;
1291 }
1292
1293 /**
1294 * @tc.name: PrintCupsClientTest_0062
1295 * @tc.desc: CancelCupsJob
1296 * @tc.type: FUNC
1297 * @tc.require:
1298 */
1299 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0062, TestSize.Level1)
1300 {
1301 OHOS::Print::PrintCupsClient printCupsClient;
1302 std::string serviceJobId = "1";
1303 PrintJob testJob;
1304 testJob.SetJobId(GetDefaultJobId());
1305 std::vector<uint32_t> files = {1};
1306 testJob.SetFdList(files);
1307 OHOS::Print::PrintPageSize pageSize;
1308 pageSize.SetId("pgid-1234");
1309 testJob.SetPageSize(pageSize);
1310 testJob.SetPrinterId("printid-1234");
1311 testJob.SetOption(JOB_OPTIONS);
1312 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1313 PrintJob testJob2;
1314 testJob2.SetJobId(serviceJobId);
1315 testJob2.SetFdList(files);
1316 testJob2.SetPageSize(pageSize);
1317 testJob2.SetPrinterId("printid-1234");
1318 testJob2.SetOption(JOB_OPTIONS);
1319 JobParameters *jobParams2 = printCupsClient.BuildJobParameters(testJob2);
1320 printCupsClient.currentJob_ = jobParams2;
1321 printCupsClient.CancelCupsJob(serviceJobId);
1322 delete jobParams;
1323 delete jobParams2;
1324 }
1325
1326 /**
1327 * @tc.name: PrintCupsClientTest_0066
1328 * @tc.desc: BuildJobParameters
1329 * @tc.type: FUNC
1330 * @tc.require:
1331 */
1332 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0066, TestSize.Level1)
1333 {
1334 OHOS::Print::PrintCupsClient printCupsClient;
1335 PrintJob testJob;
1336 testJob.SetJobId(GetDefaultJobId());
1337 std::vector<uint32_t> files = {1};
1338 testJob.SetFdList(files);
1339 OHOS::Print::PrintPageSize pageSize;
1340 pageSize.SetId("pgid-1234");
1341 testJob.SetPageSize(pageSize);
1342 testJob.SetPrinterId("printid-1234");
1343 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1344 EXPECT_EQ(jobParams, nullptr);
1345
1346 testJob.SetOption("test");
1347 printCupsClient.BuildJobParameters(testJob);
1348 EXPECT_EQ(jobParams, nullptr);
1349 delete jobParams;
1350 }
1351
1352 /**
1353 * @tc.name: PrintCupsClientTest_0067
1354 * @tc.desc: BuildJobParameters
1355 * @tc.type: FUNC
1356 * @tc.require:
1357 */
1358 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0067, TestSize.Level1)
1359 {
1360 OHOS::Print::PrintCupsClient printCupsClient;
1361 PrintJob testJob;
1362 testJob.SetJobId(GetDefaultJobId());
1363 std::vector<uint32_t> files = {1};
1364 testJob.SetFdList(files);
1365 OHOS::Print::PrintPageSize pageSize;
1366 pageSize.SetId("pgid-1234");
1367 testJob.SetPageSize(pageSize);
1368 testJob.SetPrinterId("printid-1234");
1369 testJob.SetIsLandscape(true);
1370 testJob.SetOption(R"({"key": "value"})");
1371 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1372 EXPECT_EQ(jobParams, nullptr);
1373
1374 json optionJson = json::parse(testJob.GetOption());
1375 optionJson["printerUri"] = "ipp://192.168.0.1:111/ipp/print";
1376 optionJson["printerName"] = "printer1";
1377 optionJson["documentFormat"] = "application/pdf";
1378 testJob.SetOption(optionJson.dump());
1379 jobParams = printCupsClient.BuildJobParameters(testJob);
1380 EXPECT_EQ(jobParams->printerUri, optionJson["printerUri"]);
1381 EXPECT_EQ(jobParams->printerName, PrintUtil::StandardizePrinterName(optionJson["printerName"]));
1382 EXPECT_EQ(jobParams->documentFormat, optionJson["documentFormat"]);
1383
1384 optionJson["cupsOptions"] = "testCupsOptions";
1385 optionJson["printQuality"] = "printQuality";
1386 optionJson["jobName"] = "jobName";
1387 optionJson["mediaType"] = "mediaType";
1388 testJob.SetOption(optionJson.dump());
1389 jobParams = printCupsClient.BuildJobParameters(testJob);
1390 EXPECT_EQ(jobParams->printerAttrsOption_cupsOption, optionJson["cupsOptions"]);
1391 EXPECT_EQ(jobParams->printQuality, optionJson["printQuality"]);
1392 EXPECT_EQ(jobParams->jobName, optionJson["jobName"]);
1393 EXPECT_EQ(jobParams->mediaType, optionJson["mediaType"]);
1394
1395 optionJson["printQuality"] = 1;
1396 testJob.SetOption(optionJson.dump());
1397 jobParams = printCupsClient.BuildJobParameters(testJob);
1398 EXPECT_EQ(jobParams->printQuality, CUPS_PRINT_QUALITY_NORMAL);
1399
1400 EXPECT_EQ(jobParams->isAutoRotate, true); // default true
1401 optionJson["isAutoRotate"] = false;
1402 testJob.SetOption(optionJson.dump());
1403 jobParams = printCupsClient.BuildJobParameters(testJob);
1404 EXPECT_EQ(jobParams->isAutoRotate, optionJson["isAutoRotate"]);
1405 }
1406
1407 /**
1408 * @tc.name: PrintCupsClientTest_0068
1409 * @tc.desc: DumpJobParameters
1410 * @tc.type: FUNC
1411 * @tc.require:
1412 */
1413 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0068, TestSize.Level1)
1414 {
1415 OHOS::Print::PrintCupsClient printCupsClient;
1416 PrintJob testJob;
1417 testJob.SetJobId(GetDefaultJobId());
1418 std::vector<uint32_t> files = {1};
1419 testJob.SetFdList(files);
1420 testJob.SetColorMode(1);
1421 testJob.SetCopyNumber(1);
1422 testJob.SetDuplexMode(0);
1423 OHOS::Print::PrintPageSize pageSize;
1424 pageSize.SetId("pgid-1234");
1425 testJob.SetPageSize(pageSize);
1426 testJob.SetPrinterId("printid-1234");
1427 testJob.SetOption(JOB_OPTIONS);
1428 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1429 std::string option = testJob.GetOption();
1430 json optionJson = json::parse(option);
1431 EXPECT_EQ(jobParams->jobName, optionJson["jobName"]);
1432 EXPECT_EQ(jobParams->mediaType, optionJson["mediaType"]);
1433 EXPECT_EQ(jobParams->printQuality, optionJson["printQuality"]);
1434 EXPECT_EQ(jobParams->printerName, optionJson["printerName"]);
1435 EXPECT_EQ(jobParams->printerUri, optionJson["printerUri"]);
1436 EXPECT_EQ(jobParams->documentFormat, optionJson["documentFormat"]);
1437 EXPECT_EQ(jobParams->isAutoRotate, optionJson["isAutoRotate"]);
1438 printCupsClient.DumpJobParameters(jobParams);
1439 delete jobParams;
1440 }
1441
1442 /**
1443 * @tc.name: PrintCupsClientTest_0069
1444 * @tc.desc: GetMedieSize
1445 * @tc.type: FUNC
1446 * @tc.require:
1447 */
1448 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0069, TestSize.Level1)
1449 {
1450 OHOS::Print::PrintCupsClient printCupsClient;
1451 PrintJob testJob;
1452 testJob.SetJobId(GetDefaultJobId());
1453 std::vector<uint32_t> files = {1};
1454 testJob.SetFdList(files);
1455 testJob.SetColorMode(1);
1456 testJob.SetCopyNumber(1);
1457 testJob.SetDuplexMode(0);
1458 OHOS::Print::PrintPageSize pageSize;
1459 pageSize.SetId("pgid-1234");
1460 testJob.SetPageSize(pageSize);
1461 testJob.SetPrinterId("printid-1234");
1462 testJob.SetOption(JOB_OPTIONS);
1463 std::string pageSizeName = printCupsClient.GetMedieSize(testJob);
1464 EXPECT_EQ("PrintPageSize", pageSizeName);
1465 }
1466
1467 /**
1468 * @tc.name: PrintCupsClientTest_0070
1469 * @tc.desc: GetDulpexString
1470 * @tc.type: FUNC
1471 * @tc.require:
1472 */
1473 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0070, TestSize.Level1)
1474 {
1475 OHOS::Print::PrintCupsClient printCupsClient;
1476 uint32_t duplexCode = 0;
1477 std::string ret0 = printCupsClient.GetDulpexString(duplexCode);
1478 EXPECT_EQ(ret0, CUPS_SIDES_ONE_SIDED);
1479
1480 duplexCode = 1;
1481 std::string ret1 = printCupsClient.GetDulpexString(duplexCode);
1482 EXPECT_EQ(ret1, CUPS_SIDES_TWO_SIDED_PORTRAIT);
1483
1484 duplexCode = 2;
1485 std::string ret2 = printCupsClient.GetDulpexString(duplexCode);
1486 EXPECT_EQ(ret2, CUPS_SIDES_TWO_SIDED_LANDSCAPE);
1487
1488 duplexCode = 3;
1489 std::string ret3 = printCupsClient.GetDulpexString(duplexCode);
1490 EXPECT_EQ(ret3, CUPS_SIDES_ONE_SIDED);
1491 }
1492
1493 /**
1494 * @tc.name: PrintCupsClientTest_0071
1495 * @tc.desc: GetColorString
1496 * @tc.type: FUNC
1497 * @tc.require:
1498 */
1499 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0071, TestSize.Level1)
1500 {
1501 OHOS::Print::PrintCupsClient printCupsClient;
1502 uint32_t colorCode = 0;
1503 std::string ret0 = printCupsClient.GetColorString(colorCode);
1504 EXPECT_EQ(ret0, CUPS_PRINT_COLOR_MODE_MONOCHROME);
1505
1506 colorCode = 1;
1507 std::string ret1 = printCupsClient.GetColorString(colorCode);
1508 EXPECT_EQ(ret1, CUPS_PRINT_COLOR_MODE_COLOR);
1509
1510 colorCode = 2;
1511 std::string ret2 = printCupsClient.GetColorString(colorCode);
1512 EXPECT_EQ(ret2, CUPS_PRINT_COLOR_MODE_AUTO);
1513 }
1514
1515 /**
1516 * @tc.name: PrintCupsClientTest_0073
1517 * @tc.desc: IsPrinterExist
1518 * @tc.type: FUNC
1519 * @tc.require:
1520 */
1521 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0073, TestSize.Level1)
1522 {
1523 OHOS::Print::PrintCupsClient printCupsClient;
1524 const char *printerUri = "ipp://192.168.186.1:631/ipp/print";
1525 const char *printerName = "DIRECT-PixLab_V1-0105";
1526 const char *ppdName = "DIRECT-PixLab_V1-0105.ppd";
1527 printCupsClient.IsPrinterExist(printerUri, printerName, ppdName);
1528 }
1529
1530 /**
1531 * @tc.name: PrintCupsClientTest_0074
1532 * @tc.desc: ConvertInchTo100MM
1533 * @tc.type: FUNC
1534 * @tc.require:
1535 */
1536 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0074, TestSize.Level1)
1537 {
1538 OHOS::Print::PrintCupsClient printCupsClient;
1539 float num = 1000;
1540 float ret = printCupsClient.ConvertInchTo100MM(num);
1541 EXPECT_EQ(ret, 2540);
1542 }
1543
1544 /**
1545 * @tc.name: PrintCupsClientTest_0075
1546 * @tc.desc: IsIpConflict
1547 * @tc.type: FUNC
1548 * @tc.require:
1549 */
1550 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0075, TestSize.Level1)
1551 {
1552 OHOS::Print::PrintCupsClient printCupsClient;
1553 std::string printerId = "com.ohos.spooler:usb://DIRECT-PixLab_V1-1620";
1554 std::string nic = "";
1555 bool ret1 = printCupsClient.IsIpConflict(printerId, nic);
1556 EXPECT_EQ(ret1, false);
1557
1558 printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1559 bool ret2 = printCupsClient.IsIpConflict(printerId, nic);
1560 EXPECT_EQ(ret2, false);
1561 }
1562
1563 /**
1564 * @tc.name: PrintCupsClientTest_0076
1565 * @tc.desc: ReportBlockedReason
1566 * @tc.type: FUNC
1567 * @tc.require:
1568 */
1569 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0076, TestSize.Level1)
1570 {
1571 OHOS::Print::PrintCupsClient printCupsClient;
1572 PrintJob testJob;
1573 testJob.SetJobId(GetDefaultJobId());
1574 std::vector<uint32_t> files = {1};
1575 testJob.SetFdList(files);
1576 OHOS::Print::PrintPageSize pageSize;
1577 pageSize.SetId("pgid-1234");
1578 testJob.SetPageSize(pageSize);
1579 testJob.SetPrinterId("printid-1234");
1580 testJob.SetOption(JOB_OPTIONS);
1581 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1582 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1583 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1584 jobParams->serviceJobId,
1585 1,
1586 "ipp://192.168.186.1:631/ipp/print",
1587 "DIRECT-PixLab_V1-0105"};
1588 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1589 PRINTER_STATE_MEDIA_NEEDED.c_str(), strlen(PRINTER_STATE_MEDIA_NEEDED.c_str()));
1590 printCupsClient.ReportBlockedReason(param, jobStatus);
1591 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1592 PRINTER_STATE_MARKER_LOW.c_str(), strlen(PRINTER_STATE_MARKER_LOW.c_str()));
1593 printCupsClient.ReportBlockedReason(param, jobStatus);
1594 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1595 PRINTER_STATE_MARKER_EMPTY.c_str(), strlen(PRINTER_STATE_MARKER_EMPTY.c_str()));
1596 printCupsClient.ReportBlockedReason(param, jobStatus);
1597 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1598 PRINTER_STATE_INK_EMPTY.c_str(), strlen(PRINTER_STATE_INK_EMPTY.c_str()));
1599 printCupsClient.ReportBlockedReason(param, jobStatus);
1600 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1601 PRINTER_STATE_COVER_OPEN.c_str(), strlen(PRINTER_STATE_COVER_OPEN.c_str()));
1602 printCupsClient.ReportBlockedReason(param, jobStatus);
1603 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1604 PRINTER_STATE_OFFLINE.c_str(), strlen(PRINTER_STATE_OFFLINE.c_str()));
1605 printCupsClient.ReportBlockedReason(param, jobStatus);
1606 memcpy_s(jobStatus->printer_state_reasons, sizeof(jobStatus->printer_state_reasons),
1607 PRINTER_STATE_NONE.c_str(), strlen(PRINTER_STATE_NONE.c_str()));
1608 printCupsClient.ReportBlockedReason(param, jobStatus);
1609 delete jobParams;
1610 delete jobStatus;
1611 delete param;
1612 }
1613
1614 /**
1615 * @tc.name: PrintCupsClientTest_0077
1616 * @tc.desc: DiscoverUsbPrinters
1617 * @tc.type: FUNC
1618 * @tc.require:
1619 */
1620 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0077, TestSize.Level1)
1621 {
1622 OHOS::Print::PrintCupsClient printCupsClient;
1623 std::vector<PrinterInfo> printers;
1624 printCupsClient.DiscoverUsbPrinters(printers);
1625 EXPECT_EQ(printers.size(), 0);
1626 }
1627
1628 /**
1629 * @tc.name: PrintCupsClientTest_0078
1630 * @tc.desc: BuildJobParameters
1631 * @tc.type: FUNC
1632 * @tc.require:
1633 */
1634 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0078, TestSize.Level1)
1635 {
1636 OHOS::Print::PrintCupsClient printCupsClient;
1637 PrintJob testJob;
1638 testJob.SetJobId(GetDefaultJobId());
1639 std::vector<uint32_t> files = {1};
1640 testJob.SetFdList(files);
1641 OHOS::Print::PrintPageSize pageSize;
1642 pageSize.SetId("pgid-1234");
1643 testJob.SetPageSize(pageSize);
1644 testJob.SetPrinterId("printid-1234");
1645 testJob.SetOption(R"({"key": "value"})");
1646
1647 json optionJson = json::parse(testJob.GetOption());
1648 optionJson["printerUri"] = 1;
1649 optionJson["printerName"] = "printer1";
1650 optionJson["documentFormat"] = "application/pdf";
1651 testJob.SetOption(optionJson.dump());
1652 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1653 EXPECT_EQ(jobParams, nullptr);
1654
1655 optionJson["printerUri"] = "ipp://192.168.0.1:111/ipp/print";
1656 optionJson["printerName"] = 1;
1657 testJob.SetOption(optionJson.dump());
1658 jobParams = printCupsClient.BuildJobParameters(testJob);
1659 EXPECT_EQ(jobParams, nullptr);
1660
1661 optionJson["printerName"] = "printer1";
1662 optionJson["documentFormat"] = 1;
1663 testJob.SetOption(optionJson.dump());
1664 jobParams = printCupsClient.BuildJobParameters(testJob);
1665 EXPECT_EQ(jobParams, nullptr);
1666 }
1667
1668 /**
1669 * @tc.name: PrintCupsClientTest_0079
1670 * @tc.desc: HandleFiles
1671 * @tc.type: FUNC
1672 * @tc.require:
1673 */
1674 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0079, TestSize.Level1)
1675 {
1676 OHOS::Print::PrintCupsClient printCupsClient;
1677 http_t *http = nullptr;
1678 PrintJob testJob;
1679 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1680 int32_t numFiles = 1;
1681 int32_t jobId = 1;
1682 EXPECT_EQ(printCupsClient.HandleFiles(jobParams, numFiles, http, jobId), false);
1683 jobParams = nullptr;
1684 EXPECT_EQ(printCupsClient.HandleFiles(jobParams, numFiles, http, jobId), false);
1685 delete http;
1686 }
1687
1688 /**
1689 * @tc.name: PrintCupsClientTest_0080
1690 * @tc.desc: HandleJobState
1691 * @tc.type: FUNC
1692 * @tc.require:
1693 */
1694 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0080, TestSize.Level1)
1695 {
1696 OHOS::Print::PrintCupsClient printCupsClient;
1697 http_t *http = nullptr;
1698 JobStatus *prevousJobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1699 JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}};
1700 PrintJob testJob;
1701 testJob.SetJobId(GetDefaultJobId());
1702 std::vector<uint32_t> files = {1};
1703 testJob.SetFdList(files);
1704 OHOS::Print::PrintPageSize pageSize;
1705 pageSize.SetId("pgid-1234");
1706 testJob.SetPageSize(pageSize);
1707 testJob.SetPrinterId("printid-1234");
1708 testJob.SetOption(JOB_OPTIONS);
1709 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1710 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1711 jobParams->serviceJobId,
1712 1,
1713 "ipp://192.168.186.1:631/ipp/print",
1714 "DIRECT-PixLab_V1-0105"};
1715
1716 printCupsClient.HandleJobState(http, param, jobStatus, prevousJobStatus);
1717 EXPECT_NE(prevousJobStatus, nullptr);
1718 printCupsClient.QueryJobStateAgain(http, param, jobStatus);
1719 printCupsClient.HandleJobState(http, param, jobStatus, prevousJobStatus);
1720 EXPECT_NE(prevousJobStatus, nullptr);
1721 delete prevousJobStatus;
1722 delete jobStatus;
1723 delete param;
1724 delete http;
1725 }
1726
1727 /**
1728 * @tc.name: PrintCupsClientTest_0081
1729 * @tc.desc: MonitorJobState
1730 * @tc.type: FUNC
1731 * @tc.require:
1732 */
1733 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0081, TestSize.Level1)
1734 {
1735 OHOS::Print::PrintCupsClient printCupsClient;
__anon821cf7570102()1736 CallbackFunc callback = [this](){};
1737 PrintJob testJob;
1738 testJob.SetJobId(GetDefaultJobId());
1739 std::vector<uint32_t> files = {1};
1740 testJob.SetFdList(files);
1741 OHOS::Print::PrintPageSize pageSize;
1742 pageSize.SetId("pgid-1234");
1743 testJob.SetPageSize(pageSize);
1744 testJob.SetPrinterId("printid-1234");
1745 testJob.SetOption(JOB_OPTIONS);
1746 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1747 JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility,
1748 jobParams->serviceJobId,
1749 1,
1750 "ipp://192.168.186.1:631/ipp/print",
1751 "DIRECT-PixLab_V1-0105"};
1752
1753 printCupsClient.MonitorJobState(param, callback);
1754 EXPECT_NE(param, nullptr);
1755 param = nullptr;
1756 printCupsClient.MonitorJobState(param, callback);
1757 delete param;
1758 }
1759
1760 /**
1761 * @tc.name: PrintCupsClientTest_0082
1762 * @tc.desc: ResumePrinter
1763 * @tc.type: FUNC
1764 * @tc.require:
1765 */
1766 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0082, TestSize.Level1)
1767 {
1768 OHOS::Print::PrintCupsClient printCupsClient;
1769 std::string printerName = "testPrinterName";
1770 EXPECT_EQ(printCupsClient.ResumePrinter(printerName), false);
1771 printCupsClient.printAbility_ = nullptr;
1772 EXPECT_EQ(printCupsClient.ResumePrinter(printerName), true);
1773 }
1774
1775 /**
1776 * @tc.name: PrintCupsClientTest_0083
1777 * @tc.desc: FillLandscapeOptions
1778 * @tc.type: FUNC
1779 * @tc.require:
1780 */
1781 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0083, TestSize.Level1)
1782 {
1783 OHOS::Print::PrintCupsClient printCupsClient;
1784 PrintJob testJob;
1785 testJob.SetJobId(GetDefaultJobId());
1786 std::vector<uint32_t> files = {1};
1787 testJob.SetFdList(files);
1788 OHOS::Print::PrintPageSize pageSize;
1789 pageSize.SetId("pgid-1234");
1790 testJob.SetPageSize(pageSize);
1791 testJob.SetPrinterId("printid-1234");
1792 testJob.SetIsLandscape(true);
1793 testJob.SetOption(JOB_OPTIONS);
1794 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1795 jobParams->isAutoRotate = true;
1796 jobParams->borderless = 1;
1797 jobParams->isLandscape = true;
1798 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
1799 int numOptions = 0;
1800 cups_option_t *options = nullptr;
1801 printCupsClient.FillLandscapeOptions(jobParams, numOptions, &options);
1802 EXPECT_EQ(numOptions, 0);
1803 delete jobParams;
1804 delete options;
1805 }
1806
1807 /**
1808 * @tc.name: PrintCupsClientTest_0084
1809 * @tc.desc: FillLandscapeOptions
1810 * @tc.type: FUNC
1811 * @tc.require:
1812 */
1813 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0084, TestSize.Level1)
1814 {
1815 OHOS::Print::PrintCupsClient printCupsClient;
1816 PrintJob testJob;
1817 testJob.SetJobId(GetDefaultJobId());
1818 std::vector<uint32_t> files = {1};
1819 testJob.SetFdList(files);
1820 OHOS::Print::PrintPageSize pageSize;
1821 pageSize.SetId("pgid-1234");
1822 testJob.SetPageSize(pageSize);
1823 testJob.SetPrinterId("printid-1234");
1824 testJob.SetIsLandscape(true);
1825 testJob.SetOption(JOB_OPTIONS);
1826 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1827 jobParams->isAutoRotate = false;
1828 jobParams->borderless = 1;
1829 jobParams->isLandscape = true;
1830 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
1831 int numOptions = 0;
1832 cups_option_t *options = nullptr;
1833 printCupsClient.FillLandscapeOptions(jobParams, numOptions, &options);
1834 EXPECT_EQ(numOptions, 0);
1835 delete jobParams;
1836 delete options;
1837 }
1838
1839 /**
1840 * @tc.name: PrintCupsClientTest_0085
1841 * @tc.desc: FillLandscapeOptions
1842 * @tc.type: FUNC
1843 * @tc.require:
1844 */
1845 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0085, TestSize.Level1)
1846 {
1847 OHOS::Print::PrintCupsClient printCupsClient;
1848 PrintJob testJob;
1849 testJob.SetJobId(GetDefaultJobId());
1850 std::vector<uint32_t> files = {1};
1851 testJob.SetFdList(files);
1852 OHOS::Print::PrintPageSize pageSize;
1853 pageSize.SetId("pgid-1234");
1854 testJob.SetPageSize(pageSize);
1855 testJob.SetPrinterId("printid-1234");
1856 testJob.SetIsLandscape(true);
1857 testJob.SetOption(JOB_OPTIONS);
1858 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1859 jobParams->isAutoRotate = false;
1860 jobParams->borderless = 0;
1861 jobParams->isLandscape = false;
1862 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
1863 int numOptions = 0;
1864 cups_option_t *options = nullptr;
1865 printCupsClient.FillLandscapeOptions(jobParams, numOptions, &options);
1866 EXPECT_EQ(numOptions, 0);
1867 delete jobParams;
1868 delete options;
1869 }
1870
1871 /**
1872 * @tc.name: PrintCupsClientTest_0086
1873 * @tc.desc: FillLandscapeOptions
1874 * @tc.type: FUNC
1875 * @tc.require:
1876 */
1877 HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0086, TestSize.Level1)
1878 {
1879 OHOS::Print::PrintCupsClient printCupsClient;
1880 PrintJob testJob;
1881 testJob.SetJobId(GetDefaultJobId());
1882 std::vector<uint32_t> files = {1};
1883 testJob.SetFdList(files);
1884 OHOS::Print::PrintPageSize pageSize;
1885 pageSize.SetId("pgid-1234");
1886 testJob.SetPageSize(pageSize);
1887 testJob.SetPrinterId("printid-1234");
1888 testJob.SetIsLandscape(true);
1889 testJob.SetOption(JOB_OPTIONS);
1890 JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob);
1891 jobParams->isAutoRotate = false;
1892 jobParams->borderless = 1;
1893 jobParams->isLandscape = true;
1894 jobParams->mediaType = CUPS_MEDIA_TYPE_PHOTO_GLOSSY;
1895 int numOptions = 0;
1896 cups_option_t *options = nullptr;
1897 printCupsClient.FillLandscapeOptions(jobParams, numOptions, &options);
1898 EXPECT_EQ(numOptions, 0);
1899 delete jobParams;
1900 delete options;
1901 }
1902
1903 } // namespace Print
1904 } // namespace OHOS