From 4d04d94009271f263527d5d7012d1797daaf2bf0 Mon Sep 17 00:00:00 2001 From: stella-ren Date: Mon, 9 Jan 2023 09:42:38 +0800 Subject: [PATCH] add drawing test Signed-off-by: stella-ren --- .../OH_Drawing_TypographyTest.cpp | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp b/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp index 59b7d0556..1a156e2cb 100644 --- a/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp +++ b/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp @@ -65,6 +65,8 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest002, TestSize.Level EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::LTR); OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_RTL); EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::RTL); + OH_Drawing_SetTypographyTextDirection(typoStyle, -1); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::LTR); } /* @@ -87,6 +89,8 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest003, TestSize.Level EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::START); OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_END); EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::END); + OH_Drawing_SetTypographyTextAlign(typoStyle, -1); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::LEFT); } /* @@ -156,10 +160,26 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest007, TestSize.Level HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest008, TestSize.Level1) { OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_100); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W100); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W200); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_300); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W300); OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400); EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W400); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_500); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W500); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_600); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W600); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_700); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W700); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_800); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W800); OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_900); EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W900); + OH_Drawing_SetTextStyleFontWeight(txtStyle, -1); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W400); } /* @@ -174,6 +194,8 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest009, TestSize.Level EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::ALPHABETIC); OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC); EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::IDEOGRAPHIC); + OH_Drawing_SetTextStyleBaseLine(txtStyle, -1); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::ALPHABETIC); } /* @@ -192,6 +214,8 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest010, TestSize.Level EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::OVERLINE); OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_LINE_THROUGH); EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::LINETHROUGH); + OH_Drawing_SetTextStyleDecoration(txtStyle, -1); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::NONE); } /* @@ -246,6 +270,8 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest014, TestSize.Level EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::NORMAL); OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_ITALIC); EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::ITALIC); + OH_Drawing_SetTextStyleFontStyle(txtStyle, -1); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::NORMAL); } /* @@ -289,16 +315,28 @@ HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest016, TestSize.Level OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler); double maxWidth = 800.0; OH_Drawing_TypographyLayout(typography, maxWidth); + EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography)); double position[2] = {10.0, 15.0}; OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate(); OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; uint32_t width = 20; uint32_t height = 40; OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat); + EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap)); + EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap)); OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate(); OH_Drawing_CanvasBind(cCanvas, cBitmap); OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF)); + + EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography) != 0.0, true); + EXPECT_EQ(OH_Drawing_TypographyGetLongestLine(typography) != 0.0, true); + EXPECT_EQ(OH_Drawing_TypographyGetMinIntrinsicWidth(typography) <= + OH_Drawing_TypographyGetMaxIntrinsicWidth(typography), true); + EXPECT_EQ(OH_Drawing_TypographyGetAlphabeticBaseline(typography) != 0.0, true); + EXPECT_EQ(OH_Drawing_TypographyGetIdeographicBaseline(typography) != 0.0, true); OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]); + OH_Drawing_DestroyTypography(typography); + OH_Drawing_DestroyTypographyHandler(handler); +} } -} \ No newline at end of file -- GitLab