• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include "print_service_mock_permission.h"
18 #include "mock_remote_object.h"
19 #define private public
20 #define protected public
21 #include "print_service_ability.h"
22 #include "print_bms_helper.h"
23 #undef protected
24 #undef private
25 #ifdef CUPS_ENABLE
26 #include "print_cups_client.h"
27 #endif // CUPS_ENABLE
28 #include "accesstoken_kit.h"
29 #include "array_wrapper.h"
30 #include "int_wrapper.h"
31 #include "ipc_skeleton.h"
32 #include "iservice_registry.h"
33 #include "parameters.h"
34 #include "print_constant.h"
35 #include "print_log.h"
36 #include "printer_info.h"
37 #include "print_utils.h"
38 #include "string_wrapper.h"
39 #include "system_ability_definition.h"
40 #include "want_params_wrapper.h"
41 #include "print_security_guard_manager.h"
42 #include "hisys_event_util.h"
43 #include <json/json.h>
44 #include "mock_print_callback_proxy.h"
45 #include "mock_print_extension_callback_proxy.h"
46 
47 
48 using namespace testing;
49 using namespace testing::ext;
50 
51 namespace OHOS::Print {
52 using namespace std;
53 using namespace OHOS::HiviewDFX;
54 using namespace Security::AccessToken;
55 static constexpr const char *DEFAULT_EXTENSION_ID = "com.example.ext";
56 static constexpr const char *UNLOAD_EXTENSION_ID = "com.example.ext.unload";
57 static constexpr const char *NONEXIST_EXTENSION_ID = "com.example.ext.nonexist";
58 static constexpr const char *DEFAULT_EXT_PRINTER_ID = "https://10.10.10.10/FE8083DCD35F";
59 static constexpr const char *DEFAULT_EXT_PRINTER_ID2 = "https://10.10.10.10/0FDA6E208473";
60 static constexpr const char *DEFAULT_PRINT_FILE_A = "file://data/print/a.png";
61 static constexpr const char *DEFAULT_PRINT_FILE_B = "file://data/print/b.png";
62 static constexpr const char *DEFAULT_PRINT_FILE_C = "file://data/print/c.png";
63 static const std::string PRINT_GET_FILE_EVENT_TYPE = "getPrintFileCallback_adapter";
64 static const std::string PRINTER_EVENT_TYPE = "printerStateChange";
65 static const std::string PRINTJOB_EVENT_TYPE = "jobStateChange";
66 static const std::string EXTINFO_EVENT_TYPE = "extInfoChange";
67 static const std::string PRINT_ADAPTER_EVENT_TYPE = "printCallback_adapter";
68 static const std::string EVENT_CANCEL = "cancel";
69 const uint32_t MAX_JOBQUEUE_NUM = 512;
70 static constexpr uint32_t ISO_A4_WIDTH = 8268;
71 static constexpr uint32_t ISO_A4_HEIGHT = 11692;
72 static const std::string IS_ENTERPRISE_ENABLE = "2";
73 static const std::string ENTERPRISE_SPACE_PARAM = "persist.space_mgr_service.enterprise_space_init";
74 
75 enum EXTENSION_ID_TYPE {
76     TYPE_DEFAULT,
77     TYPE_UNLOAD,
78     TYPE_NON_EXIST,
79 };
80 REGISTER_SYSTEM_ABILITY_BY_ID(PrintServiceAbility, PRINT_SERVICE_ID, true);
81 class PrintServiceAbilityTest : public testing::Test {
82 public:
83     static void SetUpTestCase(void);
84     static void TearDownTestCase(void);
85     void SetUp();
86     void TearDown();
87     std::string GetExtensionId(EXTENSION_ID_TYPE type);
88     std::string GetDefaultTaskId();
89     std::string GetDefaultJobId();
90     std::string GetDefaultPrinterId();
91     std::string GetInvalidPrinterId();
92     void InitExtPrinterList(std::vector<PrinterInfo> &printerList, size_t count);
93     void InitPrinterList(std::vector<PrinterInfo> &printerList, size_t count);
94     void InitExtPrinterIdList(std::vector<std::string> &idList, size_t count);
95     void InitFileList(std::vector<std::string> &fileList);
96     void InitExtensionList(std::vector<AppExecFwk::ExtensionAbilityInfo>& extList);
97 private:
98     std::string parameterSaved;
99 };
100 
SetUpTestCase(void)101 void PrintServiceAbilityTest::SetUpTestCase(void) {}
102 
TearDownTestCase(void)103 void PrintServiceAbilityTest::TearDownTestCase(void) {}
104 
SetUp(void)105 void PrintServiceAbilityTest::SetUp(void)
106 {
107     static int32_t testNo = 0;
108     PRINT_HILOGE("PrintServiceAbilityTest_%{public}d", ++testNo);
109     parameterSaved = OHOS::system::GetParameter(ENTERPRISE_SPACE_PARAM, "");
110     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, "");
111 }
112 
TearDown(void)113 void PrintServiceAbilityTest::TearDown(void)
114 {
115     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, parameterSaved);
116 }
117 
GetExtensionId(EXTENSION_ID_TYPE type)118 std::string PrintServiceAbilityTest::GetExtensionId(EXTENSION_ID_TYPE type)
119 {
120     switch (type) {
121         case TYPE_DEFAULT:
122             return DEFAULT_EXTENSION_ID;
123 
124         case TYPE_UNLOAD:
125             return UNLOAD_EXTENSION_ID;
126 
127         case TYPE_NON_EXIST:
128             return NONEXIST_EXTENSION_ID;
129 
130         default:
131             break;
132     }
133     return DEFAULT_EXTENSION_ID;
134 }
135 
GetDefaultTaskId()136 std::string PrintServiceAbilityTest::GetDefaultTaskId()
137 {
138     return std::to_string(0);
139 }
140 
GetDefaultJobId()141 std::string PrintServiceAbilityTest::GetDefaultJobId()
142 {
143     return std::to_string(0);
144 }
145 
GetDefaultPrinterId()146 std::string PrintServiceAbilityTest::GetDefaultPrinterId()
147 {
148     return PrintUtils::GetGlobalId(DEFAULT_EXTENSION_ID, DEFAULT_EXT_PRINTER_ID);
149 }
150 
GetInvalidPrinterId()151 std::string PrintServiceAbilityTest::GetInvalidPrinterId()
152 {
153     return PrintUtils::GetGlobalId(DEFAULT_EXTENSION_ID, "wrong printer id");
154 }
155 
InitExtPrinterList(std::vector<PrinterInfo> & printerList,size_t count)156 void PrintServiceAbilityTest::InitExtPrinterList(std::vector<PrinterInfo> &printerList, size_t count)
157 {
158     printerList.clear();
159     PrinterInfo info;
160     info.SetPrinterId(DEFAULT_EXT_PRINTER_ID);
161     printerList.emplace_back(info);
162     if (printerList.size() < count) {
163         info.SetPrinterId(DEFAULT_EXT_PRINTER_ID2);
164         printerList.emplace_back(info);
165     }
166 }
167 
InitPrinterList(std::vector<PrinterInfo> & printerList,size_t count)168 void PrintServiceAbilityTest::InitPrinterList(std::vector<PrinterInfo> &printerList, size_t count)
169 {
170     printerList.clear();
171     PrinterInfo info;
172     info.SetPrinterId(PrintUtils::GetGlobalId(DEFAULT_EXTENSION_ID, DEFAULT_EXT_PRINTER_ID));
173     printerList.emplace_back(info);
174     if (printerList.size() < count) {
175         info.SetPrinterId(PrintUtils::GetGlobalId(DEFAULT_EXTENSION_ID, DEFAULT_EXT_PRINTER_ID2));
176         printerList.emplace_back(info);
177     }
178 }
179 
InitExtPrinterIdList(std::vector<std::string> & idList,size_t count)180 void PrintServiceAbilityTest::InitExtPrinterIdList(std::vector<std::string> &idList, size_t count)
181 {
182     idList.clear();
183     idList.emplace_back(DEFAULT_EXT_PRINTER_ID);
184     if (idList.size() < count) {
185         idList.emplace_back(DEFAULT_EXT_PRINTER_ID2);
186     }
187 }
188 
InitFileList(std::vector<std::string> & fileList)189 void PrintServiceAbilityTest::InitFileList(std::vector<std::string> &fileList)
190 {
191     fileList.emplace_back(DEFAULT_PRINT_FILE_A);
192     fileList.emplace_back(DEFAULT_PRINT_FILE_B);
193     fileList.emplace_back(DEFAULT_PRINT_FILE_C);
194 }
195 
InitExtensionList(std::vector<AppExecFwk::ExtensionAbilityInfo> & extList)196 void PrintServiceAbilityTest::InitExtensionList(std::vector<AppExecFwk::ExtensionAbilityInfo>& extList)
197 {
198     std::vector<std::string> nameList = {DEFAULT_EXTENSION_ID, UNLOAD_EXTENSION_ID};
199     AppExecFwk::ExtensionAbilityInfo loadInfo;
200     for (size_t index = 0; index < nameList.size(); index++) {
201         loadInfo.bundleName = nameList[index];
202         loadInfo.moduleName = nameList[index];
203         loadInfo.name = nameList[index];
204         extList.emplace_back(loadInfo);
205     }
206 }
207 /**
208 * @tc.name: PrintServiceAbilityTest_0001
209 * @tc.desc: PrintServiceAbility ctor/dtor
210 * @tc.type: FUNC ~PrintServiceAbility()
211 * @tc.require:
212 */
213 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0001_NeedRename, TestSize.Level0)
214 {
215     PrintServiceAbility* print_service = new PrintServiceAbility(PRINT_SERVICE_ID, true);
216     if (print_service != nullptr) {
217         delete print_service;
218         print_service = nullptr;
219     }
220     PrintServiceAbility* new_print_service = new PrintServiceAbility(PRINT_SERVICE_ID, false);
221     if (new_print_service != nullptr) {
222         delete new_print_service;
223         new_print_service = nullptr;
224     }
225     EXPECT_EQ(PrintServiceAbility::GetInstance()->Init(), E_PRINT_SERVER_FAILURE);
226     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
227     std::shared_ptr<PrintServiceHelper> helper = nullptr;
228     service->SetHelper(helper);
229     EXPECT_EQ(PrintServiceAbility::GetInstance()->Init(), E_PRINT_SERVER_FAILURE);
230 }
231 /**
232 * @tc.name: PrintServiceAbilityTest_0002
233 * @tc.desc: PrintServiceAbility ctor/dtor
234 * @tc.type: FUNC ManualStart()
235 * @tc.require:
236 */
237 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0002_NeedRename, TestSize.Level0)
238 {
239     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
240     int state = static_cast<int>(service->state_);
241     service->ManualStart();
242     EXPECT_EQ(state, 0);
243 }
244 /**
245 * @tc.name: PrintServiceAbilityTest_0003
246 * @tc.desc: PrintServiceAbility ctor/dtor
247 * @tc.type: FUNC GetPrintJobOrderId()
248 * @tc.require:
249 */
250 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0003_NeedRename, TestSize.Level0)
251 {
252     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
253     service->GetPrintJobOrderId();
254     EXPECT_NE(service->currentJobOrderId_, 0);
255 }
256 /**
257 * @tc.name: PrintServiceAbilityTestPartOne_ErrorToken_ShouldNoPermission
258 * @tc.desc: PrintServiceAbility ctor/dtor
259 * @tc.type: FUNC
260 * @tc.require: return E_PRINT_NO_PERMISSION
261 */
262 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTestPartOne_ErrorToken_ShouldNoPermission, TestSize.Level1)
263 {
264     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
265     EXPECT_EQ(service->StartService(), E_PRINT_NO_PERMISSION);
266     std::vector<std::string> fileList = {};
267     std::vector<uint32_t> fdList = {};
268     std::string taskId = "";
269     std::shared_ptr<AdapterParam> adapterParam = std::make_shared<AdapterParam>();
270     EXPECT_EQ(service->StartPrint(fileList, fdList, taskId), E_PRINT_NO_PERMISSION);
271     EXPECT_EQ(service->CallSpooler(fileList, fdList, taskId), E_PRINT_NO_PERMISSION);
272     EXPECT_EQ(service->StopPrint(taskId), E_PRINT_NO_PERMISSION);
273     std::string printerId = "1234";
274     EXPECT_EQ(service->ConnectPrinter(printerId), E_PRINT_NO_PERMISSION);
275     EXPECT_EQ(service->DisconnectPrinter(printerId), E_PRINT_NO_PERMISSION);
276     std::vector<std::string> extensionIds;
277     EXPECT_EQ(service->StartDiscoverPrinter(extensionIds), E_PRINT_NO_PERMISSION);
278     EXPECT_EQ(service->StopDiscoverPrinter(), E_PRINT_NO_PERMISSION);
279     std::vector<PrintExtensionInfo> extensionInfos;
280     EXPECT_EQ(service->QueryAllExtension(extensionInfos), E_PRINT_NO_PERMISSION);
281     std::vector<PrintJob> printJobs;
282     EXPECT_EQ(service->QueryAllActivePrintJob(printJobs), E_PRINT_NO_PERMISSION);
283     std::vector<PrintJob> historyPrintJobs;
284     EXPECT_EQ(service->QueryAllPrintJob(historyPrintJobs), E_PRINT_NO_PERMISSION);
285     std::vector<std::string> printerList;
286     EXPECT_EQ(service->QueryAddedPrinter(printerList), E_PRINT_NO_PERMISSION);
287     PrinterInfo info;
288     EXPECT_EQ(service->QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_NO_PERMISSION);
289     std::vector<std::string> keyList;
290     std::vector<std::string> valueList;
291     EXPECT_EQ(service->QueryPrinterProperties(printerId, keyList, valueList), E_PRINT_NO_PERMISSION);
292     std::string printJobId = "1";
293     PrintJob printJob;
294     EXPECT_EQ(service->QueryPrintJobById(printJobId, printJob), E_PRINT_NO_PERMISSION);
295     std::string printerUri = "111.222.333";
296     std::string printerName = "pixlab_0759";
297     std::string printerMake = "pixlab b5";
298     EXPECT_EQ(service->AddPrinterToCups(printerUri, printerName, printerMake), E_PRINT_NO_PERMISSION);
299     PrinterCapability printerCaps;
300     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_NO_PERMISSION);
301     EXPECT_EQ(service->StartNativePrintJob(printJob), E_PRINT_NO_PERMISSION);
302     EXPECT_EQ(service->StartPrintJob(printJob), E_PRINT_NO_PERMISSION);
303     EXPECT_EQ(service->CancelPrintJob(printJobId), E_PRINT_NO_PERMISSION);
304     EXPECT_EQ(service->RestartPrintJob(printJobId), E_PRINT_NO_PERMISSION);
305 }
306 
307 /**
308 * @tc.name: PrintServiceAbilityTestPartTwo_ErrorToken_ShouldNoPermission
309 * @tc.desc: PrintServiceAbility ctor/dtor
310 * @tc.type: FUNC
311 * @tc.require: return E_PRINT_NO_PERMISSION
312 */
313 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTestPartTwo_ErrorToken_ShouldNoPermission, TestSize.Level1)
314 {
315     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
316     EXPECT_EQ(service->StartService(), E_PRINT_NO_PERMISSION);
317     std::string taskId = "";
318     std::string printerId = "1234";
319     std::string printJobId = "1";
320     PrintJob printJob;
321     std::vector<PrinterInfo> printerInfos;
322     EXPECT_EQ(service->AddPrinters(printerInfos), E_PRINT_NO_PERMISSION);
323     std::vector<std::string> printerIds;
324     EXPECT_EQ(service->RemovePrinters(printerIds), E_PRINT_NO_PERMISSION);
325     EXPECT_EQ(service->UpdatePrinters(printerInfos), E_PRINT_NO_PERMISSION);
326     uint32_t state = PrinterState::PRINTER_ADDED;
327     EXPECT_EQ(service->UpdatePrinterState(printerId, state), E_PRINT_NO_PERMISSION);
328     uint32_t subState = 0;
329     EXPECT_EQ(service->UpdatePrintJobStateOnlyForSystemApp(printJobId, state, subState), E_PRINT_NO_PERMISSION);
330     EXPECT_EQ(service->AdapterGetFileCallBack(printJobId, state, subState), E_PRINT_NONE);
331     state = PrintJobState::PRINT_JOB_CREATE_FILE_COMPLETED;
332     EXPECT_EQ(service->AdapterGetFileCallBack(printJobId, state, subState), E_PRINT_NO_PERMISSION);
333     std::string extInfo = "";
334     EXPECT_EQ(service->UpdateExtensionInfo(extInfo), E_PRINT_NO_PERMISSION);
335     std::string previewResult = "";
336     EXPECT_EQ(service->RequestPreview(printJob, previewResult), E_PRINT_NO_PERMISSION);
337     EXPECT_EQ(service->QueryPrinterCapability(printerId), E_PRINT_NO_PERMISSION);
338     std::string type = "";
339     sptr<IPrintCallback> listener = nullptr;
340     EXPECT_EQ(service->RegisterPrinterCallback(type, listener), E_PRINT_NO_PERMISSION);
341     EXPECT_EQ(service->UnregisterPrinterCallback(type), E_PRINT_NO_PERMISSION);
342     std::string extensionCID = "";
343     sptr<IPrintExtensionCallback> listenerCB = nullptr;
344     EXPECT_EQ(service->RegisterExtCallback(extensionCID, listenerCB), E_PRINT_NO_PERMISSION);
345     EXPECT_EQ(service->UnregisterAllExtCallback(extensionCID), E_PRINT_NO_PERMISSION);
346     EXPECT_EQ(service->LoadExtSuccess(extensionCID), E_PRINT_NO_PERMISSION);
347     std::string jobName = "a.jpeg";
348     PrintAttributes printAttributes;
349     EXPECT_EQ(service->PrintByAdapter(jobName, printAttributes, taskId), E_PRINT_NO_PERMISSION);
350     uint32_t fd = 46;
351     EXPECT_EQ(service->StartGetPrintFile(printJobId, printAttributes, fd), E_PRINT_NO_PERMISSION);
352     EXPECT_EQ(service->NotifyPrintService(printJobId, type), E_PRINT_NO_PERMISSION);
353     EXPECT_EQ(service->CallStatusBar(), E_PRINT_NO_PERMISSION);
354     uint32_t event = 0;
355     std::string jobId = GetDefaultJobId();
356     EXPECT_EQ(service->NotifyPrintServiceEvent(jobId, event), E_PRINT_NO_PERMISSION);
357     EXPECT_EQ(service->DestroyExtension(), E_PRINT_NO_PERMISSION);
358 }
359 
360 /**
361 * @tc.name: PrintServiceAbilityTestPartThree_ErrorToken_ShouldNoPermission
362 * @tc.desc: PrintServiceAbility ctor/dtor
363 * @tc.type: FUNC
364 * @tc.require: return E_PRINT_NO_PERMISSION
365 */
366 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTestPartThree_ErrorToken_ShouldNoPermission, TestSize.Level1)
367 {
368     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
369     EXPECT_EQ(service->StartService(), E_PRINT_NO_PERMISSION);
370     std::vector<std::string> fileList = {};
371     std::vector<uint32_t> fdList = {};
372     std::string taskId = "";
373     std::string printerId = "1234";
374     PrinterInfo info;
375     std::vector<std::string> valueList;
376     std::string printerName = "pixlab_0759";
377     std::string type = "";
378     sptr<IPrintCallback> listener = nullptr;
379     PrinterPreferences printerPreference;
380 
381     EXPECT_EQ(service->SetPrinterPreference(printerId, printerPreference), E_PRINT_NO_PERMISSION);
382     EXPECT_EQ(service->On(taskId, type, listener), E_PRINT_NO_PERMISSION);
383     EXPECT_EQ(service->Off(taskId, type), E_PRINT_NO_PERMISSION);
384     EXPECT_EQ(service->SetDefaultPrinter(printerId, 0), E_PRINT_NO_PERMISSION);
385     EXPECT_EQ(service->DeletePrinterFromCups(printerName), E_PRINT_NO_PERMISSION);
386     std::vector<PrinterInfo> printers;
387     EXPECT_EQ(service->DiscoverUsbPrinters(printers), E_PRINT_NO_PERMISSION);
388     EXPECT_EQ(service->UpdatePrinterInSystem(info), E_PRINT_NO_PERMISSION);
389 
390     PrintServiceMockPermission::MockPermission();
391     EXPECT_EQ(service->StartService(), E_PRINT_NONE);
392     EXPECT_EQ(service->StartPrint(fileList, fdList, taskId), E_PRINT_INVALID_PARAMETER);
393 
394     EXPECT_EQ(service->StopDiscoverPrinter(), E_PRINT_NONE);
395     EXPECT_EQ(service->StopPrint(taskId), E_PRINT_NONE);
396 }
397 
398 /**
399 * @tc.name: PrintServiceAbilityTest_0006
400 * @tc.desc: PrintServiceAbility ctor/dtor
401 * @tc.type: FUNC CallSpooler
402 * @tc.require: has token
403 */
404 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0006_NeedRename, TestSize.Level0)
405 {
406     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
407     std::vector<std::string> fileList = {};
408     std::vector<uint32_t> fdList = {};
409     std::string jobId = "";
410     EXPECT_EQ(service->CallSpooler(fileList, fdList, jobId), E_PRINT_INVALID_PARAMETER);
411     jobId = "jobId";
412     EXPECT_EQ(service->CallSpooler(fileList, fdList, jobId), E_PRINT_NONE);
413 }
414 
415 /**
416 * @tc.name: PrintServiceAbilityTest_0007
417 * @tc.desc: PrintServiceAbility ctor/dtor
418 * @tc.type: FUNC SetHelper
419 * @tc.require: has token
420 */
421 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0007_NeedRename, TestSize.Level1)
422 {
423     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
424     std::shared_ptr<PrintServiceHelper> helper = nullptr;
425     service->SetHelper(helper);
426     EXPECT_EQ(service->helper_, helper);
427     helper = make_shared<PrintServiceHelper>();
428     if (helper != nullptr) {
429         service->SetHelper(helper);
430         EXPECT_EQ(service->helper_, helper);
431     }
432 }
433 
434 /**
435 * @tc.name: PrintServiceAbilityTest_0008
436 * @tc.desc: PrintServiceAbility ctor/dtor
437 * @tc.type: FUNC ConnectPrinter
438 * @tc.require:
439 */
440 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0008_NeedRename, TestSize.Level1)
441 {
442     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
443     std::string printerId ="1234";
444     EXPECT_EQ(service->ConnectPrinter(printerId), E_PRINT_INVALID_PRINTER);
445     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
446     service->printSystemData_.discoveredPrinterInfoList_[printerId] = info;
447     service->ConnectPrinter(printerId);
448     std::string extensionId = PrintUtils::GetExtensionId(printerId);
449     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_CONNECT_PRINTER);
450     sptr<IPrintExtensionCallback> extCb = nullptr;
451     service->extCallbackMap_[cid] = extCb;
452     EXPECT_EQ(service->ConnectPrinter(printerId), E_PRINT_NONE);
453     extCb = new MockPrintExtensionCallbackProxy();
454     EXPECT_NE(extCb, nullptr);
455     if (extCb != nullptr) {
456         service->extCallbackMap_.clear();
457         service->extCallbackMap_[cid] = extCb;
458     }
459     service->ConnectPrinter(printerId);
460 }
461 
462 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0009_NeedRename, TestSize.Level1)
463 {
464     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
465     std::string printerId ="1234";
466     EXPECT_EQ(service->DisconnectPrinter(printerId), E_PRINT_INVALID_PRINTER);
467     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
468     service->printSystemData_.discoveredPrinterInfoList_[printerId] = info;
469     service->DisconnectPrinter(printerId);
470     std::string extensionId = PrintUtils::GetExtensionId(printerId);
471     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_CONNECT_PRINTER);
472     sptr<IPrintExtensionCallback> extCb = nullptr;
473     service->extCallbackMap_[cid] = extCb;
474     EXPECT_EQ(service->DisconnectPrinter(printerId), E_PRINT_SERVER_FAILURE);
475     extCb = new MockPrintExtensionCallbackProxy();
476     EXPECT_NE(extCb, nullptr);
477     if (extCb != nullptr) {
478         service->extCallbackMap_.clear();
479         service->extCallbackMap_[cid] = extCb;
480     }
481     service->DisconnectPrinter(printerId);
482 }
483 
484 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0010_NeedRename, TestSize.Level1)
485 {
486     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
487     std::vector<std::string> extensionIds;
488     EXPECT_EQ(service->StartDiscoverPrinter(extensionIds), E_PRINT_NONE);
489 }
490 
491 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0011_NeedRename, TestSize.Level1)
492 {
493     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
494     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
495     service->helper_ = helper;
496     std::string extensionCid = "";
497     sptr<IPrintExtensionCallback> listener = nullptr;
498     EXPECT_EQ(service->RegisterExtCallback(extensionCid, listener), E_PRINT_INVALID_PARAMETER);
499     extensionCid = PrintUtils::EncodeExtensionCid(GetExtensionId(TYPE_NON_EXIST), PRINT_EXTCB_START_DISCOVERY);
500     EXPECT_EQ(service->RegisterExtCallback(extensionCid, listener), E_PRINT_INVALID_EXTENSION);
501     extensionCid = PrintUtils::EncodeExtensionCid(GetExtensionId(TYPE_UNLOAD), PRINT_EXTCB_START_DISCOVERY);
502     EXPECT_EQ(service->RegisterExtCallback(extensionCid, listener), E_PRINT_INVALID_EXTENSION);
503     extensionCid = PrintUtils::EncodeExtensionCid(GetExtensionId(TYPE_DEFAULT), PRINT_EXTCB_MAX);
504     EXPECT_EQ(service->RegisterExtCallback(extensionCid, listener), E_PRINT_INVALID_EXTENSION);
505     EXPECT_EQ(service->LoadExtSuccess(GetExtensionId(TYPE_NON_EXIST)), E_PRINT_INVALID_EXTENSION);
506     EXPECT_EQ(service->LoadExtSuccess(GetExtensionId(TYPE_UNLOAD)), E_PRINT_INVALID_EXTENSION);
507 }
508 
509 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0012_NeedRename, TestSize.Level1)
510 {
511     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
512     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
513     service->helper_ = helper;
514     std::string taskId = "";
515     std::string type = "";
516     sptr<IPrintCallback> listener = nullptr;
517     EXPECT_EQ(service->On(taskId, type, listener), E_PRINT_INVALID_PARAMETER);
518     EXPECT_EQ(service->Off(taskId, type), E_PRINT_INVALID_PARAMETER);
519     taskId = "1";
520     type = "printCallback_adapter";
521     service->On(taskId, type, listener);
522     EXPECT_EQ(service->On(taskId, type, listener), E_PRINT_INVALID_PARAMETER);
523     EXPECT_EQ(service->Off(taskId, type), E_PRINT_NONE);
524     listener = new MockPrintCallbackProxy();
525     if (listener != nullptr) {
526         service->On(taskId, type, listener);
527     }
528     service->registeredListeners_[type] = listener;
529     taskId = "";
530     EXPECT_EQ(service->On(taskId, type, listener), E_PRINT_NONE);
531     EXPECT_EQ(service->Off(taskId, type), E_PRINT_NONE);
532 }
533 
534 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0013_NeedRename, TestSize.Level1)
535 {
536     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
537     std::vector<PrinterInfo> printerInfos;
538     InitExtPrinterList(printerInfos, 1);
539     EXPECT_EQ(service->AddPrinters(printerInfos), E_PRINT_NONE);
540     EXPECT_EQ(service->UpdatePrinters(printerInfos), E_PRINT_NONE);
541     std::vector<std::string> printerIds;
542     InitExtPrinterIdList(printerIds, 1);
543     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
544     info->SetPrinterId(printerIds[0]);
545     std::string printerId = printerIds[0];
546     service->printSystemData_.discoveredPrinterInfoList_[printerId] = info;
547     EXPECT_EQ(service->RemovePrinters(printerIds), E_PRINT_NONE);
548     std::vector<std::string> newPrinterIds;
549     newPrinterIds.push_back("1234");
550     auto printer = std::make_shared<PrinterInfo>();
551     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
552     service->RemovePrinters(newPrinterIds);
553     printerInfos.clear();
554     EXPECT_EQ(service->UpdatePrinters(printerInfos), E_PRINT_NONE);
555 }
556 
557 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0014_NeedRename, TestSize.Level1)
558 {
559     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
560     PrintJob testJob;
561     std::string jobId = GetDefaultJobId();
562     testJob.SetJobId(jobId);
563     testJob.SetPrinterId(GetDefaultPrinterId());
564     EXPECT_EQ(service->StartPrintJob(testJob), E_PRINT_INVALID_PRINTJOB);
565     std::shared_ptr<PrintJob> job = std::make_shared<PrintJob>();
566     service->printJobList_["1"] = job;
567     EXPECT_EQ(service->StartPrintJob(testJob), E_PRINT_INVALID_PRINTJOB);
568     service->printJobList_["0"] = job;
569     std::string extensionId = PrintUtils::GetExtensionId(GetDefaultPrinterId());
570     sptr<IPrintExtensionCallback> listener = nullptr;
571     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_PRINT);
572     service->extCallbackMap_[cid] = listener;
573     service->StartPrintJob(testJob);
574 }
575 
576 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0018_NeedRename, TestSize.Level1)
577 {
578     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
579     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
580     service->helper_ = helper;
581     std::string jobId ="1";
582     uint32_t state = PRINT_JOB_PREPARED;
583     uint32_t subState = PRINT_JOB_COMPLETED_SUCCESS;
584     service->notifyAdapterJobChanged(jobId, state, subState);
585     auto attrIt = service->printAttributesList_.find(jobId);
586     EXPECT_EQ(attrIt, service->printAttributesList_.end());
587     PrintAttributes attr;
588     service->printAttributesList_[jobId] = attr;
589     service->notifyAdapterJobChanged(jobId, state, subState);
590     attrIt = service->printAttributesList_.find(jobId);
591     EXPECT_NE(attrIt, service->printAttributesList_.end());
592     sptr<IPrintCallback> listener = nullptr;
593     service->adapterListenersByJobId_[jobId] = listener;
594     service->notifyAdapterJobChanged(jobId, state, subState);
595     attrIt = service->printAttributesList_.find(jobId);
596     EXPECT_NE(attrIt, service->printAttributesList_.end());
597 }
598 
599 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0019_NeedRename, TestSize.Level1)
600 {
601     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
602     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
603     service->helper_ = helper;
604     std::string jobId ="1";
605     uint32_t state = PRINT_JOB_PREPARED;
606     uint32_t subState = PRINT_JOB_COMPLETED_SUCCESS;
607 
608     state = PRINT_JOB_BLOCKED;
609     service->notifyAdapterJobChanged(jobId, state, subState);
610     auto attrIt = service->printAttributesList_.find(jobId);
611     EXPECT_EQ(attrIt, service->printAttributesList_.end());
612 }
613 
614 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0020_NeedRename, TestSize.Level1)
615 {
616     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
617     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
618     service->helper_ = helper;
619     std::string jobName = "a.jpeg";
620     PrintAttributes printAttributes;
621     std::string taskId ="1";
622     EXPECT_EQ(service->PrintByAdapter(jobName, printAttributes, taskId), E_PRINT_NONE);
623 }
624 
625 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0021_NeedRename, TestSize.Level1)
626 {
627     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
628     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
629     service->helper_ = helper;
630     std::string jobId = "1";
631     PrintAttributes printAttributes;
632     uint32_t fd = 46;
633     sptr<IPrintCallback> listener = nullptr;
634     service->adapterListenersByJobId_[jobId] = listener;
635     EXPECT_EQ(service->StartGetPrintFile(jobId, printAttributes, fd), E_PRINT_NONE);
636     service->adapterListenersByJobId_.clear();
637 
638     EXPECT_EQ(service->StartGetPrintFile(jobId, printAttributes, fd), E_PRINT_NONE);
639     service->printAttributesList_[jobId] = printAttributes;
640     EXPECT_EQ(service->StartGetPrintFile(jobId, printAttributes, fd), E_PRINT_NONE);
641     std::string newJobId = "2";
642     EXPECT_EQ(service->StartGetPrintFile(newJobId, printAttributes, fd), E_PRINT_NONE);
643 }
644 
645 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0022_NeedRename, TestSize.Level1)
646 {
647     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
648     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
649     service->helper_ = helper;
650     std::string printerId = "1234";
651     std::shared_ptr<PrinterInfo> info =std::make_shared<PrinterInfo>();
652     service->printSystemData_.discoveredPrinterInfoList_[printerId] = info;
653     EXPECT_EQ(service->printSystemData_.QueryDiscoveredPrinterInfoById(printerId), info);
654 }
655 
656 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0024_NeedRename, TestSize.Level1)
657 {
658     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
659     PrintJob jobInfo;
660     service->CheckJobQueueBlocked(jobInfo);
661     EXPECT_EQ(service->isJobQueueBlocked_, false);
662 }
663 
664 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0025_NeedRename, TestSize.Level1)
665 {
666     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
667     std::string extensionId = "com.ohos.spooler:0";
668     EXPECT_EQ(service->DelayStartDiscovery(extensionId), false);
669     service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
670     EXPECT_EQ(service->DelayStartDiscovery(extensionId), false);
671     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_STOP_DISCOVERY);
672     sptr<IPrintExtensionCallback> listener = nullptr;
673     service->extCallbackMap_[cid] = listener;
674     EXPECT_EQ(service->DelayStartDiscovery(extensionId), false);
675     cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_DISCOVERY);
676     service->extCallbackMap_.clear();
677     service->extCallbackMap_[cid] = listener;
678     EXPECT_EQ(service->DelayStartDiscovery(extensionId), false);
679 }
680 
681 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0026_NeedRename, TestSize.Level1)
682 {
683     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
684     service->state_ = ServiceRunningState::STATE_NOT_START;
685     service->OnStop();
686     EXPECT_EQ(service->state_, ServiceRunningState::STATE_NOT_START);
687     service->state_ = ServiceRunningState::STATE_RUNNING;
688     service->OnStop();
689     EXPECT_EQ(service->state_, ServiceRunningState::STATE_NOT_START);
690 }
691 
692 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0028_NeedRename, TestSize.Level1)
693 {
694     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
695     std::string extensionId = "com.ohos.spooler:0";
696     service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
697     EXPECT_EQ(service->StopDiscoverPrinter(), E_PRINT_NONE);
698     service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADED;
699     EXPECT_EQ(service->StopDiscoverPrinter(), E_PRINT_NONE);
700     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_STOP_DISCOVERY);
701     sptr<IPrintExtensionCallback> listener = nullptr;
702     service->extCallbackMap_[cid] = listener;
703     EXPECT_EQ(service->StopDiscoverPrinter(), E_PRINT_NONE);
704 }
705 
706 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0029_NeedRename, TestSize.Level1)
707 {
708     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
709     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
710     service->helper_ = helper;
711     std::vector<PrintJob> printJobs;
712     int32_t userId = 100;
713     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
714     service->printUserMap_.insert(std::make_pair(userId, userData));
715     EXPECT_EQ(service->QueryAllActivePrintJob(printJobs), E_PRINT_NONE);
716 }
717 
718 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0156_NeedRename, TestSize.Level1)
719 {
720     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
721     std::vector<PrintJob> printJobs;
722     int32_t userId = 100;
723     service->printUserMap_.insert(std::make_pair(userId, nullptr));
724     EXPECT_EQ(service->QueryAllPrintJob(printJobs), E_PRINT_INVALID_USERID);
725     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
726     service->printUserMap_.erase(userId);
727     service->printUserMap_.insert(std::make_pair(userId, userData));
728     EXPECT_EQ(service->QueryAllPrintJob(printJobs), E_PRINT_NONE);
729 }
730 
731 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0030_NeedRename, TestSize.Level1)
732 {
733     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
734     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
735     service->helper_ = helper;
736     std::vector<PrintJob> printJobs;
737     service->QueryAllActivePrintJob(printJobs);
738     EXPECT_EQ(service->QueryAllActivePrintJob(printJobs), E_PRINT_NONE);
739     int32_t userId = 100;
740     service->printUserMap_.insert(std::make_pair(userId, nullptr));
741     service->QueryAllActivePrintJob(printJobs);
742     EXPECT_EQ(service->QueryAllActivePrintJob(printJobs), E_PRINT_NONE);
743 }
744 
745 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0031_NeedRename, TestSize.Level1)
746 {
747     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
748     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
749     service->helper_ = helper;
750     std::vector<std::string> printerList;
751     EXPECT_EQ(service->QueryAddedPrinter(printerList), E_PRINT_NONE);
752 }
753 
754 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0032_NeedRename, TestSize.Level1)
755 {
756     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
757     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
758     service->helper_ = helper;
759     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
760     std::vector<std::string> keyList;
761     std::vector<std::string> valueList;
762     EXPECT_EQ(service->QueryPrinterProperties(printerId, keyList, valueList), E_PRINT_INVALID_PRINTER);
763     auto printerInfo = std::make_shared<PrinterInfo>();
764     keyList.push_back("printerId");
765     keyList.push_back("printerName");
766     EXPECT_EQ(service->QueryPrinterProperties(printerId, keyList, valueList), E_PRINT_INVALID_PRINTER);
767 }
768 
769 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0033_NeedRename, TestSize.Level1)
770 {
771     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
772     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
773     service->helper_ = helper;
774     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
775     PrinterInfo info;
776     EXPECT_EQ(service->QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_INVALID_PRINTER);
777     auto printerInfo = std::make_shared<PrinterInfo>();
778     printerInfo->SetPrinterName("testName");
779     printerInfo->SetUri("testUri");
780     printerInfo->SetPrinterMake("testMaker");
781     printerInfo->SetAlias("testAlias");
782     service->printSystemData_.addedPrinterMap_.Insert(printerId, printerInfo);
783     EXPECT_EQ(service->QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_NONE);
784 }
785 
786 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0034_NeedRename, TestSize.Level1)
787 {
788     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
789     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
790     service->helper_ = helper;
791     std::string printJobId = "1";
792     PrintJob printJob;
793     EXPECT_EQ(service->QueryPrintJobById(printJobId, printJob), E_PRINT_INVALID_PRINTJOB);
794     int32_t userId = 100;
795     service->printUserMap_.insert(std::make_pair(userId, nullptr));
796     EXPECT_EQ(service->QueryPrintJobById(printJobId, printJob), E_PRINT_INVALID_PRINTJOB);
797 }
798 
799 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0035_NeedRename, TestSize.Level1)
800 {
801     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
802     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
803     service->helper_ = helper;
804     std::string printerUri = "testPrinterUri";
805     std::string printerName = "testPrinterName";
806     std::string printerMake = "testPrinterMake";
807     EXPECT_EQ(service->AddPrinterToCups(printerUri, printerName, printerMake), E_PRINT_SERVER_FAILURE);
808 }
809 
810 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0036_NeedRename, TestSize.Level1)
811 {
812     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
813     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
814     service->helper_ = helper;
815     PrintJob printJob1;
816     printJob1.SetOption("test");
817     EXPECT_EQ(service->UpdatePrintJobOptionByPrinterId(printJob1), false);
818 
819     PrintJob printJob2;
820     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
821     printJob2.SetPrinterId(printerId);
822     auto printerInfo = std::make_shared<PrinterInfo>();
823     printerInfo->SetPrinterName("testName");
824     printerInfo->SetUri("testUri");
825     printerInfo->SetPrinterMake("testMaker");
826     service->printSystemData_.addedPrinterMap_.Insert(printerId, printerInfo);
827     EXPECT_EQ(service->UpdatePrintJobOptionByPrinterId(printJob2), false);
828 
829     Json::Value infoJson;
830     infoJson["printerName"] = "testPrinterName";
831     printJob2.SetOption(PrintJsonUtil::WriteString(infoJson));
832     EXPECT_EQ(service->UpdatePrintJobOptionByPrinterId(printJob2), true);
833     service->StartNativePrintJob(printJob2);
834     std::string extensionId = PrintUtils::GetExtensionId(printerId);
835     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_PRINT);
836     sptr<IPrintExtensionCallback> extCb = nullptr;
837     service->extCallbackMap_[cid] = extCb;
838     service->StartNativePrintJob(printJob2);
839 }
840 
841 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0037_NeedRename, TestSize.Level1)
842 {
843     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
844     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
845     service->helper_ = helper;
846     PrintJob printJob;
847     std::string jobId = GetDefaultJobId();
848     auto nativePrintJob = std::make_shared<PrintJob>();
849     nativePrintJob->UpdateParams(printJob);
850     nativePrintJob->Dump();
851     service->AddToPrintJobList(jobId, nativePrintJob);
852     EXPECT_NE(service->AddNativePrintJob(jobId, printJob), nativePrintJob);
853 }
854 
855 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0038_NeedRename, TestSize.Level1)
856 {
857     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
858     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
859     service->helper_ = helper;
860     PrintJob printJob;
861     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
862     printJob.SetPrinterId(printerId);
863     auto printerInfo = std::make_shared<PrinterInfo>();
864     printerInfo->SetPrinterName("testName");
865     printerInfo->SetUri("testUri");
866     printerInfo->SetPrinterMake("testMaker");
867     service->printSystemData_.addedPrinterMap_.Insert(printerId, printerInfo);
868     printJob.SetOption("test");
869     EXPECT_EQ(service->StartNativePrintJob(printJob), E_PRINT_INVALID_PRINTER);
870 }
871 
872 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0040_NeedRename, TestSize.Level1)
873 {
874     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
875     service->ManualStart();
876     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
877     service->helper_ = helper;
878     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
879     std::string jobId = GetDefaultJobId();
880     service->UpdateQueuedJobList(jobId, printJob);
881     service->UpdateQueuedJobList("0", printJob);
882     for (int i = 0; i < MAX_JOBQUEUE_NUM + 1; i++) {
883         service->queuedJobList_.insert(std::make_pair(std::to_string(i), printJob));
884     }
885     service->UpdateQueuedJobList("515", printJob);
886     int32_t userId = 100;
887     service->printUserMap_.insert(std::make_pair(userId, nullptr));
888     service->UpdateQueuedJobList("515", printJob);
889     std::string type ="0";
890     EXPECT_EQ(service->NotifyPrintService(jobId, type), E_PRINT_NONE);
891     type = "spooler_closed_for_started";
892     EXPECT_EQ(service->NotifyPrintService(jobId, type), E_PRINT_NONE);
893     type = "spooler_closed_for_cancelled";
894     EXPECT_EQ(service->NotifyPrintService(jobId, type), E_PRINT_NONE);
895     type = "";
896     EXPECT_EQ(service->NotifyPrintService(jobId, type), E_PRINT_INVALID_PARAMETER);
897 }
898 
899 HWTEST_F(PrintServiceAbilityTest, CancelPrintJob_WhenInvalidUserData_ShoudFailed, TestSize.Level1)
900 {
901     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
902     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
903     service->helper_ = helper;
904     std::string jobId = GetDefaultJobId();
905     int32_t userId = 100;
906     service->printUserMap_.insert(std::make_pair(userId, nullptr));
907     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_INVALID_USERID);
908 }
909 
910 HWTEST_F(PrintServiceAbilityTest, RestartPrintJob_WhenInvalidUserData_ShouldFailed, TestSize.Level1)
911 {
912     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
913     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
914     service->helper_ = helper;
915     std::string jobId = GetDefaultJobId();
916     EXPECT_EQ(service->RestartPrintJob(jobId), E_PRINT_INVALID_PRINTJOB);
917     int32_t userId = 100;
918     service->printUserMap_.insert(std::make_pair(userId, nullptr));
919     EXPECT_EQ(service->RestartPrintJob(jobId), E_PRINT_INVALID_PRINTJOB);
920 }
921 
922 HWTEST_F(PrintServiceAbilityTest, RestartPrintJob_WhenBedfd_ShouldFailed, TestSize.Level1)
923 {
924     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
925     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
926     service->helper_ = helper;
927     std::string jobId = "123";
928     int32_t userId = 100;
929     service->userJobMap_[jobId] = userId;
930     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
931     service->printUserMap_[userId] = userData;
932     EXPECT_EQ(service->RestartPrintJob(jobId), E_PRINT_INVALID_PRINTJOB);
933     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
934     userData->queuedJobList_[jobId] = printJob;
935     EXPECT_EQ(service->RestartPrintJob(jobId), E_PRINT_FILE_IO);
936 }
937 
938 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0042_NeedRename, TestSize.Level1)
939 {
940     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
941     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
942     service->helper_ = helper;
943     PrintJob printJob;
944     printJob.SetJobId(GetDefaultJobId());
945     service->SetPrintJobCanceled(printJob);
946     auto testPrintJob = std::make_shared<PrintJob>(printJob);
947     std::string testJobId = testPrintJob->GetJobId();
948     auto attrIt = service->printAttributesList_.find(testJobId);
949     EXPECT_EQ(attrIt, service->printAttributesList_.end());
950     std::string jobId = "123";
951     printJob.SetJobId(jobId);
952     int32_t userId = 100;
953     service->userJobMap_[jobId] = userId;
954     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
955     service->printUserMap_[userId] = userData;
956     service->SetPrintJobCanceled(printJob);
957     testPrintJob = std::make_shared<PrintJob>(printJob);
958     testJobId = testPrintJob->GetJobId();
959     attrIt = service->printAttributesList_.find(testJobId);
960     EXPECT_EQ(attrIt, service->printAttributesList_.end());
961 }
962 
963 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0043_NeedRename, TestSize.Level1)
964 {
965     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
966     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
967     service->helper_ = helper;
968     int32_t userId = 100;
969     service->CancelUserPrintJobs(userId);
970     auto userIt = service->printUserMap_.find(userId);
971     EXPECT_EQ(userIt, service->printUserMap_.end());
972 
973     service->printUserMap_.insert(std::make_pair(userId, nullptr));
974     service->CancelUserPrintJobs(userId);
975     userIt = service->printUserMap_.find(userId);
976     EXPECT_NE(userIt, service->printUserMap_.end());
977 
978     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
979     service->printUserMap_[userId] = userData;
980     service->CancelUserPrintJobs(userId);
981     userIt = service->printUserMap_.find(userId);
982     EXPECT_EQ(userIt, service->printUserMap_.end());
983 }
984 
985 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0044_NeedRename, TestSize.Level1)
986 {
987     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
988     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
989     service->helper_ = helper;
990     PrintJob printJob;
991     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
992     EXPECT_EQ(service->SendQueuePrintJob(printerId), false);
993 
994     std::string jobId = GetDefaultJobId();
995     service->printerJobMap_[printerId].insert(std::make_pair(jobId, true));
996     EXPECT_EQ(service->SendQueuePrintJob(printerId), false);
997     int32_t userId = 100;
998     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
999     service->printUserMap_[userId] = userData;
1000     EXPECT_EQ(service->SendQueuePrintJob(printerId), false);
1001 }
1002 
1003 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0045_NeedRename, TestSize.Level1)
1004 {
1005     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1006     std::string printerUri = "111.222.333";
1007     std::string printerId = "pixlab_0759";
1008     PrinterCapability printerCaps;
1009     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_NONE);
1010 }
1011 
1012 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0046_NeedRename, TestSize.Level1)
1013 {
1014     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1015     std::string jobId = "1";
1016     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1017     service->StartPrintJobCB(jobId, printJob);
1018     EXPECT_EQ(printJob->jobState_, PRINT_JOB_QUEUED);
1019 }
1020 
1021 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0048_NeedRename, TestSize.Level1)
1022 {
1023     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1024     uint32_t state = PRINTER_UNKNOWN + 1;
1025     std::string printerId ="1234";
1026     EXPECT_EQ(service->UpdatePrinterState(printerId, state), E_PRINT_INVALID_PARAMETER);
1027     state = PrinterState::PRINTER_ADDED;
1028     EXPECT_EQ(service->UpdatePrinterState(printerId, state), E_PRINT_INVALID_PRINTER);
1029     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
1030     service->printSystemData_.discoveredPrinterInfoList_[printerId] = info;
1031     EXPECT_EQ(service->UpdatePrinterState(printerId, state), E_PRINT_NONE);
1032 }
1033 
1034 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0049_NeedRename, TestSize.Level1)
1035 {
1036     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1037     std::string jobId = "1";
1038     uint32_t state = PRINTER_UNKNOWN + 1;
1039     uint32_t subState = 0;
1040     uint32_t userId = 100;
1041     EXPECT_EQ(service->checkJobState(state, subState), true);
1042     service->UpdatePrintJobState(jobId, state, subState);
1043     state = PRINT_JOB_BLOCKED;
1044     subState = PRINT_JOB_BLOCKED_OFFLINE - 1;
1045     EXPECT_EQ(service->checkJobState(state, subState), false);
1046     EXPECT_EQ(service->UpdatePrintJobState(jobId, state, subState), E_PRINT_INVALID_PARAMETER);
1047     subState = PRINT_JOB_BLOCKED_UNKNOWN + 1;
1048     EXPECT_EQ(service->checkJobState(state, subState), true);
1049     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1050     service->userJobMap_.insert(std::make_pair(jobId, userId));
1051     service->printUserMap_.insert(std::make_pair(userId, userData));
1052     EXPECT_EQ(service->UpdatePrintJobState(jobId, state, subState), E_PRINT_INVALID_PRINTJOB);
1053     state = PRINT_JOB_COMPLETED;
1054     subState = PRINT_JOB_COMPLETED_FILE_CORRUPT + 1;
1055     EXPECT_EQ(service->checkJobState(state, subState), false);
1056     EXPECT_EQ(service->UpdatePrintJobState(jobId, state, subState), E_PRINT_INVALID_PARAMETER);
1057 }
1058 
1059 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0050_NeedRename, TestSize.Level1)
1060 {
1061     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1062     std::string jobId = "1";
1063     uint32_t state = PRINT_JOB_CREATE_FILE_COMPLETED;
1064     uint32_t subState = 0;
1065     EXPECT_EQ(service->UpdatePrintJobState(jobId, state, subState), false);
1066 }
1067 
1068 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0051_NeedRename, TestSize.Level1)
1069 {
1070     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1071     std::string jobId = "1";
1072     uint32_t state = PRINTER_UNKNOWN;
1073     uint32_t subState = 0;
1074     EXPECT_EQ(service->AdapterGetFileCallBack(jobId, state, subState), E_PRINT_NONE);
1075     std::string type = PRINT_GET_FILE_EVENT_TYPE;
1076     sptr<IPrintCallback>  listener = new MockPrintCallbackProxy();
1077     service->registeredListeners_[type] = listener;
1078     service->AdapterGetFileCallBack(jobId, state, subState);
1079     subState = PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS;
1080     service->AdapterGetFileCallBack(jobId, state, subState);
1081     subState = PRINT_JOB_CREATE_FILE_COMPLETED_FAILED;
1082     service->AdapterGetFileCallBack(jobId, state, subState);
1083 }
1084 
1085 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0052_NeedRename, TestSize.Level1)
1086 {
1087     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1088     std::string jobId = "1";
1089     int32_t userId = 0;
1090     uint32_t state = PRINTER_UNKNOWN;
1091     uint32_t subState = 0;
1092     service->printUserMap_.insert(std::make_pair(userId, nullptr));
1093     EXPECT_EQ(service->CheckAndSendQueuePrintJob(jobId, state, subState), E_PRINT_INVALID_USERID);
1094     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1095     service->printUserMap_.erase(userId);
1096     service->userJobMap_.insert(std::make_pair(jobId, userId));
1097     service->printUserMap_.insert(std::make_pair(userId, userData));
1098     EXPECT_EQ(service->CheckAndSendQueuePrintJob(jobId, state, subState), E_PRINT_INVALID_PRINTJOB);
1099     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1100     std::string printerId = "1234";
1101     printJob->SetPrinterId(printerId);
1102     printJob->SetJobId(jobId);
1103     printJob->SetOption("{\"test\":\"test\"}");
1104     userData->AddPrintJobToHistoryList(printJob->GetPrinterId(), printJob->GetJobId(), printJob);
1105     EXPECT_EQ(service->CheckAndSendQueuePrintJob(printJob->GetJobId(), state, subState), E_PRINT_NONE);
1106     userData->printJobList_[jobId] = printJob;
1107     state = PRINT_JOB_BLOCKED;
1108     service->printerJobMap_[printerId].insert(std::make_pair(jobId, true));
1109     auto printerInfo = std::make_shared<PrinterInfo>();
1110     service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
1111     userData->queuedJobList_[jobId] = printJob;
1112     EXPECT_EQ(service->CheckAndSendQueuePrintJob(printJob->GetJobId(), state, subState), E_PRINT_NONE);
1113     state = PRINT_JOB_COMPLETED;
1114     EXPECT_EQ(service->CheckAndSendQueuePrintJob(printJob->GetJobId(), state, subState), E_PRINT_NONE);
1115 }
1116 
1117 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0053_NeedRename, TestSize.Level1)
1118 {
1119     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1120     std::string jobId = "1";
1121     EXPECT_EQ(service->IsQueuedJobListEmpty(jobId), false);
1122     int32_t userId = 100;
1123     service->userJobMap_[jobId] = userId;
1124     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1125     auto printJob = std::make_shared<PrintJob>();
1126     userData->queuedJobList_[jobId] = printJob;
1127     service->printUserMap_[userId] = userData;
1128     EXPECT_EQ(service->IsQueuedJobListEmpty(jobId), false);
1129     userData->queuedJobList_.clear();
1130     service->currentUserId_ = 0;
1131     EXPECT_EQ(service->IsQueuedJobListEmpty(jobId), false);
1132     service->currentUserId_ = 100;
1133     EXPECT_EQ(service->IsQueuedJobListEmpty(jobId), true);
1134 }
1135 
1136 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0055_NeedRename, TestSize.Level1)
1137 {
1138     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1139     uint32_t event = -1;
1140     std::string jobId = GetDefaultJobId();
1141     EXPECT_EQ(service->NotifyPrintServiceEvent(jobId, event), E_PRINT_INVALID_PARAMETER);
1142     event = 3;
1143     EXPECT_EQ(service->NotifyPrintServiceEvent(jobId, event), E_PRINT_INVALID_PARAMETER);
1144     event = 0;
1145     service->NotifyPrintServiceEvent(jobId, event);
1146     auto printJob = std::make_shared<PrintJob>();
1147     service->printJobList_[jobId] = printJob;
1148     service->NotifyPrintServiceEvent(jobId, event);
1149     event = 1;
1150     service->NotifyPrintServiceEvent(jobId, event);
1151     event = 2;
1152     service->NotifyPrintServiceEvent(jobId, event);
1153     event = 3;
1154     service->NotifyPrintServiceEvent(jobId, event);
1155 }
1156 
1157 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0056_NeedRename, TestSize.Level1)
1158 {
1159     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1160     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1161     service->helper_ = helper;
1162     std::string type = "";
1163     sptr<IPrintCallback> listener = nullptr;
1164     EXPECT_EQ(service->RegisterPrinterCallback(type, listener), E_PRINT_INVALID_PARAMETER);
1165     EXPECT_EQ(service->UnregisterPrinterCallback(type), E_PRINT_INVALID_TOKEN);
1166     sptr<IPrintCallback> listener2 = new MockPrintCallbackProxy();
1167     service->RegisterPrinterCallback(type, listener2);
1168     service->UnregisterPrinterCallback(type);
1169 }
1170 
1171 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0057_NeedRename, TestSize.Level1)
1172 {
1173     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1174     int event = 0;
1175     PrinterInfo info;
1176     EXPECT_EQ(service->SendPrinterChangeEvent(event, info), 0);
1177 }
1178 
1179 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0059_NeedRename, TestSize.Level1)
1180 {
1181     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1182     PrintJob jobInfo;
1183     std::string previewResult = "";
1184     service->RequestPreview(jobInfo, previewResult);
1185 
1186     std::string extensionId = "DEFAULT_EXTENSION_ID";
1187     std::string extInfo = "spooler";
1188     service->SendExtensionEvent(extensionId, extInfo);
1189     EXPECT_EQ(service->UnregisterAllExtCallback(extensionId), E_PRINT_NONE);
1190 }
1191 
1192 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0060_NeedRename, TestSize.Level1)
1193 {
1194     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1195     AppExecFwk::ExtensionAbilityInfo extInfo;
1196     extInfo.bundleName = "spooler";
1197 
1198     PrintExtensionInfo newExtInfo;
1199     PrintExtensionInfo judgeExtInfo;
1200     judgeExtInfo.SetExtensionId(extInfo.bundleName);
1201     judgeExtInfo.SetVendorId(extInfo.bundleName);
1202     judgeExtInfo.SetVendorName(extInfo.bundleName);
1203     judgeExtInfo.SetVendorIcon(0);
1204     judgeExtInfo.SetVersion("1.0.0");
1205     newExtInfo = service->ConvertToPrintExtensionInfo(extInfo);
1206     EXPECT_EQ(newExtInfo.extensionId_, judgeExtInfo.extensionId_);
1207     EXPECT_EQ(newExtInfo.vendorId_, judgeExtInfo.vendorId_);
1208     EXPECT_EQ(newExtInfo.vendorName_, judgeExtInfo.vendorName_);
1209     EXPECT_EQ(newExtInfo.vendorIcon_, judgeExtInfo.vendorIcon_);
1210     EXPECT_EQ(newExtInfo.version_, judgeExtInfo.version_);
1211 }
1212 
1213 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0061_NeedRename, TestSize.Level1)
1214 {
1215     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1216     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1217     service->helper_ = helper;
1218     std::string jobId = "123";
1219     int32_t userId = 100;
1220     service->printUserMap_[userId] = nullptr;
1221     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_INVALID_USERID);
1222     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1223     service->printUserMap_[userId] = userData;
1224     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_INVALID_PRINTJOB);
1225     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1226     printJob->SetJobId(jobId);
1227     printJob->SetPrinterId("1234");
1228     printJob->SetOption("{\"test\":\"test\"}");
1229     userData->AddPrintJobToHistoryList(printJob->GetPrinterId(), printJob->GetJobId(), printJob);
1230     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_NONE);
1231     userData->queuedJobList_[jobId] = printJob;
1232     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_NONE);
1233     printJob->SetJobState(PRINT_JOB_RUNNING);
1234     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_NONE);
1235     std::string extensionId = PrintUtils::GetExtensionId("1234");
1236     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_CANCEL_PRINT);
1237     sptr<IPrintExtensionCallback> extCb = nullptr;
1238     service->extCallbackMap_[cid] = extCb;
1239     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_NONE);
1240     printJob->SetPrinterId("com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620");
1241     std::string extensionId2 = PrintUtils::GetExtensionId("com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620");
1242     std::string cid2 = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_CANCEL_PRINT);
1243     service->extCallbackMap_[cid2] = extCb;
1244     EXPECT_EQ(service->CancelPrintJob(jobId), E_PRINT_NONE);
1245 }
1246 
1247 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0062_NeedRename, TestSize.Level1)
1248 {
1249     DelayedSingleton<PrintBMSHelper>::GetInstance()->hasBms = false;
1250     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1251     std::vector<std::string> extensionIds;
1252     std::string extensionId = "com.ohos.spooler";
1253     extensionIds.push_back(extensionId);
1254     EXPECT_EQ(service->StartDiscoverPrinter(extensionIds), E_PRINT_INVALID_EXTENSION);
1255     std::vector<PrintExtensionInfo> extensionInfos;
1256     service->QueryAllExtension(extensionInfos);
1257     service->StartDiscoverPrinter(extensionIds);
1258 }
1259 
1260 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0063_NeedRename, TestSize.Level1)
1261 {
1262     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1263     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1264     service->helper_ = helper;
1265     std::string extensionId = "com.ohos.spooler:0";
1266     service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
1267     EXPECT_EQ(service->DestroyExtension(), E_PRINT_NONE);
1268     service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADED;
1269     EXPECT_EQ(service->DestroyExtension(), E_PRINT_NONE);
1270     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_DESTROY_EXTENSION);
1271     sptr<IPrintExtensionCallback> listener = nullptr;
1272     service->extCallbackMap_[cid] = listener;
1273     EXPECT_EQ(service->DestroyExtension(), E_PRINT_NONE);
1274 }
1275 
1276 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0064_NeedRename, TestSize.Level1)
1277 {
1278     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1279     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1280     service->helper_ = helper;
1281     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1282     PrinterInfo info;
1283     EXPECT_EQ(service->QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_INVALID_PRINTER);
1284     auto printerInfo = std::make_shared<PrinterInfo>();
1285     printerInfo->SetPrinterName("testName");
1286     printerInfo->SetUri("testUri");
1287     printerInfo->SetPrinterMake("testMaker");
1288     PrinterCapability caps;
1289     Json::Value opsJson;
1290     opsJson["key"] = "value";
1291     caps.SetOption(PrintJsonUtil::WriteString(opsJson));
1292     std::vector<PrintPageSize> pageSizeList;
1293     PrintPageSize pageSize;
1294     pageSizeList.push_back(pageSize);
1295     caps.SetSupportedPageSize(pageSizeList);
1296     printerInfo->SetCapability(caps);
1297     service->printSystemData_.addedPrinterMap_.Insert(printerId, printerInfo);
1298     EXPECT_EQ(service->QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_NONE);
1299 }
1300 
1301 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0065_NeedRename, TestSize.Level1)
1302 {
1303     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1304     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1305     auto info = std::make_shared<PrinterInfo>();
1306     info->SetPrinterId(printerId);
1307     std::vector<std::string> keyList;
1308     keyList.emplace_back("pagesizeId");
1309     keyList.emplace_back("orientation");
1310     keyList.emplace_back("duplex");
1311     keyList.emplace_back("quality");
1312     keyList.emplace_back("test");
1313     std::vector<std::string> valueList;
1314     EXPECT_EQ(service->QueryPrinterProperties(printerId, keyList, valueList), E_PRINT_INVALID_PRINTER);
1315 }
1316 
1317 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0066_NeedRename, TestSize.Level1)
1318 {
1319     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1320     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1321     auto info = std::make_shared<PrinterInfo>();
1322     info->SetPrinterId(printerId);
1323     std::string savePrinterPreference = "test";
1324     std::vector<std::string> keyList;
1325     keyList.emplace_back("pagesizeId");
1326     keyList.emplace_back("orientation");
1327     keyList.emplace_back("duplex");
1328     keyList.emplace_back("quality");
1329     keyList.emplace_back("test");
1330     std::vector<std::string> valueList;
1331     EXPECT_EQ(service->QueryPrinterProperties(printerId, keyList, valueList), E_PRINT_INVALID_PRINTER);
1332 }
1333 
1334 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0067_NeedRename, TestSize.Level1)
1335 {
1336     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1337     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1338     std::string printerExtId = PrintUtils::GetGlobalId("", printerId);
1339     PrinterCapability printerCaps;
1340     printerCaps.SetOption("test");
1341     std::string printerUri = "ipp://192.168.186.1:631/ipp/print";
1342     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_NONE);
1343 }
1344 
1345 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0068_NeedRename, TestSize.Level1)
1346 {
1347     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1348     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1349     std::string printerExtId = PrintUtils::GetGlobalId("", printerId);
1350     PrinterCapability printerCaps;
1351     printerCaps.SetOption("test");
1352     std::string printerUri = "ipp://192.168.186.1:631/ipp/print";
1353     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_NONE);
1354 }
1355 
1356 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0069_NeedRename, TestSize.Level1)
1357 {
1358     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1359     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
1360     PrinterCapability printerCaps;
1361     std::string printerUri = "ipp://192.168.186.1:631/ipp/print";
1362     service->printSystemData_.discoveredPrinterInfoList_["123"] = nullptr;
1363     auto printerInfo = std::make_shared<PrinterInfo>();
1364     service->printSystemData_.discoveredPrinterInfoList_["456"] = printerInfo;
1365     service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
1366     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_NONE);
1367 }
1368 
1369 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0079_NeedRename, TestSize.Level1)
1370 {
1371     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1372     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1373     service->helper_ = helper;
1374     std::string printerId = "123";
1375     PrintJob printJob;
1376     Json::Value opsJson;
1377     opsJson["key"] = "value";
1378     printJob.SetPrinterId(printerId);
1379     printJob.SetOption(PrintJsonUtil::WriteString(opsJson));
1380     auto printer = std::make_shared<PrinterInfo>();
1381     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
1382     auto ret = service->StartNativePrintJob(printJob);
1383     EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
1384     auto extensionId = PrintUtils::GetExtensionId(printerId);
1385     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_PRINT);
1386     sptr<IPrintExtensionCallback> extCb = nullptr;
1387     service->extCallbackMap_[cid] = extCb;
1388     ret = service->StartNativePrintJob(printJob);
1389     EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
1390 }
1391 
1392 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0080_NeedRename, TestSize.Level1)
1393 {
1394     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1395     std::string printerId = "123";
1396     service->SetLastUsedPrinter(printerId);
1397     auto printer = std::make_shared<PrinterInfo>();
1398     auto ret = service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
1399     service->SetLastUsedPrinter(printerId);
1400     EXPECT_EQ(ret, 1);
1401 }
1402 
1403 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0081_NeedRename, TestSize.Level1)
1404 {
1405     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1406     uint32_t state = PRINT_JOB_UNKNOWN + 1;
1407     uint32_t subState = PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS;
1408     service->checkJobState(state, subState);
1409     std::string jobId = "123";
1410     auto ret = service->UpdatePrintJobStateOnlyForSystemApp(jobId, state, subState);
1411     EXPECT_EQ(ret, E_PRINT_NONE);
1412 }
1413 
1414 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0082_NeedRename, TestSize.Level1)
1415 {
1416     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1417     uint32_t state = PRINT_JOB_CREATE_FILE_COMPLETED;
1418     uint32_t subState = PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS;
1419     std::string jobId = "123";
1420     std::string type = PRINT_GET_FILE_EVENT_TYPE;
1421     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1422     service->registeredListeners_[type] = listener;
1423     auto ret = service->AdapterGetFileCallBack(jobId, state, subState);
1424     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1425     subState = PRINT_JOB_CREATE_FILE_COMPLETED_FAILED;
1426     ret = service->AdapterGetFileCallBack(jobId, state, subState);
1427     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1428     subState = PRINT_JOB_BLOCKED_UNKNOWN;
1429     ret = service->AdapterGetFileCallBack(jobId, state, subState);
1430     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1431 }
1432 
1433 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0083_NeedRename, TestSize.Level1)
1434 {
1435     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1436     service->ManualStart();
1437     std::string jobId = "1";
1438     int32_t userId = 100;
1439     service->userJobMap_[jobId] = userId;
1440     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1441     service->printUserMap_[userId] = userData;
1442     uint32_t state = PRINT_JOB_COMPLETED;
1443     uint32_t subState = 0;
1444     std::string printerId = "1234";
1445     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1446     printJob->SetPrinterId(printerId);
1447     userData->queuedJobList_[jobId] = printJob;
1448     service->printerJobMap_[printerId].insert(std::make_pair(jobId, true));
1449     EXPECT_EQ(service->CheckAndSendQueuePrintJob(jobId, state, subState), E_PRINT_NONE);
1450 }
1451 
1452 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0084_NeedRename, TestSize.Level1)
1453 {
1454     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1455     std::string jobId = "1";
1456     int32_t userId = 100;
1457     service->userJobMap_[jobId] = userId;
1458     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1459     service->printUserMap_[userId] = userData;
1460     uint32_t state = PRINT_JOB_COMPLETED;
1461     uint32_t subState = 0;
1462     std::string printerId = "1234";
1463     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1464     printJob->SetPrinterId(printerId);
1465     userData->printJobList_[jobId] = printJob;
1466     service->printerJobMap_[printerId].insert(std::make_pair(jobId, true));
1467     auto printerInfo = std::make_shared<PrinterInfo>();
1468     service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
1469     EXPECT_EQ(service->CheckAndSendQueuePrintJob(jobId, state, subState), E_PRINT_INVALID_PRINTJOB);
1470 }
1471 
1472 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0086_NeedRename, TestSize.Level1)
1473 {
1474     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1475     std::string printerId = "";
1476     EXPECT_EQ(service->isEprint(printerId), false);
1477 }
1478 
1479 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0087_NeedRename, TestSize.Level1)
1480 {
1481     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1482     std::string printerId = "1234";
1483     auto ret = service->QueryPrinterCapability(printerId);
1484     EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
1485     auto printerInfo = std::make_shared<PrinterInfo>();
1486     service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
1487     ret = service->QueryPrinterCapability(printerId);
1488     EXPECT_EQ(ret, E_PRINT_SERVER_FAILURE);
1489     std::string extensionId = PrintUtils::GetExtensionId(printerId);
1490     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_REQUEST_CAP);
1491     sptr<IPrintExtensionCallback> extCb = nullptr;
1492     service->extCallbackMap_[cid] = extCb;
1493     ret = service->QueryPrinterCapability(printerId);
1494     EXPECT_EQ(ret, E_PRINT_NONE);
1495 }
1496 
1497 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0088_NeedRename, TestSize.Level1)
1498 {
1499     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1500     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1501     service->helper_ = helper;
1502     std::string extensionCid = "";
1503     sptr<IPrintExtensionCallback> listener = nullptr;
1504     auto ret = service->RegisterExtCallback(extensionCid, listener);
1505     EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
1506     std::string extensionCid2 = "123:20";
1507     ret = service->RegisterExtCallback(extensionCid2, listener);
1508     EXPECT_EQ(ret, E_PRINT_INVALID_EXTENSION);
1509     std::string extensionId = "123";
1510     service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
1511     ret = service->RegisterExtCallback(extensionCid2, listener);
1512     EXPECT_EQ(ret, E_PRINT_INVALID_EXTENSION);
1513     service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADING;
1514     ret = service->RegisterExtCallback(extensionCid2, listener);
1515     EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
1516     std::string extensionCid3 = "123:2";
1517     ret = service->RegisterExtCallback(extensionCid2, listener);
1518     EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
1519 }
1520 
1521 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0089_NeedRename, TestSize.Level1)
1522 {
1523     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1524     uint32_t callbackId = 0;
1525     std::string extensionId = "123";
1526     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, callbackId);
1527     sptr<IPrintExtensionCallback> extCb = nullptr;
1528     service->extCallbackMap_[cid] = extCb;
1529     auto ret = service->UnregisterAllExtCallback(extensionId);
1530     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1531 }
1532 
1533 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0090_NeedRename, TestSize.Level1)
1534 {
1535     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1536     std::string extensionId = "123";
1537     service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
1538     auto ret = service->LoadExtSuccess(extensionId);
1539     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1540     service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADING;
1541     ret = service->LoadExtSuccess(extensionId);
1542     EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
1543 }
1544 
1545 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0091_NeedRename, TestSize.Level1)
1546 {
1547     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1548     std::string jobId = "123";
1549     std::string type = PRINT_CALLBACK_ADAPTER;
1550     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1551     EXPECT_NE(listener, nullptr);
1552     service->On(jobId, type, listener);
1553     type = PRINTER_CHANGE_EVENT_TYPE;
1554     service->On(jobId, type, listener);
1555 }
1556 
1557 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0092_NeedRename, TestSize.Level1)
1558 {
1559     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1560     service->helper_ = nullptr;
1561     AAFwk::Want want;
1562     auto ret = service->StartAbility(want);
1563     EXPECT_EQ(ret, E_PRINT_NONE);
1564 }
1565 
1566 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0093_NeedRename, TestSize.Level1)
1567 {
1568     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1569     service->printUserDataMap_[100] = nullptr;
1570     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1571     service->printUserDataMap_[101] = userData;
1572     int event = 0;
1573     PrinterInfo info;
1574     EXPECT_NE(service->SendPrinterDiscoverEvent(event, info), 0);
1575 }
1576 
1577 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0094_NeedRename, TestSize.Level1)
1578 {
1579     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1580     service->printUserDataMap_[100] = nullptr;
1581     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1582     service->printUserDataMap_[101] = userData;
1583     int event = 0;
1584     PrinterInfo info;
1585     EXPECT_NE(service->SendPrinterChangeEvent(event, info), 0);
1586 }
1587 
1588 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0095_NeedRename, TestSize.Level1)
1589 {
1590     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1591     PrinterInfo info;
1592     service->SendPrinterEvent(info);
1593     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1594     service->registeredListeners_[PRINTER_EVENT_TYPE] = listener;
1595     service->SendPrinterEvent(info);
1596     EXPECT_EQ(info.GetPrinterState(), PRINTER_UNKNOWN);
1597 }
1598 
1599 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0096_NeedRename, TestSize.Level1)
1600 {
1601     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1602     PrinterInfo info;
1603     PrinterEvent printerEvent = PRINTER_EVENT_STATE_CHANGED;
1604     service->registeredListeners_["test"] = nullptr;
1605     EXPECT_EQ(service->SendPrinterEventChangeEvent(printerEvent, info), 0);
1606 
1607     std::string eventType = "123" + PRINTER_CHANGE_EVENT_TYPE;
1608     service->registeredListeners_[eventType] = nullptr;
1609     EXPECT_EQ(service->SendPrinterEventChangeEvent(printerEvent, info), 0);
1610 
1611     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1612     service->registeredListeners_[eventType] = listener;
1613     EXPECT_EQ(service->SendPrinterEventChangeEvent(printerEvent, info), 0);
1614 }
1615 
1616 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0097_NeedRename, TestSize.Level1)
1617 {
1618     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1619     PrintJob jobInfo;
1620     jobInfo.SetJobId("1");
1621     service->SendPrintJobEvent(jobInfo);
1622     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1623     service->registeredListeners_[PRINTJOB_EVENT_TYPE] = listener;
1624     service->SendPrintJobEvent(jobInfo);
1625     jobInfo.SetJobState(PRINT_JOB_COMPLETED);
1626     service->SendPrintJobEvent(jobInfo);
1627     jobInfo.SetJobState(PRINT_JOB_BLOCKED);
1628     service->SendPrintJobEvent(jobInfo);
1629     jobInfo.SetJobState(PRINT_JOB_COMPLETED);
1630     jobInfo.SetSubState(PRINT_JOB_COMPLETED_SUCCESS);
1631     service->SendPrintJobEvent(jobInfo);
1632     jobInfo.SetSubState(PRINT_JOB_COMPLETED_FAILED);
1633     service->SendPrintJobEvent(jobInfo);
1634     jobInfo.SetSubState(PRINT_JOB_COMPLETED_CANCELLED);
1635     std::string taskEvent = PrintUtils::GetTaskEventId(jobInfo.GetJobId(), EVENT_CANCEL);
1636     service->registeredListeners_[taskEvent] = listener;
1637     service->SendPrintJobEvent(jobInfo);
1638 }
1639 
1640 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0098_NeedRename, TestSize.Level1)
1641 {
1642     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1643     std::string extensionId = "123";
1644     std::string extInfo = "123";
1645     EXPECT_EQ(service->SendExtensionEvent(extensionId, extInfo), 0);
1646     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1647     service->registeredListeners_[EXTINFO_EVENT_TYPE] = listener;
1648     EXPECT_NE(service->SendExtensionEvent(extensionId, extInfo), 0);
1649 }
1650 
1651 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0099_NeedRename, TestSize.Level1)
1652 {
1653     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1654     PrintJob jobInfo;
1655     std::string jobId = "123";
1656     jobInfo.SetJobId(jobId);
1657     service->isJobQueueBlocked_ = true;
1658     jobInfo.SetJobState(PRINT_JOB_COMPLETED);
1659     service->CheckJobQueueBlocked(jobInfo);
1660     EXPECT_EQ(service->isJobQueueBlocked_, true);
1661     service->isJobQueueBlocked_ = false;
1662     service->CheckJobQueueBlocked(jobInfo);
1663     EXPECT_EQ(service->isJobQueueBlocked_, false);
1664     jobInfo.SetJobState(PRINT_JOB_BLOCKED);
1665     service->CheckJobQueueBlocked(jobInfo);
1666     EXPECT_EQ(service->isJobQueueBlocked_, true);
1667     int32_t userId = 100;
1668     service->userJobMap_[jobId] = userId;
1669     service->currentUserId_ = userId;
1670     service->CheckJobQueueBlocked(jobInfo);
1671     EXPECT_EQ(service->isJobQueueBlocked_, true);
1672     service->isJobQueueBlocked_ = true;
1673     jobInfo.SetJobState(PRINT_JOB_COMPLETED);
1674     service->CheckJobQueueBlocked(jobInfo);
1675     EXPECT_EQ(service->isJobQueueBlocked_, true);
1676     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1677     service->printUserMap_[userId] = userData;
1678     auto job = std::make_shared<PrintJob>();
1679     job->SetJobState(PRINT_JOB_COMPLETED);
1680     auto job2 = std::make_shared<PrintJob>();
1681     job2->SetJobState(PRINT_JOB_BLOCKED);
1682     userData->queuedJobList_["1"] = job;
1683     userData->queuedJobList_["2"] = job2;
1684     service->CheckJobQueueBlocked(jobInfo);
1685     EXPECT_EQ(service->isJobQueueBlocked_, true);
1686     userData->queuedJobList_.clear();
1687     userData->queuedJobList_["1"] = job;
1688     service->CheckJobQueueBlocked(jobInfo);
1689     EXPECT_EQ(service->isJobQueueBlocked_, false);
1690     service->userJobMap_.clear();
1691     service->CheckJobQueueBlocked(jobInfo);
1692     EXPECT_EQ(service->isJobQueueBlocked_, false);
1693 }
1694 
1695 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0100_NeedRename, TestSize.Level1)
1696 {
1697     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1698     std::string jobName = "";
1699     PrintAttributes printAttributes;
1700     std::string taskId = "";
1701     auto ret = service->PrintByAdapter(jobName, printAttributes, taskId);
1702     EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
1703 }
1704 
1705 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0102_NeedRename, TestSize.Level1)
1706 {
1707     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1708     service->ManualStart();
1709     std::string jobId = "123";
1710     uint32_t state = PRINT_JOB_RUNNING;
1711     uint32_t subState = PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED;
1712     service->notifyAdapterJobChanged(jobId, state, subState);
1713     auto attrIt = service->printAttributesList_.find(jobId);
1714     EXPECT_EQ(attrIt, service->printAttributesList_.end());
1715     state = PRINT_JOB_SPOOLER_CLOSED;
1716     service->notifyAdapterJobChanged(jobId, state, subState);
1717     attrIt = service->printAttributesList_.find(jobId);
1718     EXPECT_EQ(attrIt, service->printAttributesList_.end());
1719     state = PRINT_JOB_COMPLETED;
1720     PrintAttributes printAttributes;
1721     service->printAttributesList_[jobId] = printAttributes;
1722     service->notifyAdapterJobChanged(jobId, state, subState);
1723     attrIt = service->printAttributesList_.find(jobId);
1724     EXPECT_EQ(attrIt, service->printAttributesList_.end());
1725 }
1726 
1727 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0103_NeedRename, TestSize.Level1)
1728 {
1729     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1730     service->helper_ = nullptr;
1731     AAFwk::Want want;
1732     EXPECT_FALSE(service->StartPluginPrintIconExtAbility(want));
1733     service->helper_ = std::make_shared<PrintServiceHelper>();
1734     service->StartPluginPrintIconExtAbility(want);
1735 }
1736 
1737 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0104_NeedRename, TestSize.Level1)
1738 {
1739     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1740     std::string jobId = "123";
1741     EXPECT_EQ(service->GetUserDataByJobId(jobId), nullptr);
1742     int32_t userId = 100;
1743     service->userJobMap_[jobId] = userId;
1744     EXPECT_EQ(service->GetUserDataByJobId(jobId), nullptr);
1745     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1746     service->printUserMap_[userId] = userData;
1747     EXPECT_NE(service->GetUserDataByJobId(jobId), nullptr);
1748 }
1749 
1750 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0105_NeedRename, TestSize.Level1)
1751 {
1752     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1753     std::string jobId = "123";
1754     service->RegisterAdapterListener(jobId);
1755     auto lisIt = service->adapterListenersByJobId_.find(jobId);
1756     EXPECT_EQ(lisIt, service->adapterListenersByJobId_.end());
1757     sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
1758     service->registeredListeners_[PRINT_ADAPTER_EVENT_TYPE] = listener;
1759     service->RegisterAdapterListener(jobId);
1760     lisIt = service->adapterListenersByJobId_.find(jobId);
1761     EXPECT_NE(lisIt, service->adapterListenersByJobId_.end());
1762 }
1763 
1764 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0106_NeedRename, TestSize.Level1)
1765 {
1766     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1767     std::string printerId = "1234";
1768     auto ret = service->SetDefaultPrinter(printerId, 0);
1769     EXPECT_EQ(ret, E_PRINT_NONE);
1770 }
1771 
1772 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0107_NeedRename, TestSize.Level1)
1773 {
1774     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1775     std::string printerId = "1234";
1776     EXPECT_EQ(service->CheckIsDefaultPrinter(printerId), false);
1777 }
1778 
1779 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0108_NeedRename, TestSize.Level1)
1780 {
1781     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1782     std::string printerId = "1234";
1783     EXPECT_EQ(service->CheckIsLastUsedPrinter(printerId), false);
1784 }
1785 
1786 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0109_NeedRename, TestSize.Level1)
1787 {
1788     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1789     std::string printerName = "pixlab_0759";
1790     EXPECT_EQ(service->DeletePrinterFromCups(printerName), E_PRINT_NONE);
1791 }
1792 
1793 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0111_NeedRename, TestSize.Level1)
1794 {
1795     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1796     std::string printerId = "printerId";
1797     int32_t userId1 = 100;
1798     int32_t userId2 = 101;
1799     std::shared_ptr<PrintUserData> userData1 = std::make_shared<PrintUserData>();
1800     auto ret = userData1->SetDefaultPrinter("test", 0);
1801     EXPECT_EQ(ret, E_PRINT_NONE);
1802     std::shared_ptr<PrintUserData> userData2 = std::make_shared<PrintUserData>();
1803     ret = userData1->SetDefaultPrinter(printerId, 0);
1804     EXPECT_EQ(ret, E_PRINT_NONE);
1805     service->printUserMap_[userId1] = userData1;
1806     service->printUserMap_[userId2] = userData2;
1807     service->DeletePrinterFromUserData(printerId);
1808 }
1809 
1810 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0112_NeedRename, TestSize.Level1)
1811 {
1812     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1813     service->ManualStart();
1814     std::string jobId = "1";
1815     int32_t userId = 0;
1816     service->userJobMap_[jobId] = userId;
1817     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
1818     service->printUserMap_[userId] = userData;
1819     uint32_t state = PRINT_JOB_COMPLETED;
1820     uint32_t subState = 0;
1821     std::string printerId = "1234";
1822     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
1823     printJob->SetPrinterId(printerId);
1824     printJob->SetOption("{\"test\":\"test\"}");
1825     userData->queuedJobList_[jobId] = printJob;
1826     service->printerJobMap_[printerId].insert(std::make_pair(jobId, true));
1827     auto printerInfo = std::make_shared<PrinterInfo>();
1828     service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
1829     service->currentUserId_ = 0;
1830     EXPECT_EQ(service->CheckAndSendQueuePrintJob(jobId, state, subState), E_PRINT_NONE);
1831 }
1832 
1833 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0113_NeedRename, TestSize.Level1)
1834 {
1835     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1836     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1837     service->helper_ = helper;
1838     std::string taskId = "";
1839     std::string type = PRINTER_CHANGE_EVENT_TYPE;
1840     auto ret = service->Off(taskId, type);
1841     EXPECT_EQ(ret, E_PRINT_NONE);
1842 }
1843 
1844 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0120_NeedRename, TestSize.Level1)
1845 {
1846     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1847     EXPECT_NE(service, nullptr);
1848     std::map<std::string, std::shared_ptr<PrintJob>> jobList;
1849     auto job = std::make_shared<PrintJob>();
1850     EXPECT_NE(job, nullptr);
1851     job->SetJobState(PRINT_JOB_BLOCKED);
1852     jobList.insert(std::make_pair("test", job));
1853     EXPECT_EQ(service->DetermineUserJobStatus(jobList), PRINT_JOB_BLOCKED);
1854 }
1855 
1856 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0121_NeedRename, TestSize.Level1)
1857 {
1858     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1859     EXPECT_NE(service, nullptr);
1860     std::map<std::string, std::shared_ptr<PrintJob>> jobList;
1861     auto job = std::make_shared<PrintJob>();
1862     EXPECT_NE(job, nullptr);
1863     job->SetJobState(PRINT_JOB_COMPLETED);
1864     jobList.insert(std::make_pair("test", job));
1865     EXPECT_EQ(service->DetermineUserJobStatus(jobList), PRINT_JOB_COMPLETED);
1866 }
1867 
1868 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0122_NeedRename, TestSize.Level1)
1869 {
1870     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1871     EXPECT_NE(service, nullptr);
1872     std::map<std::string, std::shared_ptr<PrintJob>> jobList;
1873     auto job = std::make_shared<PrintJob>();
1874     EXPECT_NE(job, nullptr);
1875     job->SetJobState(PRINT_JOB_RUNNING);
1876     jobList.insert(std::make_pair("test", job));
1877     EXPECT_EQ(service->DetermineUserJobStatus(jobList), PRINT_JOB_RUNNING);
1878 }
1879 
1880 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0123_NeedRename, TestSize.Level1)
1881 {
1882     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1883     int32_t userId = 100;
1884     auto userData1 = service->GetUserDataByUserId(100);
1885     EXPECT_NE(userData1, nullptr);
1886     auto userData2 = service->GetUserDataByUserId(100);
1887     EXPECT_NE(userData2, nullptr);
1888     auto job = std::make_shared<PrintJob>();
1889     EXPECT_NE(job, nullptr);
1890     job->SetJobState(PRINT_JOB_BLOCKED);
1891     userData1->queuedJobList_.insert(std::make_pair("test1", job));
1892     service->NotifyCurrentUserChanged(userId);
1893     auto job2 = std::make_shared<PrintJob>();
1894     EXPECT_NE(job2, nullptr);
1895     job2->SetJobState(PRINT_JOB_RUNNING);
1896     userData1->queuedJobList_.insert(std::make_pair("test2", job2));
1897     service->NotifyCurrentUserChanged(userId);
1898 }
1899 
1900 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0124_NeedRename, TestSize.Level1)
1901 {
1902     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1903     int32_t userId = 100;
1904     auto userData1 = service->GetUserDataByUserId(100);
1905     EXPECT_NE(userData1, nullptr);
1906     auto userData2 = service->GetUserDataByUserId(100);
1907     EXPECT_NE(userData2, nullptr);
1908     auto job = std::make_shared<PrintJob>();
1909     EXPECT_NE(job, nullptr);
1910     job->SetJobState(PRINT_JOB_COMPLETED);
1911     userData1->queuedJobList_.insert(std::make_pair("test1", job));
1912     service->NotifyCurrentUserChanged(userId);
1913     auto job2 = std::make_shared<PrintJob>();
1914     EXPECT_NE(job2, nullptr);
1915     job2->SetJobState(PRINT_JOB_RUNNING);
1916     userData1->queuedJobList_.insert(std::make_pair("test2", job2));
1917     service->NotifyCurrentUserChanged(userId);
1918 }
1919 
1920 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0125_NeedRename, TestSize.Level1)
1921 {
1922     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1923     EXPECT_NE(service, nullptr);
1924     uint32_t subState = PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED;
1925     EXPECT_EQ(service->GetListeningState(subState), PREVIEW_ABILITY_DESTROY_FOR_CANCELED);
1926     subState = PRINT_JOB_SPOOLER_CLOSED_FOR_STARTED;
1927     EXPECT_EQ(service->GetListeningState(subState), PREVIEW_ABILITY_DESTROY_FOR_STARTED);
1928     subState = PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS;
1929     EXPECT_EQ(service->GetListeningState(subState), PREVIEW_ABILITY_DESTROY);
1930     uint32_t state1 = service->GetListeningState(PRINT_JOB_SPOOLER_CLOSED, subState);
1931     uint32_t state2 = service->GetListeningState(subState);
1932     EXPECT_EQ(state1, state2);
1933     state1 = service->GetListeningState(PRINT_JOB_BLOCKED, subState);
1934     EXPECT_EQ(state1, PRINT_TASK_BLOCK);
1935     state1 = service->GetListeningState(PRINT_JOB_QUEUED, PRINT_JOB_COMPLETED_SUCCESS);
1936     EXPECT_EQ(state1, PRINT_TASK_SUCCEED);
1937     state1 = service->GetListeningState(PRINT_JOB_QUEUED, PRINT_JOB_COMPLETED_FAILED);
1938     EXPECT_EQ(state1, PRINT_TASK_FAIL);
1939     state1 = service->GetListeningState(PRINT_JOB_QUEUED, PRINT_JOB_COMPLETED_CANCELLED);
1940     EXPECT_EQ(state1, PRINT_TASK_CANCEL);
1941     state1 = service->GetListeningState(PRINT_JOB_QUEUED, PRINT_JOB_BLOCKED_OUT_OF_INK);
1942     EXPECT_EQ(state1, PRINT_TASK_FAIL);
1943 }
1944 
1945 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0126_NeedRename, TestSize.Level1)
1946 {
1947     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1948     std::string printerName = "testPrinterName";
1949     EXPECT_EQ(service->printSystemData_.QueryPrinterIdByStandardizeName(printerName), "");
1950 }
1951 
1952 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0128_NeedRename, TestSize.Level1)
1953 {
1954     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1955     std::string printerId = "Pixlab_0759";
1956     PrinterInfo info;
1957     EXPECT_EQ(service->UpdatePrinterCapability(printerId, info), true);
1958 }
1959 
1960 HWTEST_F(PrintServiceAbilityTest, DiscoverBackendPrinters_WhenNotExistUsbDevice_ShouldNull, TestSize.Level1)
1961 {
1962     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1963     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1964     service->helper_ = helper;
1965     std::vector<PrinterInfo> printers;
1966     service->DiscoverUsbPrinters(printers);
1967     EXPECT_EQ(printers.size(), 0);
1968 }
1969 
1970 HWTEST_F(PrintServiceAbilityTest, DiscoverBackendPrinters_WhenNotExistVendorDevice_ShouldNull, TestSize.Level1)
1971 {
1972     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1973     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
1974     service->helper_ = helper;
1975     std::vector<PrinterInfo> printers;
1976     service->DiscoverBackendPrinters(printers);
1977     EXPECT_EQ(printers.size(), 0);
1978 }
1979 
1980 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0130_NeedRename, TestSize.Level1)
1981 {
1982     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
1983     PrinterInfo info;
1984     info.SetPrinterId(DEFAULT_EXT_PRINTER_ID);
1985     EXPECT_EQ(service->AddPrinterToDiscovery(info), E_PRINT_NONE);
1986     EXPECT_EQ(service->UpdatePrinterInDiscovery(info), E_PRINT_NONE);
1987     info.SetPrinterId("1234");
1988     EXPECT_EQ(service->UpdatePrinterInDiscovery(info), E_PRINT_NONE);
1989 
1990     std::shared_ptr<PrinterInfo> info1 = std::make_shared<PrinterInfo>();
1991     info1->SetPrinterId(DEFAULT_EXT_PRINTER_ID);
1992     service->printSystemData_.discoveredPrinterInfoList_[DEFAULT_EXT_PRINTER_ID] = info1;
1993     EXPECT_EQ(service->RemovePrinterFromDiscovery(DEFAULT_EXT_PRINTER_ID), E_PRINT_NONE);
1994     EXPECT_EQ(service->RemovePrinterFromDiscovery(DEFAULT_EXT_PRINTER_ID), E_PRINT_INVALID_PRINTER);
1995 }
1996 
1997 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0131_NeedRename, TestSize.Level1)
1998 {
1999     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2000     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
2001     std::string printerExtId = PrintUtils::GetGlobalId("", printerId);
2002     PrinterCapability printerCaps;
2003     printerCaps.SetOption("test");
2004     std::string printerUri = "usb:ipp://192.168.186.1:631/ipp/print";
2005     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps), E_PRINT_INVALID_PRINTER);
2006 }
2007 
2008 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0132_NeedRename, TestSize.Level1)
2009 {
2010     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2011     std::string vendorName = "fwk.driver";
2012     std::string printerId = "testprinter";
2013     PrinterInfo info;
2014     info.SetPrinterId(printerId);
2015     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2016     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2017     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2018     EXPECT_TRUE(service->RemoveVendorPrinterFromDiscovery(vendorName, printerId));
2019 }
2020 
2021 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0133_NeedRename, TestSize.Level1)
2022 {
2023     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2024     std::string vendorName = "fwk.driver";
2025     std::string printerId = "testprinter";
2026     PrinterInfo info;
2027     PrinterInfo info2;
2028     info.SetPrinterId(printerId);
2029     std::string globalId = VendorManager::GetGlobalPrinterId(vendorName, printerId);
2030     EXPECT_EQ(service->QueryVendorPrinterInfo(globalId, info2), E_PRINT_INVALID_PRINTER);
2031     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2032     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2033     EXPECT_EQ(service->QueryVendorPrinterInfo(globalId, info2), E_PRINT_INVALID_PRINTER);
2034     EXPECT_TRUE(service->RemoveVendorPrinterFromDiscovery(vendorName, printerId));
2035     PrinterCapability cap;
2036     info.SetCapability(cap);
2037     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2038     EXPECT_EQ(service->QueryVendorPrinterInfo(globalId, info2), E_PRINT_NONE);
2039 }
2040 
2041 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0134_NeedRename, TestSize.Level1)
2042 {
2043     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2044     std::string vendorName = "fwk.driver";
2045     std::string printerId = "testprinter";
2046     std::string ppdName;
2047     std::string ppdData;
2048     PrinterInfo info;
2049     info.SetPrinterId(printerId);
2050     EXPECT_FALSE(service->RemoveVendorPrinterFromCups(vendorName, printerId));
2051     EXPECT_FALSE(service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData));
2052     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2053     EXPECT_FALSE(service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData));
2054     PrinterCapability cap;
2055     info.SetCapability(cap);
2056     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2057     EXPECT_FALSE(service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData));
2058     info.SetUri("uri");
2059     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2060     EXPECT_FALSE(service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData));
2061     info.SetPrinterMake("maker");
2062     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2063     service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData);
2064     ppdData = "ppd";
2065     service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData);
2066     service->RemoveVendorPrinterFromCups(vendorName, printerId);
2067     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2068 }
2069 
2070 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0135_NeedRename, TestSize.Level1)
2071 {
2072     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2073     EXPECT_EQ(service->TryConnectPrinterByIp(""), E_PRINT_INVALID_PRINTER);
2074     std::string param = "{\"protocol\":\"ipp\"}";
2075     EXPECT_EQ(service->TryConnectPrinterByIp(param), E_PRINT_INVALID_PRINTER);
2076     param = "{\"protocol\":\"ipp\",\"ip\":\"a.b.c.d\"}";
2077     EXPECT_EQ(service->TryConnectPrinterByIp(param), E_PRINT_SERVER_FAILURE);
2078 }
2079 
2080 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0136_NeedRename, TestSize.Level1)
2081 {
2082     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2083     std::string vendorName = "fwk.driver";
2084     std::string printerId = "testprinter";
2085     std::string ppdName;
2086     std::string ppdData;
2087     PrinterInfo info;
2088     info.SetPrinterName(vendorName);
2089     info.SetPrinterId(printerId);
2090     PrinterCapability cap;
2091     info.SetCapability(cap);
2092     info.SetUri("uri");
2093     info.SetPrinterMake("maker");
2094     ppdData = "ppd";
2095     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2096     service->AddVendorPrinterToCupsWithPpd(vendorName, printerId, ppdName, ppdData);
2097 
2098     std::string vendorName1 = "fwk.driver";
2099     std::string printerId1 = "testprinter1";
2100     PrinterInfo info1;
2101     info1.SetPrinterName(vendorName1);
2102     info1.SetPrinterId(printerId1);
2103     PrinterCapability cap1;
2104     info1.SetCapability(cap1);
2105     info1.SetUri("uri1");
2106     info1.SetPrinterMake("maker1");
2107     EXPECT_TRUE(service->RenamePrinterWhenAdded(info1) == "fwk.driver 1");
2108     service->RemoveVendorPrinterFromCups(vendorName, printerId);
2109 }
2110 
2111 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0137_NeedRename, TestSize.Level1)
2112 {
2113     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2114     PrinterInfo info;
2115     info.SetPrinterId(DEFAULT_EXT_PRINTER_ID);
2116     EXPECT_EQ(service->UpdatePrinterInSystem(info), E_PRINT_INVALID_PRINTER);
2117 }
2118 
2119 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0138_NeedRename, TestSize.Level1)
2120 {
2121     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2122     PrinterInfo info;
2123     info.SetPrinterId(DEFAULT_EXT_PRINTER_ID);
2124     std::string type = "testType";
2125     EXPECT_EQ(service->CheckUserIdInEventType(type), false);
2126     type = PRINTER_CHANGE_EVENT_TYPE;
2127     EXPECT_EQ(service->CheckUserIdInEventType(type), false);
2128 }
2129 
2130 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0139_NeedRename, TestSize.Level1)
2131 {
2132     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2133     std::string vendorName = "fwk.driver";
2134     std::string printerId = "testprinter";
2135     std::string ppdName;
2136     PrinterInfo info;
2137     info.SetPrinterId(printerId);
2138     EXPECT_FALSE(service->RemoveVendorPrinterFromCups(vendorName, printerId));
2139     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2140     PrinterCapability cap;
2141     info.SetCapability(cap);
2142     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2143     info.SetUri("uri");
2144     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2145     info.SetPrinterMake("maker");
2146     EXPECT_TRUE(service->UpdateVendorPrinterToDiscovery(vendorName, info));
2147     ppdName = "ppd";
2148     service->RemoveVendorPrinterFromCups(vendorName, printerId);
2149     EXPECT_TRUE(service->AddVendorPrinterToDiscovery(vendorName, info));
2150 }
2151 
2152 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0140_NeedRename, TestSize.Level1)
2153 {
2154     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2155     std::string printerId = "testPrinterId";
2156     auto printer = std::make_shared<PrinterInfo>();
2157     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
2158     PrinterInfo info;
2159     EXPECT_EQ(service->UpdatePrinterCapability(printerId, info), true);
2160 }
2161 
2162 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0141_NeedRename, TestSize.Level1)
2163 {
2164     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2165     std::string printerId = "com.ohos.spooler:testPrinterId";
2166     PrinterInfo info;
2167     info.SetPrinterId(printerId);
2168     auto infoPtr = std::make_shared<PrinterInfo>(info);
2169     service->printSystemData_.AddPrinterToDiscovery(infoPtr);
2170     std::string extensionId = "com.ohos.spooler";
2171     EXPECT_EQ(service->AddSinglePrinterInfo(info, extensionId), E_PRINT_NONE);
2172 }
2173 
2174 HWTEST_F(PrintServiceAbilityTest, SetPrinterPreference_NoDiscoveredPrinter_InvalidPrinter, TestSize.Level1)
2175 {
2176     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2177     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2178     service->helper_ = helper;
2179     std::string printerId = "123";
2180     PrinterPreferences preferences;
2181     preferences.SetBorderless(true);
2182     EXPECT_EQ(service->SetPrinterPreference(printerId, preferences), E_PRINT_INVALID_PRINTER);
2183 }
2184 
2185 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0144_NeedRename, TestSize.Level1)
2186 {
2187     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2188     std::string printerId = "com.ohos.spooler:testPrinterId";
2189     auto printer = std::make_shared<PrinterInfo>();
2190     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
2191     PrinterInfo info;
2192     EXPECT_EQ(service->UpdatePrinterCapability(printerId, info), true);
2193 }
2194 
2195 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0145_NeedRename, TestSize.Level1)
2196 {
2197     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2198     std::string userName = service->GetCallerUserName();
2199     EXPECT_FALSE(userName.empty());
2200     EXPECT_EQ(service->StartPrintJobInternal(nullptr), E_PRINT_SERVER_FAILURE);
2201 }
2202 
2203 HWTEST_F(PrintServiceAbilityTest, QueryPrinterCapabilityByUri_WhenHasMake_ShouldSucc, TestSize.Level1)
2204 {
2205     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2206     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2207     service->helper_ = helper;
2208     std::string extensionId = DelayedSingleton<PrintBMSHelper>::GetInstance()->QueryCallerBundleName();
2209     std::string printerId = "USB-PixLab_V1-1620";
2210     std::string standardizeId = PrintUtils::GetGlobalId(extensionId, printerId);
2211     PrinterCapability printerCaps;
2212     printerCaps.SetOption("test");
2213     std::string printerUri = "usb:ipp://192.168.186.1:631/ipp/print";
2214     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
2215     info->SetPrinterMake("test");
2216     service->printSystemData_.discoveredPrinterInfoList_[standardizeId] = info;
2217     // success call to cupsd but response is nothing
2218     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, standardizeId, printerCaps), E_PRINT_SERVER_FAILURE);
2219 }
2220 
2221 HWTEST_F(PrintServiceAbilityTest, QueryPrinterCapabilityByUri_WhenNotHasMake_ShouldFailed, TestSize.Level1)
2222 {
2223     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2224     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2225     service->helper_ = helper;
2226     std::string extensionId = DelayedSingleton<PrintBMSHelper>::GetInstance()->QueryCallerBundleName();
2227     std::string printerId = "USB-PixLab_V1-1620";
2228     std::string standardizeId = PrintUtils::GetGlobalId(extensionId, printerId);
2229     PrinterCapability printerCaps;
2230     printerCaps.SetOption("test");
2231     std::string printerUri = "usb:ipp://192.168.186.1:631/ipp/print";
2232     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
2233     service->printSystemData_.discoveredPrinterInfoList_[standardizeId] = info;
2234     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, standardizeId, printerCaps), E_PRINT_INVALID_PRINTER);
2235 }
2236 
2237 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0147_NeedRename, TestSize.Level1)
2238 {
2239     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2240     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2241     service->helper_ = helper;
2242     std::string extensionId = DelayedSingleton<PrintBMSHelper>::GetInstance()->QueryCallerBundleName();
2243     std::string printerId = "USB-PixLab_V1-1620";
2244     std::string standardizeId = PrintUtils::GetGlobalId(extensionId, printerId);
2245     PrinterCapability printerCaps;
2246     printerCaps.SetOption("test");
2247     std::string printerUri = "usb:ipp://192.168.186.1:631/ipp/print";
2248     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
2249     Json::Value opsJson;
2250     opsJson["key"] = "value";
2251     info->SetOption(PrintJsonUtil::WriteString(opsJson));
2252     service->printSystemData_.discoveredPrinterInfoList_[standardizeId] = info;
2253     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, standardizeId, printerCaps), E_PRINT_INVALID_PRINTER);
2254 }
2255 
2256 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0148_NeedRename, TestSize.Level1)
2257 {
2258     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2259     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2260     service->helper_ = helper;
2261     std::string extensionId = DelayedSingleton<PrintBMSHelper>::GetInstance()->QueryCallerBundleName();
2262     std::string printerId = "USB-PixLab_V1-1620";
2263     std::string standardizeId = PrintUtils::GetGlobalId(extensionId, printerId);
2264     PrinterCapability printerCaps;
2265     printerCaps.SetOption("test");
2266     std::string printerUri = "usb:ipp://192.168.186.1:631/ipp/print";
2267     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
2268     Json::Value opsJson;
2269     opsJson["make"] = 123;
2270     info->SetOption(PrintJsonUtil::WriteString(opsJson));
2271     service->printSystemData_.discoveredPrinterInfoList_[standardizeId] = info;
2272     EXPECT_EQ(service->QueryPrinterCapabilityByUri(printerUri, standardizeId, printerCaps), E_PRINT_INVALID_PRINTER);
2273 }
2274 
2275 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0149_NeedRename, TestSize.Level1)
2276 {
2277     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2278     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2279     service->helper_ = helper;
2280     std::vector<std::string> printerList;
2281     auto printer = std::make_shared<PrinterInfo>();
2282     printer->SetPrinterName("testPrinterName");
2283     std::string printerId = "testPrinterId";
2284     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
2285     EXPECT_EQ(service->QueryAddedPrinter(printerList), E_PRINT_NONE);
2286 }
2287 
2288 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0150_NeedRename, TestSize.Level1)
2289 {
2290     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2291     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2292     service->helper_ = helper;
2293     std::vector<std::string> printerList;
2294     auto printer = std::make_shared<PrinterInfo>();
2295     printer->SetPrinterName("testPrinterName");
2296     std::string printerId = "";
2297     service->printSystemData_.addedPrinterMap_.Insert(printerId, printer);
2298     EXPECT_EQ(service->QueryAddedPrinter(printerList), E_PRINT_NONE);
2299 }
2300 
2301 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0155_NeedRename, TestSize.Level1)
2302 {
2303     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2304     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2305     service->helper_ = helper;
2306     PrintJob printJob;
2307     std::string jobId = "123";
2308     printJob.SetJobId(jobId);
2309     std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-1620";
2310     printJob.SetPrinterId(printerId);
2311     auto printerInfo = std::make_shared<PrinterInfo>();
2312     printerInfo->SetPrinterName("testName");
2313     printerInfo->SetUri("testUri");
2314     printerInfo->SetPrinterMake("testMaker");
2315     Json::Value infoJson;
2316     infoJson["printerName"] = "testPrinterName";
2317     printJob.SetOption(PrintJsonUtil::WriteString(infoJson));
2318     service->printSystemData_.addedPrinterMap_.Insert(printerId, printerInfo);
2319     std::string extensionId = PrintUtils::GetExtensionId(printerId);
2320     std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_PRINT);
2321     sptr<IPrintExtensionCallback> extCb = nullptr;
2322     service->extCallbackMap_[cid] = extCb;
2323     EXPECT_EQ(service->CheckPrintJob(printJob), false);
2324     auto printJobPtr = std::make_shared<PrintJob>(printJob);
2325     service->printJobList_[jobId] = printJobPtr;
2326     EXPECT_EQ(service->CheckPrintJob(printJob), true);
2327 }
2328 
2329 /**
2330 * @tc.name: PrintServiceAbilityTest_0157
2331 * @tc.desc: PrintServiceAbility ctor/dtor
2332 * @tc.type: FUNC ConnectPrinter
2333 * @tc.require: use old version printerId
2334 */
2335 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0157_NeedRename, TestSize.Level1)
2336 {
2337     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2338     std::shared_ptr<PrinterInfo> info = std::make_shared<PrinterInfo>();
2339     info->SetPrinterId("1234");
2340     EXPECT_EQ(service->ConnectPrinter(info->GetPrinterId()), E_PRINT_INVALID_PRINTER);
2341     info->SetPrinterId("com.ohos.spooler:mdns://testId");
2342     EXPECT_EQ(service->ConnectPrinter(info->GetPrinterId()), E_PRINT_INVALID_PRINTER);
2343     PrinterInfo printer;
2344     service->printSystemData_.InsertAddedPrinter(info->GetPrinterId(), printer);
2345     EXPECT_EQ(service->ConnectPrinter(info->GetPrinterId()), E_PRINT_NONE);
2346 }
2347 
2348 /**
2349 * @tc.name: PrintServiceAbilityTest_CheckPrinterUriDifferent
2350 * @tc.desc: PrintServiceAbility ctor/dtor
2351 * @tc.type: FUNC CheckPrinterUriDifferent
2352 * @tc.require: use old version printerId
2353 */
2354 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_CheckPrinterUriSame, TestSize.Level1)
2355 {
2356     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2357     std::shared_ptr<PrinterInfo> printerInfo = std::make_shared<PrinterInfo>();
2358     printerInfo->SetPrinterId("com.ohos.spooler:mdns://testId");
2359     printerInfo->SetUri("ipp://a");
2360 
2361     PrinterInfo addedPrinter;
2362     addedPrinter.SetPrinterId("com.ohos.spooler:mdns://testId");
2363     addedPrinter.SetUri("ipp://a");
2364     service->printSystemData_.InsertAddedPrinter(addedPrinter.GetPrinterId(), addedPrinter);
2365 
2366     EXPECT_FALSE(service->CheckPrinterUriDifferent(printerInfo));
2367 }
2368 
2369 /**
2370 * @tc.name: PrintServiceAbilityTest_CheckPrinterUriDifferent
2371 * @tc.desc: PrintServiceAbility ctor/dtor
2372 * @tc.type: FUNC CheckPrinterUriDifferent
2373 * @tc.require: use new version printerId
2374 */
2375 HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_CheckPrinterUriDifferent, TestSize.Level1)
2376 {
2377     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2378     std::shared_ptr<PrinterInfo> printerInfo = std::make_shared<PrinterInfo>();
2379     printerInfo->SetPrinterId("com.ohos.spooler:mdns://testId");
2380     printerInfo->SetUri("ipp://a");
2381 
2382     PrinterInfo addedPrinter;
2383     addedPrinter.SetPrinterId("com.ohos.spooler:mdns://testId");
2384     addedPrinter.SetUri("ipps://a");
2385     service->printSystemData_.InsertAddedPrinter(addedPrinter.GetPrinterId(), addedPrinter);
2386 
2387     EXPECT_TRUE(service->CheckPrinterUriDifferent(printerInfo));
2388 }
2389 
2390 /**
2391 * @tc.name: FlushCacheFileToUserData_WhenEmptyFdlist_ShouldTrue
2392 * @tc.desc: Verify the FlushCacheFileToUserData do nothing case.
2393 * @tc.type: FUNC FlushCacheFileToUserData
2394 * @tc.require: EmptyFdlist printJob
2395 */
2396 HWTEST_F(PrintServiceAbilityTest, FlushCacheFileToUserData_WhenEmptyFdlist_ShouldFalse, TestSize.Level1)
2397 {
2398     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2399     std::string jobId = "123";
2400     int32_t userId = 100;
2401     service->userJobMap_[jobId] = userId;
2402     service->currentUserId_ = userId;
2403     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2404     service->printUserMap_[userId] = userData;
2405     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>(); // EmptyFdlist
2406     userData->queuedJobList_[jobId] = printJob;
2407     EXPECT_EQ(service->FlushCacheFileToUserData(jobId), false);
2408 }
2409 
2410 /**
2411 * @tc.name: FlushCacheFileToUserData_WhenEmptyFdlist_ShouldTrue
2412 * @tc.desc: Verify the FlushCacheFileToUserData failed case.
2413 * @tc.type: FUNC FlushCacheFileToUserData
2414 * @tc.require: BedFdlist printJob
2415 */
2416 HWTEST_F(PrintServiceAbilityTest, FlushCacheFileToUserData_WhenBedFdlist_ShouldFalse, TestSize.Level1)
2417 {
2418     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2419     std::string jobId = "123";
2420     int32_t userId = 100;
2421     service->userJobMap_[jobId] = userId;
2422     service->currentUserId_ = userId;
2423     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2424     service->printUserMap_[userId] = userData;
2425     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
2426     userData->queuedJobList_[jobId] = printJob;
2427     std::vector<uint32_t> fdList = { 999 }; // Bed Fdlist
2428     printJob->SetFdList(fdList);
2429     EXPECT_EQ(service->FlushCacheFileToUserData(jobId), false);
2430 }
2431 
2432 /**
2433 * @tc.name: DeleteCacheFileFromUserData_WhenEmptyFdlist_ShouldTrue
2434 * @tc.desc: Verify the DeleteCacheFileFromUserData failed case.
2435 * @tc.type: FUNC DeleteCacheFileFromUserData
2436 * @tc.require: EmptyFdlist printJob
2437 */
2438 HWTEST_F(PrintServiceAbilityTest, DeleteCacheFileFromUserData_WhenEmptyFdlist_ShouldFalse, TestSize.Level1)
2439 {
2440     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2441     std::string jobId = "123";
2442     int32_t userId = 100;
2443     service->userJobMap_[jobId] = userId;
2444     service->currentUserId_ = userId;
2445     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2446     service->printUserMap_[userId] = userData;
2447     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
2448     userData->queuedJobList_[jobId] = printJob;
2449     EXPECT_EQ(service->DeleteCacheFileFromUserData(jobId), false);
2450 }
2451 
2452 /**
2453 * @tc.name: OpenCacheFileFd_WhenEmptyFdlist_ShouldTrue
2454 * @tc.desc: Verify the OpenCacheFileFd do nothing case.
2455 * @tc.type: FUNC OpenCacheFileFd
2456 * @tc.require: EmptyFdlist printJob
2457 */
2458 HWTEST_F(PrintServiceAbilityTest, OpenCacheFileFd_WhenEmptyFdlist_ShouldFalse, TestSize.Level1)
2459 {
2460     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2461     std::string jobId = "123";
2462     int32_t userId = 100;
2463     service->userJobMap_[jobId] = userId;
2464     service->currentUserId_ = userId;
2465     std::vector<uint32_t> getFdList;
2466     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2467     service->printUserMap_[userId] = userData;
2468     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>(); // EmptyFdlist
2469     userData->queuedJobList_[jobId] = printJob;
2470     EXPECT_EQ(service->OpenCacheFileFd(jobId, getFdList), false);
2471 }
2472 
2473 /**
2474 * @tc.name: OpenCacheFileFd_WhenEmptyFdlist_ShouldTrue
2475 * @tc.desc: Verify the OpenCacheFileFd failed case.
2476 * @tc.type: FUNC OpenCacheFileFd
2477 * @tc.require: BedFdlist printJob
2478 */
2479 HWTEST_F(PrintServiceAbilityTest, OpenCacheFileFd_WhenBedFdlist_ShouldFalse, TestSize.Level1)
2480 {
2481     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2482     std::string jobId = "123";
2483     int32_t userId = 100;
2484     service->userJobMap_[jobId] = userId;
2485     service->currentUserId_ = userId;
2486     std::vector<uint32_t> getFdList;
2487     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2488     service->printUserMap_[userId] = userData;
2489     EXPECT_EQ(service->OpenCacheFileFd(jobId, getFdList), false);
2490     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
2491     userData->queuedJobList_[jobId] = printJob;
2492     std::vector<uint32_t> fdList = { 999 }; // Bed Fdlist
2493     printJob->SetFdList(fdList);
2494     EXPECT_EQ(service->OpenCacheFileFd(jobId, getFdList), false);
2495 }
2496 
2497 
2498 /**
2499 * @tc.name: QueryQueuedPrintJobById_WhenInvalidJobId_ShouldF
2500 * @tc.desc: Verify the QueryQueuedPrintJobById failed case.
2501 * @tc.type: FUNC QueryQueuedPrintJobById
2502 * @tc.require: BedFdlist printJob
2503 */
2504 HWTEST_F(PrintServiceAbilityTest, QueryQueuedPrintJobById_WhenBedFdlist_ShouldFalse, TestSize.Level1)
2505 {
2506     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2507     std::string jobId = "123";
2508     int32_t userId = 100;
2509     service->userJobMap_[jobId] = userId;
2510     service->currentUserId_ = userId;
2511     PrintJob getPrintJob;
2512     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2513     service->printUserMap_[userId] = userData;
2514     std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
2515     userData->queuedJobList_[jobId] = printJob;
2516     EXPECT_EQ(service->QueryQueuedPrintJobById(jobId, getPrintJob), E_PRINT_INVALID_PRINTJOB);
2517 }
2518 
2519 HWTEST_F(PrintServiceAbilityTest, QueryHistoryPrintJobById, TestSize.Level1)
2520 {
2521     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2522     std::string jobId = "1";
2523     int32_t userId = 0;
2524     PrintJob printJob;
2525     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2526     service->printUserMap_[userId] = nullptr;
2527     EXPECT_EQ(service->QueryHistoryPrintJobById(jobId, printJob), E_PRINT_INVALID_USERID);
2528     service->printUserMap_[userId] = userData;
2529     EXPECT_EQ(service->QueryHistoryPrintJobById(jobId, printJob), E_PRINT_INVALID_PRINTJOB);
2530 }
2531 
2532 HWTEST_F(PrintServiceAbilityTest, DeletePrintJobFromHistoryList, TestSize.Level1)
2533 {
2534     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2535     std::string jobId = "1";
2536     int32_t userId = 100;
2537     std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
2538     service->printUserMap_[userId] = nullptr;
2539     EXPECT_EQ(service->DeletePrintJobFromHistoryList(jobId), false);
2540     service->printUserMap_[userId] = userData;
2541     EXPECT_EQ(service->DeletePrintJobFromHistoryList(jobId), false);
2542 }
2543 
2544 HWTEST_F(PrintServiceAbilityTest, AddPrintJobToHistoryList, TestSize.Level1)
2545 {
2546     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2547     auto printJob = std::make_shared<PrintJob>();
2548     EXPECT_EQ(service->AddPrintJobToHistoryList(printJob), false);
2549 }
2550 
2551 HWTEST_F(PrintServiceAbilityTest, ConnectPrinter_UsbPrinterId_InvalidPrinter, TestSize.Level1)
2552 {
2553     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2554     std::string printerId = "com.ohos.spooler:USB-printer-1";
2555     PrinterInfo info;
2556     info.SetPrinterId(printerId);
2557     auto infoPtr = std::make_shared<PrinterInfo>(info);
2558     service->printSystemData_.AddPrinterToDiscovery(infoPtr);
2559     EXPECT_EQ(service->ConnectPrinter(info.GetPrinterId()), E_PRINT_INVALID_PRINTER);
2560 }
2561 
2562 HWTEST_F(PrintServiceAbilityTest, SetPrinterPreference_AddedPrinterId_NoError, TestSize.Level1)
2563 {
2564     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2565     std::shared_ptr<PrintServiceHelper> helper = std::make_shared<PrintServiceHelper>();
2566     service->helper_ = helper;
2567     std::string printerId = "123";
2568     PrinterInfo info;
2569     info.SetPrinterId(printerId);
2570     PrinterPreferences preferences;
2571     preferences.SetBorderless(true);
2572     service->printSystemData_.InsertAddedPrinter(printerId, info);
2573     EXPECT_EQ(service->SetPrinterPreference(printerId, preferences), E_PRINT_NONE);
2574 }
2575 
2576 HWTEST_F(PrintServiceAbilityTest, UpdatePageSizeNameWithPrinterInfo_StandardPageSize_NameUnchanged, TestSize.Level1)
2577 {
2578     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2579     PrinterInfo printerInfo;
2580     PrintPageSize pageSize;
2581     pageSize.SetId("ISO_A4");
2582     pageSize.SetName("iso_a4_210x297mm");
2583     service->UpdatePageSizeNameWithPrinterInfo(printerInfo, pageSize);
2584     EXPECT_EQ(pageSize.GetName(), "iso_a4_210x297mm");
2585 }
2586 
2587 HWTEST_F(PrintServiceAbilityTest,
2588     UpdatePageSizeNameWithPrinterInfo_FindNonStandardPageSize_NameChanged, TestSize.Level1)
2589 {
2590     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2591     PrintPageSize pageSize;
2592     pageSize.SetId("A4.borderless");
2593     pageSize.SetName("iso_a4_210x297mm");
2594 
2595     PrinterInfo printerInfo;
2596     PrinterCapability printerCapability;
2597     std::vector<PrintPageSize> supportedPageSizeList;
2598     PrintPageSize custompPageSize;
2599     custompPageSize.SetId("A4.borderless");
2600     custompPageSize.SetName("A4.borderless");
2601     supportedPageSizeList.emplace_back(custompPageSize);
2602     printerCapability.SetSupportedPageSize(supportedPageSizeList);
2603     printerInfo.SetCapability(printerCapability);
2604     service->UpdatePageSizeNameWithPrinterInfo(printerInfo, pageSize);
2605     EXPECT_EQ(pageSize.GetName(), "A4.borderless");
2606 }
2607 
2608 HWTEST_F(PrintServiceAbilityTest,
2609     UpdatePageSizeNameWithPrinterInfo_CannotFindNonStandardPageSize_NameUnchanged, TestSize.Level1)
2610 {
2611     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2612     PrintPageSize pageSize;
2613     pageSize.SetId("A4.borderless");
2614     pageSize.SetName("iso_a4_210x297mm");
2615 
2616     PrinterInfo printerInfo;
2617     PrinterCapability printerCapability;
2618     std::vector<PrintPageSize> supportedPageSizeList;
2619     PrintPageSize custompPageSize;
2620     custompPageSize.SetId("A5.borderless");
2621     custompPageSize.SetName("A5.borderless");
2622     supportedPageSizeList.emplace_back(custompPageSize);
2623     printerInfo.SetCapability(printerCapability);
2624     printerCapability.SetSupportedPageSize(supportedPageSizeList);
2625     service->UpdatePageSizeNameWithPrinterInfo(printerInfo, pageSize);
2626     EXPECT_EQ(pageSize.GetName(), "iso_a4_210x297mm");
2627 }
2628 
2629 HWTEST_F(PrintServiceAbilityTest,
2630     UpdatePrintJobOptionWithPrinterPreferences_NoValueSet_NoAdvancedOptions, TestSize.Level1)
2631 {
2632     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2633     Json::Value jobOptions;
2634     PrinterInfo printerInfo;
2635     service->UpdatePrintJobOptionWithPrinterPreferences(jobOptions, printerInfo);
2636     EXPECT_EQ(jobOptions.isMember("advancedOptions"), false);
2637 }
2638 
2639 HWTEST_F(PrintServiceAbilityTest,
2640     UpdatePrintJobOptionWithPrinterPreferences_SetWrongTypeValue_NoAdvancedOptions, TestSize.Level1)
2641 {
2642     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2643     Json::Value jobOptions;
2644     jobOptions["isReverse"] = "isReverse";
2645     jobOptions["isCollate"] = "isCollate";
2646     PrinterInfo printerInfo;
2647     service->UpdatePrintJobOptionWithPrinterPreferences(jobOptions, printerInfo);
2648     EXPECT_EQ(jobOptions.isMember("advancedOptions"), false);
2649 }
2650 
2651 HWTEST_F(PrintServiceAbilityTest,
2652     UpdatePrintJobOptionWithPrinterPreferences_SetCorrectValue_HasAdvancedOptions, TestSize.Level1)
2653 {
2654     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2655     Json::Value jobOptions;
2656     jobOptions["isReverse"] = true;
2657     jobOptions["isCollate"] = true;
2658     PrinterInfo printerInfo;
2659     Json::Value preferenceOptions;
2660     preferenceOptions["key"] = "value";
2661     PrinterPreferences preferences;
2662     preferences.SetOption(PrintJsonUtil::WriteString(preferenceOptions));
2663     printerInfo.SetPreferences(preferences);
2664     service->UpdatePrintJobOptionWithPrinterPreferences(jobOptions, printerInfo);
2665     EXPECT_EQ(jobOptions.isMember("advancedOptions"), true);
2666 }
2667 
2668 HWTEST_F(PrintServiceAbilityTest, RefreshPrinterInfoByPpd_InsertAddedPrinter_CapabilityUnchanged, TestSize.Level1)
2669 {
2670     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2671     std::string printerId1 = "printerId1";
2672     std::string printerId2 = "printerId2";
2673     PrinterInfo info;
2674     info.SetPrinterId(printerId2);
2675     service->printSystemData_.addedPrinterMap_.Insert(printerId1, nullptr);
2676     service->printSystemData_.addedPrinterMap_.Insert(printerId2, info);
2677     service->RefreshPrinterInfoByPpd();
2678     EXPECT_EQ(info.HasCapability(), false);
2679 }
2680 
2681 HWTEST_F(PrintServiceAbilityTest, ConnectUsbPrinter_NoDiscoveredPrinter_InvalidPrinter, TestSize.Level1)
2682 {
2683     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2684     std::string printerId = "printerId";
2685     EXPECT_EQ(service->ConnectUsbPrinter(printerId), E_PRINT_INVALID_PRINTER);
2686 }
2687 
2688 HWTEST_F(PrintServiceAbilityTest, ConnectUsbPrinter_NoMake_InvalidPrinter, TestSize.Level1)
2689 {
2690     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2691     std::string printerId = "printerId";
2692     PrinterInfo info;
2693     info.SetPrinterId(printerId);
2694     auto infoPtr = std::make_shared<PrinterInfo>(info);
2695     service->printSystemData_.AddPrinterToDiscovery(infoPtr);
2696     EXPECT_EQ(service->ConnectUsbPrinter(printerId), E_PRINT_INVALID_PRINTER);
2697 }
2698 
2699 HWTEST_F(PrintServiceAbilityTest, ConnectUsbPrinter_HasMake_ServerFailure, TestSize.Level1)
2700 {
2701     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2702     std::string printerId = "printerId";
2703     PrinterInfo info;
2704     info.SetPrinterId(printerId);
2705     info.SetPrinterMake("testMake");
2706     auto infoPtr = std::make_shared<PrinterInfo>(info);
2707     service->printSystemData_.AddPrinterToDiscovery(infoPtr);
2708     EXPECT_EQ(service->ConnectUsbPrinter(printerId), E_PRINT_SERVER_FAILURE);
2709 }
2710 
2711 /**
2712 * @tc.name: QueryQueuedPrintJobById_WhenInvalidJobId_ShouldF
2713 * @tc.desc: Verify the QueryQueuedPrintJobById failed case.
2714 * @tc.type: FUNC ExitLowPowerMode
2715 * @tc.require: AllreadyEnterLowPower
2716 */
2717 HWTEST_F(PrintServiceAbilityTest, ExitLowPowerMode_WhenAllreadyEnterLowPowerMode_ShouldExit, TestSize.Level1)
2718 {
2719     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2720     service->ManualStart();
2721     service->DelayEnterLowPowerMode();
2722     EXPECT_TRUE(service->isLowPowerMode_);
2723     service->ExitLowPowerMode();
2724     EXPECT_FALSE(service->isLowPowerMode_);
2725 }
2726 
2727 /**
2728 * @tc.name: QueryQueuedPrintJobById_WhenInvalidJobId_ShouldF
2729 * @tc.desc: Verify the QueryQueuedPrintJobById failed case.
2730 * @tc.type: FUNC ExitLowPowerMode
2731 * @tc.require: ExitedLowPowerMode
2732 */
2733 HWTEST_F(PrintServiceAbilityTest, ExitLowPowerMode_WhenExitedLowPower_ShouldDoNothing, TestSize.Level1)
2734 {
2735     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2736     service->ManualStart();
2737     EXPECT_FALSE(service->isLowPowerMode_);
2738     service->ExitLowPowerMode();
2739     EXPECT_FALSE(service->isLowPowerMode_);
2740 }
2741 
2742 HWTEST_F(PrintServiceAbilityTest, RefreshPrinterPageSize, TestSize.Level1)
2743 {
2744     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2745     PrinterInfo printerInfo;
2746     PrinterCapability cap;
2747     std::vector<PrintPageSize> pageSizeList;
2748     PrintPageSize pageSize;
2749     pageSize.SetWidth(ISO_A4_WIDTH);
2750     pageSize.SetHeight(ISO_A4_HEIGHT);
2751     pageSizeList.push_back(pageSize);
2752     cap.SetSupportedPageSize(pageSizeList);
2753     printerInfo.SetCapability(cap);
2754     service->RefreshPrinterPageSize(printerInfo);
2755     printerInfo.GetCapability(cap);
2756     cap.GetSupportedPageSize(pageSizeList);
2757     EXPECT_EQ(pageSizeList.size(), 1);
2758 }
2759 
2760 /**
2761 * @tc.name: RefreshPrinterStatusOnSwitchUser_NotEnterpriseEnable
2762 * @tc.desc: Verify the RefreshPrinterStatusOnSwitchUser failed case.
2763 * @tc.type: ENTERPRISE_ENABLE is true
2764 * @tc.require: ENTERPRISE_SPACE_PARAM not 2
2765 */
2766 HWTEST_F(PrintServiceAbilityTest, RefreshPrinterStatusOnSwitchUser_NotEnterpriseEnable, TestSize.Level1)
2767 {
2768 #ifdef ENTERPRISE_ENABLE
2769     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2770     std::string parameterSaved = OHOS::system::GetParameter(ENTERPRISE_SPACE_PARAM, "");
2771     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, "");
2772     bool res = service->RefreshPrinterStatusOnSwitchUser();
2773     EXPECT_FALSE(res);
2774     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, parameterSaved);
2775 #endif // ENTERPRISE_ENABLE
2776 }
2777 
2778 HWTEST_F(PrintServiceAbilityTest, RefreshPrinterStatusOnSwitchUser_EnterpriseEnable_IsEnterprise, TestSize.Level1)
2779 {
2780 #ifdef ENTERPRISE_ENABLE
2781     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2782     std::string parameterSaved = OHOS::system::GetParameter(ENTERPRISE_SPACE_PARAM, "");
2783     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, IS_ENTERPRISE_ENABLE);
2784     service->isEnterprise_ = true;
2785     bool res = service->RefreshPrinterStatusOnSwitchUser();
2786     EXPECT_TRUE(res);
2787     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, parameterSaved);
2788 #endif // ENTERPRISE_ENABLE
2789 }
2790 
2791 HWTEST_F(PrintServiceAbilityTest, RefreshPrinterStatusOnSwitchUser_EnterpriseEnable_NotEnterprise, TestSize.Level1)
2792 {
2793 #ifdef ENTERPRISE_ENABLE
2794     auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
2795     std::string parameterSaved = OHOS::system::GetParameter(ENTERPRISE_SPACE_PARAM, "");
2796     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, IS_ENTERPRISE_ENABLE);
2797     service->isEnterprise_ = false;
2798     bool res = service->RefreshPrinterStatusOnSwitchUser();
2799     EXPECT_TRUE(res);
2800     OHOS::system::SetParameter(ENTERPRISE_SPACE_PARAM, parameterSaved);
2801 #endif // ENTERPRISE_ENABLE
2802 }
2803 
2804 HWTEST_F(PrintServiceAbilityTest, GetKeyList_ShouldReturnEmptyList_WhenCompIsNull, TestSize.Level1)
2805 {
2806     PrintMapSafe<std::string> map;
2807     std::function<bool (const std::string &)> comp = nullptr;
2808     std::vector<std::string> result = map.GetKeyList(comp);
2809     EXPECT_TRUE(result.empty());
2810 }
2811 
2812 HWTEST_F(PrintServiceAbilityTest, GetKeyList_ShouldReturnEmptyList_WhenMapIsEmpty, TestSize.Level1)
2813 {
2814     PrintMapSafe<std::string> map;
__anon1ba6df6b0102(const std::string &value) 2815     std::function<bool (const std::string &)> comp = [](const std::string &value) {
2816         return value == "test";
2817     };
2818     std::vector<std::string> result = map.GetKeyList(comp);
2819     EXPECT_TRUE(result.empty());
2820 }
2821 
2822 HWTEST_F(PrintServiceAbilityTest, GetKeyList_ShouldReturnEmptyList_WhenNotElementsSatisfiesComp, TestSize.Level1)
2823 {
2824     PrintMapSafe<std::string> map;
__anon1ba6df6b0202(const std::string &value) 2825     std::function<bool (const std::string &)> comp = [](const std::string &value) {
2826         return value == "test";
2827     };
2828     map.Insert("key1", "value1");
2829     map.Insert("key2", "value2");
2830     std::vector<std::string> result = map.GetKeyList(comp);
2831     EXPECT_TRUE(result.empty());
2832 }
2833 
2834 HWTEST_F(PrintServiceAbilityTest, GetKeyList_ShouldReturnListOfKeys_WhenElementSatifiesComp, TestSize.Level1)
2835 {
2836     PrintMapSafe<std::string> map;
__anon1ba6df6b0302(const std::string &value) 2837     std::function<bool (const std::string &)> comp = [](const std::string &value) {
2838         return value == "value2";
2839     };
2840     map.Insert("key1", "value1");
2841     map.Insert("key2", "value2");
2842     std::vector<std::string> result = map.GetKeyList(comp);
2843     EXPECT_EQ(result.size(), 1); // 1 element matched
2844     EXPECT_EQ(result[0], "key2");
2845 }
2846 
2847 HWTEST_F(PrintServiceAbilityTest, GetKeyList_ShouldReturnListOfKeys_WhenMultiElementSatifiesComp, TestSize.Level1)
2848 {
2849     PrintMapSafe<std::string> map;
__anon1ba6df6b0402(const std::string &value) 2850     std::function<bool (const std::string &)> comp = [](const std::string &value) {
2851         return value == "value2";
2852     };
2853     map.Insert("key1", "value1");
2854     map.Insert("key2", "value2");
2855     map.Insert("key3", "value2");
2856     std::vector<std::string> result = map.GetKeyList(comp);
2857     EXPECT_EQ(result.size(), 2); // 2 elements matched
2858 }
2859 } // namespace OHOS::Print
2860