• 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 "print_page_size.h"
18 #include "printer_capability.h"
19 #include "print_log.h"
20 
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Print {
25 class PrintPageSizeTest : 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 PrintPageSizeTest::SetUpTestCase(void) {}
34 
TearDownTestCase(void)35 void PrintPageSizeTest::TearDownTestCase(void) {}
36 
SetUp(void)37 void PrintPageSizeTest::SetUp(void) {}
38 
TearDown(void)39 void PrintPageSizeTest::TearDown(void) {}
40 
41 /**
42  * @tc.name: PrintPageSizeTest_0002
43  * @tc.desc: Verify the FindPageSizeById function.
44  * @tc.type: FUNC
45  * @tc.require:
46  */
47 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0002, TestSize.Level1)
48 {
49     constexpr uint32_t expectWidth = 11690;
50     OHOS::Print::PrintPageSize printpageSize;
51     OHOS::Print::PrintPageSize::FindPageSizeById("ISO_A3", printpageSize);
52     EXPECT_EQ(expectWidth, printpageSize.GetWidth());
53 }
54 
55 /**
56  * @tc.name: PrintPageSizeTest_0003
57  * @tc.desc: Verify the reset function.
58  * @tc.type: FUNC
59  * @tc.require:
60  */
61 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0003, TestSize.Level1)
62 {
63     OHOS::Print::PrintPageSize printpageSize;
64     printpageSize.Reset();
65     EXPECT_EQ("", printpageSize.GetId());
66 }
67 
68 /**
69  * @tc.name: PrintPageSizeTest_0004
70  * @tc.desc: Verify the getId function.
71  * @tc.type: FUNC
72  * @tc.require:
73  */
74 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0004, TestSize.Level1)
75 {
76     OHOS::Print::PrintPageSize printpageSize;
77     printpageSize.SetId("Test");
78     EXPECT_EQ("Test", printpageSize.GetId());
79 }
80 
81 /**
82  * @tc.name: PrintPageSizeTest_0005
83  * @tc.desc: Verify the getName function.
84  * @tc.type: FUNC
85  * @tc.require:
86  */
87 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0005, TestSize.Level1)
88 {
89     OHOS::Print::PrintPageSize printpageSize;
90     printpageSize.SetName("Test");
91     EXPECT_EQ("Test", printpageSize.GetName());
92 }
93 
94 /**
95  * @tc.name: PrintPageSizeTest_0006
96  * @tc.desc: Verify the getWidth function.
97  * @tc.type: FUNC
98  * @tc.require:
99  */
100 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0006, TestSize.Level1)
101 {
102     OHOS::Print::PrintPageSize printpageSize;
103     printpageSize.SetWidth(6);
104     EXPECT_EQ((uint32_t)6, printpageSize.GetWidth());
105 }
106 
107 /**
108  * @tc.name: PrintPageSizeTest_0007
109  * @tc.desc: Verify the getHeight function.
110  * @tc.type: FUNC
111  * @tc.require:
112  */
113 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0007, TestSize.Level1)
114 {
115     OHOS::Print::PrintPageSize printpageSize;
116     printpageSize.SetHeight(6);
117     EXPECT_EQ((uint32_t)6, printpageSize.GetHeight());
118 }
119 
120 /**
121  * @tc.name: PrintPageSizeTest_0008
122  * @tc.desc: Verify the marshalling function.
123  * @tc.type: FUNC
124  * @tc.require:
125  */
126 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0008, TestSize.Level1)
127 {
128     OHOS::Print::PrintPageSize printpageSize;
129     printpageSize.SetId("id-1234");
130     printpageSize.SetName("Test");
131     printpageSize.SetWidth(6);
132     printpageSize.SetHeight(6);
133     Parcel parcel;
134     EXPECT_EQ(printpageSize.Marshalling(parcel), true);
135 }
136 
137 /**
138  * @tc.name: PrintPageSizeTest_0009
139  * @tc.desc: Verify the unmarshalling function.
140  * @tc.type: FUNC
141  * @tc.require:
142  */
143 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0009, TestSize.Level1)
144 {
145     OHOS::Print::PrintPageSize printpageSize;
146     printpageSize.SetId("id-1234");
147     Parcel parcel;
148     printpageSize.Marshalling(parcel);
149     auto result = OHOS::Print::PrintPageSize::Unmarshalling(parcel);
150     EXPECT_NE(nullptr, result);
151 }
152 
153 /**
154  * @tc.name: PrintPageSizeTest_0010
155  * @tc.desc: Verify the constructor function.
156  * @tc.type: FUNC
157  * @tc.require:
158  */
159 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0010, TestSize.Level1)
160 {
161     OHOS::Print::PrintPageSize printpageSize("Test", "Test", 6, 6);
162     EXPECT_EQ((uint32_t)6, printpageSize.GetWidth());
163 }
164 
165 /**
166  * @tc.name: PrintPageSizeTest_0011
167  * @tc.desc: Verify the copy constructor function.
168  * @tc.type: FUNC
169  * @tc.require:
170  */
171 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0011, TestSize.Level1)
172 {
173     OHOS::Print::PrintPageSize printpageSize;
174     printpageSize.SetWidth(6);
175     OHOS::Print::PrintPageSize copyPageSize(printpageSize);
176     EXPECT_EQ(copyPageSize.GetWidth(), printpageSize.GetWidth());
177 }
178 
179 /**
180  * @tc.name: PrintPageSizeTest_0012
181  * @tc.desc: Verify the copy constructor function.
182  * @tc.type: FUNC
183  * @tc.require:
184  */
185 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0012, TestSize.Level1)
186 {
187     OHOS::Print::PrintPageSize printpageSize;
188     printpageSize.SetWidth(6);
189     OHOS::Print::PrintPageSize copyPageSize = printpageSize;
190     EXPECT_EQ(copyPageSize.GetWidth(), printpageSize.GetWidth());
191 }
192 
193 /**
194  * @tc.name: PrintPageSizeTest_0013
195  * @tc.desc: MatchPageSize.
196  * @tc.type: FUNC
197  * @tc.require:
198  */
199 HWTEST_F(PrintPageSizeTest, PrintPageSizeTest_0013, TestSize.Level1)
200 {
201     PrintPageSize::MatchPageSize("aaa");
202     EXPECT_FALSE(PrintPageSize::MatchPageSize("iso_a4_210x297mm").empty());
203     OHOS::Print::PrintPageSize printPageSize;
204     EXPECT_FALSE(PrintPageSize::FindPageSizeById("ISO_AA", printPageSize));
205     EXPECT_TRUE(PrintPageSize::FindPageSizeById("ISO_A4", printPageSize));
206     OHOS::Print::PrintPageSize size;
207     size.SetId("ISO_A4");
208     EXPECT_TRUE(printPageSize == size);
209 }
210 
211 } // namespace Print
212 } // namespace OHOS