1 /*
2 * Copyright (c) 2024 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 #define private public
18 #include "print_cups_client.h"
19 #undef private
20 #include "print_constant.h"
21 #include "print_log.h"
22 #include "mock/mock_print_cups_wrapper.h"
23 #include "print_json_util.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Print {
30 static const std::string PRINTER_STATE_NONE = "none";
31 static const std::string PRINTER_STATE_MEDIA_EMPTY = "media-empty";
32 static const std::string PRINTER_STATE_MEDIA_JAM = "media-jam";
33 static const std::string PRINTER_STATE_PAUSED = "paused";
34 static const std::string PRINTER_STATE_TONER_LOW = "toner-low";
35 static const std::string PRINTER_STATE_TONER_EMPTY = "toner-empty";
36 static const std::string PRINTER_STATE_DOOR_EMPTY = "door-open";
37 static const std::string PRINTER_STATE_MEDIA_NEEDED = "media-needed";
38 static const std::string PRINTER_STATE_MARKER_LOW = "marker-supply-low";
39 static const std::string PRINTER_STATE_MARKER_EMPTY = "marker-supply-empty";
40 static const std::string PRINTER_STATE_INK_EMPTY = "marker-ink-almost-empty";
41 static const std::string PRINTER_STATE_COVER_OPEN = "cover-open";
42 static const std::string PRINTER_STATE_OTHER = "other";
43 static const std::string PRINTER_STATE_OFFLINE = "offline";
44
45 using MockTestFunc = std::function<void(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock)>;
46
47 class PrintCupsWrapperTest : public testing::Test {
48 public:
49 static void SetUpTestCase(void);
50 static void TearDownTestCase(void);
51 void SetUp();
52 void TearDown();
53 void DoMockTest(MockTestFunc func);
54 };
55
SetUpTestCase(void)56 void PrintCupsWrapperTest::SetUpTestCase(void)
57 {}
58
TearDownTestCase(void)59 void PrintCupsWrapperTest::TearDownTestCase(void)
60 {}
61
SetUp(void)62 void PrintCupsWrapperTest::SetUp(void)
63 {
64 static int32_t testNo = 0;
65 PRINT_HILOGI("PrintCupsWrapperTest_%{public}d", ++testNo);
66 }
67
TearDown(void)68 void PrintCupsWrapperTest::TearDown(void)
69 {}
70
DoMockTest(MockTestFunc func)71 void PrintCupsWrapperTest::DoMockTest(MockTestFunc func)
72 {
73 if (func == nullptr) {
74 PRINT_HILOGE("test func is null");
75 return;
76 }
77 PrintCupsClient printCupsClient;
78 if (printCupsClient.printAbility_ != nullptr) {
79 delete printCupsClient.printAbility_;
80 printCupsClient.printAbility_ = nullptr;
81 }
82 auto mock = new (std::nothrow) MockPrintCupsWrapper();
83 if (mock == nullptr) {
84 PRINT_HILOGE("mock is null");
85 return;
86 }
87 printCupsClient.printAbility_ = mock;
88 func(printCupsClient, *mock);
89 }
90
91 /**
92 * @tc.name: PrintCupsWrapperTest_0001
93 * @tc.desc: QueryPrinterAttrList
94 * @tc.type: FUNC
95 * @tc.require:
96 */
97 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0001, TestSize.Level1)
98 {
99 PrintCupsClient printCupsClient;
100 if (printCupsClient.printAbility_ != nullptr) {
101 delete printCupsClient.printAbility_;
102 printCupsClient.printAbility_ = nullptr;
103 }
104 std::string printerName = "testPrinterName";
105 std::string printUri;
106 std::string printerId;
107 std::vector<std::string> keyList;
108 std::vector<std::string> valueList;
109 EXPECT_EQ(printCupsClient.QueryPrinterAttrList(printerName, keyList, valueList), E_PRINT_SERVER_FAILURE);
110 printCupsClient.QueryPPDInformation(printerId.c_str(), valueList);
111 EXPECT_EQ(printCupsClient.DeleteCupsPrinter(printerName.c_str()), E_PRINT_SERVER_FAILURE);
112 PrinterCapability printerCap;
113 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityByUri(printUri, printerId, printerCap), E_PRINT_SERVER_FAILURE);
114 EXPECT_EQ(printCupsClient.SetDefaultPrinter(printerName.c_str()), E_PRINT_SERVER_FAILURE);
115 printCupsClient.QueryJobState(nullptr, nullptr);
116 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityFromPPD(printerName, printerCap), E_PRINT_SERVER_FAILURE);
117 }
118
119 /**
120 * @tc.name: PrintCupsWrapperTest_0002
121 * @tc.desc: QueryPrinterAttrList
122 * @tc.type: FUNC
123 * @tc.require:
124 */
125 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0002, TestSize.Level1)
126 {
__anon2539b1810102(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 127 MockTestFunc testFunc = [this](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
128 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(nullptr));
129 std::string printerName = "testPrinterName";
130 std::vector<std::string> keyList = {"key1", "key2"};
131 std::vector<std::string> valueList;
132 EXPECT_EQ(printCupsClient.QueryPrinterAttrList(printerName, keyList, valueList), E_PRINT_SERVER_FAILURE);
133 };
134 DoMockTest(testFunc);
135 }
136
137 /**
138 * @tc.name: PrintCupsWrapperTest_0003
139 * @tc.desc: QueryPrinterAttrList
140 * @tc.type: FUNC
141 * @tc.require:
142 */
143 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0003, TestSize.Level1)
144 {
145 cups_dest_t cupsDests = {0};
__anon2539b1810202(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 146 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
147 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(&cupsDests));
148 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
149 std::string printerName = "testPrinterName";
150 std::vector<std::string> keyList = {"key1", "key2"};
151 std::vector<std::string> valueList;
152 EXPECT_EQ(printCupsClient.QueryPrinterAttrList(printerName, keyList, valueList), E_PRINT_NONE);
153 };
154 DoMockTest(testFunc);
155 }
156
157 /**
158 * @tc.name: PrintCupsWrapperTest_0005
159 * @tc.desc: QueryJobState
160 * @tc.type: FUNC
161 * @tc.require:
162 */
163 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0005, TestSize.Level1)
164 {
__anon2539b1810302(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 165 MockTestFunc testFunc = [this](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
166 auto param = std::make_shared<JobMonitorParam>(nullptr, "", 0, "", "", "", nullptr);
167 JobStatus jobStatus = {0};
168 printCupsClient.QueryJobState(CUPS_HTTP_DEFAULT, nullptr);
169 printCupsClient.QueryJobState(CUPS_HTTP_DEFAULT, param);
170 printCupsClient.QueryJobState(CUPS_HTTP_DEFAULT, param);
171 EXPECT_EQ(jobStatus.job_state, 0);
172 EXPECT_EQ(printCupsClient.CheckPrinterOnline(nullptr, 1), false);
173 EXPECT_EQ(printCupsClient.CheckPrinterOnline(param, 1), false);
174 };
175 DoMockTest(testFunc);
176 }
177
178 /**
179 * @tc.name: PrintCupsWrapperTest_0010
180 * @tc.desc: QueryPrinterInfoByPrinterId
181 * @tc.type: FUNC
182 * @tc.require:
183 */
184 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0010, TestSize.Level1)
185 {
186 PrintCupsClient printCupsClient;
187 if (printCupsClient.printAbility_ != nullptr) {
188 delete printCupsClient.printAbility_;
189 printCupsClient.printAbility_ = nullptr;
190 }
191 std::string printerId = "testPrinterId";
192 PrinterInfo info;
193 EXPECT_EQ(printCupsClient.QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_SERVER_FAILURE);
194 }
195
196 /**
197 * @tc.name: PrintCupsWrapperTest_0011
198 * @tc.desc: QueryPrinterInfoByPrinterId
199 * @tc.type: FUNC
200 * @tc.require:
201 */
202 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0011, TestSize.Level1)
203 {
__anon2539b1810402(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 204 MockTestFunc testFunc = [this](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
205 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(nullptr));
206 std::string printerId = "testPrinterId";
207 PrinterInfo info;
208 EXPECT_EQ(printCupsClient.QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_SERVER_FAILURE);
209 };
210 DoMockTest(testFunc);
211 }
212
213 /**
214 * @tc.name: PrintCupsWrapperTest_0012
215 * @tc.desc: QueryPrinterInfoByPrinterId
216 * @tc.type: FUNC
217 * @tc.require:
218 */
219 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0012, TestSize.Level1)
220 {
221 cups_dest_t cupsDests = {0};
__anon2539b1810502(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 222 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
223 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(&cupsDests));
224 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
225 std::string printerId = "testPrinterId";
226 PrinterInfo info;
227 EXPECT_EQ(printCupsClient.QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_NONE);
228 };
229 DoMockTest(testFunc);
230 }
231
232 /**
233 * @tc.name: PrintCupsWrapperTest_0013
234 * @tc.desc: QueryPrinterInfoByPrinterId
235 * @tc.type: FUNC
236 * @tc.require:
237 */
238 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0013, TestSize.Level1)
239 {
240 cups_dest_t cupsDests = {0};
__anon2539b1810602(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 241 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
242 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(&cupsDests));
243 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
244 std::string printerId = "testPrinterId";
245 PrinterInfo info;
246 std::string option = "test option";
247 info.SetOption(option);
248 EXPECT_EQ(printCupsClient.QueryPrinterInfoByPrinterId(printerId, info), E_PRINT_INVALID_PARAMETER);
249 };
250 DoMockTest(testFunc);
251 }
252
253 /**
254 * @tc.name: PrintCupsWrapperTest_0014
255 * @tc.desc: QueryPrinterInfoByPrinterId
256 * @tc.type: FUNC
257 * @tc.require:
258 */
259 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0014, TestSize.Level1)
260 {
261 cups_dest_t cupsDests = {0};
__anon2539b1810702(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 262 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
263 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(&cupsDests));
264 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
265 std::string printerId = "testPrinterId";
266 PrinterInfo info;
267 Json::Value option;
268 option["printerName"] = "name";
269 option["printerUri"] = "uri";
270 info.SetOption(PrintJsonUtil::WriteString(option));
271 printCupsClient.QueryPrinterInfoByPrinterId(printerId, info);
272 };
273 DoMockTest(testFunc);
274 }
275
276 /**
277 * @tc.name: PrintCupsWrapperTest_0015
278 * @tc.desc: QueryPrinterInfoByPrinterId
279 * @tc.type: FUNC
280 * @tc.require:
281 */
282 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0015, TestSize.Level1)
283 {
284 cups_dest_t cupsDests = {0};
__anon2539b1810802(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 285 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
286 EXPECT_CALL(mock, GetNamedDest(_, _, _)).Times(1).WillOnce(Return(&cupsDests));
287 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
288 std::string printerId = "testPrinterId";
289 PrinterInfo info;
290 Json::Value option;
291 option["printerName"] = "name";
292 info.SetOption(PrintJsonUtil::WriteString(option));
293 printCupsClient.QueryPrinterInfoByPrinterId(printerId, info);
294 };
295 DoMockTest(testFunc);
296 }
297
298 /**
299 * @tc.name: PrintCupsWrapperTest_0020
300 * @tc.desc: CheckPrinterMakeModel
301 * @tc.type: FUNC
302 * @tc.require:
303 */
304 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0020, TestSize.Level1)
305 {
306 PrintCupsClient printCupsClient;
307 if (printCupsClient.printAbility_ != nullptr) {
308 delete printCupsClient.printAbility_;
309 printCupsClient.printAbility_ = nullptr;
310 }
311 JobParameters jobParams;
312 EXPECT_EQ(printCupsClient.CheckPrinterMakeModel(&jobParams), false);
313 printCupsClient.DumpJobParameters(nullptr);
314 }
315
316 /**
317 * @tc.name: PrintCupsWrapperTest_0021
318 * @tc.desc: CheckPrinterMakeModel
319 * @tc.type: FUNC
320 * @tc.require:
321 */
322 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0021, TestSize.Level1)
323 {
__anon2539b1810902(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 324 MockTestFunc testFunc = [this](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
325 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillRepeatedly(Return(nullptr));
326 JobParameters jobParams;
327 EXPECT_EQ(printCupsClient.CheckPrinterMakeModel(&jobParams), false);
328 };
329 DoMockTest(testFunc);
330 }
331
332 /**
333 * @tc.name: PrintCupsWrapperTest_0022
334 * @tc.desc: CheckPrinterMakeModel
335 * @tc.type: FUNC
336 * @tc.require:
337 */
338 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0022, TestSize.Level1)
339 {
340 cups_dest_t cupsDests = {0};
__anon2539b1810a02(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 341 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
342 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillRepeatedly(Return(&cupsDests));
343 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
344 JobParameters jobParams;
345 EXPECT_EQ(printCupsClient.CheckPrinterMakeModel(&jobParams), false);
346 };
347 DoMockTest(testFunc);
348 }
349
350 /**
351 * @tc.name: PrintCupsWrapperTest_0030
352 * @tc.desc: CheckPrinterMakeModel
353 * @tc.type: FUNC
354 * @tc.require:
355 */
356 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0030, TestSize.Level1)
357 {
358 PrintCupsClient printCupsClient;
359 if (printCupsClient.printAbility_ != nullptr) {
360 delete printCupsClient.printAbility_;
361 printCupsClient.printAbility_ = nullptr;
362 }
363 std::string name = "testName";
364 std::string uri = "testUri";
365 std::string ppd = "testPpd";
366 EXPECT_EQ(printCupsClient.IsPrinterExist(name.c_str(), uri.c_str(), ppd.c_str()), false);
367 }
368
369 /**
370 * @tc.name: PrintCupsWrapperTest_0031
371 * @tc.desc: CheckPrinterMakeModel
372 * @tc.type: FUNC
373 * @tc.require:
374 */
375 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0031, TestSize.Level1)
376 {
__anon2539b1810b02(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 377 MockTestFunc testFunc = [this](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
378 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillRepeatedly(Return(nullptr));
379 std::string name = "testName";
380 std::string uri = "testUri";
381 std::string ppd = "testPpd";
382 EXPECT_EQ(printCupsClient.IsPrinterExist(name.c_str(), uri.c_str(), ppd.c_str()), false);
383 };
384 DoMockTest(testFunc);
385 }
386
387 /**
388 * @tc.name: PrintCupsWrapperTest_0032
389 * @tc.desc: CheckPrinterMakeModel
390 * @tc.type: FUNC
391 * @tc.require:
392 */
393 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0032, TestSize.Level1)
394 {
395 cups_dest_t cupsDests = {0};
__anon2539b1810c02(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 396 MockTestFunc testFunc = [this, &cupsDests](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
397 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillRepeatedly(Return(&cupsDests));
398 EXPECT_CALL(mock, FreeDests(_, _)).WillRepeatedly(Return());
399 std::string name = "testName";
400 std::string uri = "testUri";
401 std::string ppd = "testPpd";
402 EXPECT_EQ(printCupsClient.IsPrinterExist(name.c_str(), uri.c_str(), ppd.c_str()), false);
403 };
404 DoMockTest(testFunc);
405 }
406
407 /**
408 * @tc.name: PrintCupsWrapperTest_0080
409 * @tc.desc: QueryPPDInformation
410 * @tc.type: FUNC
411 * @tc.require:
412 */
413 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0080, TestSize.Level1)
414 {
415 OHOS::Print::PrintCupsClient printCupsClient;
416 int32_t ret = printCupsClient.InitCupsResources();
417 EXPECT_EQ(ret, E_PRINT_NONE);
418 std::vector<std::string> ppds;
419 printCupsClient.QueryPPDInformation(nullptr, ppds);
420 printCupsClient.ParsePPDInfo(nullptr, nullptr, nullptr, ppds);
421 printCupsClient.StopCupsdService();
422 }
423
424 /**
425 * @tc.name: PrintCupsWrapperTest_0081
426 * @tc.desc: QueryPPDInformation
427 * @tc.type: FUNC
428 * @tc.require:
429 */
430 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0081, TestSize.Level1)
431 {
432 OHOS::Print::PrintCupsClient printCupsClient;
433 int32_t ret = printCupsClient.InitCupsResources();
434 EXPECT_EQ(ret, E_PRINT_NONE);
435 std::string makeModel = "testmodel";
436 std::vector<std::string> ppds;
437 printCupsClient.QueryPPDInformation(makeModel.c_str(), ppds);
438 printCupsClient.StopCupsdService();
439 }
440
441 /**
442 * @tc.name: PrintCupsWrapperTest_0082
443 * @tc.desc: ParsePPDInfo
444 * @tc.type: FUNC
445 * @tc.require:
446 */
447 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0082, TestSize.Level1)
448 {
449 OHOS::Print::PrintCupsClient printCupsClient;
450 std::vector<std::string> ppds;
451 ipp_t* response = ippNew();
452 EXPECT_NE(response, nullptr);
453 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "en_us");
454 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "ppd-make-and-model", nullptr, "testmodel");
455 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", nullptr, "testppd");
456 printCupsClient.ParsePPDInfo(response, nullptr, nullptr, ppds);
457 printCupsClient.ParsePPDInfo(response, "testmodel", nullptr, ppds);
458 printCupsClient.ParsePPDInfo(response, "testmodel", "testppd", ppds);
459 ippDelete(response);
460 }
461
462 /**
463 * @tc.name: PrintCupsWrapperTest_0083
464 * @tc.desc: AddPrinterToCups
465 * @tc.type: FUNC
466 * @tc.require:
467 */
468 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0083, TestSize.Level1)
469 {
470 OHOS::Print::PrintCupsClient printCupsClient;
471 int32_t ret = printCupsClient.InitCupsResources();
472 EXPECT_EQ(ret, E_PRINT_NONE);
473 std::string uri = "testuri";
474 std::string name = "testname";
475 std::string makeModel = "testmodel";
476 printCupsClient.AddPrinterToCups(uri, name, makeModel);
477 printCupsClient.DeleteCupsPrinter(name.c_str());
478 printCupsClient.StopCupsdService();
479 }
480
481 /**
482 * @tc.name: PrintCupsWrapperTest_0085
483 * @tc.desc: GetIpAddress
484 * @tc.type: FUNC
485 * @tc.require:
486 */
487 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0085, TestSize.Level1)
488 {
489 OHOS::Print::PrintCupsClient printCupsClient;
490 unsigned int num = 0x12345678;
491 std::string ip = printCupsClient.GetIpAddress(num);
492 EXPECT_STREQ(ip.c_str(), "18.52.86.120");
493 }
494
495 /**
496 * @tc.name: PrintCupsWrapperTest_0086
497 * @tc.desc: UpdateBorderlessJobParameter
498 * @tc.type: FUNC
499 * @tc.require:
500 */
501 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0086, TestSize.Level1)
502 {
503 OHOS::Print::PrintCupsClient printCupsClient;
504 Json::Value optionJson;
505 JobParameters *jobParams = nullptr;
506 printCupsClient.UpdateBorderlessJobParameter(optionJson, jobParams);
507 jobParams = new JobParameters();
508 printCupsClient.UpdateBorderlessJobParameter(optionJson, jobParams);
509 optionJson["isBorderless"] = false;
510 printCupsClient.UpdateBorderlessJobParameter(optionJson, jobParams);
511 EXPECT_EQ(jobParams->borderless, 0);
512
513 optionJson["isBorderless"] = true;
514 printCupsClient.UpdateBorderlessJobParameter(optionJson, jobParams);
515 EXPECT_EQ(jobParams->borderless, 1);
516
517 optionJson["documentCategory"] = 1;
518 printCupsClient.UpdateBorderlessJobParameter(optionJson, jobParams);
519 EXPECT_EQ(jobParams->borderless, optionJson["documentCategory"].asInt());
520 delete jobParams;
521 }
522
523 /**
524 * @tc.name: PrintCupsWrapperTest_0087
525 * @tc.desc: GetNextJob
526 * @tc.type: FUNC
527 * @tc.require:
528 */
529 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0087, TestSize.Level1)
530 {
531 PrintCupsClient printCupsClient;
532 EXPECT_EQ(printCupsClient.GetNextJob(), nullptr);
533 JobParameters *jobParams1 = new JobParameters();
534 JobParameters *jobParams2 = new JobParameters();
535 printCupsClient.jobQueue_.push_back(jobParams1);
536 printCupsClient.jobQueue_.push_back(jobParams2);
537 EXPECT_EQ(printCupsClient.GetNextJob(), jobParams1);
538 EXPECT_EQ(printCupsClient.GetNextJob(), nullptr);
539 }
540
541 /**
542 * @tc.name: PrintCupsWrapperTest_0088
543 * @tc.desc: CopyDirectory
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0088, TestSize.Level1)
548 {
549 PrintCupsClient printCupsClient;
550 std::string srcDir = "/system/bin/cups/";
551 std::string dstDir1 = "/data/local/tmp/cups_cp";
552 std::string dstDir2 = "/data/local/tmp/cups_sm";
553 printCupsClient.CopyDirectory(nullptr, dstDir1.c_str());
554 printCupsClient.SymlinkDirectory(nullptr, dstDir2.c_str());
555 printCupsClient.CopyDirectory(srcDir.c_str(), dstDir1.c_str());
556 printCupsClient.SymlinkDirectory(srcDir.c_str(), dstDir2.c_str());
557 mode_t permissions = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH;
558 EXPECT_EQ(printCupsClient.ChangeFilterPermission(dstDir1, permissions), true);
559 }
560
561 /**
562 * @tc.name: PrintCupsWrapperTest_0089
563 * @tc.desc: QueryPrinterCapabilityFromPpd
564 * @tc.type: FUNC
565 * @tc.require:
566 */
567 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0089, TestSize.Level1)
568 {
569 cups_dest_t cupsDests = {0};
570 cups_dinfo_t cupsDinfo = {0};
571 MockTestFunc testFunc =
__anon2539b1810d02(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 572 [this, &cupsDests, &cupsDinfo](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
573 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillRepeatedly(Return(&cupsDests));
574 EXPECT_CALL(mock, CopyDestInfo(_, _)).WillRepeatedly(Return(&cupsDinfo));
575 std::string printerName = "testName";
576 PrinterCapability printerCaps;
577 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityFromPPD(printerName, printerCaps), E_PRINT_NONE);
578 };
579 DoMockTest(testFunc);
580 }
581
582 /**
583 * @tc.name: PrintCupsWrapperTest_0090
584 * @tc.desc: QueryPrinterCapabilityFromPpd
585 * @tc.type: FUNC
586 * @tc.require:
587 */
588 HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0090, TestSize.Level1)
589 {
590 cups_dest_t cupsDests = {0};
591 cups_dinfo_t cupsDinfo = {0};
592 MockTestFunc testFunc =
__anon2539b1810e02(PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) 593 [this, &cupsDests, &cupsDinfo](PrintCupsClient &printCupsClient, MockPrintCupsWrapper &mock) {
594 EXPECT_CALL(mock, GetNamedDest(_, _, _)).WillOnce(Return(nullptr)).WillRepeatedly(Return(&cupsDests));
595 EXPECT_CALL(mock, CopyDestInfo(_, _)).WillOnce(Return(nullptr)).WillRepeatedly(Return(&cupsDinfo));
596 std::string printerName = "testName";
597 PrinterCapability printerCaps;
598 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityFromPPD(printerName, printerCaps), E_PRINT_SERVER_FAILURE);
599 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityFromPPD(printerName, printerCaps), E_PRINT_SERVER_FAILURE);
600 EXPECT_EQ(printCupsClient.QueryPrinterCapabilityFromPPD(printerName, printerCaps), E_PRINT_NONE);
601 };
602 DoMockTest(testFunc);
603 }
604 } // namespace Print
605 } // namespace OHOS