1 /*
2 * Copyright (c) 2023 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 #define private public
18 #include "print_attributes.h"
19 #undef private
20 #include "print_margin.h"
21 #include "print_page_size.h"
22 #include "print_range.h"
23
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Print {
28 class PrintAttributesTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 void SetUp();
33 void TearDown();
34 OHOS::Print::PrintAttributes GetDefaultPrintAttributes();
35 };
36
SetUpTestCase(void)37 void PrintAttributesTest::SetUpTestCase(void) {}
38
TearDownTestCase(void)39 void PrintAttributesTest::TearDownTestCase(void) {}
40
SetUp(void)41 void PrintAttributesTest::SetUp(void) {}
42
TearDown(void)43 void PrintAttributesTest::TearDown(void) {}
44
GetDefaultPrintAttributes()45 OHOS::Print::PrintAttributes PrintAttributesTest::GetDefaultPrintAttributes()
46 {
47 OHOS::Print::PrintAttributes printAttributes;
48 printAttributes.SetCopyNumber(1);
49 OHOS::Print::PrintRange range;
50 range.SetStartPage(1);
51 printAttributes.SetPageRange(range);
52 printAttributes.SetIsSequential(true);
53 OHOS::Print::PrintPageSize pageSize;
54 pageSize.SetId("1");
55 printAttributes.SetPageSize(pageSize);
56 printAttributes.SetIsLandscape(true);
57 printAttributes.SetDirectionMode(1);
58 printAttributes.SetColorMode(1);
59 printAttributes.SetDuplexMode(1);
60 OHOS::Print::PrintMargin margin;
61 margin.SetTop(1);
62 printAttributes.SetMargin(margin);
63 printAttributes.SetOption("1");
64 return printAttributes;
65 }
66
67 /**
68 * @tc.name: PrintAttributesTest_001
69 * @tc.desc: Verify the Dump function.
70 * @tc.type: FUNC
71 * @tc.require:
72 */
73 HWTEST_F(PrintAttributesTest, PrintAttributesTest_001, TestSize.Level1)
74 {
75 OHOS::Print::PrintAttributes printAttributes(GetDefaultPrintAttributes());
76 printAttributes.Dump();
77 EXPECT_EQ(printAttributes.hasCopyNumber_, true);
78 EXPECT_EQ(printAttributes.copyNumber_, 1);
79
80 EXPECT_EQ(printAttributes.hasPageRange_, true);
81
82 EXPECT_EQ(printAttributes.hasSequential_, true);
83 EXPECT_EQ(printAttributes.isSequential_, true);
84
85 EXPECT_EQ(printAttributes.hasPageSize_, true);
86
87 EXPECT_EQ(printAttributes.hasLandscape_, true);
88 EXPECT_EQ(printAttributes.isLandscape_, true);
89
90 EXPECT_EQ(printAttributes.hasDirectionMode_, true);
91 EXPECT_EQ(printAttributes.directionMode_, 1);
92
93 EXPECT_EQ(printAttributes.hasColorMode_, true);
94 EXPECT_EQ(printAttributes.colorMode_, 1);
95
96 EXPECT_EQ(printAttributes.hasDuplexMode_, true);
97 EXPECT_EQ(printAttributes.duplexMode_, 1);
98
99 EXPECT_EQ(printAttributes.hasMargin_, true);
100
101 EXPECT_EQ(printAttributes.hasOption_, true);
102 EXPECT_EQ(printAttributes.option_, "1");
103 }
104
105 /**
106 * @tc.name: PrintAttributesTest_002
107 * @tc.desc: Verify the UpdateParams function.
108 * @tc.type: FUNC
109 * @tc.require:
110 */
111 HWTEST_F(PrintAttributesTest, PrintAttributesTest_002, TestSize.Level1)
112 {
113 OHOS::Print::PrintAttributes printAttributes;
114 OHOS::Print::PrintAttributes right;
115 printAttributes.UpdateParams(right);
116 EXPECT_EQ(printAttributes.GetCopyNumber(), 0);
117 }
118
119 /**
120 * @tc.name: PrintAttributesTest_003
121 * @tc.desc: Verify the SetCopyNumber function.
122 * @tc.type: FUNC
123 * @tc.require:
124 */
125 HWTEST_F(PrintAttributesTest, PrintAttributesTest_003, TestSize.Level1)
126 {
127 OHOS::Print::PrintAttributes printAttributes;
128 printAttributes.SetCopyNumber(1);
129 EXPECT_EQ(printAttributes.HasCopyNumber(), true);
130 EXPECT_EQ(printAttributes.GetCopyNumber(), 1);
131 }
132
133 /**
134 * @tc.name: PrintAttributesTest_004
135 * @tc.desc: Verify the SetPageRange function.
136 * @tc.type: FUNC
137 * @tc.require:
138 */
139 HWTEST_F(PrintAttributesTest, PrintAttributesTest_004, TestSize.Level1)
140 {
141 OHOS::Print::PrintAttributes printAttributes;
142 OHOS::Print::PrintRange range, getRange;
143 range.SetStartPage(1);
144 printAttributes.SetPageRange(range);
145 printAttributes.GetPageRange(getRange);
146 EXPECT_EQ(printAttributes.HasPageRange(), true);
147 EXPECT_EQ(getRange.GetStartPage(), 1);
148 }
149
150 /**
151 * @tc.name: PrintAttributesTest_005
152 * @tc.desc: Verify the SetIsSequential function.
153 * @tc.type: FUNC
154 * @tc.require:
155 */
156 HWTEST_F(PrintAttributesTest, PrintAttributesTest_005, TestSize.Level1)
157 {
158 OHOS::Print::PrintAttributes printAttributes;
159 printAttributes.SetIsSequential(true);
160 EXPECT_EQ(printAttributes.HasSequential(), true);
161 EXPECT_EQ(printAttributes.GetIsSequential(), true);
162 }
163
164 /**
165 * @tc.name: PrintAttributesTest_006
166 * @tc.desc: Verify the SetPageSize function.
167 * @tc.type: FUNC
168 * @tc.require:
169 */
170 HWTEST_F(PrintAttributesTest, PrintAttributesTest_006, TestSize.Level1)
171 {
172 OHOS::Print::PrintAttributes printAttributes;
173 OHOS::Print::PrintPageSize pageSize, getPageSize;
174 pageSize.SetId("1");
175 printAttributes.SetPageSize(pageSize);
176 printAttributes.GetPageSize(getPageSize);
177 EXPECT_EQ(printAttributes.HasPageSize(), true);
178 EXPECT_EQ(getPageSize.GetId(), "1");
179 }
180
181 /**
182 * @tc.name: PrintAttributesTest_007
183 * @tc.desc: Verify the SetIsLandscape function.
184 * @tc.type: FUNC
185 * @tc.require:
186 */
187 HWTEST_F(PrintAttributesTest, PrintAttributesTest_007, TestSize.Level1)
188 {
189 OHOS::Print::PrintAttributes printAttributes;
190 printAttributes.SetIsLandscape(true);
191 EXPECT_EQ(printAttributes.HasLandscape(), true);
192 EXPECT_EQ(printAttributes.GetIsLandscape(), true);
193 }
194
195 /**
196 * @tc.name: PrintAttributesTest_008
197 * @tc.desc: Verify the SetDirectionMode function.
198 * @tc.type: FUNC
199 * @tc.require:
200 */
201 HWTEST_F(PrintAttributesTest, PrintAttributesTest_008, TestSize.Level1)
202 {
203 OHOS::Print::PrintAttributes printAttributes;
204 printAttributes.SetDirectionMode(1);
205 EXPECT_EQ(printAttributes.HasDirectionMode(), true);
206 EXPECT_EQ(printAttributes.GetDirectionMode(), 1);
207 }
208
209 /**
210 * @tc.name: PrintAttributesTest_009
211 * @tc.desc: Verify the SetColorMode function.
212 * @tc.type: FUNC
213 * @tc.require:
214 */
215 HWTEST_F(PrintAttributesTest, PrintAttributesTest_009, TestSize.Level1)
216 {
217 OHOS::Print::PrintAttributes printAttributes;
218 printAttributes.SetColorMode(1);
219 EXPECT_EQ(printAttributes.HasColorMode(), true);
220 EXPECT_EQ(printAttributes.GetColorMode(), 1);
221 }
222
223 /**
224 * @tc.name: PrintAttributesTest_0010
225 * @tc.desc: Verify the SetDuplexMode function.
226 * @tc.type: FUNC
227 * @tc.require:
228 */
229 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0010, TestSize.Level1)
230 {
231 OHOS::Print::PrintAttributes printAttributes;
232 printAttributes.SetDuplexMode(1);
233 EXPECT_EQ(printAttributes.HasDuplexMode(), true);
234 EXPECT_EQ(printAttributes.GetDuplexMode(), 1);
235 }
236
237 /**
238 * @tc.name: PrintAttributesTest_0011
239 * @tc.desc: Verify the SetMargin function.
240 * @tc.type: FUNC
241 * @tc.require:
242 */
243 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0011, TestSize.Level1)
244 {
245 OHOS::Print::PrintAttributes printAttributes;
246 OHOS::Print::PrintMargin margin, getMargin;
247 margin.SetTop(1);
248 printAttributes.SetMargin(margin);
249 printAttributes.GetMargin(getMargin);
250 EXPECT_EQ(printAttributes.HasMargin(), true);
251 EXPECT_EQ(getMargin.GetTop(), 1);
252 }
253
254 /**
255 * @tc.name: PrintAttributesTest_0012
256 * @tc.desc: Verify the SetOption function.
257 * @tc.type: FUNC
258 * @tc.require:
259 */
260 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0012, TestSize.Level1)
261 {
262 OHOS::Print::PrintAttributes printAttributes;
263 printAttributes.SetOption("1");
264 EXPECT_EQ(printAttributes.HasOption(), true);
265 EXPECT_EQ(printAttributes.GetOption(), "1");
266 }
267
268 /**
269 * @tc.name: PrintAttributesTest_0013
270 * @tc.desc: Verify the marshalling function.
271 * @tc.type: FUNC
272 * @tc.require:
273 */
274 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0013, TestSize.Level1)
275 {
276 OHOS::Print::PrintAttributes printAttributes = GetDefaultPrintAttributes();
277 Parcel parcel;
278 EXPECT_TRUE(printAttributes.Marshalling(parcel));
279 auto result = OHOS::Print::PrintAttributes::Unmarshalling(parcel);
280 EXPECT_NE(nullptr, result);
281 }
282
283 /**
284 * @tc.name: PrintAttributesTest_0014
285 * @tc.desc: Verify the marshalling function.
286 * @tc.type: FUNC
287 * @tc.require:
288 */
289 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0014, TestSize.Level1)
290 {
291 OHOS::Print::PrintAttributes printAttributes;
292 printAttributes.Dump();
293 Parcel parcel;
294 EXPECT_TRUE(printAttributes.Marshalling(parcel));
295 auto result = OHOS::Print::PrintAttributes::Unmarshalling(parcel);
296 EXPECT_NE(nullptr, result);
297 }
298
299 /**
300 * @tc.name: PrintAttributesTest_0015
301 * @tc.desc: Verify the marshalling function.
302 * @tc.type: FUNC
303 * @tc.require:
304 */
305 HWTEST_F(PrintAttributesTest, PrintAttributesTest_0015, TestSize.Level1)
306 {
307 OHOS::Print::PrintAttributes printAttributes;
308 printAttributes.Dump();
309 Parcel parcel;
310 EXPECT_FALSE(printAttributes.ReadFromParcel(parcel));
311 }
312
313 } // namespace Print
314 } // namespace OHOS
315