!618 [Bug]: dt坏味道修复

Merge pull request !618 from 田迅/dt
This commit is contained in:
openharmony_ci 2025-01-17 02:07:53 +00:00 committed by Gitee
commit f025db18ab
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 109 additions and 186 deletions

View File

@ -58,7 +58,7 @@ public:
int32_t QueryAllPrintJob(std::vector<PrintJob> &printJobs);
int32_t SetDefaultPrinter(const std::string &printerId, uint32_t type);
int32_t SetLastUsedPrinter(const std::string &printerId);
void ParseUserData();
bool ParseUserData();
void SetUserId(int32_t userId);
std::string GetLastUsedPrinter();
std::string GetDefaultPrinter();

View File

@ -221,17 +221,18 @@ void PrintUserData::DeletePrinterFromUsedPrinterList(const std::string &printerI
}
}
void PrintUserData::ParseUserData()
bool PrintUserData::ParseUserData()
{
std::string fileData = "";
if (!GetFileData(fileData)) {
PRINT_HILOGW("get file data failed");
return;
return false;
}
nlohmann::json jsonObject;
if (CheckFileData(fileData, jsonObject)) {
ParseUserDataFromJson(jsonObject);
}
return true;
}
void PrintUserData::ParseUserDataFromJson(nlohmann::json &jsonObject)

View File

