1 /*
2 * Copyright (c) 2024 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 "swiper_test_ng.h"
17
18 #include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_paint_property.h"
19 #include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h"
20 #include "core/components_ng/pattern/text/text_model_ng.h"
21
22 namespace OHOS::Ace::NG {
23
24 namespace {} // namespace
25
26 class SwiperLayoutTestNg : public SwiperTestNg {
27 public:
28 void CheckItems(int32_t start, int32_t end, float prevMargin, float itemWidth);
29 };
30
31 /**
32 * @tc.name: ChangeSwiperSize001
33 * @tc.desc: Test change swiper size
34 * @tc.type: FUNC
35 */
36 HWTEST_F(SwiperLayoutTestNg, ChangeSwiperSize001, TestSize.Level1)
37 {
38 /**
39 * @tc.steps: step1. Not set size and item
40 */
41 SwiperModelNG swiperModel;
42 swiperModel.Create();
43 GetInstance();
44 FlushLayoutTask(frameNode_);
45 EXPECT_TRUE(IsEqual(frameNode_->GetGeometryNode()->GetFrameSize(), SizeF(0.f, 0.f)));
46
47 /**
48 * @tc.steps: step2. Add a item
49 */
50 TextModelNG textModel;
51 textModel.Create("text");
52 RefPtr<UINode> currentNode = ViewStackProcessor::GetInstance()->Finish();
53 auto currentFrameNode = AceType::DynamicCast<FrameNode>(currentNode);
54 currentFrameNode->MountToParent(frameNode_);
55 frameNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
56 FlushLayoutTask(frameNode_);
57 EXPECT_TRUE(IsEqual(frameNode_->GetGeometryNode()->GetFrameSize(), SizeF(0.f, 0.f)));
58
59 /**
60 * @tc.steps: step3. Set size
61 */
62 ViewAbstract::SetWidth(AceType::RawPtr(frameNode_), CalcLength(SWIPER_WIDTH));
63 ViewAbstract::SetHeight(AceType::RawPtr(frameNode_), CalcLength(SWIPER_HEIGHT));
64 FlushLayoutTask(frameNode_);
65 EXPECT_TRUE(IsEqual(frameNode_->GetGeometryNode()->GetFrameSize(), SizeF(SWIPER_WIDTH, SWIPER_HEIGHT)));
66
67 /**
68 * @tc.steps: step4. Change size
69 * @tc.expected: swiper size are changed
70 */
71 ViewAbstract::SetWidth(AceType::RawPtr(frameNode_), CalcLength(300.f));
72 ViewAbstract::SetHeight(AceType::RawPtr(frameNode_), CalcLength(500.f));
73 FlushLayoutTask(frameNode_);
74 EXPECT_TRUE(IsEqual(frameNode_->GetGeometryNode()->GetFrameSize(), SizeF(300.f, 500.f)));
75 }
76
CheckItems(int32_t start,int32_t end,float prevMargin,float itemWidth)77 void SwiperLayoutTestNg::CheckItems(int32_t start, int32_t end, float prevMargin, float itemWidth)
78 {
79 float offset = prevMargin - itemWidth;
80 float startPos = -itemWidth;
81 for (int i = start; i <= end; ++i) {
82 EXPECT_EQ(pattern_->itemPosition_.at(i).startPos, startPos);
83 EXPECT_EQ(pattern_->itemPosition_.at(i).endPos, startPos + itemWidth);
84 EXPECT_EQ(GetChildOffset(frameNode_, i).GetX(), offset);
85 startPos += itemWidth;
86 offset += itemWidth;
87 }
88 }
89
90 /**
91 * @tc.name: SwiperChangeWidth001
92 * @tc.desc: Test Swiper changing width and re-layout
93 * @tc.type: FUNC
94 */
95 HWTEST_F(SwiperLayoutTestNg, SwiperChangeWidth001, TestSize.Level1)
96 {
97 CreateWithItem(
__anon87f955260202(SwiperModelNG model) 98 [](SwiperModelNG model) {
99 model.SetDirection(Axis::HORIZONTAL);
100 model.SetDisplayCount(3);
101 model.SetPreviousMargin(Dimension(20), false);
102 model.SetNextMargin(Dimension(20), false);
103 },
104 5);
105 EXPECT_EQ(pattern_->itemPosition_.size(), 5);
106
107 ChangeIndex(1);
108 EXPECT_EQ(pattern_->currentIndex_, 1);
109 const float itemWidth1 = (SWIPER_WIDTH - 2 * 20.0f) / 3.0f;
110 CheckItems(0, 3, 20.0f, itemWidth1);
111
112 layoutProperty_->UpdateUserDefinedIdealSize(CalcSize(CalcLength(1000.0f), CalcLength(300.0f)));
113 frameNode_->MarkModifyDone();
114 FlushLayoutTask(frameNode_);
115 EXPECT_EQ(frameNode_->GetGeometryNode()->GetFrameSize().Width(), 1000.0f);
116 const float itemWidth2 = (1000.0f - 2 * 20.0f) / 3.0f;
117 CheckItems(0, 3, 20.0f, itemWidth2);
118 }
119
120 /**
121 * @tc.name: SwiperChangeWidth002
122 * @tc.desc: Test Swiper's parent changing width and re-layout
123 * @tc.type: FUNC
124 */
125 HWTEST_F(SwiperLayoutTestNg, SwiperChangeWidth002, TestSize.Level1)
126 {
127 CreateWithItem(
__anon87f955260302(SwiperModelNG model) 128 [](SwiperModelNG model) {
129 model.SetDirection(Axis::HORIZONTAL);
130 model.SetDisplayCount(3);
131 model.SetPreviousMargin(Dimension(20), false);
132 model.SetNextMargin(Dimension(20), false);
133 },
134 5);
135 layoutProperty_->ClearUserDefinedIdealSize(true, true);
136
137 auto parent = FrameNode::CreateFrameNode("parent", -1, AceType::MakeRefPtr<LinearLayoutPattern>(false));
138 parent->layoutProperty_->UpdateUserDefinedIdealSize(CalcSize(CalcLength(400.0f), CalcLength(300.0f)));
139 frameNode_->MountToParent(parent);
140
141 FlushLayoutTask(parent);
142
143 ChangeIndex(1);
144 EXPECT_EQ(pattern_->currentIndex_, 1);
145
146 const float itemWidth1 = (400.0f - 2 * 20.0f) / 3.0f;
147 CheckItems(0, 3, 20.0f, itemWidth1);
148
149 parent->layoutProperty_->UpdateUserDefinedIdealSize(CalcSize(CalcLength(800.0f), CalcLength(300.0f)));
150 FlushLayoutTask(parent);
151 EXPECT_EQ(frameNode_->GetGeometryNode()->GetFrameSize().Width(), 800.0f);
152 const float itemWidth2 = (800.0f - 2 * 20.0f) / 3.0f;
153 CheckItems(0, 3, 20.0f, itemWidth2);
154 }
155
156 /**
157 * @tc.name: SwiperFlex001
158 * @tc.desc: Test Swiper with Flex parent and layout
159 * @tc.type: FUNC
160 */
161 HWTEST_F(SwiperLayoutTestNg, SwiperFlex001, TestSize.Level1)
162 {
163 CreateWithItem(
__anon87f955260402(SwiperModelNG model) 164 [](SwiperModelNG model) {
165 model.SetDirection(Axis::HORIZONTAL);
166 model.SetDisplayCount(1);
167 },
168 5);
169 layoutProperty_->UpdateFlexGrow(2.0f);
170 layoutProperty_->UpdateFlexShrink(1.0f);
171 layoutProperty_->ClearUserDefinedIdealSize(true, true);
172
173 auto parent = FrameNode::CreateFrameNode("parent", -1, AceType::MakeRefPtr<LinearLayoutPattern>(false));
174 parent->layoutProperty_->UpdateUserDefinedIdealSize(CalcSize(CalcLength(500.0f), CalcLength(300.0f)));
175 frameNode_->MountToParent(parent);
176 // sibling node
177 auto sibling = FrameNode::CreateFrameNode("sibling", -1, AceType::MakeRefPtr<LinearLayoutPattern>(true));
178 sibling->layoutProperty_->UpdateUserDefinedIdealSize(CalcSize(CalcLength(100.0f), CalcLength(300.0f)));
179 sibling->MountToParent(parent);
180 parent->MarkModifyDone();
181
182 FlushLayoutTask(parent);
183 EXPECT_EQ(GetChildSize(frameNode_, 0).Width(), 400.0f);
184 EXPECT_EQ(pattern_->itemPosition_.size(), 1);
185
186 // ----currently doesn't work because Animation callbacks run synchronously
187 // WillRepeatedly([]() { FlushLayoutTask(parent) })
188
189 pattern_->ShowNext();
190 FlushLayoutTask(parent);
191 EXPECT_EQ(pattern_->currentIndex_, 1);
192 EXPECT_EQ(pattern_->itemPosition_.at(1).startPos, 400.0f);
193 EXPECT_EQ(GetChildOffset(frameNode_, 1).GetX(), 400.0f);
194 EXPECT_TRUE(GetChildFrameNode(frameNode_, 1)->IsActive());
195
196 // because FlushUITasks are not run, have to manually trigger offset update
197 pattern_->UpdateCurrentOffset(-400.0f);
198 FlushLayoutTask(parent);
199 EXPECT_EQ(pattern_->itemPosition_.size(), 1);
200 EXPECT_EQ(GetChildOffset(frameNode_, 1).GetX(), 0.0f);
201 }
202
203 /**
204 * @tc.name: SwiperLayoutAlgorithmLayout003
205 * @tc.desc: Test SwiperLayoutAlgorithm SwiperLayoutAlgorithmLayout
206 * @tc.type: FUNC
207 */
208 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayout003, TestSize.Level1)
209 {
__anon87f955260502(SwiperModelNG model) 210 CreateWithItem([](SwiperModelNG model) {
211 model.SetIndicatorType(SwiperIndicatorType::DIGIT);
212 });
213 Dimension dimension = 20.0_vp;
214 layoutProperty_->UpdateLeft(dimension);
215 layoutProperty_->UpdateTop(dimension);
216 layoutProperty_->UpdateDirection(Axis::HORIZONTAL);
217
218 /**
219 * @tc.steps: step3. call Layout.
220 * @tc.expected: indicatorNodeWrapper MarginFrameOffset is 20.0, 20.0 .
221 */
222 }
223
224 /**
225 * @tc.name: SwiperLayoutAlgorithmLayout004
226 * @tc.desc: Test SwiperLayoutAlgorithm SwiperLayoutAlgorithmLayout
227 * @tc.type: FUNC
228 */
229 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayout004, TestSize.Level1)
230 {
__anon87f955260602(SwiperModelNG model) 231 CreateWithItem([](SwiperModelNG model) {
232 model.SetIndicatorType(SwiperIndicatorType::DIGIT);
233 });
234 Dimension dimension = 20.0_vp;
235 layoutProperty_->UpdateRight(dimension);
236 layoutProperty_->UpdateBottom(dimension);
237 layoutProperty_->UpdateDirection(Axis::VERTICAL);
238
239 /**
240 * @tc.steps: step3. call Layout.
241 * @tc.expected: indicatorNodeWrapper MarginFrameOffset is 634.0, 1086.0 .
242 */
243 }
244
245 /**
246 * @tc.name: SwiperLayoutAlgorithmLayout005
247 * @tc.desc: Test SwiperLayoutAlgorithm Layout with arrow
248 * @tc.type: FUNC
249 */
250 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayout005, TestSize.Level1)
251 {
__anon87f955260702(SwiperModelNG model) 252 CreateWithItem([](SwiperModelNG model) {
253 model.SetDisplayArrow(true); // show arrow
254 model.SetHoverShow(false);
255 model.SetArrowStyle(ARROW_PARAMETERS);
256 });
257 auto indicatorGeometryNode = indicatorNode_->GetGeometryNode();
258 auto leftArrowGeometryNode = leftArrowNode_->GetGeometryNode();
259 auto rightArrowGeometryNode = rightArrowNode_->GetGeometryNode();
260
261 /**
262 * @tc.cases: case1. Axis is HORIZONTAL, arrow is in the switch.
263 */
264 indicatorGeometryNode->SetFrameOffset(OffsetF(250.0f, 190.0f));
265 indicatorGeometryNode->SetFrameSize(SizeF(144.0f, 48.0f));
266 FlushLayoutTask(frameNode_);
267 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(8.0f, 388.0f)));
268 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(448.0f, 388.0f)));
269
270 /**
271 * @tc.cases: case2. Axis is HORIZONTAL, arrow is outside the switch.
272 */
273 indicatorGeometryNode->SetFrameOffset(OffsetF(15.0f, 240.0f));
274 indicatorGeometryNode->SetFrameSize(SizeF(625.0f, 48.0f));
275 FlushLayoutTask(frameNode_);
276 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(8.0f, 388.0f)));
277 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(448.0f, 388.0f)));
278
279 /**
280 * @tc.cases: case3. Axis is HORIZONTAL, arrow is in the switch, not show indicator.
281 */
282 layoutProperty_->UpdateShowIndicator(false);
283 FlushLayoutTask(frameNode_);
284 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(8.0f, 388.0f)));
285 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(448.0f, 388.0f)));
286
287 /**
288 * @tc.cases: case4. Axis is VERTICAL, arrow is in the switch.
289 */
290 layoutProperty_->UpdateDirection(Axis::VERTICAL);
291 layoutProperty_->UpdateShowIndicator(true);
292 indicatorGeometryNode->SetFrameOffset(OffsetF(20.0f, 50.0f));
293 indicatorGeometryNode->SetFrameSize(SizeF(20.0f, 100.0f));
294 FlushLayoutTask(frameNode_);
295 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 8.0f)));
296 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 448.0f)));
297
298 /**
299 * @tc.cases: case5. Axis is VERTICAL, arrow is outside the switch.
300 */
301 indicatorGeometryNode->SetFrameOffset(OffsetF(20.0f, 15.0f));
302 indicatorGeometryNode->SetFrameSize(SizeF(20.0f, 220.0f));
303 FlushLayoutTask(frameNode_);
304 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 8.0f)));
305 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 448.0f)));
306
307 /**
308 * @tc.cases: case6. Axis is VERTICAL, arrow is in the switch, not show indicator.
309 */
310 layoutProperty_->UpdateShowIndicator(false);
311 FlushLayoutTask(frameNode_);
312 EXPECT_TRUE(IsEqual(leftArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 8.0f)));
313 EXPECT_TRUE(IsEqual(rightArrowGeometryNode->GetMarginFrameOffset(), OffsetF(228.0f, 448.0f)));
314 }
315
316 /**
317 * @tc.name: SwiperLayoutAlgorithmMeasure001
318 * @tc.desc: Test SwiperLayoutAlgorithm Measure with arrow
319 * @tc.type: FUNC
320 */
321 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmMeasure001, TestSize.Level1)
322 {
__anon87f955260802(SwiperModelNG model) 323 CreateWithItem([](SwiperModelNG model) {
324 model.SetDisplayArrow(true); // show arrow
325 model.SetHoverShow(false);
326 model.SetArrowStyle(ARROW_PARAMETERS);
327 });
328
329 /**
330 * @tc.steps: step4. call Measure.
331 * @tc.expected: Return button measure, SizeF(3.0f, 3.0f).
332 */
333 layoutProperty_->UpdateBackgroundSize(3.0_vp);
334 FlushLayoutTask(frameNode_);
335 EXPECT_EQ(leftArrowNode_->GetGeometryNode()->GetFrameSize(), SizeF(3.0f, 3.0f));
336 EXPECT_EQ(rightArrowNode_->GetGeometryNode()->GetFrameSize(), SizeF(3.0f, 3.0f));
337 }
338
339 /**
340 * @tc.name: SwiperPatternCreateLayoutAlgorithm001
341 * @tc.desc: CreateLayoutAlgorithm
342 * @tc.type: FUNC
343 */
344 HWTEST_F(SwiperLayoutTestNg, SwiperPatternCreateLayoutAlgorithm001, TestSize.Level1)
345 {
__anon87f955260902(SwiperModelNG model) 346 CreateWithItem([](SwiperModelNG model) {});
347 pattern_->jumpIndex_ = 0;
348 pattern_->targetIndex_ = 1;
349 layoutProperty_->UpdateLoop(true);
350 struct SwiperItemInfo swiperItemInfo;
351 swiperItemInfo.startPos = 1.0f;
352
353 /**
354 * @tc.steps: step3. call CreateLayoutAlgorithm.
355 * @tc.expected: Related function runs ok.
356 */
357 for (int i = 0; i <= 1; i++) {
358 for (int j = 0; j <= 1; j++) {
359 pattern_->CreateLayoutAlgorithm();
360 layoutProperty_->UpdateLoop(false);
361 }
362 pattern_->itemPosition_.emplace(std::make_pair(1, swiperItemInfo));
363 }
364 }
365
366 /**
367 * @tc.name: SwiperLayoutAlgorithmLayoutBackwardItem001
368 * @tc.desc: LayoutBackwardItem
369 * @tc.type: FUNC
370 */
371 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutBackwardItem001, TestSize.Level1)
372 {
__anon87f955260a02(SwiperModelNG model) 373 CreateWithItem([](SwiperModelNG model) {});
374 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955260b02() 375 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
376 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
377 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
378 LayoutConstraintF layoutConstraint;
379 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
380 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
381 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
382 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
383 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
384 Axis axis = Axis::HORIZONTAL;
385 int32_t currentIndex = 1;
386 float endPos = 0.1f;
387 float startPos = 0.2f;
388 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
389 swiperLayoutAlgorithm->isLoop_ = true;
390 auto firstLayoutWrapper =
391 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
392 layoutWrapper.AppendChild(firstLayoutWrapper);
393
394 /**
395 * @tc.steps: step2. call LayoutBackwardItem.
396 * @tc.expected: Related function runs ok.
397 */
398 for (int i = 0; i <= 1; i++) {
399 for (int j = 0; j <= 1; j++) {
400 swiperLayoutAlgorithm->LayoutBackwardItem(
401 &layoutWrapper, layoutConstraint, axis, currentIndex, endPos, startPos);
402 if (i == 1) {
403 swiperLayoutAlgorithm->isLoop_ = true;
404 continue;
405 }
406 swiperLayoutAlgorithm->isLoop_ = false;
407 }
408 currentIndex = 0;
409 }
410
411 currentIndex = 1;
412 indicatorNode_->tag_ = V2::SWIPER_LEFT_ARROW_ETS_TAG;
413 for (int i = 0; i <= 1; i++) {
414 for (int j = 0; j <= 1; j++) {
415 swiperLayoutAlgorithm->LayoutBackwardItem(
416 &layoutWrapper, layoutConstraint, axis, currentIndex, endPos, startPos);
417 if (i == 1) {
418 indicatorNode_->tag_ = V2::SWIPER_RIGHT_ARROW_ETS_TAG;
419 continue;
420 }
421 indicatorNode_->tag_ = V2::SWIPER_INDICATOR_ETS_TAG;
422 }
423 indicatorNode_->tag_ = V2::SWIPER_ETS_TAG;
424 }
425 }
426
427 /**
428 * @tc.name: SwiperLayoutAlgorithmLayoutForward001
429 * @tc.desc: LayoutForward
430 * @tc.type: FUNC
431 */
432 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward001, TestSize.Level1)
433 {
__anon87f955260c02(SwiperModelNG model) 434 CreateWithItem([](SwiperModelNG model) {});
435 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
436 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955260d02() 437 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
438 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
439 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
440 LayoutConstraintF layoutConstraint;
441 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
442 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
443 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
444 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
445 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
446 Axis axis = Axis::HORIZONTAL;
447 int32_t startIndex = 1;
448 float startPos = 0.0f;
449 swiperLayoutAlgorithm->targetIndex_ = 1;
450
451 /**
452 * @tc.steps: step2. call LayoutForward.
453 * @tc.expected: Related function runs ok.
454 */
455 for (int i = 0; i <= 1; i++) {
456 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
457 swiperLayoutAlgorithm->targetIndex_ = 0;
458 }
459 }
460
461 /**
462 * @tc.name: SwiperLayoutAlgorithmLayoutBackward001
463 * @tc.desc: LayoutBackward
464 * @tc.type: FUNC
465 */
466 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutBackward001, TestSize.Level1)
467 {
__anon87f955260e02(SwiperModelNG model) 468 CreateWithItem([](SwiperModelNG model) {});
469 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
470 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955260f02() 471 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
472 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
473 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
474 LayoutConstraintF layoutConstraint;
475 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
476 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
477 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
478 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
479 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
480 Axis axis = Axis::HORIZONTAL;
481 int32_t endIndex = 1;
482 float endPos = 0.0f;
483 swiperLayoutAlgorithm->targetIndex_ = 1;
484
485 /**
486 * @tc.steps: step2. call LayoutBackward.
487 * @tc.expected: Related function runs ok.
488 */
489 for (int i = 0; i <= 1; i++) {
490 swiperLayoutAlgorithm->LayoutBackward(&layoutWrapper, layoutConstraint, axis, endIndex, endPos);
491 swiperLayoutAlgorithm->targetIndex_ = 0;
492 }
493 }
494
495 /**
496 * @tc.name: SwiperLayoutAlgorithmSetInactive001
497 * @tc.desc: SetInactive
498 * @tc.type: FUNC
499 */
500 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmSetInactive001, TestSize.Level1)
501 {
__anon87f955261002(SwiperModelNG model) 502 CreateWithItem([](SwiperModelNG model) {});
503 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
504 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261102() 505 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
506 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
__anon87f955261202(SwiperModelNG model) 507 CreateWithItem([](SwiperModelNG model) {});
508 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, layoutProperty_);
509 float startMainPos = 0.1f;
510 float endMainPos = 0.0f;
511 int32_t targetIndex = 1;
512 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 1, 2 }));
513 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(2, SwiperItemInfo { 1, 2 }));
514 swiperLayoutAlgorithm->prevMargin_ = 0.0;
515 swiperLayoutAlgorithm->nextMargin_ = 0.0;
516
517 /**
518 * @tc.steps: step2. call SetInactive.
519 * @tc.expected: Related function runs ok.
520 */
521 for (int i = 0; i <= 1; i++) {
522 for (int j = 0; j <= 1; j++) {
523 swiperLayoutAlgorithm->SetInactive(&layoutWrapper, startMainPos, endMainPos, targetIndex);
524 startMainPos = 3;
525 }
526 swiperLayoutAlgorithm->prevMargin_ = 1.0;
527 }
528
529 for (int i = 0; i <= 1; i++) {
530 for (int j = 0; j <= 1; j++) {
531 swiperLayoutAlgorithm->SetInactive(&layoutWrapper, startMainPos, endMainPos, targetIndex);
532 endMainPos = 3;
533 }
534 swiperLayoutAlgorithm->nextMargin_ = 1.0;
535 }
536 }
537
538 /**
539 * @tc.name: SwiperLayoutAlgorithmLayoutForward002
540 * @tc.desc: LayoutForward
541 * @tc.type: FUNC
542 */
543 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward002, TestSize.Level1)
544 {
__anon87f955261302(SwiperModelNG model) 545 CreateWithItem([](SwiperModelNG model) {});
546 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
547 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261402() 548 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
549 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
550 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
551 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955261502() 552 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
553 layoutWrapper.currentChildCount_ = 2;
554 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
555 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
556 LayoutConstraintF layoutConstraint;
557 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
558 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
559 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
560 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
561 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
562 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
563 Axis axis = Axis::HORIZONTAL;
564 int32_t startIndex = 1;
565 float startPos = 0.0f;
566 swiperLayoutAlgorithm->targetIndex_ = 1;
567 swiperLayoutAlgorithm->SetTotalItemCount(1);
568 swiperLayoutAlgorithm->SetIsLoop(false);
569
570 /**
571 * @tc.steps: step2. call LayoutForward.
572 * @tc.expected: Related function runs ok.
573 */
574 for (int i = 0; i <= 1; i++) {
575 for (int j = 0; j <= 1; j++) {
576 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
577 if (i == 1) {
578 break;
579 }
580 swiperLayoutAlgorithm->SetIsLoop(true);
581 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateMinSize(Dimension(1));
582 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdatePrevMargin(Dimension(1));
583 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateNextMargin(Dimension(1));
584 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateDisplayCount(1);
585 }
586 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateMinSize(Dimension(-1));
587 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdatePrevMargin(Dimension(-1));
588 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateNextMargin(Dimension(1));
589 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.layoutProperty_)->UpdateDisplayCount(0);
590 }
591
592 for (int i = 0; i <= 1; i++) {
593 for (int j = 0; j <= 1; j++) {
594 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
595 if (i == 1) {
596 swiperLayoutAlgorithm->overScrollFeature_ = false;
597 }
598 swiperLayoutAlgorithm->overScrollFeature_ = true;
599 }
600 swiperLayoutAlgorithm->canOverScroll_ = true;
601 }
602 }
603
604 /**
605 * @tc.name: SwiperLayoutAlgorithmLayoutBackward002
606 * @tc.desc: LayoutBackward
607 * @tc.type: FUNC
608 */
609 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutBackward002, TestSize.Level1)
610 {
__anon87f955261602(SwiperModelNG model) 611 CreateWithItem([](SwiperModelNG model) {});
612 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
613 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261702() 614 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
615 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
616 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
617 LayoutConstraintF layoutConstraint;
618 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
619 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
620 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
621 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
622 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
623 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
624 Axis axis = Axis::HORIZONTAL;
625 int32_t endIndex = -1;
626 float endPos = 0.0f;
627 swiperLayoutAlgorithm->targetIndex_ = 1;
628 swiperLayoutAlgorithm->SetIsLoop(false);
629 swiperLayoutAlgorithm->totalItemCount_ = 2;
630 swiperLayoutAlgorithm->itemPosition_.clear();
631 layoutWrapper.currentChildCount_ = 2;
632
633 /**
634 * @tc.steps: step2. call LayoutBackward.
635 * @tc.expected: Related function runs ok.
636 */
637 for (int i = 0; i <= 1; i++) {
638 for (int j = 0; j <= 1; j++) {
639 swiperLayoutAlgorithm->LayoutBackward(&layoutWrapper, layoutConstraint, axis, endIndex, endPos);
640 if (i == 1) {
641 endIndex = 1;
642 auto indicatorNode_test =
643 FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon87f955261802() 644 []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
645 layoutWrapper.childrenMap_.emplace(
646 std::make_pair(1, AceType::MakeRefPtr<LayoutWrapperNode>(
647 indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
648 continue;
649 }
650 swiperLayoutAlgorithm->SetIsLoop(true);
651 }
652 swiperLayoutAlgorithm->SetIsLoop(false);
653 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 1, 2 }));
654 swiperLayoutAlgorithm->overScrollFeature_ = true;
655 }
656 }
657
658 /**
659 * @tc.name: SwiperLayoutAlgorithmPlaceDigitChild001
660 * @tc.desc: PlaceDigitChild
661 * @tc.type: FUNC
662 */
663 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmPlaceDigitChild001, TestSize.Level1)
664 {
__anon87f955261902(SwiperModelNG model) 665 CreateWithItem([](SwiperModelNG model) {});
666 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
667 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
668 auto indicatorWrapper =
669 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
670 auto layoutProperty = AceType::MakeRefPtr<SwiperLayoutProperty>();
671 auto firstChild = AccessibilityManager::DynamicCast<FrameNode>(indicatorNode_);
672 RefPtr<GeometryNode> firstGeometryNode = AceType::MakeRefPtr<GeometryNode>();
673 firstGeometryNode->Reset();
674 firstGeometryNode->SetFrameSize(SizeF(20.0, 20.0));
675 RefPtr<LayoutWrapperNode> firstLayoutWrapper =
676 AceType::MakeRefPtr<LayoutWrapperNode>(firstChild, firstGeometryNode, firstChild->GetLayoutProperty());
677 indicatorWrapper->AppendChild(firstLayoutWrapper);
678 auto lastChild = AccessibilityManager::DynamicCast<FrameNode>(indicatorNode_);
679 RefPtr<GeometryNode> lastGeometryNode = AceType::MakeRefPtr<GeometryNode>();
680 lastGeometryNode->Reset();
681 lastGeometryNode->SetFrameSize(SizeF(30.0, 30.0));
682 RefPtr<LayoutWrapperNode> lastLayoutWrapper =
683 AceType::MakeRefPtr<LayoutWrapperNode>(lastChild, lastGeometryNode, lastChild->GetLayoutProperty());
684 indicatorWrapper->AppendChild(lastLayoutWrapper);
685 layoutProperty->UpdateLeft(Dimension(1));
686 layoutProperty->UpdateTop(Dimension(1));
687 indicatorWrapper->layoutProperty_ = AceType::MakeRefPtr<LayoutProperty>();
688 LayoutConstraintF layoutConstraintF;
689 layoutConstraintF.parentIdealSize = OptionalSizeF(0.1f, 0.2f);
690 indicatorWrapper->GetLayoutProperty()->layoutConstraint_ = layoutConstraintF;
691 indicatorWrapper->currentChildCount_ = 1;
692
693 /**
694 * @tc.steps: step2. call PlaceDigitChild.
695 * @tc.expected: Related function runs ok.
696 */
697 for (int i = 0; i <= 1; i++) {
698 for (int j = 0; j <= 1; j++) {
699 swiperLayoutAlgorithm->PlaceDigitChild(indicatorWrapper, layoutProperty);
700 if (i == 1) {
701 layoutProperty->UpdateDirection(Axis::VERTICAL);
702 continue;
703 }
704 indicatorWrapper->currentChildCount_ = 2;
705 layoutProperty->padding_ = std::make_unique<PaddingProperty>();
706 layoutProperty->UpdateLeft(Dimension(0));
707 layoutProperty->UpdateRight(Dimension(1));
708 layoutProperty->UpdateTop(Dimension(0));
709 layoutProperty->UpdateBottom(Dimension(1));
710 }
711 layoutProperty->UpdateRight(Dimension(0));
712 layoutProperty->UpdateBottom(Dimension(0));
713 }
714 }
715
716 /**
717 * @tc.name: SwiperLayoutAlgorithmGetNodeLayoutWrapperByTag001
718 * @tc.desc: GetNodeLayoutWrapperByTag
719 * @tc.type: FUNC
720 */
721 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmGetNodeLayoutWrapperByTag001, TestSize.Level1)
722 {
__anon87f955261a02(SwiperModelNG model) 723 CreateWithItem([](SwiperModelNG model) {});
724 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
725 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261b02() 726 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
727 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
728 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
729 string tagName = V2::SWIPER_INDICATOR_ETS_TAG;
730 layoutWrapper.currentChildCount_ = 0;
731 indicatorNode_->pattern_ = AceType::MakeRefPtr<SwiperPattern>();
732 ASSERT_NE(indicatorNode_->pattern_, nullptr);
733 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->indicatorId_ = 1;
734 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->leftButtonId_ = 1;
735 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->rightButtonId_ = 1;
736
737 /**
738 * @tc.steps: step2. call GetNodeLayoutWrapperByTag.
739 * @tc.expected: Related function runs ok.
740 */
741 for (int i = 0; i <= 1; i++) {
742 for (int j = 0; j <= 1; j++) {
743 if (i == 1 && j == 1) {
744 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->indicatorId_.reset();
745 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->leftButtonId_ = 1;
746 }
747 for (int k = 0; k <= 1; k++) {
748 swiperLayoutAlgorithm->GetNodeLayoutWrapperByTag(&layoutWrapper, tagName);
749 if (i == 0 && j == 1) {
750 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->leftButtonId_.reset();
751 continue;
752 } else if (i == 1 && j == 0) {
753 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->indicatorId_ = 1;
754 continue;
755 } else if (i == 1 && j == 1) {
756 break;
757 }
758 layoutWrapper.currentChildCount_ = 1;
759 }
760 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->indicatorId_.reset();
761 }
762 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->rightButtonId_.reset();
763 }
764 AceType::DynamicCast<SwiperPattern>(indicatorNode_->pattern_)->leftButtonId_.reset();
765 swiperLayoutAlgorithm->GetNodeLayoutWrapperByTag(&layoutWrapper, tagName);
766 }
767
768 /**
769 * @tc.name: SwiperLayoutAlgorithmGetChildMaxSize001
770 * @tc.desc: GetChildMaxSize
771 * @tc.type: FUNC
772 */
773 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmGetChildMaxSize001, TestSize.Level1)
774 {
__anon87f955261c02(SwiperModelNG model) 775 CreateWithItem([](SwiperModelNG model) {});
776 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
777 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261d02() 778 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
779 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
780 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
781 layoutWrapper.currentChildCount_ = 2;
782 layoutWrapper.childrenMap_.emplace(std::make_pair(
783 0, AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty())));
784 layoutWrapper.childrenMap_.emplace(std::make_pair(
785 1, AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, nullptr, indicatorNode_->GetLayoutProperty())));
786 LayoutConstraintF layoutConstraint;
787 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
788 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
789 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
790 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
791 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
792 Axis axis = Axis::HORIZONTAL;
793 bool isMainAxis = true;
794 swiperLayoutAlgorithm->totalItemCount_ = 3;
795
796 /**
797 * @tc.steps: step2. call GetChildMaxSize.
798 * @tc.expected: Related function runs ok.
799 */
800 for (int i = 0; i <= 1; i++) {
801 swiperLayoutAlgorithm->GetChildMaxSize(&layoutWrapper, axis, isMainAxis);
802 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 1, 2 }));
803 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 1, 2 }));
804 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(2, SwiperItemInfo { 1, 2 }));
805 isMainAxis = false;
806 }
807 }
808
809 /**
810 * @tc.name: SwiperLayoutAlgorithmMeasureSwiper001
811 * @tc.desc: MeasureSwiper
812 * @tc.type: FUNC
813 */
814 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmMeasureSwiper001, TestSize.Level1)
815 {
__anon87f955261e02(SwiperModelNG model) 816 CreateWithItem([](SwiperModelNG model) {});
817 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
818 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955261f02() 819 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
820 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
821 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
822 layoutWrapper.currentChildCount_ = 2;
823 LayoutConstraintF layoutConstraint;
824 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
825 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
826 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
827 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
828 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
829 Axis axis = Axis::HORIZONTAL;
830 swiperLayoutAlgorithm->totalItemCount_ = 2;
831
832 /**
833 * @tc.steps: step2. call MeasureSwiper
834 * @tc.expected: Related function runs ok.
835 */
836 for (int i = 0; i <= 1; i++) {
837 for (int j = 0; j <= 1; j++) {
838 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
839 if (i == 1) {
840 int32_t targetIndex_test = 1;
841 swiperLayoutAlgorithm->SetTargetIndex(targetIndex_test);
842 continue;
843 }
844 swiperLayoutAlgorithm->prevMargin_ = 1.0f;
845 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 1, 1 }));
846 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 1, -1 }));
847 }
848 swiperLayoutAlgorithm->isLoop_ = false;
849 }
850
851 for (int i = 0; i <= 1; i++) {
852 for (int j = 0; j <= 1; j++) {
853 for (int k = 0; k <= 1; k++) {
854 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
855 if (j == 1) {
856 swiperLayoutAlgorithm->startMainPos_ = -1.0f;
857 continue;
858 }
859 if (i == 1) {
860 break;
861 }
862 swiperLayoutAlgorithm->jumpIndex_ = 1;
863 swiperLayoutAlgorithm->startMainPos_ = 1.0f;
864 }
865 if (i == 1) {
866 break;
867 }
868 swiperLayoutAlgorithm->jumpIndex_ = 0;
869 }
870 swiperLayoutAlgorithm->jumpIndex_ = 1;
871 swiperLayoutAlgorithm->startMainPos_ = -1.0f;
872 }
873
874 swiperLayoutAlgorithm->startMainPos_ = -1.0f;
875 for (int i = 0; i <= 1; i++) {
876 for (int j = 0; j <= 1; j++) {
877 for (int k = 0; k <= 1; k++) {
878 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
879 if (j == 1) {
880 swiperLayoutAlgorithm->startMainPos_ = -1.0f;
881 swiperLayoutAlgorithm->spaceWidth_ = 0.0f;
882 continue;
883 }
884 if (i == 1 && j == 1) {
885 break;
886 }
887 swiperLayoutAlgorithm->startMainPos_ = 2.0f;
888 swiperLayoutAlgorithm->spaceWidth_ = -2.0f;
889 }
890 if (i == 1) {
891 swiperLayoutAlgorithm->isLoop_ = true;
892 continue;
893 }
894 if (i == 1 && j == 1) {
895 break;
896 }
897 swiperLayoutAlgorithm->isLoop_ = false;
898 }
899 swiperLayoutAlgorithm->prevMargin_ = -1.0f;
900 }
901
902 swiperLayoutAlgorithm->jumpIndex_.reset();
903 for (int i = 0; i <= 1; i++) {
904 for (int j = 0; j <= 1; j++) {
905 for (int k = 0; k <= 1; k++) {
906 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
907 if (i == 1 && j == 0) {
908 swiperLayoutAlgorithm->endMainPos_ = -2.0f;
909 continue;
910 }
911 if (i == 1 && j == 1) {
912 swiperLayoutAlgorithm->prevMargin_ = 1.0f;
913 continue;
914 }
915 if (i == 1 && j == 1 && k == 1) {
916 break;
917 }
918 swiperLayoutAlgorithm->targetIndex_ = 1;
919 swiperLayoutAlgorithm->itemPosition_.clear();
920 }
921 if (i == 1) {
922 swiperLayoutAlgorithm->targetIndex_ = 0;
923 continue;
924 }
925 swiperLayoutAlgorithm->startMainPos_ = 2.0f;
926 }
927 swiperLayoutAlgorithm->targetIndex_ = -1.0f;
928 }
929
930 swiperLayoutAlgorithm->targetIndex_.reset();
931 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 1, 1 }));
932 for (int i = 0; i <= 1; i++) {
933 for (int j = 0; j <= 1; j++) {
934 for (int k = 0; k <= 1; k++) {
935 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
936 if (j == 1) {
937 swiperLayoutAlgorithm->itemPosition_.clear();
938 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 1, 1 }));
939 continue;
940 }
941 swiperLayoutAlgorithm->itemPosition_.clear();
942 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 3, 1 }));
943 swiperLayoutAlgorithm->currentOffset_ = -1.0f;
944 }
945 swiperLayoutAlgorithm->itemPosition_.clear();
946 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 3, 1 }));
947 }
948 swiperLayoutAlgorithm->overScrollFeature_ = true;
949 }
950
951 for (int i = 0; i <= 1; i++) {
952 for (int j = 0; j <= 1; j++) {
953 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
954 if (i == 1) {
955 swiperLayoutAlgorithm->endMainPos_ = 1.0f;
956 continue;
957 }
958 swiperLayoutAlgorithm->endMainPos_ = 2.0f;
959 }
960 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(-1, SwiperItemInfo { 3, 1 }));
961 }
962 swiperLayoutAlgorithm->overScrollFeature_ = false;
963 swiperLayoutAlgorithm->currentOffset_ = 0;
964 for (int i = 0; i <= 1; i++) {
965 for (int j = 0; j <= 1; j++) {
966 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
967 if (i == 1) {
968 swiperLayoutAlgorithm->startMainPos_ = 0;
969 continue;
970 }
971 swiperLayoutAlgorithm->startMainPos_ = 4;
972 }
973 swiperLayoutAlgorithm->itemPosition_.clear();
974 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(-1, SwiperItemInfo { 1, 1 }));
975 }
976 }
977
978 /**
979 * @tc.name: SwiperLayoutAlgorithmMeasureSwiper002
980 * @tc.desc: MeasureSwiper
981 * @tc.type: FUNC
982 */
983 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmMeasureSwiper002, TestSize.Level1)
984 {
__anon87f955262002(SwiperModelNG model) 985 CreateWithItem([](SwiperModelNG model) {});
986 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
987 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955262102() 988 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
989 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
990 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
991 layoutWrapper.currentChildCount_ = 2;
992 LayoutConstraintF layoutConstraint;
993 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
994 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
995 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
996 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
997 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
998 Axis axis = Axis::HORIZONTAL;
999 swiperLayoutAlgorithm->totalItemCount_ = 2;
1000 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 1.0f, 2.0f }));
1001 swiperLayoutAlgorithm->isLoop_ = false;
1002 swiperLayoutAlgorithm->targetIndex_ = 1;
1003
1004 /**
1005 * @tc.steps: step2. call MeasureSwiper
1006 * @tc.expected: Related function runs ok.
1007 */
1008 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
1009 }
1010
1011 /**
1012 * @tc.name: SwiperPatternCreateLayoutAlgorithm002
1013 * @tc.desc: CreateLayoutAlgorithm
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(SwiperLayoutTestNg, SwiperPatternCreateLayoutAlgorithm002, TestSize.Level1)
1017 {
__anon87f955262202(SwiperModelNG model) 1018 CreateWithItem([](SwiperModelNG model) {});
1019 pattern_->jumpIndex_.reset();
1020 pattern_->targetIndex_ = 1;
1021
1022 /**
1023 * @tc.steps: step2. call CreateLayoutAlgorithm.
1024 * @tc.expected: Related function runs ok.
1025 */
1026 pattern_->CreateLayoutAlgorithm();
1027 }
1028
1029 /**
1030 * @tc.name: SwiperPatternCreateLayoutAlgorithm003
1031 * @tc.desc: CreateLayoutAlgorithm
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(SwiperLayoutTestNg, SwiperPatternCreateLayoutAlgorithm003, TestSize.Level1)
1035 {
__anon87f955262302(SwiperModelNG model) 1036 CreateWithItem([](SwiperModelNG model) {});
1037 float velocity = 0.1f;
1038
1039 /**
1040 * @tc.steps: step2. call CreateLayoutAlgorithm.
1041 * @tc.expected: Related function runs ok.
1042 */
1043 for (int i = 0; i <= 1; i++) {
1044 pattern_->UpdateAnimationProperty(velocity);
1045 pattern_->isDragging_ = true;
1046 }
1047 }
1048
1049 /**
1050 * @tc.name: SwiperLayoutAlgorithmMeasureSwiper003
1051 * @tc.desc: MeasureSwiper
1052 * @tc.type: FUNC
1053 */
1054 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmMeasureSwiper003, TestSize.Level1)
1055 {
__anon87f955262402(SwiperModelNG model) 1056 CreateWithItem([](SwiperModelNG model) {});
1057 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1058 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955262502() 1059 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1060 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1061 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1062 layoutWrapper.currentChildCount_ = 2;
1063 LayoutConstraintF layoutConstraint;
1064 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1065 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1066 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1067 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1068 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1069 Axis axis = Axis::HORIZONTAL;
1070 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 1.0f, 0.0f }));
1071 swiperLayoutAlgorithm->prevMargin_ = -1.0f;
1072
1073 /**
1074 * @tc.steps: step2. call MeasureSwiper
1075 * @tc.expected: Related function runs ok.
1076 */
1077 swiperLayoutAlgorithm->MeasureSwiper(&layoutWrapper, layoutConstraint, axis);
1078 }
1079
1080 /**
1081 * @tc.name: SwiperLayoutAlgorithmLayoutForwardItem001
1082 * @tc.desc: LayoutForwardItem
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForwardItem001, TestSize.Level1)
1086 {
__anon87f955262602(SwiperModelNG model) 1087 CreateWithItem([](SwiperModelNG model) {});
1088 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955262702() 1089 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1090 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1091 auto layoutWrapper = LayoutWrapperNode(frameNode_, geometryNode, frameNode_->GetLayoutProperty());
1092 LayoutConstraintF layoutConstraint;
1093 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1094 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1095 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1096 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1097 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1098 Axis axis = Axis::HORIZONTAL;
1099 int32_t currentIndex = 0;
1100 float endPos = 0.1f;
1101 float startPos = 0.2f;
1102 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1103 swiperLayoutAlgorithm->isLoop_ = true;
1104 auto firstLayoutWrapper =
1105 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1106 layoutWrapper.currentChildCount_ = 1;
1107 layoutWrapper.AppendChild(firstLayoutWrapper);
1108 swiperLayoutAlgorithm->totalItemCount_ = 2;
1109 indicatorNode_->layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1110 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty())->ResetDisplayCount();
1111 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty())
1112 ->UpdateDisplayMode(SwiperDisplayMode::AUTO_LINEAR);
1113
1114 /**
1115 * @tc.steps: step2. call LayoutForwardItem.
1116 * @tc.expected: Related function runs ok.
1117 */
1118 swiperLayoutAlgorithm->LayoutForwardItem(&layoutWrapper, layoutConstraint, axis, currentIndex, endPos, startPos);
1119 }
1120
1121 /**
1122 * @tc.name: SwiperLayoutAlgorithmLayoutBackward004
1123 * @tc.desc: LayoutBackward
1124 * @tc.type: FUNC
1125 */
1126 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutBackward004, TestSize.Level1)
1127 {
__anon87f955262802(SwiperModelNG model) 1128 CreateWithItem([](SwiperModelNG model) {});
1129 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1130 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955262902() 1131 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1132 indicatorNode_->layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1133 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1134 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1135 LayoutConstraintF layoutConstraint;
1136 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1137 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1138 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1139 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1140 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1141 Axis axis = Axis::HORIZONTAL;
1142 int32_t endIndex = -1;
1143 float endPos = 2.0f;
1144 swiperLayoutAlgorithm->targetIndex_ = 1;
1145 swiperLayoutAlgorithm->isLoop_ = false;
1146 swiperLayoutAlgorithm->startMainPos_ = 0.0f;
1147 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 0.0f, 2.0f }));
1148 swiperLayoutAlgorithm->totalItemCount_ = 1;
1149 swiperLayoutAlgorithm->nextMargin_ = 0.0f;
1150 swiperLayoutAlgorithm->endMainPos_ = 1.0f;
1151 swiperLayoutAlgorithm->spaceWidth_ = 0.0f;
1152 swiperLayoutAlgorithm->overScrollFeature_ = false;
1153 int32_t currentIndex = 0;
1154 EXPECT_FALSE(
1155 swiperLayoutAlgorithm->LayoutBackwardItem(&layoutWrapper, layoutConstraint, axis, currentIndex, 0.0f, endPos));
1156 EXPECT_FLOAT_EQ(endPos, 2.0f);
1157 swiperLayoutAlgorithm->contentMainSize_ = 1.0f;
1158
1159 /**
1160 * @tc.steps: step2. call LayoutBackward.
1161 * @tc.expected: Related function runs ok.
1162 */
1163 for (int i = 0; i <= 1; i++) {
1164 for (int j = 0; j <= 1; j++) {
1165 swiperLayoutAlgorithm->LayoutBackward(&layoutWrapper, layoutConstraint, axis, endIndex, endPos);
1166 swiperLayoutAlgorithm->startMainPos_ = 0.0f;
1167 if (i == 1) {
1168 swiperLayoutAlgorithm->canOverScroll_ = false;
1169 continue;
1170 }
1171 swiperLayoutAlgorithm->canOverScroll_ = true;
1172 }
1173 swiperLayoutAlgorithm->jumpIndex_ = 1;
1174 }
1175 EXPECT_FLOAT_EQ(swiperLayoutAlgorithm->startMainPos_, 0.0f);
1176 EXPECT_TRUE(GreatNotEqual(endPos, swiperLayoutAlgorithm->startMainPos_));
1177 for (int i = 0; i <= 1; i++) {
1178 for (int j = 0; j <= 1; j++) {
1179 swiperLayoutAlgorithm->LayoutBackward(&layoutWrapper, layoutConstraint, axis, endIndex, endPos);
1180 swiperLayoutAlgorithm->startMainPos_ = 0.0f;
1181 if (i == 1) {
1182 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 2.0f, 2.0f }));
1183 swiperLayoutAlgorithm->mainSizeIsDefined_ = false;
1184 continue;
1185 }
1186 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 0.0f, 2.0f }));
1187 swiperLayoutAlgorithm->mainSizeIsDefined_ = true;
1188 }
1189 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 2.0f, 2.0f }));
1190 }
1191 EXPECT_FLOAT_EQ(swiperLayoutAlgorithm->contentMainSize_, 1.0f);
1192 }
1193
1194 /**
1195 * @tc.name: SwiperLayoutAlgorithmLayoutForward003
1196 * @tc.desc: LayoutForward
1197 * @tc.type: FUNC
1198 */
1199 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward003, TestSize.Level1)
1200 {
__anon87f955262a02(SwiperModelNG model) 1201 CreateWithItem([](SwiperModelNG model) {});
1202 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1203 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955262b02() 1204 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1205 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1206 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1207 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955262c02() 1208 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1209 layoutWrapper.currentChildCount_ = 2;
1210 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
1211 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
1212 LayoutConstraintF layoutConstraint;
1213 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1214 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1215 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1216 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1217 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1218 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1219 Axis axis = Axis::HORIZONTAL;
1220 int32_t startIndex = 1;
1221 float startPos = 0.0f;
1222 swiperLayoutAlgorithm->targetIndex_ = 1;
1223 swiperLayoutAlgorithm->SetTotalItemCount(2);
1224 swiperLayoutAlgorithm->SetIsLoop(true);
1225 auto layoutProperty_ = AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty());
1226 layoutProperty_->UpdateMinSize(Dimension(1));
1227 layoutProperty_->UpdateDisplayCount(1);
1228 layoutProperty_->UpdateDisplayMode(SwiperDisplayMode::STRETCH);
1229
1230 /**
1231 * @tc.steps: step2. call LayoutForward.
1232 * @tc.expected: Related function runs ok.
1233 */
1234 for (int i = 0; i <= 1; i++) {
1235 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
1236 layoutProperty_->UpdateMinSize(Dimension(0));
1237 layoutProperty_->UpdateDisplayCount(0);
1238 layoutProperty_->UpdateDisplayMode(SwiperDisplayMode::AUTO_LINEAR);
1239 }
1240 }
1241
1242 /**
1243 * @tc.name: SwiperLayoutAlgorithmLayoutForward004
1244 * @tc.desc: LayoutForward
1245 * @tc.type: FUNC
1246 */
1247 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward004, TestSize.Level1)
1248 {
__anon87f955262d02(SwiperModelNG model) 1249 CreateWithItem([](SwiperModelNG model) {});
1250 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1251 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955262e02() 1252 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1253 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1254 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1255 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955262f02() 1256 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1257 layoutWrapper.currentChildCount_ = 2;
1258 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
1259 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
1260 LayoutConstraintF layoutConstraint;
1261 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1262 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1263 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1264 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1265 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1266 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1267 Axis axis = Axis::HORIZONTAL;
1268 int32_t startIndex = 1;
1269 float startPos = 0.0f;
1270 swiperLayoutAlgorithm->targetIndex_ = 1;
1271 swiperLayoutAlgorithm->SetTotalItemCount(2);
1272 swiperLayoutAlgorithm->SetIsLoop(true);
1273 swiperLayoutAlgorithm->SetCanOverScroll(false);
1274 auto layoutProperty_ = AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty());
1275 layoutProperty_->UpdateMinSize(Dimension(0));
1276 layoutProperty_->UpdateDisplayCount(1);
1277 layoutProperty_->UpdatePrevMargin(Dimension(0));
1278 layoutProperty_->UpdateNextMargin(Dimension(0));
1279 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(0, SwiperItemInfo { 0.0f, 1.0f }));
1280
1281 /**
1282 * @tc.steps: step2. call LayoutForward.
1283 * @tc.expected: Related function runs ok.
1284 */
1285 for (int i = 0; i <= 1; i++) {
1286 for (int j = 0; j <= 1; j++) {
1287 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
1288 if (i == 1) {
1289 swiperLayoutAlgorithm->mainSizeIsDefined_ = false;
1290 continue;
1291 }
1292 swiperLayoutAlgorithm->mainSizeIsDefined_ = true;
1293 }
1294 layoutProperty_->UpdateMinSize(Dimension(1));
1295 }
1296 EXPECT_FLOAT_EQ(swiperLayoutAlgorithm->endMainPos_, 480.0f);
1297 }
1298
1299 /**
1300 * @tc.name: SwiperLayoutAlgorithmLayoutForward005
1301 * @tc.desc: LayoutForward
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward005, TestSize.Level1)
1305 {
__anon87f955263002(SwiperModelNG model) 1306 CreateWithItem([](SwiperModelNG model) {});
1307 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1308 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955263102() 1309 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1310 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1311 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1312 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955263202() 1313 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1314 layoutWrapper.currentChildCount_ = 2;
1315 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
1316 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
1317 LayoutConstraintF layoutConstraint;
1318 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1319 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1320 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1321 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1322 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1323 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1324 Axis axis = Axis::HORIZONTAL;
1325 int32_t startIndex = 1;
1326 float startPos = 0.0f;
1327 swiperLayoutAlgorithm->targetIndex_ = 1;
1328 swiperLayoutAlgorithm->SetTotalItemCount(2);
1329 swiperLayoutAlgorithm->SetIsLoop(true);
1330 auto layoutProperty_ = AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty());
1331 layoutProperty_->UpdateMinSize(Dimension(1));
1332 layoutProperty_->UpdateDisplayCount(1);
1333 layoutProperty_->UpdateDisplayMode(SwiperDisplayMode::STRETCH);
1334 float currentEndPos = startPos;
1335 float currentStartPos = 0.0f;
1336 auto currentIndex = startIndex - 1;
1337 auto result = swiperLayoutAlgorithm->LayoutForwardItem(
1338 &layoutWrapper, layoutConstraint, axis, currentIndex, currentStartPos, currentEndPos);
1339 EXPECT_TRUE(result);
1340
1341 /**
1342 * @tc.steps: step2. call LayoutForward.
1343 * @tc.expected: Related function runs ok.
1344 */
1345 for (int i = 0; i <= 1; i++) {
1346 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
1347 startIndex = 2;
1348 }
1349 }
1350
1351 /**
1352 * @tc.name: SwiperLayoutAlgorithmLayoutForward006
1353 * @tc.desc: LayoutForward
1354 * @tc.type: FUNC
1355 */
1356 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward006, TestSize.Level1)
1357 {
__anon87f955263302(SwiperModelNG model) 1358 CreateWithItem([](SwiperModelNG model) {});
1359 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1360 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955263402() 1361 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1362 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1363 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1364 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955263502() 1365 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1366 layoutWrapper.currentChildCount_ = 2;
1367 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
1368 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
1369 LayoutConstraintF layoutConstraint;
1370 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1371 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1372 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1373 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1374 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1375 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1376 Axis axis = Axis::HORIZONTAL;
1377 int32_t startIndex = 1;
1378 float startPos = 0.0f;
1379 swiperLayoutAlgorithm->targetIndex_ = 1;
1380 swiperLayoutAlgorithm->SetTotalItemCount(1);
1381 swiperLayoutAlgorithm->SetIsLoop(true);
1382 auto layoutProperty_ = AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty());
1383 layoutProperty_->UpdateMinSize(Dimension(1));
1384 layoutProperty_->UpdateDisplayCount(1);
1385 layoutProperty_->UpdateDisplayMode(SwiperDisplayMode::STRETCH);
1386 swiperLayoutAlgorithm->jumpIndex_ = 1;
1387 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 0.0f, 1.0f }));
1388 swiperLayoutAlgorithm->endMainPos_ = 1.0f;
1389
1390 /**
1391 * @tc.steps: step2. call LayoutForward.
1392 * @tc.expected: Related function runs ok.
1393 */
1394 for (int i = 0; i <= 1; i++) {
1395 for (int j = 0; j <= 1; j++) {
1396 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
1397 swiperLayoutAlgorithm->endMainPos_ = 1.0f;
1398 if (i == 1) {
1399 swiperLayoutAlgorithm->canOverScroll_ = false;
1400 continue;
1401 }
1402 swiperLayoutAlgorithm->canOverScroll_ = true;
1403 }
1404 swiperLayoutAlgorithm->jumpIndex_.reset();
1405 }
1406 }
1407
1408 /**
1409 * @tc.name: SwiperLayoutAlgorithmLayoutForward007
1410 * @tc.desc: LayoutForward
1411 * @tc.type: FUNC
1412 */
1413 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForward007, TestSize.Level1)
1414 {
__anon87f955263602(SwiperModelNG model) 1415 CreateWithItem([](SwiperModelNG model) {});
1416 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1417 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955263702() 1418 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1419 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1420 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1421 auto indicatorNode_test = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
__anon87f955263802() 1422 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1423 layoutWrapper.currentChildCount_ = 2;
1424 layoutWrapper.childrenMap_.emplace(std::make_pair(1,
1425 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_test, geometryNode, indicatorNode_->GetLayoutProperty())));
1426 LayoutConstraintF layoutConstraint;
1427 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1428 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1429 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1430 layoutWrapper.layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1431 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1432 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1433 Axis axis = Axis::HORIZONTAL;
1434 int32_t startIndex = 1;
1435 float startPos = 0.0f;
1436 swiperLayoutAlgorithm->targetIndex_ = 1;
1437 swiperLayoutAlgorithm->SetTotalItemCount(1);
1438 swiperLayoutAlgorithm->SetIsLoop(true);
1439 auto layoutProperty_ = AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty());
1440 layoutProperty_->UpdateMinSize(Dimension(1));
1441 layoutProperty_->UpdateDisplayCount(1);
1442 layoutProperty_->UpdateDisplayMode(SwiperDisplayMode::STRETCH);
1443 swiperLayoutAlgorithm->jumpIndex_ = 1;
1444 swiperLayoutAlgorithm->itemPosition_.emplace(std::make_pair(1, SwiperItemInfo { 0.0f, 0.0f }));
1445 swiperLayoutAlgorithm->prevMargin_ = 0.0f;
1446 swiperLayoutAlgorithm->contentMainSize_ = 0.0f;
1447
1448 /**
1449 * @tc.steps: step2. call LayoutForward.
1450 * @tc.expected: Related function runs ok.
1451 */
1452 swiperLayoutAlgorithm->LayoutForward(&layoutWrapper, layoutConstraint, axis, startIndex, startPos);
1453 EXPECT_FALSE(swiperLayoutAlgorithm->itemPosition_.empty());
1454 }
1455
1456 /**
1457 * @tc.name: SwiperPatternAlgorithmMeasure001
1458 * @tc.desc: Measure
1459 * @tc.type: FUNC
1460 */
1461 HWTEST_F(SwiperLayoutTestNg, SwiperPatternAlgorithmMeasure001, TestSize.Level1)
1462 {
__anon87f955263902(SwiperModelNG model) 1463 CreateWithItem([](SwiperModelNG model) {
1464 model.SetDisplayArrow(true); // show arrow
1465 model.SetHoverShow(false);
1466 model.SetArrowStyle(ARROW_PARAMETERS);
1467 });
1468 layoutProperty_->UpdateBackgroundSize(3.0_vp);
1469 FlushLayoutTask(frameNode_);
1470
1471 /**
1472 * @tc.steps: step4. call Measure.
1473 * @tc.expected: Return button measure, SizeF(3.0f, 3.0f).
1474 */
1475 auto swiperPatternAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1476 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1477 FlushLayoutTask(frameNode_);
1478 EXPECT_TRUE(swiperPatternAlgorithm->mainSizeIsMeasured_);
1479
1480 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1481 frameNode_->isConstraintNotChanged_ = true;
1482 FlushLayoutTask(frameNode_);
1483 EXPECT_TRUE(frameNode_->isConstraintNotChanged_);
1484 }
1485
1486 /**
1487 * @tc.name: SwiperLayoutAlgorithmLayout006
1488 * @tc.desc: Test SwiperLayoutAlgorithm Layout with arrow
1489 * @tc.type: FUNC
1490 */
1491 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayout006, TestSize.Level1)
1492 {
__anon87f955263a02(SwiperModelNG model) 1493 CreateWithItem([](SwiperModelNG model) {
1494 model.SetDisplayArrow(true); // show arrow
1495 model.SetHoverShow(false);
1496 model.SetArrowStyle(ARROW_PARAMETERS);
1497 });
1498 auto indicatorGeometryNode = indicatorNode_->GetGeometryNode();
1499 indicatorGeometryNode->SetFrameOffset(OffsetF(250.0f, 190.0f));
1500 indicatorGeometryNode->SetFrameSize(SizeF(144.0f, 48.0f));
1501
1502 /**
1503 * @tc.cases: case3. Axis is HORIZONTAL, arrow is in the switch, not show indicator.
1504 */
1505 layoutProperty_->UpdateShowIndicator(false);
1506 pattern_->leftButtonId_.reset();
1507 pattern_->rightButtonId_.reset();
1508 FlushLayoutTask(frameNode_);
1509
1510 pattern_->leftButtonId_.emplace(1);
1511 pattern_->rightButtonId_.emplace(1);
1512 FlushLayoutTask(frameNode_);
1513 }
1514
1515 /**
1516 * @tc.name: SwiperLayoutAlgorithmLayoutForwardItem002
1517 * @tc.desc: LayoutForwardItem
1518 * @tc.type: FUNC
1519 */
1520 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmLayoutForwardItem002, TestSize.Level1)
1521 {
__anon87f955263b02(SwiperModelNG model) 1522 CreateWithItem([](SwiperModelNG model) {});
1523 auto indicatorNode_ =
__anon87f955263c02() 1524 FrameNode::GetOrCreateFrameNode("test", 1, []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1525 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1526 auto layoutWrapper = LayoutWrapperNode(frameNode_, geometryNode, frameNode_->GetLayoutProperty());
1527 LayoutConstraintF layoutConstraint;
1528 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1529 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1530 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1531 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1532 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1533 Axis axis = Axis::HORIZONTAL;
1534 int32_t currentIndex = 0;
1535 float endPos = 0.1f;
1536 float startPos = 0.2f;
1537 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1538 swiperLayoutAlgorithm->isLoop_ = true;
1539 auto firstLayoutWrapper =
1540 AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1541 layoutWrapper.currentChildCount_ = 1;
1542 layoutWrapper.AppendChild(firstLayoutWrapper);
1543 swiperLayoutAlgorithm->totalItemCount_ = 2;
1544 indicatorNode_->layoutProperty_ = AceType::MakeRefPtr<SwiperLayoutProperty>();
1545 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty())->ResetDisplayCount();
1546 AceType::DynamicCast<SwiperLayoutProperty>(layoutWrapper.GetLayoutProperty())
1547 ->UpdateDisplayMode(SwiperDisplayMode::AUTO_LINEAR);
1548
1549 /**
1550 * @tc.steps: step2. call LayoutForwardItem in different layoutWrapper and make the return value false.
1551 * @tc.expected: Related function runs ok.
1552 */
1553 currentIndex = 0;
1554 auto swiperNode2 = FrameNode::GetOrCreateFrameNode(
__anon87f955263d02() 1555 V2::SWIPER_RIGHT_ARROW_ETS_TAG, 2, []() { return AceType::MakeRefPtr<SwiperPattern>(); });
1556 auto layoutWrapper2 = LayoutWrapperNode(swiperNode2, geometryNode, swiperNode2->GetLayoutProperty());
1557 swiperLayoutAlgorithm->LayoutForwardItem(&layoutWrapper2, layoutConstraint, axis, currentIndex, endPos, startPos);
1558 auto result2 = swiperLayoutAlgorithm->LayoutForwardItem(
1559 &layoutWrapper2, layoutConstraint, axis, currentIndex, endPos, startPos);
1560 EXPECT_FALSE(result2);
1561 currentIndex = 0;
1562 auto swiperNode3 = FrameNode::GetOrCreateFrameNode(
__anon87f955263e02() 1563 V2::SWIPER_LEFT_ARROW_ETS_TAG, 3, []() { return AceType::MakeRefPtr<SwiperPattern>(); });
1564 auto layoutWrapper3 = LayoutWrapperNode(swiperNode3, geometryNode, swiperNode3->GetLayoutProperty());
1565 swiperLayoutAlgorithm->LayoutForwardItem(&layoutWrapper3, layoutConstraint, axis, currentIndex, endPos, startPos);
1566 auto result3 = swiperLayoutAlgorithm->LayoutForwardItem(
1567 &layoutWrapper3, layoutConstraint, axis, currentIndex, endPos, startPos);
1568 EXPECT_FALSE(result3);
1569 currentIndex = 0;
1570 auto swiperNode4 = FrameNode::GetOrCreateFrameNode(
__anon87f955263f02() 1571 V2::SWIPER_INDICATOR_ETS_TAG, 4, []() { return AceType::MakeRefPtr<SwiperPattern>(); });
1572 auto layoutWrapper4 = LayoutWrapperNode(swiperNode4, geometryNode, swiperNode2->GetLayoutProperty());
1573 swiperLayoutAlgorithm->LayoutForwardItem(&layoutWrapper4, layoutConstraint, axis, currentIndex, endPos, startPos);
1574 auto result4 = swiperLayoutAlgorithm->LayoutForwardItem(
1575 &layoutWrapper2, layoutConstraint, axis, currentIndex, endPos, startPos);
1576 EXPECT_FALSE(result4);
1577
1578 /**
1579 * @tc.steps: step3. call LayoutForwardItem in different layoutWrapper and make the return value ture.
1580 * @tc.expected: Related function runs ok.
1581 */
1582 currentIndex = 0;
1583 auto wrapper = layoutWrapper.GetOrCreateChildByIndex(1);
1584 auto layoutProperty = wrapper->GetLayoutProperty();
1585 layoutProperty->UpdateVisibility(VisibleType::GONE);
1586 swiperLayoutAlgorithm->LayoutForwardItem(&layoutWrapper, layoutConstraint, axis, currentIndex, endPos, startPos);
1587 auto result = swiperLayoutAlgorithm->LayoutForwardItem(
1588 &layoutWrapper2, layoutConstraint, axis, currentIndex, endPos, startPos);
1589 EXPECT_NE(result, true);
1590 }
1591
1592 /**
1593 * @tc.name: SwiperLayoutAlgorithmGetChildMaxSize002
1594 * @tc.desc: GetChildMaxSize
1595 * @tc.type: FUNC
1596 */
1597 HWTEST_F(SwiperLayoutTestNg, SwiperLayoutAlgorithmGetChildMaxSize002, TestSize.Level1)
1598 {
1599 /**
1600 * @tc.steps: step1. Default value
1601 */
__anon87f955264002(SwiperModelNG model) 1602 CreateWithItem([](SwiperModelNG model) {});
1603 auto swiperLayoutAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1604
1605 auto indicatorNode_ = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG,
__anon87f955264102() 1606 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
1607 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1608 auto layoutWrapper = LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1609
1610 layoutWrapper.currentChildCount_ = 2;
1611 layoutWrapper.childrenMap_.emplace(std::make_pair(
1612 0, AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty())));
1613 layoutWrapper.childrenMap_.emplace(std::make_pair(
1614 1, AceType::MakeRefPtr<LayoutWrapperNode>(indicatorNode_, nullptr, indicatorNode_->GetLayoutProperty())));
1615
1616 LayoutConstraintF layoutConstraint;
1617 layoutConstraint.maxSize = SizeF(720.f, 1136.f);
1618 layoutConstraint.percentReference = SizeF(720.f, 1136.f);
1619 layoutConstraint.parentIdealSize.SetSize(SizeF(720.f, 1136.f));
1620 ASSERT_NE(layoutWrapper.layoutProperty_, nullptr);
1621
1622 layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(layoutConstraint);
1623 Axis axis = Axis::HORIZONTAL;
1624 bool isMainAxis = true;
1625 swiperLayoutAlgorithm->totalItemCount_ = 3;
1626
1627 /**
1628 * @tc.steps: step2. call GetChildMaxSize.
1629 * @tc.expected: GetChildMaxSize->itemPosition_ not empty
1630 */
1631 swiperLayoutAlgorithm->itemPosition_.clear();
1632 swiperLayoutAlgorithm->GetChildMaxSize(&layoutWrapper, axis, isMainAxis);
1633 EXPECT_TRUE(swiperLayoutAlgorithm->itemPosition_.empty());
1634 }
1635
1636 /**
1637 * @tc.name: SwiperPatternAlgorithmMeasure003
1638 * @tc.desc: Measure
1639 * @tc.type: FUNC
1640 */
1641 HWTEST_F(SwiperLayoutTestNg, SwiperPatternAlgorithmMeasure003, TestSize.Level1)
1642 {
__anon87f955264202(SwiperModelNG model) 1643 CreateWithItem([](SwiperModelNG model) {
1644 model.SetDisplayArrow(true); // show arrow
1645 model.SetHoverShow(false);
1646 model.SetArrowStyle(ARROW_PARAMETERS);
1647 });
1648 layoutProperty_->UpdateBackgroundSize(3.0_vp);
1649 FlushLayoutTask(frameNode_);
1650
1651 auto swiperPatternAlgorithm = AceType::DynamicCast<SwiperLayoutAlgorithm>(pattern_->CreateLayoutAlgorithm());
1652 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1653 FlushLayoutTask(frameNode_);
1654 EXPECT_TRUE(swiperPatternAlgorithm->mainSizeIsMeasured_);
1655
1656 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1657 frameNode_->isConstraintNotChanged_ = true;
1658 FlushLayoutTask(frameNode_);
1659 EXPECT_TRUE(frameNode_->isConstraintNotChanged_);
1660
1661 /**
1662 * @tc.steps: step1. Set totalItemCount_ Equal to 0
1663 * @tc.expected: SwitchPatternAlgorithm ->totalitemCount_== 0 condition is true
1664 */
1665 swiperPatternAlgorithm->totalItemCount_ = 0;
1666 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1667 FlushLayoutTask(frameNode_);
1668 EXPECT_TRUE(swiperPatternAlgorithm->totalItemCount_ == 0);
1669
1670 /**
1671 * @tc.steps: step1. Set totalItem Count_ Greater than 0
1672 * @tc.expected: SwitchPatternAlgorithm ->totalitemCount_ Condition greater than 0 is true
1673 */
1674 swiperPatternAlgorithm->totalItemCount_ = 10;
1675 swiperPatternAlgorithm->mainSizeIsMeasured_ = true;
1676 frameNode_->isConstraintNotChanged_ = true;
1677 FlushLayoutTask(frameNode_);
1678 EXPECT_TRUE(swiperPatternAlgorithm->totalItemCount_ > 0);
1679 }
1680
1681 /**
1682 * @tc.name: ItemWidth001
1683 * @tc.desc: Test SwiperIndicator ItemWidth
1684 * @tc.type: FUNC
1685 */
1686 HWTEST_F(SwiperLayoutTestNg, ItemWidth001, TestSize.Level1)
1687 {
__anon87f955264302(SwiperModelNG model) 1688 CreateWithItem([](SwiperModelNG model) {});
1689 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1690 RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
1691 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1692 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1693 paintProperty->UpdateItemWidth(Dimension(-1.0, DimensionUnit::PX));
1694
1695 /**
1696 * @tc.steps: step3. userSize is less not equal 0.
1697 */
1698 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1699 LayoutWrapperNode layoutWrapper =
1700 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1701 algorithm->Measure(&layoutWrapper);
1702 }
1703
1704 /**
1705 * @tc.name: ItemWidth002
1706 * @tc.desc: Test SwiperIndicator ItemWidth
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(SwiperLayoutTestNg, ItemWidth002, TestSize.Level1)
1710 {
__anon87f955264402(SwiperModelNG model) 1711 CreateWithItem([](SwiperModelNG model) {
1712 model.SetDirection(Axis::VERTICAL);
1713 });
1714 layoutProperty_->UpdateDirection(Axis::VERTICAL);
1715 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1716 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1717 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1718 paintProperty->UpdateItemWidth(Dimension(-1000.0, DimensionUnit::PX));
1719
1720 /**
1721 * @tc.steps: step3. ItemWidth is great then 0.
1722 */
1723 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1724 LayoutWrapperNode layoutWrapper =
1725 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1726 algorithm->Measure(&layoutWrapper);
1727 }
1728
1729 /**
1730 * @tc.name: ItemHeight001
1731 * @tc.desc: Test SwiperIndicator ItemHeight
1732 * @tc.type: FUNC
1733 */
1734 HWTEST_F(SwiperLayoutTestNg, ItemHeight001, TestSize.Level1)
1735 {
__anon87f955264502(SwiperModelNG model) 1736 CreateWithItem([](SwiperModelNG model) {});
1737 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1738 RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
1739 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1740 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1741 paintProperty->UpdateItemHeight(Dimension(-1.0, DimensionUnit::PX));
1742
1743 /**
1744 * @tc.steps: step3. ItemHeight is less not equal 0.
1745 */
1746 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1747 LayoutWrapperNode layoutWrapper =
1748 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1749 algorithm->Measure(&layoutWrapper);
1750 }
1751
1752 /**
1753 * @tc.name: ItemHeight002
1754 * @tc.desc: Test SwiperIndicator ItemHeight
1755 * @tc.type: FUNC
1756 */
1757 HWTEST_F(SwiperLayoutTestNg, ItemHeight002, TestSize.Level1)
1758 {
__anon87f955264602(SwiperModelNG model) 1759 CreateWithItem([](SwiperModelNG model) {
1760 model.SetDirection(Axis::VERTICAL);
1761 });
1762 layoutProperty_->UpdateDirection(Axis::VERTICAL);
1763 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1764 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1765 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1766 paintProperty->UpdateItemHeight(Dimension(-1000.0, DimensionUnit::PX));
1767
1768 /**
1769 * @tc.steps: step3. ItemHeight is great then 0.
1770 */
1771 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1772 LayoutWrapperNode layoutWrapper =
1773 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1774 algorithm->Measure(&layoutWrapper);
1775 }
1776
1777 /**
1778 * @tc.name: SelectedItemWidth001
1779 * @tc.desc: Test SwiperIndicator SelectedItemWidth
1780 * @tc.type: FUNC
1781 */
1782 HWTEST_F(SwiperLayoutTestNg, SelectedItemWidth001, TestSize.Level1)
1783 {
__anon87f955264702(SwiperModelNG model) 1784 CreateWithItem([](SwiperModelNG model) {});
1785 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1786 RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
1787 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1788 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1789 paintProperty->UpdateSelectedItemWidth(Dimension(-1.0, DimensionUnit::PX));
1790
1791 /**
1792 * @tc.steps: step3. SelectedItemWidth is less not equal 0.
1793 */
1794 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1795 LayoutWrapperNode layoutWrapper =
1796 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1797 algorithm->Measure(&layoutWrapper);
1798 }
1799
1800 /**
1801 * @tc.name: SelectedItemWidth002
1802 * @tc.desc: Test SwiperIndicator SelectedItemWidth
1803 * @tc.type: FUNC
1804 */
1805 HWTEST_F(SwiperLayoutTestNg, SelectedItemWidth002, TestSize.Level1)
1806 {
__anon87f955264802(SwiperModelNG model) 1807 CreateWithItem([](SwiperModelNG model) {
1808 model.SetDirection(Axis::VERTICAL);
1809 });
1810 layoutProperty_->UpdateDirection(Axis::VERTICAL);
1811 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1812 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1813 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1814 paintProperty->UpdateSelectedItemWidth(Dimension(-1000.0, DimensionUnit::PX));
1815
1816 /**
1817 * @tc.steps: step3. SelectedItemWidth is great then 0.
1818 */
1819 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1820 LayoutWrapperNode layoutWrapper =
1821 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1822 algorithm->Measure(&layoutWrapper);
1823 }
1824
1825 /**
1826 * @tc.name: SelectedItemHeight001
1827 * @tc.desc: Test SwiperIndicator SelectedItemHeight
1828 * @tc.type: FUNC
1829 */
1830 HWTEST_F(SwiperLayoutTestNg, SelectedItemHeight001, TestSize.Level1)
1831 {
__anon87f955264902(SwiperModelNG model) 1832 CreateWithItem([](SwiperModelNG model) {});
1833 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1834 RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
1835 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1836 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1837 paintProperty->UpdateSelectedItemHeight(Dimension(-1.0, DimensionUnit::PX));
1838
1839 /**
1840 * @tc.steps: step3. SelectedItemHeight is less not equal 0.
1841 */
1842 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1843 LayoutWrapperNode layoutWrapper =
1844 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1845 algorithm->Measure(&layoutWrapper);
1846 }
1847
1848 /**
1849 * @tc.name: SelectedItemHeight002
1850 * @tc.desc: Test SwiperIndicator SelectedItemHeight
1851 * @tc.type: FUNC
1852 */
1853 HWTEST_F(SwiperLayoutTestNg, SelectedItemHeight002, TestSize.Level1)
1854 {
__anon87f955264a02(SwiperModelNG model) 1855 CreateWithItem([](SwiperModelNG model) {
1856 model.SetDirection(Axis::VERTICAL);
1857 });
1858 layoutProperty_->UpdateDirection(Axis::VERTICAL);
1859 auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
1860 auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
1861 auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
1862 paintProperty->UpdateSelectedItemHeight(Dimension(-1000.0, DimensionUnit::PX));
1863
1864 /**
1865 * @tc.steps: step3. SelectedItemHeight is great then 0.
1866 */
1867 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1868 LayoutWrapperNode layoutWrapper =
1869 LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
1870 algorithm->Measure(&layoutWrapper);
1871 }
1872 } // namespace OHOS::Ace::NG
1873