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 "printer_capability.h"
18 #include "print_margin.h"
19 #include "print_resolution.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Print {
25 class PrinterCapabilityTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase(void)33 void PrinterCapabilityTest::SetUpTestCase(void) {}
34
TearDownTestCase(void)35 void PrinterCapabilityTest::TearDownTestCase(void) {}
36
SetUp(void)37 void PrinterCapabilityTest::SetUp(void) {}
38
TearDown(void)39 void PrinterCapabilityTest::TearDown(void) {}
40
41 /**
42 * @tc.name: PrinterCapabilityTest_0002
43 * @tc.desc: Verify settings and obtain colorMode function.
44 * @tc.type: FUNC
45 * @tc.require:
46 */
47 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0002, TestSize.Level1)
48 {
49 PrinterCapability capability;
50 capability.SetColorMode(6);
51 capability.Reset();
52 EXPECT_EQ((uint32_t)0, capability.GetColorMode());
53 }
54
55 /**
56 * @tc.name: PrinterCapabilityTest_0003
57 * @tc.desc: Verify settings and obtain hasMargin function.
58 * @tc.type: FUNC
59 * @tc.require:
60 */
61 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0003, TestSize.Level1)
62 {
63 PrinterCapability capability;
64 PrintMargin margin;
65 capability.SetMinMargin(margin);
66 EXPECT_EQ(true, capability.HasMargin());
67 }
68
69 /**
70 * @tc.name: PrinterCapabilityTest_0004
71 * @tc.desc: Verify settings and obtain hasMargin function.
72 * @tc.type: FUNC
73 * @tc.require:
74 */
75 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0004, TestSize.Level1)
76 {
77 PrinterCapability capability;
78 PrintMargin margin, copyMargin;
79 capability.SetMinMargin(margin);
80 capability.GetMinMargin(copyMargin);
81 EXPECT_FALSE(copyMargin.HasRight());
82 }
83
84 /**
85 * @tc.name: PrinterCapabilityTest_0005
86 * @tc.desc: Verify settings and obtain pageSize function.
87 * @tc.type: FUNC
88 * @tc.require:
89 */
90 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0005, TestSize.Level1)
91 {
92 PrinterCapability capability;
93 std::vector<PrintPageSize> pagesize, getPagesize;
94 PrintPageSize testPagesize;
95 testPagesize.SetWidth(1);
96 pagesize.emplace_back(testPagesize);
97 capability.SetSupportedPageSize(pagesize);
98 capability.GetSupportedPageSize(getPagesize);
99 EXPECT_EQ(pagesize.size(), getPagesize.size());
100 }
101
102 /**
103 * @tc.name: PrinterCapabilityTest_0006
104 * @tc.desc: Verify settings and obtain Resolution function.
105 * @tc.type: FUNC
106 * @tc.require:
107 */
108 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0006, TestSize.Level1)
109 {
110 PrinterCapability capability;
111 std::vector<PrintResolution> resolution, getResolution;
112 PrintResolution testResolution;
113 testResolution.SetHorizontalDpi(1);
114 resolution.emplace_back(testResolution);
115 capability.SetResolution(resolution);
116 capability.GetResolution(getResolution);
117 EXPECT_EQ(resolution.size(), getResolution.size());
118 }
119
120 /**
121 * @tc.name: PrinterCapabilityTest_0007
122 * @tc.desc: Verify settings and obtain hasResolution function.
123 * @tc.type: FUNC
124 * @tc.require:
125 */
126 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0007, TestSize.Level1)
127 {
128 PrinterCapability capability;
129 std::vector<PrintResolution> resolution;
130 capability.SetResolution(resolution);
131 EXPECT_EQ(true, capability.HasResolution());
132 }
133
134 /**
135 * @tc.name: PrinterCapabilityTest_0008
136 * @tc.desc: Verify settings and obtain colorMode function.
137 * @tc.type: FUNC
138 * @tc.require:
139 */
140 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0008, TestSize.Level1)
141 {
142 PrinterCapability capability;
143 capability.SetColorMode(6);
144 EXPECT_EQ((uint32_t)6, capability.GetColorMode());
145 }
146
147 /**
148 * @tc.name: PrinterCapabilityTest_0009
149 * @tc.desc: Verify settings and obtain duplexMode function.
150 * @tc.type: FUNC
151 * @tc.require:
152 */
153 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0009, TestSize.Level1)
154 {
155 PrinterCapability capability;
156 capability.SetDuplexMode(6);
157 EXPECT_EQ((uint32_t)6, capability.GetDuplexMode());
158 }
159
160 /**
161 * @tc.name: PrinterCapabilityTest_0010
162 * @tc.desc: Verify the marshalling function.
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0010, TestSize.Level1)
167 {
168 PrinterCapability capability;
169 PrintMargin margin, getMargin;
170 std::vector<PrintResolution> resolutionList;
171 std::vector<PrintPageSize> pagesize;
172 capability.SetColorMode(6);
173 capability.SetDuplexMode(6);
174
175 capability.SetMinMargin(margin);
176 capability.SetSupportedPageSize(pagesize);
177 capability.SetResolution(resolutionList);
178 Parcel parcel;
179 EXPECT_EQ(capability.Marshalling(parcel), true);
180 }
181
182 /**
183 * @tc.name: PrinterCapabilityTest_0011
184 * @tc.desc: Verify the marshalling function.
185 * @tc.type: FUNC
186 * @tc.require:
187 */
188 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0011, TestSize.Level1)
189 {
190 PrinterCapability capability;
191 PrintMargin margin, getMargin;
192 std::vector<PrintResolution> resolutionList;
193 std::vector<PrintPageSize> pagesize;
194 capability.SetColorMode(6);
195 capability.SetDuplexMode(6);
196 capability.SetSupportedPageSize(pagesize);
197 Parcel parcel;
198 EXPECT_EQ(capability.Marshalling(parcel), true);
199 }
200
201 /**
202 * @tc.name: PrinterCapabilityTest_0012
203 * @tc.desc: Verify the unmarshalling function.
204 * @tc.type: FUNC
205 * @tc.require:
206 */
207 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0012, TestSize.Level1)
208 {
209 PrinterCapability capability;
210 PrintMargin margin, getMargin;
211 std::vector<PrintResolution> resolutionList;
212 std::vector<PrintPageSize> pagesize;
213 capability.SetColorMode(6);
214 capability.SetDuplexMode(6);
215 capability.SetMinMargin(margin);
216 capability.SetSupportedPageSize(pagesize);
217 capability.SetResolution(resolutionList);
218 Parcel parcel;
219 capability.Marshalling(parcel);
220 auto result = OHOS::Print::PrinterCapability::Unmarshalling(parcel);
221 EXPECT_NE(nullptr, result);
222 capability.Dump();
223 }
224
225 /**
226 * @tc.name: PrinterCapabilityTest_0013
227 * @tc.desc: Verify the constructor function.
228 * @tc.type: FUNC
229 * @tc.require:
230 */
231 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0013, TestSize.Level1)
232 {
233 PrinterCapability capability;
234 capability.SetColorMode(6);
235 PrinterCapability copyCapability(capability);
236 EXPECT_EQ((uint32_t)6, capability.GetColorMode());
237 }
238
239 /**
240 * @tc.name: PrinterCapabilityTest_0014
241 * @tc.desc: Verify the constructor function.
242 * @tc.type: FUNC
243 * @tc.require:
244 */
245 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0014, TestSize.Level1)
246 {
247 PrinterCapability capability;
248 capability.SetColorMode(6);
249 PrinterCapability copyCapability = capability;
250 EXPECT_EQ((uint32_t)6, capability.GetColorMode());
251 }
252
253 /**
254 * @tc.name: PrinterCapabilityTest_0015
255 * @tc.desc: GetPrinterAttrValue.
256 * @tc.type: FUNC
257 * @tc.require:
258 */
259 HWTEST_F(PrinterCapabilityTest, PrinterCapabilityTest_0015, TestSize.Level1)
260 {
261 PrinterCapability capability;
262 capability.GetPrinterAttrGroupJson();
263 capability.SetPrinterAttrNameAndValue("key1", "value1");
264 capability.SetPrinterAttrNameAndValue("key2", "value2");
265 EXPECT_STREQ(capability.GetPrinterAttrValue("key1"), "value1");
266 EXPECT_STREQ(capability.GetPrinterAttrValue("key"), "");
267 capability.ClearCurPrinterAttrGroup();
268 }
269 } // namespace Print
270 } // namespace OHOS
271