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
19 using namespace testing;
20 using namespace testing::ext;
21 using json = nlohmann::json;
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 EXPECT_TRUE(json::accept(jsonString));
64 auto jsonObject = json::parse(jsonString);
65 EXPECT_TRUE(jsonObject.is_array());
66 EXPECT_EQ(jsonObject.size(), count);
67 }
68 } // namespace
69
70 namespace OHOS::Print {
71 using PreAttrTestFunc = std::function<void(ipp_t *)>;
72 using PostAttrTestFunc = std::function<void(PrinterCapability &)>;
73 class PrintCupsAttributeTest : public testing::Test {
74 public:
75 static void SetUpTestCase(void);
76 static void TearDownTestCase(void);
77 void SetUp();
78 void TearDown();
79
80 void DoTest(PreAttrTestFunc preFunc, PostAttrTestFunc postFunc);
81 };
82
SetUpTestCase(void)83 void PrintCupsAttributeTest::SetUpTestCase(void)
84 {}
85
TearDownTestCase(void)86 void PrintCupsAttributeTest::TearDownTestCase(void)
87 {}
88
SetUp(void)89 void PrintCupsAttributeTest::SetUp(void)
90 {}
91
TearDown(void)92 void PrintCupsAttributeTest::TearDown(void)
93 {}
94
DoTest(PreAttrTestFunc preFunc,PostAttrTestFunc postFunc)95 void PrintCupsAttributeTest::DoTest(PreAttrTestFunc preFunc, PostAttrTestFunc postFunc)
96 {
97 if (preFunc == nullptr || postFunc == nullptr) {
98 return;
99 }
100 ipp_t *request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
101 if (request == nullptr) {
102 return;
103 }
104 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", nullptr, "printer-uri");
105 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", nullptr, "user");
106 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", 1, nullptr, ATTR_TEST_ALL);
107 ipp_t *response = ippNewResponse(request);
108 ippDelete(request);
109 request = nullptr;
110 if (response == nullptr) {
111 return;
112 }
113 preFunc(response);
114 PrinterCapability printerCaps;
115 ParsePrinterAttributes(response, printerCaps);
116 ippDelete(response);
117 response = nullptr;
118 postFunc(printerCaps);
119 }
120
121 /**
122 * @tc.name: PrintCupsAttributeTest_0001
123 * @tc.desc: printer idle state test
124 */
125 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0001, TestSize.Level1)
126 {
__anon13cfc4390202(ipp_t *response) 127 PreAttrTestFunc preFunc = [this](ipp_t *response) {
128 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_IDLE);
129 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", nullptr, "Printer info test");
130 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "Printer location test");
131 };
__anon13cfc4390302(PrinterCapability &printerCaps) 132 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
133 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "idle");
134 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "Printer location test");
135 };
136 DoTest(preFunc, postFunc);
137 }
138
139 /**
140 * @tc.name: PrintCupsAttributeTest_0002
141 * @tc.desc: printer processing state test
142 */
143 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0002, TestSize.Level1)
144 {
__anon13cfc4390402(ipp_t *response) 145 PreAttrTestFunc preFunc = [this](ipp_t *response) {
146 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_PROCESSING);
147 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", nullptr, "");
148 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "");
149 };
__anon13cfc4390502(PrinterCapability &printerCaps) 150 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
151 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "processing");
152 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
153 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
154 };
155 DoTest(preFunc, postFunc);
156 }
157
158 /**
159 * @tc.name: PrintCupsAttributeTest_0003
160 * @tc.desc: printer stopped state test
161 */
162 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0003, TestSize.Level1)
163 {
__anon13cfc4390602(ipp_t *response) 164 PreAttrTestFunc preFunc = [this](ipp_t *response) {
165 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_STOPPED);
166 };
__anon13cfc4390702(PrinterCapability &printerCaps) 167 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
168 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "stopped");
169 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
170 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
171 };
172 DoTest(preFunc, postFunc);
173 }
174
175 /**
176 * @tc.name: PrintCupsAttributeTest_0004
177 * @tc.desc: printer empty state test
178 */
179 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0004, TestSize.Level1)
180 {
__anon13cfc4390802(ipp_t *response) 181 PreAttrTestFunc preFunc = [this](ipp_t *response) {};
__anon13cfc4390902(PrinterCapability &printerCaps) 182 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
183 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-state"), "");
184 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-info"), "");
185 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("printer-location"), "");
186 };
187 DoTest(preFunc, postFunc);
188 }
189
190 /**
191 * @tc.name: PrintCupsAttributeTest_0005
192 * @tc.desc: printer sides test
193 */
194 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0005, TestSize.Level1)
195 {
__anon13cfc4390a02(ipp_t *response) 196 PreAttrTestFunc preFunc = [this](ipp_t *response) {
197 ippAddStrings(response,
198 IPP_TAG_PRINTER,
199 IPP_TAG_KEYWORD,
200 "sides-supported",
201 ATTR_TEST_SIDES_COUNT,
202 nullptr,
203 ATTR_TEST_SIDES_ARRAY);
204 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default", nullptr, ATTR_TEST_SIDES_ARRAY[0]);
205 };
__anon13cfc4390b02(PrinterCapability &printerCaps) 206 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
207 std::string sideString = printerCaps.GetPrinterAttrValue("sides-supported");
208 TestAttrCount(sideString, ATTR_TEST_SIDES_COUNT);
209 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("sides-default"), "0");
210 };
211 DoTest(preFunc, postFunc);
212 }
213
214 /**
215 * @tc.name: PrintCupsAttributeTest_0006
216 * @tc.desc: printer sides test
217 */
218 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0006, TestSize.Level1)
219 {
__anon13cfc4390c02(ipp_t *response) 220 PreAttrTestFunc preFunc = [this](ipp_t *response) {
221 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default", nullptr, ATTR_TEST_SIDES_ARRAY[1]);
222 };
__anon13cfc4390d02(PrinterCapability &printerCaps) 223 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
224 std::string sideString = printerCaps.GetPrinterAttrValue("sides-supported");
225 TestAttrCount(sideString, 0);
226 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("sides-default"), "1");
227 };
228 DoTest(preFunc, postFunc);
229 }
230
231 /**
232 * @tc.name: PrintCupsAttributeTest_0007
233 * @tc.desc: printer color mode test
234 */
235 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0007, TestSize.Level1)
236 {
__anon13cfc4390e02(ipp_t *response) 237 PreAttrTestFunc preFunc = [this](ipp_t *response) {
238 ippAddStrings(response,
239 IPP_TAG_PRINTER,
240 IPP_TAG_KEYWORD,
241 "print-color-mode-supported",
242 ATTR_TEST_COLOR_MODE_COUNT,
243 nullptr,
244 ATTR_TEST_COLOR_MODE_ARRAY);
245 ippAddString(response,
246 IPP_TAG_PRINTER,
247 IPP_TAG_KEYWORD,
248 "print-color-mode-default",
249 nullptr,
250 ATTR_TEST_COLOR_MODE_ARRAY[0]);
251 };
__anon13cfc4390f02(PrinterCapability &printerCaps) 252 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
253 std::string colorModeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
254 TestAttrCount(colorModeString, ATTR_TEST_COLOR_MODE_COUNT);
255 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultColorMode"), "0");
256 };
257 DoTest(preFunc, postFunc);
258 }
259
260 /**
261 * @tc.name: PrintCupsAttributeTest_0008
262 * @tc.desc: printer color mode test
263 */
264 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0008, TestSize.Level1)
265 {
__anon13cfc4391002(ipp_t *response) 266 PreAttrTestFunc preFunc = [this](ipp_t *response) {
267 ippAddString(response,
268 IPP_TAG_PRINTER,
269 IPP_TAG_KEYWORD,
270 "print-color-mode-default",
271 nullptr,
272 ATTR_TEST_COLOR_MODE_ARRAY[1]);
273 };
__anon13cfc4391102(PrinterCapability &printerCaps) 274 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
275 std::string colorModeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
276 TestAttrCount(colorModeString, 0);
277 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultColorMode"), "1");
278 };
279 DoTest(preFunc, postFunc);
280 }
281
282 /**
283 * @tc.name: PrintCupsAttributeTest_0009
284 * @tc.desc: printer page size test
285 */
286 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0009, TestSize.Level1)
287 {
__anon13cfc4391202(ipp_t *response) 288 PreAttrTestFunc preFunc = [this](ipp_t *response) {
289 ippAddStrings(response,
290 IPP_TAG_PRINTER,
291 IPP_TAG_KEYWORD,
292 "media-supported",
293 ATTR_TEST_PAGE_SIZE_COUNT,
294 nullptr,
295 ATTR_TEST_PAGE_SIZE_ARRAY);
296 ippAddString(
297 response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default", nullptr, ATTR_TEST_PAGE_SIZE_ARRAY[0]);
298 };
__anon13cfc4391302(PrinterCapability &printerCaps) 299 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
300 std::string pageSizeString = printerCaps.GetPrinterAttrValue("supportedPageSizeArray");
301 TestAttrCount(pageSizeString, ATTR_TEST_PAGE_SIZE_COUNT);
302 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultPageSizeId"), "ISO_B3");
303 };
304 DoTest(preFunc, postFunc);
305 }
306
307 /**
308 * @tc.name: PrintCupsAttributeTest_0010
309 * @tc.desc: printer page size test
310 */
311 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0010, TestSize.Level1)
312 {
__anon13cfc4391402(ipp_t *response) 313 PreAttrTestFunc preFunc = [this](ipp_t *response) {
314 ippAddString(response,
315 IPP_TAG_PRINTER,
316 IPP_TAG_KEYWORD,
317 "print-color-mode-default",
318 nullptr,
319 ATTR_TEST_COLOR_MODE_ARRAY[1]);
320 };
__anon13cfc4391502(PrinterCapability &printerCaps) 321 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
322 std::string pageSizeString = printerCaps.GetPrinterAttrValue("print-color-mode-supported");
323 TestAttrCount(pageSizeString, 0);
324 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("defaultPageSizeId"), "");
325 };
326 DoTest(preFunc, postFunc);
327 }
328
329 /**
330 * @tc.name: PrintCupsAttributeTest_0011
331 * @tc.desc: printer quality / copies test
332 */
333 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0011, TestSize.Level1)
334 {
__anon13cfc4391602(ipp_t *response) 335 PreAttrTestFunc preFunc = [this](ipp_t *response) {
336 ippAddIntegers(response,
337 IPP_TAG_PRINTER,
338 IPP_TAG_ENUM,
339 "print-quality-supported",
340 ATTR_TEST_QUALITY_COUNT,
341 ATTR_TEST_QUALITY_ARRAY);
342 ippAddRange(response, IPP_TAG_PRINTER, "copies-supported", 1, ATTR_TEST_MAX_COPIES);
343 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", 1);
344 };
__anon13cfc4391702(PrinterCapability &printerCaps) 345 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
346 std::string qualityString = printerCaps.GetPrinterAttrValue("print-quality-supported");
347 TestAttrCount(qualityString, ATTR_TEST_QUALITY_COUNT);
348 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-supported"), std::to_string(ATTR_TEST_MAX_COPIES).c_str());
349 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-default"), "1");
350 };
351 DoTest(preFunc, postFunc);
352 }
353
354 /**
355 * @tc.name: PrintCupsAttributeTest_0012
356 * @tc.desc: printer quality / copies test
357 */
358 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0012, TestSize.Level1)
359 {
__anon13cfc4391802(ipp_t *response) 360 PreAttrTestFunc preFunc = [this](ipp_t *response) {};
__anon13cfc4391902(PrinterCapability &printerCaps) 361 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
362 std::string pageSizeString = printerCaps.GetPrinterAttrValue("print-quality-supported");
363 EXPECT_TRUE(pageSizeString.empty());
364 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-supported"), "");
365 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("copies-default"), "");
366 };
367 DoTest(preFunc, postFunc);
368 }
369
370 /**
371 * @tc.name: PrintCupsAttributeTest_0013
372 * @tc.desc: printer resolution test
373 */
374 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0013, TestSize.Level1)
375 {
__anon13cfc4391a02(ipp_t *response) 376 PreAttrTestFunc preFunc = [this](ipp_t *response) {
377 ippAddResolution(response,
378 IPP_TAG_PRINTER,
379 "printer-resolution-supported",
380 IPP_RES_PER_INCH,
381 ATTR_TEST_RESOLUTION_DEFAULT,
382 ATTR_TEST_RESOLUTION_DEFAULT);
383 ippAddResolution(response,
384 IPP_TAG_PRINTER,
385 "printer-resolution-default",
386 IPP_RES_PER_INCH,
387 ATTR_TEST_RESOLUTION_DEFAULT,
388 ATTR_TEST_RESOLUTION_DEFAULT);
389 };
__anon13cfc4391b02(PrinterCapability &printerCaps) 390 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
391 std::string supportedResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-supported");
392 TestAttrCount(supportedResolutionString, 1);
393 std::string defaultResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-default");
394 EXPECT_TRUE(json::accept(defaultResolutionString));
395 auto defaultResolutionJson = json::parse(defaultResolutionString);
396 EXPECT_TRUE(defaultResolutionJson.contains("horizontalDpi"));
397 EXPECT_TRUE(defaultResolutionJson.contains("verticalDpi"));
398 EXPECT_TRUE(defaultResolutionJson["horizontalDpi"].is_number());
399 EXPECT_TRUE(defaultResolutionJson["verticalDpi"].is_number());
400 EXPECT_EQ(defaultResolutionJson["horizontalDpi"], ATTR_TEST_RESOLUTION_DEFAULT);
401 EXPECT_EQ(defaultResolutionJson["verticalDpi"], ATTR_TEST_RESOLUTION_DEFAULT);
402 };
403 DoTest(preFunc, postFunc);
404 }
405
406 /**
407 * @tc.name: PrintCupsAttributeTest_0014
408 * @tc.desc: printer resolution test
409 */
410 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0014, TestSize.Level1)
411 {
__anon13cfc4391c02(ipp_t *response) 412 PreAttrTestFunc preFunc = [this](ipp_t *response) {
413 ippAddResolution(response,
414 IPP_TAG_PRINTER,
415 "printer-resolution-default",
416 IPP_RES_PER_CM,
417 ATTR_TEST_RESULUTION_SMALL_DPCM,
418 ATTR_TEST_RESULUTION_SMALL_DPCM);
419 };
__anon13cfc4391d02(PrinterCapability &printerCaps) 420 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
421 std::string supportedResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-supported");
422 EXPECT_TRUE(supportedResolutionString.empty());
423 std::string defaultResolutionString = printerCaps.GetPrinterAttrValue("printer-resolution-default");
424 EXPECT_TRUE(json::accept(defaultResolutionString));
425 auto defaultResolutionJson = json::parse(defaultResolutionString);
426 EXPECT_TRUE(defaultResolutionJson.contains("horizontalDpi"));
427 EXPECT_TRUE(defaultResolutionJson.contains("verticalDpi"));
428 EXPECT_TRUE(defaultResolutionJson["horizontalDpi"].is_number());
429 EXPECT_TRUE(defaultResolutionJson["verticalDpi"].is_number());
430 EXPECT_EQ(defaultResolutionJson["horizontalDpi"], ATTR_TEST_RESOLUTION_SMALL);
431 EXPECT_EQ(defaultResolutionJson["verticalDpi"], ATTR_TEST_RESOLUTION_SMALL);
432 };
433 DoTest(preFunc, postFunc);
434 }
435
436 /**
437 * @tc.name: PrintCupsAttributeTest_0015
438 * @tc.desc: printer media test
439 */
440 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0015, TestSize.Level1)
441 {
__anon13cfc4391e02(ipp_t *response) 442 PreAttrTestFunc preFunc = [this](ipp_t *response) {
443 auto mediaCol = ippNew();
444 if (mediaCol == nullptr) {
445 return;
446 }
447 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-bottom-margin", ATTR_TEST_PAPER_BOTTOM);
448 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-left-margin", ATTR_TEST_PAPER_LEFT);
449 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-right-margin", ATTR_TEST_PAPER_RIGHT);
450 ippAddInteger(mediaCol, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-top-margin", ATTR_TEST_PAPER_TOP);
451 ippAddBoolean(mediaCol, IPP_TAG_PRINTER, "duplex-supported", 1);
452 ippAddString(mediaCol, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source", nullptr, "Front Input Slot");
453 ippAddString(mediaCol, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type", nullptr, "stationery");
454 ippAddCollection(response, IPP_TAG_PRINTER, "media-col-default", mediaCol);
455 ippDelete(mediaCol);
456 };
__anon13cfc4391f02(PrinterCapability &printerCaps) 457 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
458 EXPECT_STREQ(
459 printerCaps.GetPrinterAttrValue("media-top-margin-default"), std::to_string(ATTR_TEST_PAPER_TOP).c_str());
460 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-bottom-margin-default"),
461 std::to_string(ATTR_TEST_PAPER_BOTTOM).c_str());
462 EXPECT_STREQ(
463 printerCaps.GetPrinterAttrValue("media-left-margin-default"), std::to_string(ATTR_TEST_PAPER_LEFT).c_str());
464 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-right-margin-default"),
465 std::to_string(ATTR_TEST_PAPER_RIGHT).c_str());
466 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-source-default"), "Front Input Slot");
467 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-type-default"), "stationery");
468 };
469 DoTest(preFunc, postFunc);
470 }
471
472 /**
473 * @tc.name: PrintCupsAttributeTest_0016
474 * @tc.desc: printer margin test
475 */
476 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0016, TestSize.Level1)
477 {
__anon13cfc4392002(ipp_t *response) 478 PreAttrTestFunc preFunc = [this](ipp_t *response) {
479 ippAddInteger(
480 response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-bottom-margin-supported", ATTR_TEST_PAPER_BOTTOM);
481 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-left-margin-supported", ATTR_TEST_PAPER_LEFT);
482 ippAddInteger(
483 response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-right-margin-supported", ATTR_TEST_PAPER_RIGHT);
484 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "media-top-margin-supported", ATTR_TEST_PAPER_TOP);
485 };
__anon13cfc4392102(PrinterCapability &printerCaps) 486 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
487 EXPECT_STREQ(
488 printerCaps.GetPrinterAttrValue("media-top-margin-supported"), std::to_string(ATTR_TEST_PAPER_TOP).c_str());
489 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-bottom-margin-supported"),
490 std::to_string(ATTR_TEST_PAPER_BOTTOM).c_str());
491 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-left-margin-supported"),
492 std::to_string(ATTR_TEST_PAPER_LEFT).c_str());
493 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("media-right-margin-supported"),
494 std::to_string(ATTR_TEST_PAPER_RIGHT).c_str());
495 };
496 DoTest(preFunc, postFunc);
497 }
498
499 /**
500 * @tc.name: PrintCupsAttributeTest_0017
501 * @tc.desc: printer orientation test
502 */
503 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0017, TestSize.Level1)
504 {
__anon13cfc4392202(ipp_t *response) 505 PreAttrTestFunc preFunc = [this](ipp_t *response) {
506 ippAddInteger(response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "orientation-requested-default", IPP_ORIENT_PORTRAIT);
507 ippAddIntegers(response,
508 IPP_TAG_PRINTER,
509 IPP_TAG_ENUM,
510 "orientation-requested-supported",
511 ATTR_TEST_ORIENTATION_COUNT,
512 ATTR_TEST_ORIENTATION_ARRAY);
513 };
__anon13cfc4392302(PrinterCapability &printerCaps) 514 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
515 EXPECT_STREQ(printerCaps.GetPrinterAttrValue("orientation-requested-default"), "3");
516 std::string orientationString = printerCaps.GetPrinterAttrValue("orientation-requested-supported");
517 TestAttrCount(orientationString, ATTR_TEST_ORIENTATION_COUNT);
518 };
519 DoTest(preFunc, postFunc);
520 }
521
522 /**
523 * @tc.name: PrintCupsAttributeTest_0018
524 * @tc.desc: printer other attributes test
525 */
526 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0018, TestSize.Level1)
527 {
__anon13cfc4392402(ipp_t *response) 528 PreAttrTestFunc preFunc = [this](ipp_t *response) {
529 ippAddStrings(response,
530 IPP_TAG_PRINTER,
531 IPP_CONST_TAG(IPP_TAG_KEYWORD),
532 "media-source-supported",
533 ATTR_TEST_SOURCE_COUNT,
534 nullptr,
535 ATTR_TEST_SOURCE_ARRAY);
536 ippAddStrings(response,
537 IPP_TAG_PRINTER,
538 IPP_CONST_TAG(IPP_TAG_KEYWORD),
539 "multiple-document-handling-supported",
540 ATTR_TEST_DOCUMENT_HANDLING_COUNT,
541 nullptr,
542 ATTR_TEST_DOCUMENT_HANDLING_ARRAY);
543 };
__anon13cfc4392502(PrinterCapability &printerCaps) 544 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
545 std::string sourceString = printerCaps.GetPrinterAttrValue("media-source-supported");
546 TestAttrCount(sourceString, ATTR_TEST_SOURCE_COUNT);
547 std::string documentHandlingString = printerCaps.GetPrinterAttrValue("multiple-document-handling-supported");
548 TestAttrCount(documentHandlingString, ATTR_TEST_DOCUMENT_HANDLING_COUNT);
549 };
550 DoTest(preFunc, postFunc);
551 }
552
553 /**
554 * @tc.name: PrintCupsAttributeTest_0019
555 * @tc.desc: printer option test
556 */
557 HWTEST_F(PrintCupsAttributeTest, PrintCupsAttributeTest_0019, TestSize.Level1)
558 {
__anon13cfc4392602(ipp_t *response) 559 PreAttrTestFunc preFunc = [this](ipp_t *response) {
560 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-make-and-model", nullptr, "Test make and model");
561 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uuid", nullptr, "Test printer uuid");
562 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-name", nullptr, "Test printer name");
563 ippAddString(response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", nullptr, "Printer location test");
564 ippAddStrings(response,
565 IPP_TAG_PRINTER,
566 IPP_CONST_TAG(IPP_TAG_KEYWORD),
567 "media-type-supported",
568 ATTR_TEST_MEDIA_TYPE_COUNT,
569 nullptr,
570 ATTR_TEST_MEDIA_TYPE_ARRAY);
571 };
__anon13cfc4392702(PrinterCapability &printerCaps) 572 PostAttrTestFunc postFunc = [this](PrinterCapability &printerCaps) {
573 std::string mediaTypeString = printerCaps.GetPrinterAttrValue("media-type-supported");
574 TestAttrCount(mediaTypeString, ATTR_TEST_MEDIA_TYPE_COUNT);
575 };
576 DoTest(preFunc, postFunc);
577 }
578 } // namespace OHOS::Print