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 #include "print_cups_attribute.h"
18 #include "print_json_util.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace {
24 const char *const ATTR_TEST_ALL[] = {"all"};
25 const size_t ATTR_TEST_SIDES_COUNT = 3;
26 const char *const ATTR_TEST_SIDES_ARRAY[ATTR_TEST_SIDES_COUNT] = {
27 "one-sided", "two-sided-long-edge", "two-sided-short-edge"};
28
29 const size_t ATTR_TEST_COLOR_MODE_COUNT = 2;
30 const char *const ATTR_TEST_COLOR_MODE_ARRAY[ATTR_TEST_COLOR_MODE_COUNT] = {"monochrome", "color"};
31
32 const size_t ATTR_TEST_PAGE_SIZE_COUNT = 4;
33 const char *const ATTR_TEST_PAGE_SIZE_ARRAY[ATTR_TEST_PAGE_SIZE_COUNT] = {
34 "iso_b3_353x500mm", "iso_a4_210x297mm", "na_letter_8.5x11in", "om_card_54x86mm"};
35
36 const size_t ATTR_TEST_QUALITY_COUNT = 3;
37 const int ATTR_TEST_QUALITY_ARRAY[ATTR_TEST_QUALITY_COUNT] = {IPP_QUALITY_DRAFT, IPP_QUALITY_NORMAL, IPP_QUALITY_HIGH};
38 const int ATTR_TEST_MAX_COPIES = 99;
39 const int ATTR_TEST_RESOLUTION_SMALL = 250; // need change
40 const int ATTR_TEST_RESOLUTION_DEFAULT = 600;
41 const int ATTR_TEST_RESULUTION_SMALL_DPCM = 100;
42
43 const int ATTR_TEST_PAPER_LEFT = 100;
44 const int ATTR_TEST_PAPER_RIGHT = 200;
45 const int ATTR_TEST_PAPER_TOP = 300;
46 const int ATTR_TEST_PAPER_BOTTOM = 400;
47
48 const int ATTR_TEST_ORIENTATION_COUNT = 3;
49 const int ATTR_TEST_ORIENTATION_ARRAY[ATTR_TEST_ORIENTATION_COUNT] = {
50 IPP_ORIENT_PORTRAIT, IPP_ORIENT_LANDSCAPE, IPP_ORIENT_REVERSE_PORTRAIT};
51
52 const int ATTR_TEST_SOURCE_COUNT = 2;
53 const char *const ATTR_TEST_SOURCE_ARRAY[ATTR_TEST_SOURCE_COUNT] = {"main source", "front slot"};
54
55 const int ATTR_TEST_DOCUMENT_HANDLING_COUNT = 2;
56 const char *const ATTR_TEST_DOCUMENT_HANDLING_ARRAY[] = {"separate-uncollated", "multi-collated"};
57
58 const int ATTR_TEST_MEDIA_TYPE_COUNT = 3;
59 const char *const ATTR_TEST_MEDIA_TYPE_ARRAY[ATTR_TEST_MEDIA_TYPE_COUNT] = {"envelope", "stationery", "transparency"};
60
TestAttrCount(const std::string & jsonString,int count)61 void TestAttrCount(const std::string &jsonString, int count)
62 {
63 Json::Value jsonArrayObject;
64 if (OHOS::Print::PrintJsonUtil::Parse(jsonString, jsonArrayObject)) {
65 return;
66 }
67 if (jsonArrayObject.isArray()) {
68 EXPECT_EQ(jsonArrayObject.size(), count);
69 }
70 }
71 } // namespace
72
73 namespace OHOS::Print {
74 using PreAttrTestFunc = std::function<void(ipp_t *)>;
75 using PostResponseTestFunc = std::function<void(ipp_t *)>;
76 using PostAttrTestFunc = std::function<void(PrinterCapability &)>;
77 class PrintCupsAttributeTest : public testing::Test {
78 public:
79 static void SetUpTestCase(void);
80 static void TearDownTestCase(void);
81 void SetUp();
82 void TearDown();
83 void DoTestResponse(PreAttrTestFunc preFunc, PostResponseTestFunc postFunc);
84 void DoTest(PreAttrTestFunc preFunc, PostAttrTestFunc postFunc);
85 };
86
SetUpTestCase(void)87 void PrintCupsAttributeTest::SetUpTestCase(void)
88 {}
89
TearDownTestCase(void)90 void PrintCupsAttributeTest::TearDownTestCase(void)
91 {}
92
SetUp(void)93 void PrintCupsAttributeTest::SetUp(void)
94 {}
95
TearDown(void)96 void PrintCupsAttributeTest::TearDown(void)
97 {}
98
DoTestResponse(PreAttrTestFunc preFunc,PostResponseTestFunc postFunc)99 void PrintCupsAttributeTest::DoTestResponse(PreAttrTestFunc preFunc, PostResponseTestFunc postFunc)
100 {
101 if (preFunc == nullptr || postFunc == nullptr) {
102 return;
103 }
104 ipp_t *request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
105 if (request == nullptr) {
106 return;
107 }
108 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", nullptr, "printer-uri");
109 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", nullptr, "user");
110 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", 1, nullptr, ATTR_TEST_ALL);
111 ipp_t *response = ippNewResponse(request);
112 ippDelete(request);
113 if (response == nullptr) {
114 return;
115 }
116 preFunc(response);
117 postFunc(response);
118 ippDelete(response);
119 }
120
DoTest(PreAttrTestFunc preFunc,PostAttrTestFunc postFunc)121 void PrintCupsAttributeTest::DoTest(PreAttrTestFunc preFunc, PostAttrTestFunc postFunc)
122 {
123 PostResponseTestFunc postResponseFunc = [this, postFunc](ipp_t *response) {
124 PrinterCapability printerCaps;
125 ParsePrinterAttributesFromIPP(response, printerCaps);
126 if (postFunc != nullptr) {
127 postFunc(printerCaps);
128 }
129 };
130 DoTestResponse(preFunc, postResponseFunc);
131 }
132
133 /**
134 * @tc.name: PrintCupsAttributeTest_0001
135 * @tc.desc: printer idle state test
136 */
137 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0001_NeedRename, TestSize.Level1)
138 {
__anon3a3e489b0302(ipp_t *response) 139 PreAttrTestFunc preFunc = [this](ipp_t *response) {
140 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_IDLE);
141 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", nullptr, "Printer info test");
142 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "Printer location test");
143 };
__anon3a3e489b0402(PrinterCapability &printerCaps) 144 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
145 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "idle");
146 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "Printer location test");
147 };
148 DoTest(preFunc, postFunc);
149 }
150
151 /**
152 * @tc.name: PrintCupsAttributeTest_0002
153 * @tc.desc: printer processing state test
154 */
155 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0002_NeedRename, TestSize.Level1)
156 {
__anon3a3e489b0502(ipp_t *response) 157 PreAttrTestFunc preFunc = [this](ipp_t *response) {
158 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_PROCESSING);
159 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", nullptr, "");
160 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "");
161 };
__anon3a3e489b0602(PrinterCapability &printerCaps) 162 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
163 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "processing");
164 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
165 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
166 };
167 DoTest(preFunc, postFunc);
168 }
169
170 /**
171 * @tc.name: PrintCupsAttributeTest_0003
172 * @tc.desc: printer stopped state test
173 */
174 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0003_NeedRename, TestSize.Level1)
175 {
__anon3a3e489b0702(ipp_t *response) 176 PreAttrTestFunc preFunc = [this](ipp_t *response) {
177 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_STOPPED);
178 };
__anon3a3e489b0802(PrinterCapability &printerCaps) 179 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
180 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "stopped");
181 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
182 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
183 };
184 DoTest(preFunc, postFunc);
185 }
186
187 /**
188 * @tc.name: PrintCupsAttributeTest_0004
189 * @tc.desc: printer empty state test
190 */
191 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0004_NeedRename, TestSize.Level1)
192 {
__anon3a3e489b0902(ipp_t *response) 193 PreAttrTestFunc preFunc = [this](ipp_t *response) {};
__anon3a3e489b0a02(PrinterCapability &printerCaps) 194 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
195 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "");
196 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
197 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
198 };
199 DoTest(preFunc, postFunc);
200 }
201
202 /**
203 * @tc.name: PrintCupsAttributeTest_0005
204 * @tc.desc: printer sides test
205 */
206 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0005_NeedRename, TestSize.Level1)
207 {
__anon3a3e489b0b02(ipp_t *response) 208 PreAttrTestFunc preFunc = [this](ipp_t *response) {
209 ippAddStrings(response,
210 IPP_TAG_PRINTER,
211 IPP_TAG_KEYWORD,
212 "sides-supported",
213 ATTR_TEST_SIDES_COUNT,
214 nullptr,
215 ATTR_TEST_SIDES_ARRAY);
216 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default", nullptr, ATTR_TEST_SIDES_ARRAY[0]);
217 };
__anon3a3e489b0c02(PrinterCapability &printerCaps) 218 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
219 std::string sideString = printerCaps.GetPrinterAttrValue("sides-supported");
220 TestAttrCount(sideString, ATTR_TEST_SIDES_COUNT);
221 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("sides-default"), "0");
222 };
223 DoTest(preFunc, postFunc);
224 }
225
226 /**
227 * @tc.name: PrintCupsAttributeTest_0006
228 * @tc.desc: printer sides test
229 */
230 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0006_NeedRename, TestSize.Level1)
231 {
__anon3a3e489b0d02(ipp_t *response) 232 PreAttrTestFunc preFunc = [this](ipp_t *response) {
233 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default", nullptr, ATTR_TEST_SIDES_ARRAY[1]);
234 };
__anon3a3e489b0e02(PrinterCapability &printerCaps) 235 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
236 std::string sideString = printerCaps.GetPrinterAttrValue("sides-supported");
237 TestAttrCount(sideString, 0);
238 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("sides-default"), "1");
239 };
240 DoTest(preFunc, postFunc);
241 }
242
243 /**
244 * @tc.name: PrintCupsAttributeTest_0007
245 * @tc.desc: printer color mode test
246 */
247 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0007_NeedRename, TestSize.Level1)
248 {
__anon3a3e489b0f02(ipp_t *response) 249 PreAttrTestFunc preFunc = [this](ipp_t *response) {
250 ippAddStrings(response,
251 IPP_TAG_PRINTER,
252 IPP_TAG_KEYWORD,
253 "print-color-mode-supported",
254 ATTR_TEST_COLOR_MODE_COUNT,
255 nullptr,
256 ATTR_TEST_COLOR_MODE_ARRAY);
257 ippAddString(response,
258 IPP_TAG_PRINTER,
259 IPP_TAG_KEYWORD,
260 "print-color-mode-default",
261 nullptr,
262 ATTR_TEST_COLOR_MODE_ARRAY[0]);
263 };
__anon3a3e489b1002(PrinterCapability &printerCaps) 264 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
265 std::string colorModeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
266 TestAttrCount(colorModeString, ATTR_TEST_COLOR_MODE_COUNT);
267 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultColorMode"), "0");
268 };
269 DoTest(preFunc, postFunc);
270 }
271
272 /**
273 * @tc.name: PrintCupsAttributeTest_0008
274 * @tc.desc: printer color mode test
275 */
276 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0008_NeedRename, TestSize.Level1)
277 {
__anon3a3e489b1102(ipp_t *response) 278 PreAttrTestFunc preFunc = [this](ipp_t *response) {
279 ippAddString(response,
280 IPP_TAG_PRINTER,
281 IPP_TAG_KEYWORD,
282 "print-color-mode-default",
283 nullptr,
284 ATTR_TEST_COLOR_MODE_ARRAY[1]);
285 };
__anon3a3e489b1202(PrinterCapability &printerCaps) 286 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
287 std::string colorModeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
288 TestAttrCount(colorModeString, 0);
289 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultColorMode"), "1");
290 };
291 DoTest(preFunc, postFunc);
292 }
293
294 /**
295 * @tc.name: PrintCupsAttributeTest_0009
296 * @tc.desc: printer page size test
297 */
298 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0009_NeedRename, TestSize.Level1)
299 {
__anon3a3e489b1302(ipp_t *response) 300 PreAttrTestFunc preFunc = [this](ipp_t *response) {
301 ippAddStrings(response,
302 IPP_TAG_PRINTER,
303 IPP_TAG_KEYWORD,
304 "media-supported",
305 ATTR_TEST_PAGE_SIZE_COUNT,
306 nullptr,
307 ATTR_TEST_PAGE_SIZE_ARRAY);
308 ippAddString(
309 response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default", nullptr, ATTR_TEST_PAGE_SIZE_ARRAY[0]);
310 };
__anon3a3e489b1402(PrinterCapability &printerCaps) 311 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
312 std::vector<PrintPageSize> pageSizeList;
313 printerCaps.GetSupportedPageSize(pageSizeList);
314 EXPECT_EQ(pageSizeList.size(), ATTR_TEST_PAGE_SIZE_COUNT);
315 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultPageSizeId"), "ISO_B3");
316 };
317 DoTest(preFunc, postFunc);
318 }
319
320 /**
321 * @tc.name: PrintCupsAttributeTest_0010
322 * @tc.desc: printer page size test
323 */
324 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0010_NeedRename, TestSize.Level1)
325 {
__anon3a3e489b1502(ipp_t *response) 326 PreAttrTestFunc preFunc = [this](ipp_t *response) {
327 ippAddString(response,
328 IPP_TAG_PRINTER,
329 IPP_TAG_KEYWORD,
330 "print-color-mode-default",
331 nullptr,
332 ATTR_TEST_COLOR_MODE_ARRAY[1]);
333 };
__anon3a3e489b1602(PrinterCapability &printerCaps) 334 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
335 std::string pageSizeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
336 TestAttrCount(pageSizeString, 0);
337 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultPageSizeId"), "");
338 };
339 DoTest(preFunc, postFunc);
340 }
341
342 /**
343 * @tc.name: PrintCupsAttributeTest_0011
344 * @tc.desc: printer quality / copies test
345 */
346 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0011_NeedRename, TestSize.Level1)
347 {
__anon3a3e489b1702(ipp_t *response) 348 PreAttrTestFunc preFunc = [this](ipp_t *response) {
349 ippAddIntegers(response,
350 IPP_TAG_PRINTER,
351 IPP_TAG_ENUM,
352 "print-quality-supported",
353 ATTR_TEST_QUALITY_COUNT,
354 ATTR_TEST_QUALITY_ARRAY);
355 ippAddRange(response, IPP_TAG_PRINTER, "copies-supported", 1, ATTR_TEST_MAX_COPIES);
356 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", 1);
357 };
__anon3a3e489b1802(PrinterCapability &printerCaps) 358 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
359 std::string qualityString = printerCaps.GetPrinterAttrValue("print-quality-supported");
360 TestAttrCount(qualityString, ATTR_TEST_QUALITY_COUNT);
361 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-supported"), std::to_string(ATTR_TEST_MAX_COPIES).c_str());
362 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-default"), "1");
363 };
364 DoTest(preFunc, postFunc);
365 }
366
367 /**
368 * @tc.name: PrintCupsAttributeTest_0012
369 * @tc.desc: printer quality / copies test
370 */
371 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0012_NeedRename, TestSize.Level1)
372 {
__anon3a3e489b1902(ipp_t *response) 373 PreAttrTestFunc preFunc = [this](ipp_t *response) {};
__anon3a3e489b1a02(PrinterCapability &printerCaps) 374 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
375 std::string pageSizeString = printerCaps.GetPrinterAttrValue("print-quality-supported");
376 EXPECT_TRUE(pageSizeString.empty());
377 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-supported"), "");
378 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-default"), "");
379 };
380 DoTest(preFunc, postFunc);
381 }
382
383 /**
384 * @tc.name: PrintCupsAttributeTest_0013
385 * @tc.desc: printer resolution test
386 */
387 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0013_NeedRename, TestSize.Level1)
388 {
__anon3a3e489b1b02(ipp_t *response) 389 PreAttrTestFunc preFunc = [this](ipp_t *response) {
390 ippAddResolution(response,
391 IPP_TAG_PRINTER,
392 "printer-resolution-supported",
393 IPP_RES_PER_INCH,
394 ATTR_TEST_RESOLUTION_DEFAULT,
395 ATTR_TEST_RESOLUTION_DEFAULT);
396 ippAddResolution(response,
397 IPP_TAG_PRINTER,
398 "printer-resolution-default",
399 IPP_RES_PER_INCH,
400 ATTR_TEST_RESOLUTION_DEFAULT,
401 ATTR_TEST_RESOLUTION_DEFAULT);
402 };
__anon3a3e489b1c02(PrinterCapability &printerCaps) 403 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
404 std::string supportedResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-supported");
405 TestAttrCount(supportedResolutionString, 1);
406 std::string defaultResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-default");
407 std::istringstream iss(defaultResolutionString);
408 Json::Value defaultResolutionJson;
409 EXPECT_TRUE(OHOS::Print::PrintJsonUtil::ParseFromStream(iss, defaultResolutionJson));
410 EXPECT_TRUE(PrintJsonUtil::IsMember(defaultResolutionJson, "horizontalDpi"));
411 EXPECT_TRUE(PrintJsonUtil::IsMember(defaultResolutionJson, "verticalDpi"));
412 EXPECT_TRUE(defaultResolutionJson["horizontalDpi"].isInt());
413 EXPECT_TRUE(defaultResolutionJson["verticalDpi"].isInt());
414 EXPECT_EQ(defaultResolutionJson["horizontalDpi"], ATTR_TEST_RESOLUTION_DEFAULT);
415 EXPECT_EQ(defaultResolutionJson["verticalDpi"], ATTR_TEST_RESOLUTION_DEFAULT);
416 };
417 DoTest(preFunc, postFunc);
418 }
419
420 /**
421 * @tc.name: PrintCupsAttributeTest_0014
422 * @tc.desc: printer resolution test
423 */
424 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0014_NeedRename, TestSize.Level1)
425 {
__anon3a3e489b1d02(ipp_t *response) 426 PreAttrTestFunc preFunc = [this](ipp_t *response) {
427 ippAddResolution(response,
428 IPP_TAG_PRINTER,
429 "printer-resolution-default",
430 IPP_RES_PER_CM,
431 ATTR_TEST_RESULUTION_SMALL_DPCM,
432 ATTR_TEST_RESULUTION_SMALL_DPCM);
433 };
__anon3a3e489b1e02(PrinterCapability &printerCaps) 434 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
435 std::string supportedResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-supported");
436 EXPECT_TRUE(supportedResolutionString.empty());
437 std::string defaultResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-default");
438 std::istringstream iss(defaultResolutionString);
439 Json::Value defaultResolutionJson;
440 EXPECT_TRUE(OHOS::Print::PrintJsonUtil::ParseFromStream(iss, defaultResolutionJson));
441 EXPECT_TRUE(defaultResolutionJson.isMember("horizontalDpi"));
442 EXPECT_TRUE(defaultResolutionJson.isMember("verticalDpi"));
443 EXPECT_TRUE(defaultResolutionJson["horizontalDpi"].isInt());
444 EXPECT_TRUE(defaultResolutionJson["verticalDpi"].isInt());
445 EXPECT_EQ(defaultResolutionJson["horizontalDpi"], ATTR_TEST_RESOLUTION_SMALL);
446 EXPECT_EQ(defaultResolutionJson["verticalDpi"], ATTR_TEST_RESOLUTION_SMALL);
447 };
448 DoTest(preFunc, postFunc);
449 }
450
451 /**
452 * @tc.name: PrintCupsAttributeTest_0015
453 * @tc.desc: printer media test
454 */
455 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0015_NeedRename, TestSize.Level1)
456 {
__anon3a3e489b1f02(ipp_t *response) 457 PreAttrTestFunc preFunc = [this](ipp_t *response) {
458 auto mediaCol = ippNew();
459 if (mediaCol == nullptr) {
460 return;
461 }
462 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-bottom-margin", ATTR_TEST_PAPER_BOTTOM);
463 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-left-margin", ATTR_TEST_PAPER_LEFT);
464 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-right-margin", ATTR_TEST_PAPER_RIGHT);
465 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-top-margin", ATTR_TEST_PAPER_TOP);
466 ippAddBoolean(mediaCol, IPP_TAG_PRINTER, "duplex-supported", 1);
467 ippAddString(mediaCol, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source", nullptr, "Front Input Slot");
468 ippAddString(mediaCol, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type", nullptr, "stationery");
469 ippAddCollection(response, IPP_TAG_PRINTER, "media-col-default", mediaCol);
470 ippDelete(mediaCol);
471 };
__anon3a3e489b2002(PrinterCapability &printerCaps) 472 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
473 EXPECT_STREQ(
474 printerCaps.GetPrinterAttrValue("media-top-margin-default"), std::to_string(ATTR_TEST_PAPER_TOP).c_str());
475 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-bottom-margin-default"),
476 std::to_string(ATTR_TEST_PAPER_BOTTOM).c_str());
477 EXPECT_STREQ(
478 printerCaps.GetPrinterAttrValue("media-left-margin-default"), std::to_string(ATTR_TEST_PAPER_LEFT).c_str());
479 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-right-margin-default"),
480 std::to_string(ATTR_TEST_PAPER_RIGHT).c_str());
481 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-source-default"), "Front Input Slot");
482 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-type-default"), "stationery");
483 };
484 DoTest(preFunc, postFunc);
485 }
486
487 /**
488 * @tc.name: PrintCupsAttributeTest_0016
489 * @tc.desc: printer margin test
490 */
491 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0016_NeedRename, TestSize.Level1)
492 {
__anon3a3e489b2102(ipp_t *response) 493 PreAttrTestFunc preFunc = [this](ipp_t *response) {
494 ippAddInteger(
495 response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-bottom-margin-supported", ATTR_TEST_PAPER_BOTTOM);
496 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-left-margin-supported", ATTR_TEST_PAPER_LEFT);
497 ippAddInteger(
498 response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-right-margin-supported", ATTR_TEST_PAPER_RIGHT);
499 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-top-margin-supported", ATTR_TEST_PAPER_TOP);
500 };
__anon3a3e489b2202(PrinterCapability &printerCaps) 501 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
502 EXPECT_STREQ(
503 printerCaps.GetPrinterAttrValue("media-top-margin-supported"), std::to_string(ATTR_TEST_PAPER_TOP).c_str());
504 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-bottom-margin-supported"),
505 std::to_string(ATTR_TEST_PAPER_BOTTOM).c_str());
506 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-left-margin-supported"),
507 std::to_string(ATTR_TEST_PAPER_LEFT).c_str());
508 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-right-margin-supported"),
509 std::to_string(ATTR_TEST_PAPER_RIGHT).c_str());
510 };
511 DoTest(preFunc, postFunc);
512 }
513
514 /**
515 * @tc.name: PrintCupsAttributeTest_0017
516 * @tc.desc: printer orientation test
517 */
518 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0017_NeedRename, TestSize.Level1)
519 {
__anon3a3e489b2302(ipp_t *response) 520 PreAttrTestFunc preFunc = [this](ipp_t *response) {
521 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "orientation-requested-default", IPP_ORIENT_PORTRAIT);
522 ippAddIntegers(response,
523 IPP_TAG_PRINTER,
524 IPP_TAG_ENUM,
525 "orientation-requested-supported",
526 ATTR_TEST_ORIENTATION_COUNT,
527 ATTR_TEST_ORIENTATION_ARRAY);
528 };
__anon3a3e489b2402(PrinterCapability &printerCaps) 529 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
530 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("orientation-requested-default"), "3");
531 std::string orientationString = printerCaps.GetPrinterAttrValue("orientation-requested-supported");
532 TestAttrCount(orientationString, ATTR_TEST_ORIENTATION_COUNT);
533 };
534 DoTest(preFunc, postFunc);
535 }
536
537 /**
538 * @tc.name: PrintCupsAttributeTest_0018
539 * @tc.desc: printer other attributes test
540 */
541 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0018_NeedRename, TestSize.Level1)
542 {
__anon3a3e489b2502(ipp_t *response) 543 PreAttrTestFunc preFunc = [this](ipp_t *response) {
544 ippAddStrings(response,
545 IPP_TAG_PRINTER,
546 IPP_CONST_TAG(IPP_TAG_KEYWORD),
547 "media-source-supported",
548 ATTR_TEST_SOURCE_COUNT,
549 nullptr,
550 ATTR_TEST_SOURCE_ARRAY);
551 ippAddStrings(response,
552 IPP_TAG_PRINTER,
553 IPP_CONST_TAG(IPP_TAG_KEYWORD),
554 "multiple-document-handling-supported",
555 ATTR_TEST_DOCUMENT_HANDLING_COUNT,
556 nullptr,
557 ATTR_TEST_DOCUMENT_HANDLING_ARRAY);
558 };
__anon3a3e489b2602(PrinterCapability &printerCaps) 559 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
560 std::string sourceString = printerCaps.GetPrinterAttrValue("media-source-supported");
561 TestAttrCount(sourceString, ATTR_TEST_SOURCE_COUNT);
562 std::string documentHandlingString = printerCaps.GetPrinterAttrValue("multiple-document-handling-supported");
563 TestAttrCount(documentHandlingString, ATTR_TEST_DOCUMENT_HANDLING_COUNT);
564 };
565 DoTest(preFunc, postFunc);
566 }
567
568 /**
569 * @tc.name: PrintCupsAttributeTest_0019
570 * @tc.desc: printer option test
571 */
572 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0019_NeedRename, TestSize.Level1)
573 {
__anon3a3e489b2702(ipp_t *response) 574 PreAttrTestFunc preFunc = [this](ipp_t *response) {
575 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-make-and-model", nullptr, "Test make and model");
576 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uuid", nullptr, "Test printer uuid");
577 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", nullptr, "Test printer name");
578 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "Printer location test");
579 ippAddStrings(response,
580 IPP_TAG_PRINTER,
581 IPP_CONST_TAG(IPP_TAG_KEYWORD),
582 "media-type-supported",
583 ATTR_TEST_MEDIA_TYPE_COUNT,
584 nullptr,
585 ATTR_TEST_MEDIA_TYPE_ARRAY);
586 };
__anon3a3e489b2802(PrinterCapability &printerCaps) 587 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
588 std::string mediaTypeString = printerCaps.GetPrinterAttrValue("media-type-supported");
589 TestAttrCount(mediaTypeString, ATTR_TEST_MEDIA_TYPE_COUNT);
590 };
591 DoTest(preFunc, postFunc);
592 }
593
594 /**
595 * @tc.name: PrintCupsAttributeTest_0020
596 * @tc.desc: ParsePrinterStatusAttributes test
597 */
598 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0020_NeedRename, TestSize.Level1)
599 {
__anon3a3e489b2902(ipp_t *response) 600 PreAttrTestFunc preFunc = [this](ipp_t *response) {
601 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PSTATE_IDLE);
602 };
__anon3a3e489b2a02(ipp_t *response) 603 PostResponseTestFunc postFunc = [this](ipp_t *response) {
604 PrinterStatus status = PRINTER_STATUS_UNAVAILABLE;
605 EXPECT_TRUE(ParsePrinterStatusAttributes(response, status));
606 EXPECT_EQ(status, PRINTER_STATUS_IDLE);
607 };
608 DoTestResponse(preFunc, postFunc);
609 }
610 /**
611 * @tc.name: PrintCupsAttributeTest_0021
612 * @tc.desc: ParsePrinterStatusAttributes test
613 */
614 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0021_NeedRename, TestSize.Level1)
615 {
__anon3a3e489b2b02(ipp_t *response) 616 PreAttrTestFunc preFunc = [this](ipp_t *response) {
617 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", nullptr, "Test printer name");
618 };
__anon3a3e489b2c02(ipp_t *response) 619 PostResponseTestFunc postFunc = [this](ipp_t *response) {
620 PrinterStatus status = PRINTER_STATUS_UNAVAILABLE;
621 EXPECT_FALSE(ParsePrinterStatusAttributes(response, status));
622 };
623 DoTestResponse(preFunc, postFunc);
624 }
625
626 /**
627 * @tc.name: PrintCupsAttributeTest_0022
628 * @tc.desc: ParsePrinterStatusAttributes test
629 */
630 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0022_NeedRename, TestSize.Level1)
631 {
__anon3a3e489b2d02(ipp_t *response) 632 PreAttrTestFunc preFunc = [this](ipp_t *response) {
633 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", 0);
634 };
__anon3a3e489b2e02(ipp_t *response) 635 PostResponseTestFunc postFunc = [this](ipp_t *response) {
636 PrinterStatus status = PRINTER_STATUS_UNAVAILABLE;
637 EXPECT_FALSE(ParsePrinterStatusAttributes(response, status));
638 };
639 DoTestResponse(preFunc, postFunc);
640 }
641
642 /**
643 * @tc.name: PrintCupsAttributeTest_0023
644 * @tc.desc: ParsePrinterStatusAttributes test
645 */
646 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0023_NeedRename, TestSize.Level1)
647 {
__anon3a3e489b2f02(ipp_t *response) 648 PreAttrTestFunc preFunc = [this](ipp_t *response) {
649 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PSTATE_STOPPED + 1);
650 };
__anon3a3e489b3002(ipp_t *response) 651 PostResponseTestFunc postFunc = [this](ipp_t *response) {
652 PrinterStatus status = PRINTER_STATUS_UNAVAILABLE;
653 EXPECT_FALSE(ParsePrinterStatusAttributes(response, status));
654 };
655 DoTestResponse(preFunc, postFunc);
656 }
657 } // namespace OHOS::Print