@ -411,6 +411,7 @@ HWTEST_F(PrintJobTest, PrintJobTest_0025, TestSize.Level1)
job.SetIsSequential(true);
job.Marshalling(parcel);
EXPECT_EQ(job.GetIsSequential(), false);
}
/**

View File

@ -601,7 +601,7 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0028, TestSize.Level1)
[&testPrinterIds](const std::vector<std::string> &printerIds) {
EXPECT_EQ(testPrinterIds.size(), printerIds.size());
for (size_t index = 0; index < testPrinterIds.size(); index++) {
EXPECT_EQ(testPrinterIds[index], testPrinterIds[index]);
EXPECT_EQ(testPrinterIds[index], printerIds[index]);
}
return E_PRINT_NONE;
});
@ -1788,7 +1788,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0089, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerFail();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1805,7 +1806,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0090, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerFail();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1822,7 +1824,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0091, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerFail();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1839,7 +1842,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0092, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerFail();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1856,7 +1860,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0093, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerSuccess();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1873,7 +1878,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0094, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerSuccess();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1890,7 +1896,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0095, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerSuccess();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**
@ -1907,7 +1914,8 @@ HWTEST_F(PrintManagerClientTest, PrintManagerClientTest_0096, TestSize.Level1)
PrintManagerClient::GetInstance()->LoadServerSuccess();
PrintManagerClient::GetInstance()->ResetProxy();
PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
int32_t ret = PrintManagerClient::GetInstance()->RegisterExtCallback(testExtensionId, testCallbackId, testCb);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
/**

View File

@ -418,7 +418,7 @@ HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0012, TestSize.Level1)
[&testPrinterIds](const std::vector<std::string> &printerIds) {
EXPECT_EQ(testPrinterIds.size(), printerIds.size());
for (size_t index = 0; index < testPrinterIds.size(); index++) {
EXPECT_EQ(testPrinterIds[index], testPrinterIds[index]);
EXPECT_EQ(testPrinterIds[index], printerIds[index]);
}
return E_PRINT_NONE;
});

View File

@ -625,6 +625,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_028, TestSize.
httplib::Response responseData;
size_t requestId = 1;
printHttpRequestProcess.ProcessHttpResponse(responseData, requestId);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -652,6 +653,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_029, TestSize.
readTempBuffer.assign(tempStr.begin(), tempStr.end());
printHttpRequestProcess.readBufMap[requestId] = readTempBuffer;
printHttpRequestProcess.ProcessHttpResponse(responseData, requestId);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -666,6 +668,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_030, TestSize.
httplib::Response responseData;
size_t requestId = 1;
printHttpRequestProcess.ProcessHttpResponseGetAttr(responseData, requestId);
EXPECT_EQ(requestId, 1);
}
/**
@ -693,6 +696,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_031, TestSize.
readTempBuffer.assign(tempStr.begin(), tempStr.end());
printHttpRequestProcess.readGetAttrBufMap[requestId] = readTempBuffer;
printHttpRequestProcess.ProcessHttpResponseGetAttr(responseData, requestId);
EXPECT_EQ(requestId, 1);
}
/**
@ -707,6 +711,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_032, TestSize.
httplib::Response responseData;
size_t requestId = 1;
printHttpRequestProcess.ProcessHttpResponseSendDoc(responseData, requestId);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -734,6 +739,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_033, TestSize.
readTempBuffer.assign(tempStr.begin(), tempStr.end());
printHttpRequestProcess.readSendDocBufMap[requestId] = readTempBuffer;
printHttpRequestProcess.ProcessHttpResponseSendDoc(responseData, requestId);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -820,7 +826,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_037, TestSize.
std::string reqData = HTTP_REQ_DATA;
size_t data_length = 1;
printHttpRequestProcess.CalcReqIdOperaId(reqData.c_str(), data_length, requestId);
EXPECT_EQ(requestId, 0);
EXPECT_EQ(printHttpRequestProcess.needWriteData, false);
}
/**
@ -832,8 +838,9 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_037, TestSize.
HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_038, TestSize.Level1)
{
OHOS::Print::PrintHttpRequestProcess printHttpRequestProcess;
printHttpRequestProcess.needWriteData = true;
printHttpRequestProcess.needWriteData = false;
printHttpRequestProcess.CreatWriteDataTask();
EXPECT_EQ(printHttpRequestProcess.needWriteData, true);
}
/**
@ -851,6 +858,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_040, TestSize.
size_t requestId = 0;
printHttpRequestProcess.needWriteData = true;
printHttpRequestProcess.ProcessOtherRequest(data, data_length, sHeadersAndBody, requestId);
EXPECT_STREQ(data, "test");
}
/**
@ -994,6 +1002,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_049, TestSize.
printHttpRequestProcess.reqIdOperaIdMap[requestId] = HTTP_REQUEST_GET_ATTR;
std::string sHeadersAndBody = "";
printHttpRequestProcess.ProcessHttpResp(requestId, responseData, sHeadersAndBody);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -1011,6 +1020,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_050, TestSize.
printHttpRequestProcess.deviceOpen = false;
std::string sHeadersAndBody = "";
printHttpRequestProcess.ProcessHttpResp(requestId, responseData, sHeadersAndBody);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -1028,6 +1038,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_051, TestSize.
printHttpRequestProcess.deviceOpen = true;
std::string sHeadersAndBody = "";
printHttpRequestProcess.ProcessHttpResp(requestId, responseData, sHeadersAndBody);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -1045,6 +1056,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_052, TestSize.
printHttpRequestProcess.reqIdOperaIdMap[requestId] = testOperationId;
std::string sHeadersAndBody = "";
printHttpRequestProcess.ProcessHttpResp(requestId, responseData, sHeadersAndBody);
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -1086,6 +1098,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_055, TestSize.
{
OHOS::Print::PrintHttpRequestProcess printHttpRequestProcess;
printHttpRequestProcess.StartWriteDataToPrinterLooper();
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
/**
@ -1098,6 +1111,7 @@ HWTEST_F(PrintHttpRequestProcessTest, PrintHttpRequestProcessTest_056, TestSize.
{
OHOS::Print::PrintHttpRequestProcess printHttpRequestProcess;
printHttpRequestProcess.StartReadSendDocDataFromPrinterLooper();
EXPECT_EQ(printHttpRequestProcess.needReadSendDoc, false);
}
} // namespace Print

View File

@ -660,7 +660,7 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0029, TestSize.Level1)
int32_t userId = 100;
std::shared_ptr<PrintUserData> userData = std::make_shared<PrintUserData>();
service->printUserMap_.insert(std::make_pair(userId, userData));
service->QueryAllPrintJob(printJobs);
EXPECT_EQ(service->QueryAllPrintJob(printJobs), E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0030, TestSize.Level1)
@ -670,9 +670,11 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0030, TestSize.Level1)
service->helper_ = helper;
std::vector<PrintJob> printJobs;
service->QueryAllPrintJob(printJobs);
EXPECT_EQ(service->QueryAllPrintJob(printJobs), E_PRINT_NONE);
int32_t userId = 100;
service->printUserMap_.insert(std::make_pair(userId, nullptr));
service->QueryAllPrintJob(printJobs);
EXPECT_EQ(service->QueryAllPrintJob(printJobs), E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0031, TestSize.Level1)
@ -1313,14 +1315,17 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0072, TestSize.Level1)
std::string supportedOpts;
std::vector<std::string> optAttrs;
service->BuildPrinterPreferenceByOption(key, supportedOpts, optAttrs);
EXPECT_STREQ(supportedOpts.c_str(), "");
std::string supportedOpts2 = "test";
service->BuildPrinterPreferenceByOption(key, supportedOpts2, optAttrs);
EXPECT_STREQ(supportedOpts.c_str(), "");
nlohmann::json optJson;
nlohmann::json itemJson;
itemJson["key"] = "value";
optJson["testList"] = itemJson;
std::string supportedOpts3 = optJson.dump();
service->BuildPrinterPreferenceByOption(key, supportedOpts3, optAttrs);
EXPECT_STREQ(supportedOpts.c_str(), "");
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0073, TestSize.Level1)
@ -1443,12 +1448,14 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0079, TestSize.Level1)
printJob.SetOption(opsJson.dump());
auto cupsPrinter = std::make_shared<CupsPrinterInfo>();
service->printSystemData_.addedPrinterMap_.Insert(printerId, cupsPrinter);
service->StartNativePrintJob(printJob);
auto ret = service->StartNativePrintJob(printJob);
EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
auto extensionId = PrintUtils::GetExtensionId(printerId);
std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_START_PRINT);
sptr<IPrintExtensionCallback> extCb = nullptr;
service->extCallbackMap_[cid] = extCb;
service->StartNativePrintJob(printJob);
ret = service->StartNativePrintJob(printJob);
EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0080, TestSize.Level1)
@ -1457,8 +1464,9 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0080, TestSize.Level1)
std::string printerId = "123";
service->SetLastUsedPrinter(printerId);
auto cupsPrinter = std::make_shared<CupsPrinterInfo>();
service->printSystemData_.addedPrinterMap_.Insert(printerId, cupsPrinter);
auto ret = service->printSystemData_.addedPrinterMap_.Insert(printerId, cupsPrinter);
service->SetLastUsedPrinter(printerId);
EXPECT_EQ(ret, 1);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0081, TestSize.Level1)
@ -1468,7 +1476,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0081, TestSize.Level1)
uint32_t subState = PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS;
service->checkJobState(state, subState);
std::string jobId = "123";
service->UpdatePrintJobStateOnlyForSystemApp(jobId, state, subState);
auto ret = service->UpdatePrintJobStateOnlyForSystemApp(jobId, state, subState);
EXPECT_EQ(ret, E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0082, TestSize.Level1)
@ -1480,11 +1489,14 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0082, TestSize.Level1)
std::string type = PRINT_GET_FILE_EVENT_TYPE;
sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
service->registeredListeners_[type] = listener;
service->AdapterGetFileCallBack(jobId, state, subState);
auto ret = service->AdapterGetFileCallBack(jobId, state, subState);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
subState = PRINT_JOB_CREATE_FILE_COMPLETED_FAILED;
service->AdapterGetFileCallBack(jobId, state, subState);
ret = service->AdapterGetFileCallBack(jobId, state, subState);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
subState = PRINT_JOB_BLOCKED_UNKNOWN;
service->AdapterGetFileCallBack(jobId, state, subState);
ret = service->AdapterGetFileCallBack(jobId, state, subState);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0083, TestSize.Level1)
@ -1551,15 +1563,18 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0087, TestSize.Level1)
{
auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
std::string printerId = "1234";
service->QueryPrinterCapability(printerId);
auto ret = service->QueryPrinterCapability(printerId);
EXPECT_EQ(ret, E_PRINT_INVALID_PRINTER);
auto printerInfo = std::make_shared<PrinterInfo>();
service->printSystemData_.discoveredPrinterInfoList_[printerId] = printerInfo;
service->QueryPrinterCapability(printerId);
ret = service->QueryPrinterCapability(printerId);
EXPECT_EQ(ret, E_PRINT_SERVER_FAILURE);
std::string extensionId = PrintUtils::GetExtensionId(printerId);
std::string cid = PrintUtils::EncodeExtensionCid(extensionId, PRINT_EXTCB_REQUEST_CAP);
sptr<IPrintExtensionCallback> extCb = nullptr;
service->extCallbackMap_[cid] = extCb;
service->QueryPrinterCapability(printerId);
ret = service->QueryPrinterCapability(printerId);
EXPECT_EQ(ret, E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0088, TestSize.Level1)
@ -1569,16 +1584,21 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0088, TestSize.Level1)
service->helper_ = helper;
std::string extensionCid = "";
sptr<IPrintExtensionCallback> listener = nullptr;
service->RegisterExtCallback(extensionCid, listener);
auto ret = service->RegisterExtCallback(extensionCid, listener);
EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
std::string extensionCid2 = "123:20";
service->RegisterExtCallback(extensionCid2, listener);
ret = service->RegisterExtCallback(extensionCid2, listener);
EXPECT_EQ(ret, E_PRINT_INVALID_EXTENSION);
std::string extensionId = "123";
service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
service->RegisterExtCallback(extensionCid2, listener);
ret = service->RegisterExtCallback(extensionCid2, listener);
EXPECT_EQ(ret, E_PRINT_INVALID_EXTENSION);
service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADING;
service->RegisterExtCallback(extensionCid2, listener);
ret = service->RegisterExtCallback(extensionCid2, listener);
EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
std::string extensionCid3 = "123:2";
service->RegisterExtCallback(extensionCid2, listener);
ret = service->RegisterExtCallback(extensionCid2, listener);
EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0089, TestSize.Level1)
@ -1589,7 +1609,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0089, TestSize.Level1)
std::string cid = PrintUtils::EncodeExtensionCid(extensionId, callbackId);
sptr<IPrintExtensionCallback> extCb = nullptr;
service->extCallbackMap_[cid] = extCb;
service->UnregisterAllExtCallback(extensionId);
auto ret = service->UnregisterAllExtCallback(extensionId);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0090, TestSize.Level1)
@ -1597,9 +1618,11 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0090, TestSize.Level1)
auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
std::string extensionId = "123";
service->extensionStateList_[extensionId] = PRINT_EXTENSION_UNLOAD;
service->LoadExtSuccess(extensionId);
auto ret = service->LoadExtSuccess(extensionId);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
service->extensionStateList_[extensionId] = PRINT_EXTENSION_LOADING;
service->LoadExtSuccess(extensionId);
ret = service->LoadExtSuccess(extensionId);
EXPECT_EQ(ret, E_PRINT_NO_PERMISSION);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0091, TestSize.Level1)
@ -1619,7 +1642,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0092, TestSize.Level1)
auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
service->helper_ = nullptr;
AAFwk::Want want;
service->StartAbility(want);
auto ret = service->StartAbility(want);
EXPECT_EQ(ret, E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0093, TestSize.Level1)
@ -1652,6 +1676,7 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0095, TestSize.Level1)
sptr<IPrintCallback> listener = new MockPrintCallbackProxy();
service->registeredListeners_[PRINTER_EVENT_TYPE] = listener;
service->SendPrinterEvent(info);
EXPECT_EQ(info.GetPrinterState(), PRINTER_UNKNOWN);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0096, TestSize.Level1)
@ -1756,7 +1781,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0100, TestSize.Level1)
std::string jobName = "";
PrintAttributes printAttributes;
std::string taskId = "";
service->PrintByAdapter(jobName, printAttributes, taskId);
auto ret = service->PrintByAdapter(jobName, printAttributes, taskId);
EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0102, TestSize.Level1)
@ -1821,7 +1847,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0106, TestSize.Level1)
{
auto service = std::make_shared<PrintServiceAbility>(PRINT_SERVICE_ID, true);
std::string printerId = "1234";
service->SetDefaultPrinter(printerId, 0);
auto ret = service->SetDefaultPrinter(printerId, 0);
EXPECT_EQ(ret, E_PRINT_NONE);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0107, TestSize.Level1)
@ -1852,9 +1879,11 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0111, TestSize.Level1)
int32_t userId1 = 100;
int32_t userId2 = 101;
std::shared_ptr<PrintUserData> userData1 = std::make_shared<PrintUserData>();
userData1->SetDefaultPrinter("test", 0);
auto ret = userData1->SetDefaultPrinter("test", 0);
EXPECT_EQ(ret, E_PRINT_NONE);
std::shared_ptr<PrintUserData> userData2 = std::make_shared<PrintUserData>();
userData1->SetDefaultPrinter(printerId, 0);
ret = userData1->SetDefaultPrinter(printerId, 0);
EXPECT_EQ(ret, E_PRINT_NONE);
service->printUserMap_[userId1] = userData1;
service->printUserMap_[userId2] = userData2;
service->DeletePrinterFromUserData(printerId);
@ -1889,7 +1918,8 @@ HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0113, TestSize.Level1)
service->helper_ = helper;
std::string taskId = "";
std::string type = PRINTER_CHANGE_EVENT_TYPE;
service->Off(taskId, type);
auto ret = service->Off(taskId, type);
EXPECT_EQ(ret, E_PRINT_INVALID_PARAMETER);
}
HWTEST_F(PrintServiceAbilityTest, PrintServiceAbilityTest_0120, TestSize.Level1)

View File

@ -96,90 +96,6 @@ job.SetOption("{"printerUri": "uri", "printerName": "name", "documentFormat": "f
"printerName": "name"}");
EXPECT_EQ(client.BuildJobParameters(job), nullptr);
}
TEST_F(nullTest, ReportBlockedReason_WhenParamIsNull_ShouldReturn)
{
PrintCupsClient client;
JobMonitorParam *param = nullptr;
JobStatus *jobStatus = new JobStatus();
client.ReportBlockedReason(param, jobStatus);
// 由于param为nullptr所以没有任何断言因为没有任何实际的行为可断言
// 但是,如果函数没有任何副作用,那么这是一个有效的测试
}
TEST_F(nullTest, ReportBlockedReason_WhenJobStatusIsNull_ShouldReturn)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
JobStatus *jobStatus = nullptr;
client.ReportBlockedReason(param, jobStatus);
// 由于jobStatus为nullptr所以没有任何断言因为没有任何实际的行为可以断言
// 但是,如果函数没有任何副作用,那么这是一个有效的测试
}
TEST_F(nullTest, ReportBlockedReason_WhenServiceAbilityIsNull_ShouldReturn)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
param->serviceAbility = nullptr;
JobStatus *jobStatus = new JobStatus();
client.ReportBlockedReason(param, jobStatus);
// 由于param->serviceAbility为nullptr所以没有任何断言因为没有任何实际的行为可以断言
// 但是,如果函数没有任何副作用,那么这是一个有效的测试
}
TEST_F(nullTest, ReportBlockedReason_WhenPrinterStateReasonsContainOffline_ShouldUpdatePrintJobState)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
param->serviceAbility = new ServiceAbility();
JobStatus *jobStatus = new JobStatus();
jobStatus->printer_state_reasons = "offline";
client.ReportBlockedReason(param, jobStatus);
// 断言param->serviceAbility->UpdatePrintJobState被正确调用
}
TEST_F(nullTest, ReportBlockedReason_WhenPrinterStateReasonsContainPaused_ShouldUpdatePrintJobState)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
param->serviceAbility = new ServiceAbility();
JobStatus *jobStatus = new JobStatus();
jobStatus->printer_state_reasons = "paused";
client.ReportBlockedReason(param, jobStatus);
// 断言param->serviceAbility->UpdatePrintJobState被正确调用
}
TEST_F(nullTest, ReportBlockedReason_WhenPrinterStateReasonsContainOther_ShouldUpdatePrintJobStateUnknown)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
param->serviceAbility = new ServiceAbility();
JobStatus *jobStatus = new JobStatus();
jobStatus->printer_state_reasons = "other";
client.ReportBlockedReason(param, jobStatus);
// 断言param->serviceAbility->UpdatePrintJobState被正确调用并且substate为PRINT_JOB_BLOCKED_UNKNOWN
}
TEST_F(nullTest, ReportBlockedReason_WhenPrinterStateReasonsContainMediaEmpty_ShouldUpdatePrintJobStateOutOfPaper)
{
PrintCupsClient client;
JobMonitorParam *param = new JobMonitorParam();
param->serviceAbility = new ServiceAbility();
JobStatus *jobStatus = new JobStatus();
jobStatus->printer_state_reasons = "media-empty";
client.ReportBlockedReason(param, jobStatus);
// 断言param->serviceAbility->UpdatePrintJobState被正确调用并且substate包含PRINT_JOB_BLOCKED_OUT_OF_PAPER
}
// 其他测试用例类似
TEST_F(nullTest, testStartCupsJob)
{
PrintCupsClient client;
JobParameters jobParams;
jobParams.fdList.push_back(1);
jobParams.printerName = "printer";
jobParams.printerId = 1;
jobParams.printerUri = "printerUri";
jobParams.serviceAbility = new PrintServiceAbility();
jobParams.serviceJobId = 1;
auto callback = undefined {
PRINT_HILOGI("callback");
};
client.StartCupsJob(&jobParams, callback);
}
TEST_F(nullTest, testUpdatePrintJobStateInJobParams)
{
PrintCupsClient client;
@ -193,23 +109,6 @@ jobParams.serviceJobId = 1;
client.UpdatePrintJobStateInJobParams(&jobParams, 1, 1);
EXPECT_EQ(client.printerId, 1);
}
TEST_F(nullTest, testHandleJobState)
{
PrintCupsClient client;
JobMonitorParam param;
JobStatus jobStatus;
JobStatus previousJobStatus;
client.HandleJobState(nullptr, &param, &jobStatus, &previousJobStatus);
}
TEST_F(nullTest, testMonitorJobState)
{
PrintCupsClient client;
JobMonitorParam param;
auto callback = undefined {
PRINT_HILOGI("callback");
};
client.MonitorJobState(&param, callback);
}
TEST_F(nullTest, testQueryJobStateAgain)
{
PrintCupsClient client;

View File

@ -32,12 +32,6 @@ delete printServiceAbility;
printServiceAbility = nullptr
}
};
HWTEST_F(PrintServiceAbilityTest, GetInstance_ShouldReturnSameInstance, TestSize.Level0)
{
sptr<PrintServiceAbility> instance1 = PrintServiceAbility::GetInstance();
sptr<PrintServiceAbility> instance2 = PrintServiceAbility::GetInstance();
EXPECT_EQ(instance1, instance2);
}
HWTEST_F(PrintServiceAbilityTest, GetInstance_ShouldReturnDifferentInstance, TestSize.Level0)
{
sptr<PrintServiceAbility> instance1 = PrintServiceAbility::GetInstance();

View File

@ -85,40 +85,6 @@ TEST_F(PrintUserDataTest, UnregisterPrinterCallback_ShouldNotChangeListeners_Whe
EXPECT_NE(registeredListeners_.find(type), registeredListeners_.end());
}
TEST_F(PrintUserDataTest, testRegisterPrinterCallback)
{
PrintUserData printUserData;
std::string type = "testType";
sptr<IPrintCallback> listener = new PrintCallback();
printUserData.RegisterPrinterCallback(type, listener);
// 验证是否正确调用了RegisterPrinterCallback方法
// 由于该方法没有返回值,我们需要通过观察方法调用的副作用来验证
// 例如如果RegisterPrinterCallback方法修改了PrintUserData的内部状态我们可以检查这个状态是否符合预期
// 这里我们假设RegisterPrinterCallback方法的预期行为是正确的因此我们不需要进一步的断言
}
TEST_F(PrintUserDataTest, testRegisterPrinterCallbackWithNullListener)
{
PrintUserData printUserData;
std::string type = "testType";
sptr<IPrintCallback> listener = nullptr;
printUserData.RegisterPrinterCallback(type, listener);
// 验证是否正确处理了空的listener
// 由于listener为空我们期望RegisterPrinterCallback方法能够正确处理这种情况而不抛出异常或崩溃
// 这里我们不需要进一步的断言因为如果方法没有正确处理空的listener那么它应该在运行时抛出异常或崩溃
}
TEST_F(PrintUserDataTest, testRegisterPrinterCallbackWithMultipleListeners)
{
PrintUserData printUserData;
std::string type = "testType";
sptr<IPrintCallback> listener1 = new PrintCallback();
sptr<IPrintCallback> listener2 = new PrintCallback();
printUserData.RegisterPrinterCallback(type, listener1);
printUserData.RegisterPrinterCallback(type, listener2);
// 验证是否正确处理了多个listener
// 由于我们没有具体的实现细节我们只能假设如果方法能够正确处理多个listener那么它应该不会抛出异常或崩溃
// 这里我们不需要进一步的断言因为如果方法没有正确处理多个listener那么它应该在运行时抛出异常或崩溃
}
TEST_F(PrintUserDataTest, SendPrinterEvent_ShouldCallOnCallback_WhenListenerExists)
{
// Arrange

View File

@ -282,12 +282,16 @@ HWTEST_F(PrintUsbManagerTest, PrintUsbManagerTest_011, TestSize.Level1)
std::string devStr = IPP_PRINTER;
std::string devStrNull = "";
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
EXPECT_EQ(printUsbManager.printDeviceMap.size(), 1);
isAttach = false;
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
EXPECT_EQ(printUsbManager.printDeviceMap.size(), 0);
printUsbManager.DealUsbDevStatusChange(devStrNull, isAttach);
EXPECT_EQ(printUsbManager.printDeviceMap.size(), 0);
isAttach = true;
devStr = NON_IPP_PRINTER;
printUsbManager.DealUsbDevStatusChange(NON_IPP_PRINTER, isAttach);
EXPECT_EQ(printUsbManager.printDeviceMap.size(), 0);
}
/**

View File

@ -124,6 +124,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0006, TestSize.Level1)
userData->RegisterPrinterCallback(type, listener);
userData->RegisterPrinterCallback(type2, newListener);
userData->SendPrinterEvent(type, event, info);
EXPECT_EQ(userData->registeredListeners_.size(), 2);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0007, TestSize.Level1)
@ -175,6 +176,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0010, TestSize.Level1)
int event = 0;
userData->RegisterPrinterCallback(type, listener);
userData->SendPrinterEvent(type, event, info);
EXPECT_EQ(userData->registeredListeners_.size(), 1);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0011, TestSize.Level1)
@ -201,7 +203,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0012, TestSize.Level1)
std::shared_ptr<PrintJob> printJob = std::make_shared<PrintJob>();
userData->jobOrderList_.insert(std::make_pair(jobOrderId, jobId));
std::vector<PrintJob> printJobs;
userData->QueryAllPrintJob(printJobs);
EXPECT_EQ(userData->QueryAllPrintJob(printJobs), E_PRINT_NONE);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0013, TestSize.Level1)
@ -219,6 +221,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0014, TestSize.Level1)
userData->SetLastUsedPrinter(printerId);
std::string printerId2 = "";
userData->SetLastUsedPrinter(printerId2);
EXPECT_EQ(userData->lastUsedPrinterId_, printerId);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0015, TestSize.Level1)
@ -230,20 +233,20 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0015, TestSize.Level1)
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0016, TestSize.Level1)
{
auto userData = std::make_shared<OHOS::Print::PrintUserData>();
userData->ParseUserData();
EXPECT_EQ(userData->ParseUserData(), true);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0017, TestSize.Level1)
{
auto userData = std::make_shared<OHOS::Print::PrintUserData>();
std::string fileData = "";
userData->GetFileData(fileData);
EXPECT_EQ(userData->GetFileData(fileData), true);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0018, TestSize.Level1)
{
auto userData = std::make_shared<OHOS::Print::PrintUserData>();
userData->SetUserDataToFile();
EXPECT_EQ(userData->SetUserDataToFile(), true);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0019, TestSize.Level1)
@ -258,7 +261,8 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0020, TestSize.Level1)
std::string printerId = "com.ohos.spooler:p2p://DIRECT-PixLab_V1-0105";
userData->SetDefaultPrinter(printerId, 0);
std::string printerId2 = "";
userData->SetDefaultPrinter(printerId2, 0);
auto ret = userData->SetDefaultPrinter(printerId2, 0);
EXPECT_EQ(ret, E_PRINT_NONE);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0021, TestSize.Level1)
@ -284,6 +288,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0021, TestSize.Level1)
userDataList3["100"] = userData3;
jsonObject3["print_user_data"] = userDataList3;
userData->ParseUserDataFromJson(jsonObject3);
EXPECT_EQ(userData->useLastUsedPrinterForDefault_, true);
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0022, TestSize.Level1)
@ -323,6 +328,7 @@ HWTEST_F(PrintUserDataTest, PrintUserDataTest_0022, TestSize.Level1)
userDataList4["100"] = userData4;
jsonObject4["print_user_data"] = userDataList4;
printUserData->ParseUserDataFromJson(jsonObject4);
EXPECT_EQ(printUserData->lastUsedPrinterId_, "123");
}
HWTEST_F(PrintUserDataTest, PrintUserDataTest_0023, TestSize.Level1)