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