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_info.h"
18
19 using namespace testing::ext;
20
21 namespace OHOS {
22 namespace Print {
23 class PrinterInfoTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 void SetUp();
28 void TearDown();
29 };
30
SetUpTestCase(void)31 void PrinterInfoTest::SetUpTestCase(void) {}
32
TearDownTestCase(void)33 void PrinterInfoTest::TearDownTestCase(void) {}
34
SetUp(void)35 void PrinterInfoTest::SetUp(void) {}
36
TearDown(void)37 void PrinterInfoTest::TearDown(void) {}
38
39 /**
40 * @tc.name: PrinterInfoTest_0002
41 * @tc.desc: Verify settings and obtain id function.
42 * @tc.type: FUNC
43 * @tc.require:
44 */
45 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0002, TestSize.Level1)
46 {
47 OHOS::Print::PrinterInfo info;
48 info.SetPrinterId("001");
49 EXPECT_EQ("001", info.GetPrinterId());
50 }
51
52 /**
53 * @tc.name: PrinterInfoTest_0003
54 * @tc.desc: Verify settings and obtain name function.
55 * @tc.type: FUNC
56 * @tc.require:
57 */
58 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0003, TestSize.Level1)
59 {
60 OHOS::Print::PrinterInfo info;
61 info.SetPrinterName("OpenHarmony");
62 EXPECT_EQ("OpenHarmony", info.GetPrinterName());
63 }
64
65 /**
66 * @tc.name: PrinterInfoTest_0004
67 * @tc.desc: Verify settings and obtain icon function.
68 * @tc.type: FUNC
69 * @tc.require:
70 */
71 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0004, TestSize.Level1)
72 {
73 OHOS::Print::PrinterInfo info;
74 info.SetPrinterIcon(0);
75 EXPECT_EQ((uint32_t)0, info.GetPrinterIcon());
76 }
77
78 /**
79 * @tc.name: PrinterInfoTest_0005
80 * @tc.desc: Verify settings and obtain state function.
81 * @tc.type: FUNC
82 * @tc.require:
83 */
84 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0005, TestSize.Level1)
85 {
86 OHOS::Print::PrinterInfo info;
87 info.SetPrinterState(0);
88 EXPECT_EQ((uint32_t)0, info.GetPrinterState());
89 }
90
91 /**
92 * @tc.name: PrinterInfoTest_0006
93 * @tc.desc: Verify settings and obtain description function.
94 * @tc.type: FUNC
95 * @tc.require:
96 */
97 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0006, TestSize.Level1)
98 {
99 OHOS::Print::PrinterInfo info;
100 info.SetDescription("normal");
101 EXPECT_EQ("normal", info.GetDescription());
102 }
103
104 /**
105 * @tc.name: PrinterInfoTest_0007
106 * @tc.desc: Verify settings and obtain option function.
107 * @tc.type: FUNC
108 * @tc.require:
109 */
110 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0007, TestSize.Level1)
111 {
112 OHOS::Print::PrinterInfo info;
113 info.SetOption("运行成功:success");
114 EXPECT_EQ("运行成功:success", info.GetOption());
115 }
116
117 /**
118 * @tc.name: PrinterInfoTest_0008
119 * @tc.desc: Verify settings and obtain capability function.
120 * @tc.type: FUNC
121 * @tc.require:
122 */
123 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0008, TestSize.Level1)
124 {
125 OHOS::Print::PrinterInfo info;
126 OHOS::Print::PrinterCapability capability, getCapabillity;
127 info.SetCapability(capability);
128 info.GetCapability(getCapabillity);
129 EXPECT_EQ((uint32_t)0, getCapabillity.GetColorMode());
130 }
131
132 /**
133 * @tc.name: PrinterInfoTest_0009
134 * @tc.desc: Verify settings and obtain hasCapability function.
135 * @tc.type: FUNC
136 * @tc.require:
137 */
138 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0009, TestSize.Level1)
139 {
140 OHOS::Print::PrinterInfo info;
141 OHOS::Print::PrinterCapability capability;
142 info.SetCapability(capability);
143 EXPECT_EQ(true, info.HasCapability());
144 }
145
146 /**
147 * @tc.name: PrinterInfoTest_0010
148 * @tc.desc: Verify settings and obtain hasOption function.
149 * @tc.type: FUNC
150 * @tc.require:
151 */
152 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0010, TestSize.Level1)
153 {
154 OHOS::Print::PrinterInfo info;
155 info.SetOption("运行成功:success");
156 EXPECT_EQ(true, info.HasOption());
157 }
158
159 /**
160 * @tc.name: PrinterInfoTest_0011
161 * @tc.desc: Verify settings and obtain marshalling function.
162 * @tc.type: FUNC
163 * @tc.require:
164 */
165 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0011, TestSize.Level1)
166 {
167 OHOS::Print::PrinterInfo info;
168 info.SetPrinterId("001");
169 info.SetPrinterName("OpenHarmony");
170 info.SetPrinterState(0);
171 info.SetPrinterIcon(-1);
172 Parcel parcel;
173 EXPECT_EQ(true, info.Marshalling(parcel));
174 }
175
176 /**
177 * @tc.name: PrinterInfoTest_0012
178 * @tc.desc: Verify settings and obtain marshalling function.
179 * @tc.type: FUNC
180 * @tc.require:
181 */
182 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0012, TestSize.Level1)
183 {
184 OHOS::Print::PrinterInfo info;
185 info.SetPrinterId("001");
186 info.SetPrinterName("OpenHarmony");
187 info.SetPrinterState(0);
188 info.SetPrinterIcon(0);
189 Parcel parcel;
190 EXPECT_EQ(true, info.Marshalling(parcel));
191 }
192
193 /**
194 * @tc.name: PrinterInfoTest_0013
195 * @tc.desc: Verify settings and obtain marshalling function.
196 * @tc.type: FUNC
197 * @tc.require:
198 */
199 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0013, TestSize.Level1)
200 {
201 OHOS::Print::PrinterInfo info;
202 info.SetPrinterId("001");
203 info.SetPrinterName("OpenHarmony");
204 info.SetPrinterState(0);
205 info.SetPrinterIcon(0);
206 info.SetDescription("");
207 Parcel parcel;
208 EXPECT_EQ(true, info.Marshalling(parcel));
209 }
210
211 /**
212 * @tc.name: PrinterInfoTest_0014
213 * @tc.desc: Verify settings and obtain marshalling function.
214 * @tc.type: FUNC
215 * @tc.require:
216 */
217 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0014, TestSize.Level1)
218 {
219 OHOS::Print::PrinterInfo info;
220 info.SetPrinterId("001");
221 info.SetPrinterName("OpenHarmony");
222 info.SetPrinterState(0);
223 info.SetPrinterIcon(0);
224 info.SetDescription("description");
225 Parcel parcel;
226 EXPECT_EQ(true, info.Marshalling(parcel));
227 }
228
229 /**
230 * @tc.name: PrinterInfoTest_0015
231 * @tc.desc: Verify settings and obtain marshalling function.
232 * @tc.type: FUNC
233 * @tc.require:
234 */
235 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0015, TestSize.Level1)
236 {
237 OHOS::Print::PrinterInfo info;
238 info.SetPrinterId("001");
239 info.SetPrinterName("OpenHarmony");
240 info.SetPrinterState(0);
241 info.SetPrinterIcon(0);
242 info.SetDescription("description");
243 OHOS::Print::PrinterCapability capability;
244 info.SetCapability(capability);
245 Parcel parcel;
246 EXPECT_EQ(true, info.Marshalling(parcel));
247 }
248
249 /**
250 * @tc.name: PrinterInfoTest_0016
251 * @tc.desc: Verify settings and obtain marshalling function.
252 * @tc.type: FUNC
253 * @tc.require:
254 */
255 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0016, TestSize.Level1)
256 {
257 OHOS::Print::PrinterInfo info;
258 info.SetPrinterId("001");
259 info.SetPrinterName("OpenHarmony");
260 info.SetPrinterState(0);
261 info.SetPrinterIcon(0);
262 info.SetDescription("description");
263 OHOS::Print::PrinterCapability capability;
264 info.SetCapability(capability);
265 info.SetOption("option");
266 Parcel parcel;
267 EXPECT_EQ(true, info.Marshalling(parcel));
268 }
269
270 /**
271 * @tc.name: PrinterInfoTest_0017
272 * @tc.desc: Verify settings and obtain marshalling function.
273 * @tc.type: FUNC
274 * @tc.require:
275 */
276 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0017, TestSize.Level1)
277 {
278 OHOS::Print::PrinterInfo info;
279 info.SetPrinterId("001");
280 info.SetPrinterName("OpenHarmony");
281 info.SetPrinterState(0);
282 info.SetPrinterIcon(0);
283 Parcel parcel;
284 info.Marshalling(parcel);
285 auto result = OHOS::Print::PrinterInfo::Unmarshalling(parcel);
286 EXPECT_NE(nullptr, result);
287 }
288
289 /**
290 * @tc.name: PrinterInfoTest_0018
291 * @tc.desc: Verify the constructor function.
292 * @tc.type: FUNC
293 * @tc.require:
294 */
295 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0018, TestSize.Level1)
296 {
297 OHOS::Print::PrinterInfo info;
298 info.SetPrinterId("001");
299 OHOS::Print::PrinterInfo copyInfo(info);
300 EXPECT_EQ(copyInfo.GetPrinterId(), info.GetPrinterId());
301 }
302
303 /**
304 * @tc.name: PrinterInfoTest_0019
305 * @tc.desc: Verify the constructor function.
306 * @tc.type: FUNC
307 * @tc.require:
308 */
309 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0019, TestSize.Level1)
310 {
311 OHOS::Print::PrinterInfo info;
312 info.SetPrinterId("001");
313 info.SetPrinterStatus(1);
314 OHOS::Print::PrinterInfo copyInfo = info;
315 EXPECT_EQ(copyInfo.GetPrinterId(), info.GetPrinterId());
316 info.SetIsLastUsedPrinter(true);
317 info.SetIsDefaultPrinter(true);
318 EXPECT_TRUE(info.HasIsDefaultPrinter());
319 EXPECT_TRUE(info.GetIsDefaultPrinter());
320 EXPECT_TRUE(info.HasIsLastUsedPrinter());
321 EXPECT_TRUE(info.GetIsLastUsedPrinter());
322 EXPECT_TRUE(info.HasPrinterStatus());
323 info.Dump();
324 }
325 } // namespace Print
326 } // namespace OHOS
327