diff --git a/test/unittest/fwk_inner_napi_test/print_callback_stub_test.cpp b/test/unittest/fwk_inner_napi_test/print_callback_stub_test.cpp index 5bddb63..7f4d13a 100644 --- a/test/unittest/fwk_inner_napi_test/print_callback_stub_test.cpp +++ b/test/unittest/fwk_inner_napi_test/print_callback_stub_test.cpp @@ -192,5 +192,80 @@ HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0006, TestSize.Level1) EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE); EXPECT_TRUE(reply.ReadBool()); } + +/** + * @tc.name: PrintServiceProxyTest_0008 + * @tc.desc: Verify the capability function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0008, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + uint32_t code = static_cast(PRINT_CALLBACK_PRINT_JOB_ADAPTER); + + std::string jobId = "job:1234"; + auto oldAttrs = PrintAttributes::Unmarshalling(data); + auto newAttrs = PrintAttributes::Unmarshalling(data); + if (oldAttrs == nullptr || newAttrs == nullptr) { + return; + } + + EXPECT_TRUE(data.WriteInterfaceToken(IPrintCallback::GetDescriptor())); + auto callback = std::make_shared(); + EXPECT_NE(callback, nullptr); + EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE); + EXPECT_TRUE(reply.ReadBool()); +} + +/** + * @tc.name: PrintServiceProxyTest_0009 + * @tc.desc: Verify the capability function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0009, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + uint32_t code = static_cast(PRINT_CALLBACK_PRINT_JOB_CHANGED_ADAPTER); + + auto testState = static_cast(PRINT_JOB_RUNNING); + auto testSubState = static_cast(PRINTER_ADDED); + std::string jobId = "job:1234"; + + EXPECT_TRUE(data.WriteInterfaceToken(IPrintCallback::GetDescriptor())); + EXPECT_TRUE(data.WriteUint32(testState)); + EXPECT_TRUE(data.WriteUint32(testSubState)); + auto callback = std::make_shared(); + EXPECT_NE(callback, nullptr); + EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE); + EXPECT_TRUE(reply.ReadBool()); +} + +/** + * @tc.name: PrintCallbackStubTest_0010 + * @tc.desc: Verify the capability function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCallbackStubTest, PrintCallbackStubTest_0010, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + uint32_t code = static_cast(PRINT_CALLBACK_PRINT_GET_FILE_ADAPTER); + + auto testState = static_cast(PRINT_JOB_RUNNING); + EXPECT_TRUE(data.WriteInterfaceToken(IPrintCallback::GetDescriptor())); + EXPECT_TRUE(data.WriteUint32(testState)); + auto callback = std::make_shared(); + EXPECT_NE(callback, nullptr); + EXPECT_EQ(callback->OnRemoteRequest(code, data, reply, option), E_PRINT_NONE); + EXPECT_TRUE(reply.ReadBool()); +} } // namespace Print } // namespace OHOS diff --git a/test/unittest/fwk_print_cups_client_test/print_cups_client_test.cpp b/test/unittest/fwk_print_cups_client_test/print_cups_client_test.cpp index cad173c..940126f 100644 --- a/test/unittest/fwk_print_cups_client_test/print_cups_client_test.cpp +++ b/test/unittest/fwk_print_cups_client_test/print_cups_client_test.cpp @@ -1652,5 +1652,113 @@ HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0078, TestSize.Level1) jobParams = printCupsClient.BuildJobParameters(testJob); EXPECT_EQ(jobParams, nullptr); } + +/** + * @tc.name: PrintCupsClientTest_0079 + * @tc.desc: HandleFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0079, TestSize.Level1) +{ + OHOS::Print::PrintCupsClient printCupsClient; + http_t *http = nullptr; + PrintJob testJob; + JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob); + int32_t numFiles = 1; + int32_t jobId = 1; + EXPECT_EQ(printCupsClient.HandleFiles(jobParams, numFiles, http, jobId), false); + jobParams = nullptr; + EXPECT_EQ(printCupsClient.HandleFiles(jobParams, numFiles, http, jobId), false); + delete http; +} + +/** + * @tc.name: PrintCupsClientTest_0080 + * @tc.desc: HandleJobState + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0080, TestSize.Level1) +{ + OHOS::Print::PrintCupsClient printCupsClient; + http_t *http = nullptr; + JobStatus *prevousJobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}}; + JobStatus *jobStatus = new (std::nothrow) JobStatus{{'\0'}, (ipp_jstate_t)0, {'\0'}}; + PrintJob testJob; + testJob.SetJobId(GetDefaultJobId()); + std::vector files = {1}; + testJob.SetFdList(files); + OHOS::Print::PrintPageSize pageSize; + pageSize.SetId("pgid-1234"); + testJob.SetPageSize(pageSize); + testJob.SetPrinterId("printid-1234"); + testJob.SetOption(JOB_OPTIONS); + JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob); + JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility, + jobParams->serviceJobId, + 1, + "ipp://192.168.186.1:631/ipp/print", + "DIRECT-PixLab_V1-0105"}; + + printCupsClient.HandleJobState(http, param, jobStatus, prevousJobStatus); + EXPECT_NE(prevousJobStatus, nullptr); + printCupsClient.QueryJobStateAgain(http, param, jobStatus); + printCupsClient.HandleJobState(http, param, jobStatus, prevousJobStatus); + EXPECT_NE(prevousJobStatus, nullptr); + delete prevousJobStatus; + delete jobStatus; + delete param; + delete http; +} + +/** + * @tc.name: PrintCupsClientTest_0081 + * @tc.desc: MonitorJobState + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0081, TestSize.Level1) +{ + OHOS::Print::PrintCupsClient printCupsClient; + CallbackFunc callback = [this](){}; + PrintJob testJob; + testJob.SetJobId(GetDefaultJobId()); + std::vector files = {1}; + testJob.SetFdList(files); + OHOS::Print::PrintPageSize pageSize; + pageSize.SetId("pgid-1234"); + testJob.SetPageSize(pageSize); + testJob.SetPrinterId("printid-1234"); + testJob.SetOption(JOB_OPTIONS); + JobParameters *jobParams = printCupsClient.BuildJobParameters(testJob); + JobMonitorParam *param = new (std::nothrow) JobMonitorParam{jobParams->serviceAbility, + jobParams->serviceJobId, + 1, + "ipp://192.168.186.1:631/ipp/print", + "DIRECT-PixLab_V1-0105"}; + + printCupsClient.MonitorJobState(param, callback); + EXPECT_NE(param, nullptr); + param = nullptr; + printCupsClient.MonitorJobState(param, callback); + delete param; +} + +/** + * @tc.name: PrintCupsClientTest_0082 + * @tc.desc: ResumePrinter + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0082, TestSize.Level1) +{ + OHOS::Print::PrintCupsClient printCupsClient; + std::string printerName = "testPrinterName"; + EXPECT_EQ(printCupsClient.ResumePrinter(printerName), E_PRINT_SERVER_FAILURE); + printCupsClient.printAbility_ = nullptr; + EXPECT_EQ(printCupsClient.ResumePrinter(printerName), E_PRINT_SERVER_FAILURE); +} + } // namespace Print } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/fwk_print_service_ability_test/print_service_ability_test.cpp b/test/unittest/fwk_print_service_ability_test/print_service_ability_test.cpp index 4734b0c..2e0488f 100644 --- a/test/unittest/fwk_print_service_ability_test/print_service_ability_test.cpp +++ b/test/unittest/fwk_print_service_ability_test/print_service_ability_test.cpp @@ -2164,4 +2164,15 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0137, TestSize.Level1) info.SetOption(infoJson.dump()); EXPECT_EQ(service->UpdatePrinterInSystem(info), E_PRINT_INVALID_PARAMETER); } + +HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0138, TestSize.Level1) +{ + auto service = std::make_shared(PRINT_SERVICE_ID, true); + PrinterInfo info; + info.SetPrinterId(DEFAULT_EXT_PRINTER_ID); + std::string type = "testType"; + EXPECT_EQ(service->CheckUserIdInEventType(type), false); + type = PRINTER_CHANGE_EVENT_TYPE; + EXPECT_EQ(service->CheckUserIdInEventType(type), false); +} } // namespace OHOS::Print diff --git a/test/unittest/service_test/print_http_server_manager_test.cpp b/test/unittest/service_test/print_http_server_manager_test.cpp index 8f5e88e..4053d01 100644 --- a/test/unittest/service_test/print_http_server_manager_test.cpp +++ b/test/unittest/service_test/print_http_server_manager_test.cpp @@ -152,6 +152,49 @@ HWTEST_F(PrintHttpServerManagerTest, PrintHttpServerManagerTest_004, TestSize.Le printHttpServerManager.StopServer(printerName); } +/** + * @tc.name: PrintHttpServerManagerTest_005 + * @tc.desc: Verify the AllocatePort function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintHttpServerManagerTest, PrintHttpServerManagerTest_005, TestSize.Level1) +{ + OHOS::Print::PrintHttpServerManager printHttpServerManager; + std::string printerName = "HUAWEI PixLab V1-0105"; + std::shared_ptr newServer = std::make_shared(); + EXPECT_NE(newServer, nullptr); + std::shared_ptr newProcess = std::make_shared(); + EXPECT_NE(newProcess, nullptr); + int32_t port = 0; + printHttpServerManager.printHttpServerMap[printerName] = newServer; + EXPECT_EQ(printHttpServerManager.AllocatePort(newServer, port), true); + printHttpServerManager.printHttpPortMap[printerName] = 60000; + printHttpServerManager.printHttpProcessMap[printerName] = newProcess; + EXPECT_EQ(printHttpServerManager.AllocatePort(newServer, port), true); +} + +/** + * @tc.name: PrintHttpServerManagerTest_006 + * @tc.desc: Verify the DealUsbDevDetch function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PrintHttpServerManagerTest, PrintHttpServerManagerTest_006, TestSize.Level1) +{ + OHOS::Print::PrintHttpServerManager printHttpServerManager; + std::string printerName = "HUAWEI PixLab V1-0105"; + std::shared_ptr newServer = std::make_shared(); + EXPECT_NE(newServer, nullptr); + std::shared_ptr newProcess = std::make_shared(); + EXPECT_NE(newProcess, nullptr); + printHttpServerManager.printHttpServerMap[printerName] = newServer; + printHttpServerManager.printHttpPortMap[printerName] = 60000; + printHttpServerManager.printHttpProcessMap[printerName] = newProcess; + std::string devStr = ""; + printHttpServerManager.DealUsbDevDetach(devStr); +} + } // namespace Print } // namespace OHOS #endif // IPPOVERUSB_ENABLE \ No newline at end of file