• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NeedRename, 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_NeedRename, 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_NeedRename, TestSize.Level2)
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_NeedRename, 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_NeedRename, TestSize.Level2)
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_NeedRename, 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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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_NeedRename, TestSize.Level2)
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 
326 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0020_NeedRename, TestSize.Level2)
327 {
328     OHOS::Print::PrinterInfo info;
329     info.SetPrinterUuid("001");
330     OHOS::Print::PrinterInfo copyInfo(info);
331     EXPECT_EQ(copyInfo.GetPrinterUuid(), info.GetPrinterUuid());
332 }
333 
334 /**
335  * @tc.name: PrinterInfoTest_0021
336  * @tc.desc: Verify settings and obtain marshalling function.
337  * @tc.type: FUNC
338  * @tc.require:
339  */
340 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0021_NeedRename, TestSize.Level2)
341 {
342     OHOS::Print::PrinterInfo info;
343     info.SetPrinterId("001");
344     info.SetPrinterName("OpenHarmony");
345     info.SetPrinterState(0);
346     info.SetPrinterStatus(0);
347     Parcel parcel;
348     EXPECT_EQ(true, info.Marshalling(parcel));
349 }
350 
351 /**
352  * @tc.name: PrinterInfoTest_0022
353  * @tc.desc: Verify settings and obtain marshalling function.
354  * @tc.type: FUNC
355  * @tc.require:
356  */
357 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0022_NeedRename, TestSize.Level2)
358 {
359     OHOS::Print::PrinterInfo info;
360     info.SetPrinterId("001");
361     info.SetPrinterName("OpenHarmony");
362     info.SetPrinterState(0);
363     info.SetUri("test://test");
364     Parcel parcel;
365     EXPECT_EQ(true, info.Marshalling(parcel));
366 }
367 
368 /**
369  * @tc.name: PrinterInfoTest_0023
370  * @tc.desc: Verify settings and obtain marshalling function.
371  * @tc.type: FUNC
372  * @tc.require:
373  */
374 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0023_NeedRename, TestSize.Level2)
375 {
376     OHOS::Print::PrinterInfo info;
377     info.SetPrinterId("001");
378     info.SetPrinterName("OpenHarmony");
379     info.SetPrinterState(0);
380     info.SetPrinterMake("test_maker");
381     Parcel parcel;
382     EXPECT_EQ(true, info.Marshalling(parcel));
383 }
384 
385 /**
386  * @tc.name: PrinterInfoTest_0024
387  * @tc.desc: Verify settings and obtain marshalling function.
388  * @tc.type: FUNC
389  * @tc.require:
390  */
391 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0024_NeedRename, TestSize.Level2)
392 {
393     OHOS::Print::PrinterInfo info;
394     info.SetPrinterId("001");
395     info.SetPrinterName("OpenHarmony");
396     info.SetPrinterState(0);
397     info.SetPrinterUuid("test_uuid");
398     Parcel parcel;
399     EXPECT_EQ(true, info.Marshalling(parcel));
400 }
401 
402 /**
403  * @tc.name: PrinterInfoTest_0025
404  * @tc.desc: Verify settings and obtain marshalling function.
405  * @tc.type: FUNC
406  * @tc.require:
407  */
408 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0025_NeedRename, TestSize.Level2)
409 {
410     OHOS::Print::PrinterInfo info;
411     info.SetPrinterId("001");
412     info.SetPrinterName("OpenHarmony");
413     info.SetPrinterState(0);
414     info.SetIsLastUsedPrinter(true);
415     Parcel parcel;
416     EXPECT_EQ(true, info.Marshalling(parcel));
417 }
418 
419 /**
420  * @tc.name: PrinterInfoTest_0026
421  * @tc.desc: Verify settings and obtain marshalling function.
422  * @tc.type: FUNC
423  * @tc.require:
424  */
425 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0026_NeedRename, TestSize.Level2)
426 {
427     OHOS::Print::PrinterInfo info;
428     info.SetPrinterId("001");
429     info.SetPrinterName("OpenHarmony");
430     info.SetPrinterState(0);
431     info.SetIsDefaultPrinter(true);
432     Parcel parcel;
433     EXPECT_EQ(true, info.Marshalling(parcel));
434 }
435 
436 /**
437  * @tc.name: PrinterInfoTest_0027
438  * @tc.desc: Verify the constructor function.
439  * @tc.type: FUNC
440  * @tc.require:
441  */
442 HWTEST_F(PrinterInfoTest, PrinterInfoTest_0027_NeedRename, TestSize.Level2)
443 {
444     OHOS::Print::PrinterInfo info;
445     info.SetPrinterId("001");
446     info.SetPrinterName("OpenHarmony");
447     info.SetPrinterState(0);
448     info.SetPrinterIcon(0);
449     info.SetDescription("test");
450     info.Dump();
451     Parcel parcel;
452     EXPECT_EQ(true, info.Marshalling(parcel));
453 }
454 } // namespace Print
455 } // namespace OHOS
456