1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <memory>
18 #include "print_service_proxy.h"
19 #include "print_manager_client.h"
20 #include "iremote_broker.h"
21 #include "print_constant.h"
22 #include "print_job.h"
23 #include "print_log.h"
24 #include "printer_info.h"
25 #include "mock_remote_object.h"
26 #include "mock_print_service.h"
27 #include "mock_print_callback_stub.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Print {
34 class PrintServiceProxyTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void PrintServiceProxyTest::SetUpTestCase(void) {}
43
TearDownTestCase(void)44 void PrintServiceProxyTest::TearDownTestCase(void) {}
45
SetUp(void)46 void PrintServiceProxyTest::SetUp(void) {}
47
TearDown(void)48 void PrintServiceProxyTest::TearDown(void) {}
49
50 /**
51 * @tc.name: PrintServiceProxyTest_0001
52 * @tc.desc: Verify the capability function.
53 * @tc.type: FUNC
54 * @tc.require:
55 */
56 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0001_NeedRename, TestSize.Level0)
57 {
58 std::vector<std::string> testFileList = {"file://data/print/a.png",
59 "file://data/print/b.png", "file://data/print/c.png"};
60 std::vector<uint32_t> testFdList = {1, 2};
61 std::string testTaskId = "2";
62 sptr<MockRemoteObject> obj = new MockRemoteObject();
63 EXPECT_NE(obj, nullptr);
64 auto proxy = std::make_shared<PrintServiceProxy>(obj);
65 EXPECT_NE(proxy, nullptr);
66 auto service = std::make_shared<MockPrintService>();
67 EXPECT_NE(service, nullptr);
68 EXPECT_CALL(*service, StartPrint(_, _, _)).Times(Exactly(1)).WillOnce(
69 [&testFileList, &testFdList, &testTaskId](const std::vector<std::string> &fileList,
__anona70dbd580102(const std::vector<std::string> &fileList, const std::vector<uint32_t> &fdList, std::string &taskId) 70 const std::vector<uint32_t> &fdList, std::string &taskId) {
71 EXPECT_EQ(testFileList.size(), fileList.size());
72 for (size_t index = 0; index < testFileList.size(); index++) {
73 EXPECT_EQ(testFileList[index], fileList[index]);
74 }
75 EXPECT_EQ(testFdList.size(), fdList.size());
76 for (size_t index = 0; index < testFdList.size(); index++) {
77 EXPECT_NE(testFdList[index], fdList[index]);
78 }
79 EXPECT_EQ(testTaskId, taskId);
80 return E_PRINT_NONE;
81 });
82 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
83 ON_CALL(*obj, SendRequest)
__anona70dbd580202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 84 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
85 service->OnRemoteRequest(code, data, reply, option);
86 return E_PRINT_NONE;
87 });
88 proxy->StartPrint(testFileList, testFdList, testTaskId);
89 }
90
91 /**
92 * @tc.name: PrintServiceProxyTest_0002
93 * @tc.desc: Verify the capability function.
94 * @tc.type: FUNC
95 * @tc.require:
96 */
97 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0002_NeedRename, TestSize.Level0)
98 {
99 std::vector<std::string> testFileList = {};
100 std::vector<uint32_t> testFdList = {};
101 std::string testTaskId = "2";
102 sptr<MockRemoteObject> obj = new MockRemoteObject();
103 EXPECT_NE(obj, nullptr);
104 auto proxy = std::make_shared<PrintServiceProxy>(obj);
105 EXPECT_NE(proxy, nullptr);
106 auto service = std::make_shared<MockPrintService>();
107 EXPECT_NE(service, nullptr);
108 EXPECT_CALL(*service, StartPrint(_, _, _)).Times(Exactly(1)).WillOnce(
109 [&testFileList, &testFdList, &testTaskId](const std::vector<std::string> &fileList,
__anona70dbd580302(const std::vector<std::string> &fileList, const std::vector<uint32_t> &fdList, std::string &taskId) 110 const std::vector<uint32_t> &fdList, std::string &taskId) {
111 EXPECT_EQ(testFileList.size(), fileList.size());
112 for (size_t index = 0; index < testFileList.size(); index++) {
113 EXPECT_EQ(testFileList[index], fileList[index]);
114 }
115 EXPECT_EQ(testFdList.size(), fdList.size());
116 for (size_t index = 0; index < testFdList.size(); index++) {
117 EXPECT_EQ(testFdList[index], fdList[index]);
118 }
119 EXPECT_EQ(testTaskId, taskId);
120 return E_PRINT_NONE;
121 });
122 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
123 ON_CALL(*obj, SendRequest)
__anona70dbd580402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 124 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
125 service->OnRemoteRequest(code, data, reply, option);
126 return E_PRINT_NONE;
127 });
128 proxy->StartPrint(testFileList, testFdList, testTaskId);
129 }
130
131 /**
132 * @tc.name: PrintServiceProxyTest_0003
133 * @tc.desc: Verify the capability function.
134 * @tc.type: FUNC
135 * @tc.require:
136 */
137 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0003_NeedRename, TestSize.Level0)
138 {
139 std::string testTaskId = "2";
140 sptr<MockRemoteObject> obj = new MockRemoteObject();
141 EXPECT_NE(obj, nullptr);
142 auto proxy = std::make_shared<PrintServiceProxy>(obj);
143 EXPECT_NE(proxy, nullptr);
144 auto service = std::make_shared<MockPrintService>();
145 EXPECT_NE(service, nullptr);
146 EXPECT_CALL(*service, StopPrint(_)).Times(Exactly(1)).WillOnce(
__anona70dbd580502(const std::string &taskId) 147 [&testTaskId](const std::string &taskId) {
148 EXPECT_EQ(testTaskId, taskId);
149 return E_PRINT_NONE;
150 });
151 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
152 ON_CALL(*obj, SendRequest)
__anona70dbd580602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 153 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
154 service->OnRemoteRequest(code, data, reply, option);
155 return E_PRINT_NONE;
156 });
157 proxy->StopPrint(testTaskId);
158 }
159
160 /**
161 * @tc.name: PrintServiceProxyTest_0004
162 * @tc.desc: Verify the capability function.
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0004_NeedRename, TestSize.Level0)
167 {
168 std::string testPrintId = "2";
169 sptr<MockRemoteObject> obj = new MockRemoteObject();
170 EXPECT_NE(obj, nullptr);
171 auto proxy = std::make_shared<PrintServiceProxy>(obj);
172 EXPECT_NE(proxy, nullptr);
173 auto service = std::make_shared<MockPrintService>();
174 EXPECT_NE(service, nullptr);
175 EXPECT_CALL(*service, ConnectPrinter(_)).Times(Exactly(1)).WillOnce(
__anona70dbd580702(const std::string &printId) 176 [&testPrintId](const std::string &printId) {
177 EXPECT_EQ(testPrintId, printId);
178 return E_PRINT_NONE;
179 });
180 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
181 ON_CALL(*obj, SendRequest)
__anona70dbd580802(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 182 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
183 service->OnRemoteRequest(code, data, reply, option);
184 return E_PRINT_NONE;
185 });
186 proxy->ConnectPrinter(testPrintId);
187 }
188
189 /**
190 * @tc.name: PrintServiceProxyTest_0005
191 * @tc.desc: Verify the capability function.
192 * @tc.type: FUNC
193 * @tc.require:
194 */
195 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0005_NeedRename, TestSize.Level0)
196 {
197 std::string testPrintId = "2";
198 sptr<MockRemoteObject> obj = new MockRemoteObject();
199 EXPECT_NE(obj, nullptr);
200 auto proxy = std::make_shared<PrintServiceProxy>(obj);
201 EXPECT_NE(proxy, nullptr);
202 auto service = std::make_shared<MockPrintService>();
203 EXPECT_NE(service, nullptr);
204 EXPECT_CALL(*service, DisconnectPrinter(_)).Times(Exactly(1)).WillOnce(
__anona70dbd580902(const std::string &printId) 205 [&testPrintId](const std::string &printId) {
206 EXPECT_EQ(testPrintId, printId);
207 return E_PRINT_NONE;
208 });
209 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
210 ON_CALL(*obj, SendRequest)
__anona70dbd580a02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 211 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
212 service->OnRemoteRequest(code, data, reply, option);
213 return E_PRINT_NONE;
214 });
215 proxy->DisconnectPrinter(testPrintId);
216 }
217
218 /**
219 * @tc.name: PrintServiceProxyTest_0006
220 * @tc.desc: Verify the capability function.
221 * @tc.type: FUNC
222 * @tc.require:
223 */
224 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0006_NeedRename, TestSize.Level0)
225 {
226 PrintExtensionInfo info1, info2;
227 info1.SetExtensionId("extensionId-1");
228 info1.SetExtensionId("extensionId-2");
229 std::vector<PrintExtensionInfo> testExtInfos = {info1, info2};
230 sptr<MockRemoteObject> obj = new MockRemoteObject();
231 EXPECT_NE(obj, nullptr);
232 auto proxy = std::make_shared<PrintServiceProxy>(obj);
233 EXPECT_NE(proxy, nullptr);
234 auto service = std::make_shared<MockPrintService>();
235 EXPECT_NE(service, nullptr);
236 EXPECT_CALL(*service, QueryAllExtension(_)).Times(Exactly(1)).WillOnce(
__anona70dbd580b02(std::vector<PrintExtensionInfo> &extensionInfos) 237 [&testExtInfos](std::vector<PrintExtensionInfo> &extensionInfos) {
238 extensionInfos.assign(testExtInfos.begin(), testExtInfos.end());
239 return E_PRINT_NONE;
240 });
241 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
242 ON_CALL(*obj, SendRequest)
__anona70dbd580c02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 243 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
244 service->OnRemoteRequest(code, data, reply, option);
245 return E_PRINT_NONE;
246 });
247 std::vector<PrintExtensionInfo> result;
248 proxy->QueryAllExtension(result);
249 EXPECT_EQ(testExtInfos.size(), result.size());
250 }
251
252 /**
253 * @tc.name: PrintServiceProxyTest_0007
254 * @tc.desc: Verify the capability function.
255 * @tc.type: FUNC
256 * @tc.require:
257 */
258 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0007_NeedRename, TestSize.Level0)
259 {
260 std::vector<std::string> testExtList = {};
261 sptr<MockRemoteObject> obj = new MockRemoteObject();
262 EXPECT_NE(obj, nullptr);
263 auto proxy = std::make_shared<PrintServiceProxy>(obj);
264 EXPECT_NE(proxy, nullptr);
265 auto service = std::make_shared<MockPrintService>();
266 EXPECT_NE(service, nullptr);
267 EXPECT_CALL(*service, StartDiscoverPrinter(_)).Times(Exactly(1)).WillOnce(
__anona70dbd580d02(const std::vector<std::string> &extensionList) 268 [&testExtList](const std::vector<std::string> &extensionList) {
269 EXPECT_EQ(testExtList.size(), extensionList.size());
270 return E_PRINT_NONE;
271 });
272 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
273 ON_CALL(*obj, SendRequest)
__anona70dbd580e02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 274 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
275 service->OnRemoteRequest(code, data, reply, option);
276 return E_PRINT_NONE;
277 });
278 proxy->StartDiscoverPrinter(testExtList);
279 }
280
281 /**
282 * @tc.name: PrintServiceProxyTest_0008
283 * @tc.desc: Verify the capability function.
284 * @tc.type: FUNC
285 * @tc.require:
286 */
287 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0008_NeedRename, TestSize.Level0)
288 {
289 sptr<MockRemoteObject> obj = new MockRemoteObject();
290 EXPECT_NE(obj, nullptr);
291 auto proxy = std::make_shared<PrintServiceProxy>(obj);
292 EXPECT_NE(proxy, nullptr);
293 auto service = std::make_shared<MockPrintService>();
294 EXPECT_NE(service, nullptr);
295 EXPECT_CALL(*service, StopDiscoverPrinter()).Times(Exactly(1)).WillOnce(
__anona70dbd580f02() 296 []() {
297 return E_PRINT_NONE;
298 });
299 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
300 ON_CALL(*obj, SendRequest)
__anona70dbd581002(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 301 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
302 service->OnRemoteRequest(code, data, reply, option);
303 return E_PRINT_NONE;
304 });
305 proxy->StopDiscoverPrinter();
306 }
307
308 /**
309 * @tc.name: PrintServiceProxyTest_0009
310 * @tc.desc: Verify the capability function.
311 * @tc.type: FUNC
312 * @tc.require:
313 */
314 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0009_NeedRename, TestSize.Level0)
315 {
316 OHOS::Print::PrintJob testJob;
317 testJob.SetJobId("jobId-123");
318 sptr<MockRemoteObject> obj = new MockRemoteObject();
319 EXPECT_NE(obj, nullptr);
320 auto proxy = std::make_shared<PrintServiceProxy>(obj);
321 EXPECT_NE(proxy, nullptr);
322 auto service = std::make_shared<MockPrintService>();
323 EXPECT_NE(service, nullptr);
324 EXPECT_CALL(*service, StartPrintJob(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581102(const PrintJob &jobinfo) 325 [&testJob](const PrintJob &jobinfo) {
326 EXPECT_EQ(testJob.GetJobId(), jobinfo.GetJobId());
327 return E_PRINT_NONE;
328 });
329 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
330 ON_CALL(*obj, SendRequest)
__anona70dbd581202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 331 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
332 service->OnRemoteRequest(code, data, reply, option);
333 return E_PRINT_NONE;
334 });
335 proxy->StartPrintJob(testJob);
336 }
337
338 /**
339 * @tc.name: PrintServiceProxyTest_0010
340 * @tc.desc: Verify the capability function.
341 * @tc.type: FUNC
342 * @tc.require:
343 */
344 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0010_NeedRename, TestSize.Level0)
345 {
346 std::string testJobId = "jobId-123";
347 sptr<MockRemoteObject> obj = new MockRemoteObject();
348 EXPECT_NE(obj, nullptr);
349 auto proxy = std::make_shared<PrintServiceProxy>(obj);
350 EXPECT_NE(proxy, nullptr);
351 auto service = std::make_shared<MockPrintService>();
352 EXPECT_NE(service, nullptr);
353 EXPECT_CALL(*service, CancelPrintJob(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581302(const std::string &jobId) 354 [&testJobId](const std::string &jobId) {
355 EXPECT_EQ(testJobId, jobId);
356 return E_PRINT_NONE;
357 });
358 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
359 ON_CALL(*obj, SendRequest)
__anona70dbd581402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 360 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
361 service->OnRemoteRequest(code, data, reply, option);
362 return E_PRINT_NONE;
363 });
364 proxy->CancelPrintJob(testJobId);
365 }
366
367 /**
368 * @tc.name: PrintServiceProxyTest_0010
369 * @tc.desc: Verify the restart function.
370 * @tc.type: FUNC
371 * @tc.require:
372 */
373 HWTEST_F(PrintServiceProxyTest, RestartPrintJob_ShouldCallSA, TestSize.Level0)
374 {
375 std::string testJobId = "jobId-123";
376 sptr<MockRemoteObject> obj = new MockRemoteObject();
377 EXPECT_NE(obj, nullptr);
378 auto proxy = std::make_shared<PrintServiceProxy>(obj);
379 EXPECT_NE(proxy, nullptr);
380 auto service = std::make_shared<MockPrintService>();
381 EXPECT_NE(service, nullptr);
382 EXPECT_CALL(*service, RestartPrintJob(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581502(const std::string &jobId) 383 [&testJobId](const std::string &jobId) {
384 EXPECT_EQ(testJobId, jobId);
385 return E_PRINT_NONE;
386 });
387 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
388 ON_CALL(*obj, SendRequest)
__anona70dbd581602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 389 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
390 service->OnRemoteRequest(code, data, reply, option);
391 return E_PRINT_NONE;
392 });
393 proxy->RestartPrintJob(testJobId);
394 }
395
396 /**
397 * @tc.name: PrintServiceProxyTest_0011
398 * @tc.desc: Verify the capability function.
399 * @tc.type: FUNC
400 * @tc.require:
401 */
402 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0011_NeedRename, TestSize.Level0)
403 {
404 OHOS::Print::PrinterInfo info1, info2;
405 info1.SetOption("option-1");
406 info2.SetOption("option-2");
407 std::vector<PrinterInfo> testPrinterInfos = {info1, info2};
408 sptr<MockRemoteObject> obj = new MockRemoteObject();
409 EXPECT_NE(obj, nullptr);
410 auto proxy = std::make_shared<PrintServiceProxy>(obj);
411 EXPECT_NE(proxy, nullptr);
412 auto service = std::make_shared<MockPrintService>();
413 EXPECT_NE(service, nullptr);
414 EXPECT_CALL(*service, AddPrinters(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581702(const std::vector<PrinterInfo> &printerInfos) 415 [&testPrinterInfos](const std::vector<PrinterInfo> &printerInfos) {
416 EXPECT_EQ(testPrinterInfos.size(), printerInfos.size());
417 for (size_t index = 0; index < testPrinterInfos.size(); index++) {
418 EXPECT_EQ(testPrinterInfos[index].GetOption(), printerInfos[index].GetOption());
419 }
420 return E_PRINT_NONE;
421 });
422 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
423 ON_CALL(*obj, SendRequest)
__anona70dbd581802(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 424 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
425 service->OnRemoteRequest(code, data, reply, option);
426 return E_PRINT_NONE;
427 });
428 proxy->AddPrinters(testPrinterInfos);
429 }
430
431 /**
432 * @tc.name: PrintServiceProxyTest_0012
433 * @tc.desc: Verify the capability function.
434 * @tc.type: FUNC
435 * @tc.require:
436 */
437 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0012_NeedRename, TestSize.Level0)
438 {
439 std::vector<std::string> testPrinterIds = {"printerId-1", "printerId-2"};
440 sptr<MockRemoteObject> obj = new MockRemoteObject();
441 EXPECT_NE(obj, nullptr);
442 auto proxy = std::make_shared<PrintServiceProxy>(obj);
443 EXPECT_NE(proxy, nullptr);
444 auto service = std::make_shared<MockPrintService>();
445 EXPECT_NE(service, nullptr);
446 EXPECT_CALL(*service, RemovePrinters(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581902(const std::vector<std::string> &printerIds) 447 [&testPrinterIds](const std::vector<std::string> &printerIds) {
448 EXPECT_EQ(testPrinterIds.size(), printerIds.size());
449 for (size_t index = 0; index < testPrinterIds.size(); index++) {
450 EXPECT_EQ(testPrinterIds[index], printerIds[index]);
451 }
452 return E_PRINT_NONE;
453 });
454 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
455 ON_CALL(*obj, SendRequest)
__anona70dbd581a02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 456 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
457 service->OnRemoteRequest(code, data, reply, option);
458 return E_PRINT_NONE;
459 });
460 proxy->RemovePrinters(testPrinterIds);
461 }
462
463 /**
464 * @tc.name: PrintServiceProxyTest_0013
465 * @tc.desc: Verify the capability function.
466 * @tc.type: FUNC
467 * @tc.require:
468 */
469 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0013_NeedRename, TestSize.Level0)
470 {
471 OHOS::Print::PrinterInfo info1, info2;
472 info1.SetOption("option-1");
473 info2.SetOption("option-2");
474 std::vector<PrinterInfo> testPrinterInfos = {info1, info2};
475 sptr<MockRemoteObject> obj = new MockRemoteObject();
476 EXPECT_NE(obj, nullptr);
477 auto proxy = std::make_shared<PrintServiceProxy>(obj);
478 EXPECT_NE(proxy, nullptr);
479 auto service = std::make_shared<MockPrintService>();
480 EXPECT_NE(service, nullptr);
481 EXPECT_CALL(*service, UpdatePrinters(_)).Times(Exactly(1)).WillOnce(
__anona70dbd581b02(const std::vector<PrinterInfo> &printerInfos) 482 [&testPrinterInfos](const std::vector<PrinterInfo> &printerInfos) {
483 EXPECT_EQ(testPrinterInfos.size(), printerInfos.size());
484 for (size_t index = 0; index < testPrinterInfos.size(); index++) {
485 EXPECT_EQ(testPrinterInfos[index].GetOption(), printerInfos[index].GetOption());
486 }
487 return E_PRINT_NONE;
488 });
489 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
490 ON_CALL(*obj, SendRequest)
__anona70dbd581c02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 491 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
492 service->OnRemoteRequest(code, data, reply, option);
493 return E_PRINT_NONE;
494 });
495 proxy->UpdatePrinters(testPrinterInfos);
496 }
497
498 /**
499 * @tc.name: PrintServiceProxyTest_0014
500 * @tc.desc: Verify the capability function.
501 * @tc.type: FUNC
502 * @tc.require:
503 */
504 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0014_NeedRename, TestSize.Level0)
505 {
506 std::string testPrinterId = "printId-123";
507 uint32_t testState = 1;
508 sptr<MockRemoteObject> obj = new MockRemoteObject();
509 EXPECT_NE(obj, nullptr);
510 auto proxy = std::make_shared<PrintServiceProxy>(obj);
511 EXPECT_NE(proxy, nullptr);
512 auto service = std::make_shared<MockPrintService>();
513 EXPECT_NE(service, nullptr);
514 EXPECT_CALL(*service, UpdatePrinterState(_, _)).Times(Exactly(1)).WillOnce(
__anona70dbd581d02(const std::string &printerId, uint32_t state) 515 [&testPrinterId, &testState](const std::string &printerId, uint32_t state) {
516 EXPECT_EQ(testPrinterId, printerId);
517 EXPECT_EQ(testState, state);
518 return E_PRINT_NONE;
519 });
520 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
521 ON_CALL(*obj, SendRequest)
__anona70dbd581e02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 522 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
523 service->OnRemoteRequest(code, data, reply, option);
524 return E_PRINT_NONE;
525 });
526 proxy->UpdatePrinterState(testPrinterId, testState);
527 }
528
529 /**
530 * @tc.name: PrintServiceProxyTest_0015
531 * @tc.desc: Verify the capability function.
532 * @tc.type: FUNC
533 * @tc.require:
534 */
535 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0015_NeedRename, TestSize.Level1)
536 {
537 std::string testJobId = "printId-123";
538 uint32_t testState = 1;
539 uint32_t testSubState = 1;
540 sptr<MockRemoteObject> obj = new MockRemoteObject();
541 EXPECT_NE(obj, nullptr);
542 auto proxy = std::make_shared<PrintServiceProxy>(obj);
543 EXPECT_NE(proxy, nullptr);
544 auto service = std::make_shared<MockPrintService>();
545 EXPECT_NE(service, nullptr);
546 EXPECT_CALL(*service, UpdatePrintJobStateOnlyForSystemApp(_, _, _)).Times(Exactly(1)).WillOnce(
547 [&testJobId, &testState, &testSubState](const std::string &jobId,
__anona70dbd581f02(const std::string &jobId, uint32_t state, uint32_t subState) 548 uint32_t state, uint32_t subState) {
549 EXPECT_EQ(testJobId, jobId);
550 EXPECT_EQ(testState, state);
551 EXPECT_EQ(testSubState, subState);
552 return E_PRINT_NONE;
553 });
554 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
555 ON_CALL(*obj, SendRequest)
__anona70dbd582002(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 556 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
557 service->OnRemoteRequest(code, data, reply, option);
558 return E_PRINT_NONE;
559 });
560 proxy->UpdatePrintJobStateOnlyForSystemApp(testJobId, testState, testSubState);
561 }
562
563 /**
564 * @tc.name: PrintServiceProxyTest_0016
565 * @tc.desc: Verify the capability function.
566 * @tc.type: FUNC
567 * @tc.require:
568 */
569 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0016_NeedRename, TestSize.Level1)
570 {
571 std::string testExtInfo = "extInfo-123";
572 sptr<MockRemoteObject> obj = new MockRemoteObject();
573 EXPECT_NE(obj, nullptr);
574 auto proxy = std::make_shared<PrintServiceProxy>(obj);
575 EXPECT_NE(proxy, nullptr);
576 auto service = std::make_shared<MockPrintService>();
577 EXPECT_NE(service, nullptr);
578 EXPECT_CALL(*service, UpdateExtensionInfo(_)).Times(Exactly(1)).WillOnce(
__anona70dbd582102(const std::string &extInfo) 579 [&testExtInfo](const std::string &extInfo) {
580 EXPECT_EQ(testExtInfo, extInfo);
581 return E_PRINT_NONE;
582 });
583 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
584 ON_CALL(*obj, SendRequest)
__anona70dbd582202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 585 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
586 service->OnRemoteRequest(code, data, reply, option);
587 return E_PRINT_NONE;
588 });
589 proxy->UpdateExtensionInfo(testExtInfo);
590 }
591
592 /**
593 * @tc.name: PrintServiceProxyTest_0017
594 * @tc.desc: Verify the capability function.
595 * @tc.type: FUNC
596 * @tc.require:
597 */
598 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0017_NeedRename, TestSize.Level1)
599 {
600 PrintJob testJobInfo;
601 std::string testPreviewResult = "extInfo-123";
602 testJobInfo.SetPrinterId("printId-123");
603 sptr<MockRemoteObject> obj = new MockRemoteObject();
604 EXPECT_NE(obj, nullptr);
605 auto proxy = std::make_shared<PrintServiceProxy>(obj);
606 EXPECT_NE(proxy, nullptr);
607 auto service = std::make_shared<MockPrintService>();
608 EXPECT_NE(service, nullptr);
609 EXPECT_CALL(*service, RequestPreview(_, _)).Times(Exactly(1)).WillOnce(
__anona70dbd582302(const PrintJob &jobinfo, std::string &previewResult) 610 [&testJobInfo, &testPreviewResult](const PrintJob &jobinfo, std::string &previewResult) {
611 EXPECT_EQ(testJobInfo.GetPrinterId(), jobinfo.GetPrinterId());
612 return E_PRINT_NONE;
613 });
614 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
615 ON_CALL(*obj, SendRequest)
__anona70dbd582402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 616 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
617 service->OnRemoteRequest(code, data, reply, option);
618 return E_PRINT_NONE;
619 });
620 proxy->RequestPreview(testJobInfo, testPreviewResult);
621 }
622
623 /**
624 * @tc.name: PrintServiceProxyTest_0018
625 * @tc.desc: Verify the capability function.
626 * @tc.type: FUNC
627 * @tc.require:
628 */
629 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0018_NeedRename, TestSize.Level1)
630 {
631 std::string testPrintId = "printId-123";
632 sptr<MockRemoteObject> obj = new MockRemoteObject();
633 EXPECT_NE(obj, nullptr);
634 auto proxy = std::make_shared<PrintServiceProxy>(obj);
635 EXPECT_NE(proxy, nullptr);
636 auto service = std::make_shared<MockPrintService>();
637 EXPECT_NE(service, nullptr);
638 EXPECT_CALL(*service, QueryPrinterCapability(_)).Times(Exactly(1)).WillOnce(
__anona70dbd582502(const std::string &printerId) 639 [&testPrintId](const std::string &printerId) {
640 EXPECT_EQ(testPrintId, printerId);
641 return E_PRINT_NONE;
642 });
643 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
644 ON_CALL(*obj, SendRequest)
__anona70dbd582602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 645 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
646 service->OnRemoteRequest(code, data, reply, option);
647 return E_PRINT_NONE;
648 });
649 proxy->QueryPrinterCapability(testPrintId);
650 }
651
652 /**
653 * @tc.name: PrintServiceProxyTest_0019
654 * @tc.desc: Verify the capability function.
655 * @tc.type: FUNC
656 * @tc.require:
657 */
658 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0019_NeedRename, TestSize.Level1)
659 {
660 std::vector<PrintJob> testPrintJobs = {};
661 sptr<MockRemoteObject> obj = new MockRemoteObject();
662 EXPECT_NE(obj, nullptr);
663 auto proxy = std::make_shared<PrintServiceProxy>(obj);
664 EXPECT_NE(proxy, nullptr);
665 auto service = std::make_shared<MockPrintService>();
666 EXPECT_NE(service, nullptr);
667 EXPECT_CALL(*service, QueryAllActivePrintJob(_)).Times(Exactly(1)).WillOnce(
__anona70dbd582702(std::vector<PrintJob> &printJobs) 668 [&testPrintJobs](std::vector<PrintJob> &printJobs) {
669 EXPECT_EQ(testPrintJobs.size(), printJobs.size());
670 return E_PRINT_NONE;
671 });
672 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
673 ON_CALL(*obj, SendRequest)
__anona70dbd582802(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 674 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
675 service->OnRemoteRequest(code, data, reply, option);
676 return E_PRINT_NONE;
677 });
678 proxy->QueryAllActivePrintJob(testPrintJobs);
679 }
680
681 /**
682 * @tc.name: PrintServiceProxyTest_0020
683 * @tc.desc: Verify the capability function.
684 * @tc.type: FUNC
685 * @tc.require:
686 */
687 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0020_NeedRename, TestSize.Level1)
688 {
689 std::string testPrintJobId = "jobId-123";
690 PrintJob testPrintJob;
691 testPrintJob.SetJobId("jobId-123");
692 sptr<MockRemoteObject> obj = new MockRemoteObject();
693 EXPECT_NE(obj, nullptr);
694 auto proxy = std::make_shared<PrintServiceProxy>(obj);
695 EXPECT_NE(proxy, nullptr);
696 auto service = std::make_shared<MockPrintService>();
697 EXPECT_NE(service, nullptr);
698 EXPECT_CALL(*service, QueryPrintJobById(_, _)).Times(Exactly(1)).WillOnce(
__anona70dbd582902(std::string &printJobId, PrintJob &printJob) 699 [&testPrintJobId, &testPrintJob](std::string &printJobId, PrintJob &printJob) {
700 EXPECT_EQ(testPrintJobId, printJobId);
701 return E_PRINT_NONE;
702 });
703 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
704 ON_CALL(*obj, SendRequest)
__anona70dbd582a02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 705 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
706 service->OnRemoteRequest(code, data, reply, option);
707 return E_PRINT_NONE;
708 });
709 proxy->QueryPrintJobById(testPrintJobId, testPrintJob);
710 }
711
712 /**
713 * @tc.name: PrintServiceProxyTest_0021
714 * @tc.desc: Verify the capability function.
715 * @tc.type: FUNC
716 * @tc.require:
717 */
718 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0021_NeedRename, TestSize.Level1)
719 {
720 std::string testTaskId = "taskId-123";
721 std::string testType = "type";
722 sptr<MockRemoteObject> obj = new MockRemoteObject();
723 EXPECT_NE(obj, nullptr);
724 auto proxy = std::make_shared<PrintServiceProxy>(obj);
725 EXPECT_NE(proxy, nullptr);
726 auto service = std::make_shared<MockPrintService>();
727 EXPECT_NE(service, nullptr);
728 EXPECT_CALL(*service, Off(_, _)).Times(Exactly(1)).WillOnce(
__anona70dbd582b02(const std::string taskId, const std::string &type) 729 [&testTaskId, &testType](const std::string taskId, const std::string &type) {
730 EXPECT_EQ(testTaskId, taskId);
731 EXPECT_EQ(testType, type);
732 return E_PRINT_NONE;
733 });
734 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
735 ON_CALL(*obj, SendRequest)
__anona70dbd582c02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 736 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
737 service->OnRemoteRequest(code, data, reply, option);
738 return E_PRINT_NONE;
739 });
740 proxy->Off(testTaskId, testType);
741 }
742
743 /**
744 * @tc.name: PrintServiceProxyTest_0022
745 * @tc.desc: Verify the capability function.
746 * @tc.type: FUNC
747 * @tc.require:
748 */
749 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0022_NeedRename, TestSize.Level1)
750 {
751 std::string testExtId = "extId-123";
752 sptr<MockRemoteObject> obj = new MockRemoteObject();
753 EXPECT_NE(obj, nullptr);
754 auto proxy = std::make_shared<PrintServiceProxy>(obj);
755 EXPECT_NE(proxy, nullptr);
756 auto service = std::make_shared<MockPrintService>();
757 EXPECT_NE(service, nullptr);
758 EXPECT_CALL(*service, UnregisterAllExtCallback(_)).Times(Exactly(1)).WillOnce(
__anona70dbd582d02(const std::string &extensionId) 759 [&testExtId](const std::string &extensionId) {
760 EXPECT_EQ(testExtId, extensionId);
761 return E_PRINT_NONE;
762 });
763 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
764 ON_CALL(*obj, SendRequest)
__anona70dbd582e02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 765 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
766 service->OnRemoteRequest(code, data, reply, option);
767 return E_PRINT_NONE;
768 });
769 proxy->UnregisterAllExtCallback(testExtId);
770 }
771
772 /**
773 * @tc.name: PrintServiceProxyTest_0023
774 * @tc.desc: Verify the capability function.
775 * @tc.type: FUNC
776 * @tc.require:
777 */
778 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0023_NeedRename, TestSize.Level1)
779 {
780 std::string testExtId = "extId-123";
781 sptr<MockRemoteObject> obj = new MockRemoteObject();
782 EXPECT_NE(obj, nullptr);
783 auto proxy = std::make_shared<PrintServiceProxy>(obj);
784 EXPECT_NE(proxy, nullptr);
785 auto service = std::make_shared<MockPrintService>();
786 EXPECT_NE(service, nullptr);
787 EXPECT_CALL(*service, LoadExtSuccess(_)).Times(Exactly(1)).WillOnce(
__anona70dbd582f02(const std::string &extensionId) 788 [&testExtId](const std::string &extensionId) {
789 EXPECT_EQ(testExtId, extensionId);
790 return E_PRINT_NONE;
791 });
792 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
793 ON_CALL(*obj, SendRequest)
__anona70dbd583002(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 794 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
795 service->OnRemoteRequest(code, data, reply, option);
796 return E_PRINT_NONE;
797 });
798 proxy->LoadExtSuccess(testExtId);
799 }
800
801
802 /**
803 * @tc.name: PrintServiceProxyTest_0024
804 * @tc.desc: Verify the capability function.
805 * @tc.type: FUNC
806 * @tc.require:
807 */
808 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0024_NeedRename, TestSize.Level1)
809 {
810 std::string testExtId = "extId-123";
811 sptr<MockRemoteObject> obj = new MockRemoteObject();
812 EXPECT_NE(obj, nullptr);
813 auto proxy = std::make_shared<PrintServiceProxy>(obj);
814 EXPECT_EQ(E_PRINT_INVALID_PARAMETER, proxy->RegisterExtCallback(testExtId, nullptr));
815 }
816
817 /**
818 * @tc.name: PrintServiceProxyTest_0025
819 * @tc.desc: Verify the capability function.
820 * @tc.type: FUNC
821 * @tc.require:
822 */
823 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0025_NeedRename, TestSize.Level1)
824 {
825 sptr<MockRemoteObject> obj = new MockRemoteObject();
826 EXPECT_NE(obj, nullptr);
827 auto proxy = std::make_shared<PrintServiceProxy>(obj);
828 EXPECT_EQ(E_PRINT_INVALID_PARAMETER, proxy->UnregisterPrinterCallback(""));
829 }
830
831 /**
832 * @tc.name: PrintServiceProxyTest_0026
833 * @tc.desc: Verify the capability function.
834 * @tc.type: FUNC
835 * @tc.require:
836 */
837 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0026_NeedRename, TestSize.Level1)
838 {
839 sptr<MockRemoteObject> obj = new MockRemoteObject();
840 EXPECT_NE(obj, nullptr);
841 auto proxy = std::make_shared<PrintServiceProxy>(obj);
842 EXPECT_NE(proxy, nullptr);
843 auto service = std::make_shared<MockPrintCallbackStub>();
844 EXPECT_NE(service, nullptr);
845 const int testRetCode = -259;
846 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
847 ON_CALL(*obj, SendRequest)
__anona70dbd583102(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 848 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
849 service->OnRemoteRequest(code, data, reply, option);
850 return testRetCode;
851 });
852 std::string testJobId = "jobId-123";
853 EXPECT_EQ(E_PRINT_RPC_FAILURE, proxy->NotifyPrintServiceEvent(testJobId, 0));
854 }
855
856 /**
857 * @tc.name: PrintServiceProxyTest_0028
858 * @tc.desc: Verify the capability function.
859 * @tc.type: FUNC
860 * @tc.require:
861 */
862 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0028_NeedRename, TestSize.Level1)
863 {
864 std::string testType = "type";
865 sptr<IPrintCallback> testListener = new (std::nothrow) DummyPrintCallbackStub();
866 sptr<MockRemoteObject> obj = new MockRemoteObject();
867 EXPECT_NE(obj, nullptr);
868 auto proxy = std::make_shared<PrintServiceProxy>(obj);
869 EXPECT_EQ(E_PRINT_NONE, proxy->RegisterPrinterCallback(testType, testListener));
870 }
871
872 /**
873 * @tc.name: PrintServiceProxyTest_0029
874 * @tc.desc: Verify the DiscoverUsbPrinters function.
875 * @tc.type: FUNC
876 * @tc.require:
877 */
878 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0029_NeedRename, TestSize.Level1)
879 {
880 std::vector<PrinterInfo> testPrinters = {};
881 sptr<MockRemoteObject> obj = new MockRemoteObject();
882 EXPECT_NE(obj, nullptr);
883 auto proxy = std::make_shared<PrintServiceProxy>(obj);
884 EXPECT_NE(proxy, nullptr);
885 auto service = std::make_shared<MockPrintService>();
886 EXPECT_NE(service, nullptr);
887 EXPECT_CALL(*service, DiscoverUsbPrinters(_)).Times(Exactly(1)).WillOnce(
__anona70dbd583202(std::vector<PrinterInfo> &printers) 888 [&testPrinters](std::vector<PrinterInfo> &printers) {
889 EXPECT_EQ(testPrinters.size(), printers.size());
890 return E_PRINT_NONE;
891 });
892 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
893 ON_CALL(*obj, SendRequest)
__anona70dbd583302(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 894 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
895 service->OnRemoteRequest(code, data, reply, option);
896 return E_PRINT_NONE;
897 });
898 proxy->DiscoverUsbPrinters(testPrinters);
899 }
900
901 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0030_NeedRename, TestSize.Level1)
902 {
903 OHOS::Print::PrinterInfo testInfo1;
904 testInfo1.SetOption("option-1");
905 sptr<MockRemoteObject> obj = new MockRemoteObject();
906 EXPECT_NE(obj, nullptr);
907 auto proxy = std::make_shared<PrintServiceProxy>(obj);
908 EXPECT_NE(proxy, nullptr);
909 auto service = std::make_shared<MockPrintService>();
910 EXPECT_NE(service, nullptr);
911 EXPECT_CALL(*service, AddPrinterToDiscovery(_)).Times(Exactly(1)).WillOnce(
__anona70dbd583402(const PrinterInfo &printerInfo) 912 [&testInfo1](const PrinterInfo &printerInfo) {
913 EXPECT_EQ(testInfo1.GetOption(), printerInfo.GetOption());
914 return E_PRINT_NONE;
915 });
916 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
917 ON_CALL(*obj, SendRequest)
__anona70dbd583502(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 918 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
919 service->OnRemoteRequest(code, data, reply, option);
920 return E_PRINT_NONE;
921 });
922 proxy->AddPrinterToDiscovery(testInfo1);
923 }
924
925 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0031_NeedRename, TestSize.Level1)
926 {
927 OHOS::Print::PrinterInfo testInfo1;
928 testInfo1.SetOption("option-1");
929 sptr<MockRemoteObject> obj = new MockRemoteObject();
930 EXPECT_NE(obj, nullptr);
931 auto proxy = std::make_shared<PrintServiceProxy>(obj);
932 EXPECT_NE(proxy, nullptr);
933 auto service = std::make_shared<MockPrintService>();
934 EXPECT_NE(service, nullptr);
935 EXPECT_CALL(*service, UpdatePrinterInDiscovery(_)).Times(Exactly(1)).WillOnce(
__anona70dbd583602(const PrinterInfo &printerInfo) 936 [&testInfo1](const PrinterInfo &printerInfo) {
937 EXPECT_EQ(testInfo1.GetOption(), printerInfo.GetOption());
938 return E_PRINT_NONE;
939 });
940 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
941 ON_CALL(*obj, SendRequest)
__anona70dbd583702(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 942 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
943 service->OnRemoteRequest(code, data, reply, option);
944 return E_PRINT_NONE;
945 });
946 proxy->UpdatePrinterInDiscovery(testInfo1);
947 }
948
949 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0032_NeedRename, TestSize.Level1)
950 {
951 std::string testPrinterId = "111";
952 sptr<MockRemoteObject> obj = new MockRemoteObject();
953 EXPECT_NE(obj, nullptr);
954 auto proxy = std::make_shared<PrintServiceProxy>(obj);
955 EXPECT_NE(proxy, nullptr);
956 auto service = std::make_shared<MockPrintService>();
957 EXPECT_NE(service, nullptr);
958 EXPECT_CALL(*service, RemovePrinterFromDiscovery(_)).Times(Exactly(1)).WillOnce(
__anona70dbd583802(const std::string &printerId) 959 [&testPrinterId](const std::string &printerId) {
960 EXPECT_EQ(testPrinterId, printerId);
961 return E_PRINT_NONE;
962 });
963 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
964 ON_CALL(*obj, SendRequest)
__anona70dbd583902(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 965 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
966 service->OnRemoteRequest(code, data, reply, option);
967 return E_PRINT_NONE;
968 });
969 proxy->RemovePrinterFromDiscovery(testPrinterId);
970 }
971
972 HWTEST_F(PrintServiceProxyTest, PrintServiceProxyTest_0033_NeedRename, TestSize.Level1)
973 {
974 OHOS::Print::PrinterInfo testInfo1;
975 testInfo1.SetOption("option-1");
976 sptr<MockRemoteObject> obj = new MockRemoteObject();
977 EXPECT_NE(obj, nullptr);
978 auto proxy = std::make_shared<PrintServiceProxy>(obj);
979 EXPECT_NE(proxy, nullptr);
980 auto service = std::make_shared<MockPrintService>();
981 EXPECT_NE(service, nullptr);
982 EXPECT_CALL(*service, UpdatePrinterInSystem(_)).Times(Exactly(1)).WillOnce(
__anona70dbd583a02(const PrinterInfo &printerInfo) 983 [&testInfo1](const PrinterInfo &printerInfo) {
984 EXPECT_EQ(testInfo1.GetOption(), printerInfo.GetOption());
985 return E_PRINT_NONE;
986 });
987 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
988 ON_CALL(*obj, SendRequest)
__anona70dbd583b02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 989 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
990 service->OnRemoteRequest(code, data, reply, option);
991 return E_PRINT_NONE;
992 });
993 proxy->UpdatePrinterInSystem(testInfo1);
994 }
995
996 } // namespace Print
997 } // namespace OHOS