mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-08 09:53:20 +00:00
commit
a48e9788ba
@ -1282,4 +1282,59 @@ HWTEST_F(SpanStringTestNg, MutableSpanString018, TestSize.Level1)
|
||||
EXPECT_EQ((*it)->interval.first, 11);
|
||||
EXPECT_EQ((*it)->interval.second, 14);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SpanStringTest009
|
||||
* @tc.desc: Test basic function of span object
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SpanStringTestNg, SpanString009, TestSize.Level1)
|
||||
{
|
||||
std::string buffer;
|
||||
RefPtr<FontSpan> fontSpan = AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10);
|
||||
buffer = fontSpan->ToString();
|
||||
EXPECT_FALSE(buffer.empty());
|
||||
EXPECT_EQ(buffer.find("FontSpan"), 0);
|
||||
|
||||
auto spanItem = AceType::MakeRefPtr<NG::SpanItem>();
|
||||
auto decorationSpan =
|
||||
AceType::MakeRefPtr<DecorationSpan>(TextDecoration::OVERLINE, Color::RED, TextDecorationStyle::WAVY, 0, 1);
|
||||
EXPECT_FALSE(fontSpan->IsAttributesEqual(decorationSpan));
|
||||
decorationSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
|
||||
buffer.clear();
|
||||
buffer = decorationSpan->ToString();
|
||||
EXPECT_FALSE(buffer.empty());
|
||||
EXPECT_EQ(buffer.find("DecorationSpan"), 0);
|
||||
EXPECT_FALSE(decorationSpan->IsAttributesEqual(fontSpan));
|
||||
|
||||
auto baselineOffsetSpan = AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(4), 0, 2);
|
||||
EXPECT_FALSE(baselineOffsetSpan->IsAttributesEqual(decorationSpan));
|
||||
baselineOffsetSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
|
||||
buffer.clear();
|
||||
buffer = baselineOffsetSpan->ToString();
|
||||
EXPECT_FALSE(buffer.empty());
|
||||
EXPECT_EQ(buffer.find("BaselineOffsetSpan"), 0);
|
||||
|
||||
auto letterSpacingSpan = AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 0, 3);
|
||||
EXPECT_FALSE(letterSpacingSpan->IsAttributesEqual(decorationSpan));
|
||||
letterSpacingSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
|
||||
buffer.clear();
|
||||
buffer = letterSpacingSpan->ToString();
|
||||
EXPECT_FALSE(buffer.empty());
|
||||
EXPECT_EQ(buffer.find("LetterSpacingSpan"), 0);
|
||||
|
||||
Shadow textShadow;
|
||||
textShadow.SetBlurRadius(1.0);
|
||||
textShadow.SetColor(Color::BLACK);
|
||||
textShadow.SetOffsetX(6.0);
|
||||
textShadow.SetOffsetY(6.0);
|
||||
vector<Shadow> textShadows { textShadow };
|
||||
auto textShadowSpan = AceType::MakeRefPtr<TextShadowSpan>(textShadows, 7, 9);
|
||||
EXPECT_FALSE(textShadowSpan->IsAttributesEqual(decorationSpan));
|
||||
textShadowSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
|
||||
buffer.clear();
|
||||
buffer = textShadowSpan->ToString();
|
||||
EXPECT_FALSE(buffer.empty());
|
||||
EXPECT_EQ(buffer.find("TextShadowSpan"), 0);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1907,4 +1907,242 @@ HWTEST_F(TextTestNg, TextLayoutAlgorithmTest008, TestSize.Level1)
|
||||
textLayoutAlgorithm->AdaptMaxTextSize(textStyle, "abc", parentLayoutConstraint, AceType::RawPtr(textFrameNode)),
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UpdateSelectOverlayOrCreate001
|
||||
* @tc.desc: Test TextPattern UpdateSelectOverlayOrCreate.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, UpdateSelectOverlayOrCreate001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textFrameNode.
|
||||
*/
|
||||
auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
|
||||
ASSERT_NE(textFrameNode, nullptr);
|
||||
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
ASSERT_NE(geometryNode, nullptr);
|
||||
auto textPattern = textFrameNode->GetPattern<TextPattern>();
|
||||
ASSERT_NE(textPattern, nullptr);
|
||||
/**
|
||||
* @tc.steps: step2. Construct data and call UpdateSelectOverlayOrCreate
|
||||
*/
|
||||
SelectOverlayInfo selectOverlayInfo;
|
||||
selectOverlayInfo.singleLineHeight = NODE_ID;
|
||||
textPattern->UpdateSelectOverlayOrCreate(selectOverlayInfo, true);
|
||||
EXPECT_EQ(selectOverlayInfo.hitTestMode, HitTestMode::HTMDEFAULT);
|
||||
|
||||
auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
|
||||
auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
|
||||
auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr, false);
|
||||
textPattern->selectOverlayProxy_ = proxy;
|
||||
textPattern->UpdateSelectOverlayOrCreate(selectOverlayInfo, true);
|
||||
EXPECT_TRUE(textPattern->selectOverlayProxy_ && !textPattern->selectOverlayProxy_->IsClosed());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleOnSelectAll
|
||||
* @tc.desc: Test TextPattern HandleOnSelectAll
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, OnModifyDone003, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textPattern.
|
||||
*/
|
||||
auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
|
||||
ASSERT_NE(textFrameNode, nullptr);
|
||||
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
ASSERT_NE(geometryNode, nullptr);
|
||||
auto textPattern = textFrameNode->GetPattern<TextPattern>();
|
||||
ASSERT_NE(textPattern, nullptr);
|
||||
/**
|
||||
* @tc.steps: step2. Construct data and call HandleOnSelectAll
|
||||
*/
|
||||
textPattern->sourceType_ = SourceType::MOUSE;
|
||||
textPattern->HandleOnSelectAll();
|
||||
EXPECT_TRUE(textPattern->IsUsingMouse());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CreateImageSourceInfo001
|
||||
* @tc.desc: Test TextPattern HandleOnSelectAll
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, CreateImageSourceInfo001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textPattern.
|
||||
*/
|
||||
auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
|
||||
ASSERT_NE(textFrameNode, nullptr);
|
||||
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
ASSERT_NE(geometryNode, nullptr);
|
||||
auto textPattern = textFrameNode->GetPattern<TextPattern>();
|
||||
ASSERT_NE(textPattern, nullptr);
|
||||
/**
|
||||
* @tc.steps: step2. Construct data and call CreatImageSourceInfo
|
||||
*/
|
||||
ImageSpanOptions textOptions;
|
||||
textPattern->CreateImageSourceInfo(textOptions);
|
||||
textOptions.image = "textImage";
|
||||
textOptions.bundleName = "textBundleName";
|
||||
textOptions.moduleName = "textModuleName";
|
||||
textPattern->CreateImageSourceInfo(textOptions);
|
||||
EXPECT_TRUE(textOptions.image.has_value());
|
||||
EXPECT_TRUE(textOptions.bundleName.has_value());
|
||||
EXPECT_TRUE(textOptions.moduleName.has_value());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: create001
|
||||
* @tc.desc: Test create with spanstring.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, TextTestNg_create001, TestSize.Level1)
|
||||
{
|
||||
TextModelNG textModelNG;
|
||||
textModelNG.Create(CREATE_VALUE);
|
||||
/**
|
||||
* @tc.steps: step1. Create spanBases
|
||||
*/
|
||||
auto spanStringWithSpans = AceType::MakeRefPtr<SpanString>("01234567891");
|
||||
/**
|
||||
* @tc.steps: step2. call spanBases
|
||||
*/
|
||||
textModelNG.Create(spanStringWithSpans);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetTextSelectableMode001
|
||||
* @tc.desc: Test SetTextSelectableMode by frameNode..
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, TextTestNg_SetTextSelectableMode001, TestSize.Level1)
|
||||
{
|
||||
TextModelNG textModelNG;
|
||||
textModelNG.Create(CREATE_VALUE);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
|
||||
ASSERT_NE(layoutProperty, nullptr);
|
||||
RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
|
||||
|
||||
auto retFont = textModelNG.GetFont(frameNode);
|
||||
textModelNG.SetFontSize(ADAPT_ZERO_FONT_SIZE_VALUE);
|
||||
EXPECT_EQ(textModelNG.GetFontSize(frameNode), ADAPT_ZERO_FONT_SIZE_VALUE);
|
||||
|
||||
textModelNG.SetTextSelectableMode(frameNode, TextSelectableMode::SELECTABLE_UNFOCUSABLE);
|
||||
textModelNG.SetTextSelectableMode(TextSelectableMode::SELECTABLE_UNFOCUSABLE);
|
||||
ASSERT_EQ(textModelNG.GetTextSelectableMode(frameNode), TextSelectableMode::SELECTABLE_UNFOCUSABLE);
|
||||
|
||||
textModelNG.SetEllipsisMode(frameNode, EllipsisMode::HEAD);
|
||||
textModelNG.SetEllipsisMode(EllipsisMode::HEAD);
|
||||
ASSERT_EQ(textModelNG.GetEllipsisMode(frameNode), EllipsisMode::HEAD);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitSpanStringController001
|
||||
* @tc.desc: Test InitSpanStringController.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, TextTestNg_InitSpanStringController001, TestSize.Level1)
|
||||
{
|
||||
TextModelNG textModelNG;
|
||||
textModelNG.Create(CREATE_VALUE);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
|
||||
ASSERT_NE(layoutProperty, nullptr);
|
||||
RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
|
||||
|
||||
auto spanStringWithSpans = AceType::MakeRefPtr<SpanString>("01234567893421");
|
||||
|
||||
textModelNG.InitSpanStringController(frameNode, spanStringWithSpans);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitTextController001
|
||||
* @tc.desc: Test InitTextController.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, TextTestNg_InitTextController001, TestSize.Level1)
|
||||
{
|
||||
TextModelNG textModelNG;
|
||||
textModelNG.Create(CREATE_VALUE);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
|
||||
ASSERT_NE(layoutProperty, nullptr);
|
||||
RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
|
||||
|
||||
auto ret = textModelNG.InitTextController(frameNode);
|
||||
EXPECT_NE(ret, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetTextDetectEnable001
|
||||
* @tc.desc: Test SetTextDetectEnable.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestNg, TextTestNg_SetTextDetectEnable001, TestSize.Level1)
|
||||
{
|
||||
TextModelNG textModelNG;
|
||||
textModelNG.Create(CREATE_VALUE);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
|
||||
ASSERT_NE(layoutProperty, nullptr);
|
||||
RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
|
||||
|
||||
textModelNG.SetTextDetectEnable(frameNode, true);
|
||||
ASSERT_NE(textModelNG.GetTextDetectEnable(frameNode), false);
|
||||
|
||||
auto ret = textModelNG.GetTextController();
|
||||
EXPECT_NE(ret, nullptr);
|
||||
|
||||
textModelNG.SetClipEdge(true);
|
||||
EXPECT_TRUE(true);
|
||||
|
||||
auto strContent = textModelNG.GetContent(frameNode);
|
||||
EXPECT_EQ(strContent, CREATE_VALUE);
|
||||
|
||||
auto retLineHeight = textModelNG.GetLineHeight(frameNode);
|
||||
EXPECT_EQ(retLineHeight, 0.0f);
|
||||
|
||||
auto retLineSpacing = textModelNG.GetLineSpacing(frameNode);
|
||||
EXPECT_EQ(retLineSpacing, 0.0f);
|
||||
|
||||
auto retDecoration = textModelNG.GetDecoration(frameNode);
|
||||
EXPECT_EQ(retDecoration, TextDecoration::NONE);
|
||||
|
||||
auto retTextDecorationColor = textModelNG.GetTextDecorationColor(frameNode);
|
||||
EXPECT_EQ(retTextDecorationColor, Color::BLACK);
|
||||
|
||||
auto retTextDecorationStyle = textModelNG.GetTextDecorationStyle(frameNode);
|
||||
EXPECT_EQ(retTextDecorationStyle, TextDecorationStyle::SOLID);
|
||||
|
||||
auto retTextCase = textModelNG.GetTextCase(frameNode);
|
||||
EXPECT_EQ(retTextCase, TextCase::NORMAL);
|
||||
|
||||
auto retLetterSpacing = textModelNG.GetLetterSpacing(frameNode);
|
||||
EXPECT_EQ(retLetterSpacing, ADAPT_ZERO_FONT_SIZE_VALUE);
|
||||
|
||||
auto retMaxLines = textModelNG.GetMaxLines(frameNode);
|
||||
EXPECT_NE(retMaxLines, 0.0f);
|
||||
|
||||
auto retTextAlign = textModelNG.GetTextAlign(frameNode);
|
||||
EXPECT_EQ(retTextAlign, TextAlign::START);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -379,4 +379,156 @@ HWTEST_F(TextTestFourNg, TextRace001, TestSize.Level1)
|
||||
textPaintMethod.DoStartTextRace();
|
||||
textContentModifier->StopTextRace();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetTextRacePercent001
|
||||
* @tc.desc: test GetTextRacePercent.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, GetTextRacePercent001, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
|
||||
textContentModifier->GetTextRacePercent();
|
||||
textContentModifier->racePercentFloat_->Set(1.0f);
|
||||
auto ret = textContentModifier->GetTextRacePercent();
|
||||
EXPECT_EQ(ret, 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DetermineTextRace001
|
||||
* @tc.desc: test DetermineTextRace.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, DetermineTextRace001, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
|
||||
textContentModifier->DetermineTextRace();
|
||||
textContentModifier->marqueeSet_ = false;
|
||||
textContentModifier->marqueeOption_.start = false;
|
||||
textContentModifier->marqueeOption_.startPolicy = MarqueeStartPolicy::DEFAULT;
|
||||
textContentModifier->DetermineTextRace();
|
||||
EXPECT_FALSE(textContentModifier->marqueeSet_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DetermineTextRace002
|
||||
* @tc.desc: test GetTextRacePercent.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, DetermineTextRace002, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
|
||||
textContentModifier->marqueeSet_ = true;
|
||||
textContentModifier->marqueeOption_.start = true;
|
||||
textContentModifier->marqueeOption_.startPolicy = MarqueeStartPolicy::ON_FOCUS;
|
||||
textContentModifier->textRacing_ = true;
|
||||
textContentModifier->marqueeFocused_ = true;
|
||||
textContentModifier->marqueeHovered_ = true;
|
||||
textContentModifier->DetermineTextRace();
|
||||
textContentModifier->marqueeFocused_ = false;
|
||||
textContentModifier->marqueeHovered_ = false;
|
||||
textContentModifier->DetermineTextRace();
|
||||
EXPECT_TRUE(textContentModifier->marqueeSet_);
|
||||
|
||||
textContentModifier->marqueeSet_ = true;
|
||||
textContentModifier->marqueeOption_.start = true;
|
||||
textContentModifier->marqueeOption_.startPolicy = MarqueeStartPolicy::ON_FOCUS;
|
||||
textContentModifier->textRacing_ = false;
|
||||
textContentModifier->marqueeFocused_ = true;
|
||||
textContentModifier->marqueeHovered_ = false;
|
||||
textContentModifier->DetermineTextRace();
|
||||
textContentModifier->marqueeFocused_ = false;
|
||||
textContentModifier->marqueeHovered_ = true;
|
||||
textContentModifier->DetermineTextRace();
|
||||
textContentModifier->marqueeFocused_ = true;
|
||||
textContentModifier->marqueeHovered_ = true;
|
||||
textContentModifier->DetermineTextRace();
|
||||
textContentModifier->marqueeFocused_ = false;
|
||||
textContentModifier->marqueeHovered_ = false;
|
||||
textContentModifier->DetermineTextRace();
|
||||
EXPECT_TRUE(textContentModifier->marqueeSet_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AllowTextRace001
|
||||
* @tc.desc: test AllowTextRace.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, AllowTextRace001, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
textContentModifier->AllowTextRace();
|
||||
|
||||
textContentModifier->marqueeSet_ = false;
|
||||
textContentModifier->marqueeOption_.start = false;
|
||||
bool ret = textContentModifier->AllowTextRace();
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
textContentModifier->marqueeSet_ = true;
|
||||
textContentModifier->marqueeOption_.start = true;
|
||||
textContentModifier->marqueeOption_.loop = 1;
|
||||
textContentModifier->marqueeCount_ = 2;
|
||||
ret = textContentModifier->AllowTextRace();
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AllowTextRace002
|
||||
* @tc.desc: test AllowTextRace.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, AllowTextRace002, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
textContentModifier->AllowTextRace();
|
||||
|
||||
textContentModifier->marqueeSet_ = true;
|
||||
textContentModifier->marqueeOption_.start = true;
|
||||
textContentModifier->marqueeOption_.loop = 0;
|
||||
textContentModifier->marqueeCount_ = -1;
|
||||
textContentModifier->marqueeOption_.startPolicy = MarqueeStartPolicy::ON_FOCUS;
|
||||
textContentModifier->marqueeFocused_ = false;
|
||||
textContentModifier->marqueeHovered_ = false;
|
||||
bool ret = textContentModifier->AllowTextRace();
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
textContentModifier->marqueeOption_.startPolicy = MarqueeStartPolicy::DEFAULT;
|
||||
textContentModifier->marqueeFocused_ = true;
|
||||
textContentModifier->marqueeHovered_ = true;
|
||||
ret = textContentModifier->AllowTextRace();
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PauseTextRace001
|
||||
* @tc.desc: test PauseTextRace.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestFourNg, PauseTextRace001, TestSize.Level1)
|
||||
{
|
||||
RefPtr<TextContentModifier> textContentModifier =
|
||||
AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
|
||||
ASSERT_NE(textContentModifier, nullptr);
|
||||
|
||||
textContentModifier->textRacing_ = false;
|
||||
textContentModifier->PauseTextRace();
|
||||
|
||||
textContentModifier->textRacing_ = true;
|
||||
textContentModifier->PauseTextRace();
|
||||
EXPECT_FALSE(textContentModifier->textRacing_);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -1972,4 +1972,129 @@ HWTEST_F(TextTestTwoNg, TextContentModifier005, TestSize.Level1)
|
||||
EXPECT_EQ(textPaintMethod->textContentModifier_->imageNodeList_.size(), 1);
|
||||
textPattern->pManager_->Reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TextOverlayModifierTest002
|
||||
* @tc.desc: test IsSelectedRectsChanged function.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestTwoNg, TextOverlayModifierTest002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textOverlayModifier
|
||||
*/
|
||||
TextOverlayModifier textOverlayModifier;
|
||||
std::vector<RectF> rectList;
|
||||
rectList.push_back(RectF(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
|
||||
rectList.push_back(RectF(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
|
||||
textOverlayModifier.SetSelectedRects(rectList);
|
||||
/**
|
||||
* @tc.steps: step2. test IsSelectedRectsChanged
|
||||
*/
|
||||
RectF secondRect(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE);
|
||||
textOverlayModifier.selectedRects_[0] = secondRect;
|
||||
bool rectsChanged = textOverlayModifier.IsSelectedRectsChanged(rectList);
|
||||
EXPECT_EQ(rectsChanged, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TextOverlayModifierTest003
|
||||
* @tc.desc: test TextOverlayModifier function.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestTwoNg, TextOverlayModifierTest003, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textOverlayModifier
|
||||
*/
|
||||
TextOverlayModifier textOverlayModifier;
|
||||
OffsetF paintOffset;
|
||||
textOverlayModifier.SetPrintOffset(paintOffset);
|
||||
textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. change version and save initial version
|
||||
*/
|
||||
int32_t settingHighApiVersion = 12;
|
||||
int32_t settingLowApiVersion = 10;
|
||||
int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(settingHighApiVersion);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. test TextOverlayModifier
|
||||
*/
|
||||
TextOverlayModifier();
|
||||
EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. test TextOverlayModifier again and reuse initial ApiTargetVersion
|
||||
*/
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(settingLowApiVersion);
|
||||
TextOverlayModifier();
|
||||
EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TextOverlayModifierTest004
|
||||
* @tc.desc: test onDraw function.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TextTestTwoNg, TextOverlayModifierTest004, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create textOverlayModifier
|
||||
*/
|
||||
TextOverlayModifier textOverlayModifier;
|
||||
OffsetF paintOffset;
|
||||
textOverlayModifier.SetPrintOffset(paintOffset);
|
||||
textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. create selectedRects_
|
||||
*/
|
||||
std::vector<RectF> rectList;
|
||||
rectList.push_back(RectF(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
|
||||
textOverlayModifier.SetSelectedRects(rectList);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. create canvas
|
||||
*/
|
||||
|
||||
Testing::MockCanvas canvas;
|
||||
EXPECT_CALL(canvas, Save()).WillRepeatedly(Return());
|
||||
EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, DrawRect(_)).WillRepeatedly(Return());
|
||||
EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, Restore()).WillRepeatedly(Return());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. change ApiVersion and set isClip_ is true
|
||||
*/
|
||||
|
||||
int32_t changeApiVersion = 12;
|
||||
int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(changeApiVersion);
|
||||
TextOverlayModifier();
|
||||
EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. create context and textContentRect
|
||||
*/
|
||||
DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
|
||||
RectF textContentRect = CONTENT_RECT;
|
||||
textOverlayModifier.SetContentRect(textContentRect);
|
||||
|
||||
/**
|
||||
* @tc.steps: step6. test onDraw
|
||||
*/
|
||||
textOverlayModifier.SetShowSelect(true);
|
||||
textOverlayModifier.onDraw(context);
|
||||
RectF finalSelectRect = textOverlayModifier.selectedRects_[0];
|
||||
EXPECT_EQ(textOverlayModifier.paintOffset_->Get(), paintOffset);
|
||||
EXPECT_EQ(finalSelectRect.Width(), 5);
|
||||
EXPECT_EQ(textOverlayModifier.contentRect_, textContentRect);
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user