diff --git a/graphic/BUILD.gn b/graphic/BUILD.gn index 6b916b460b6d25984345a22604cbca2b56caf44c..a28994d171683d8762e082cf712dd945249b5f9d 100755 --- a/graphic/BUILD.gn +++ b/graphic/BUILD.gn @@ -17,6 +17,7 @@ group("graphic") { if (is_standard_system) { deps = [ "effectKit:EffectKitTest", + "graphicnapidrawingtest:GraphicNapiDrawingTest", "webGL:webGL_hap_test", "windowStage:ActsWindowStageTest", "windowstandard:window_hap_test", diff --git a/graphic/graphicnapidrawingtest/BUILD.gn b/graphic/graphicnapidrawingtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..946e910cc2c3fbb0715496c56f8ebf6cf77c2c09 --- /dev/null +++ b/graphic/graphicnapidrawingtest/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hit/GraphicNapiDrawingTest" + +############################################################################### + +ohos_moduletest_suite("GraphicNapiDrawingTest") { + module_out_path = module_output_path + + sources = [ + "NativeDrawingBitmapTest.cpp", + "NativeDrawingBrushTest.cpp", + "NativeDrawingCanvasTest.cpp", + "NativeDrawingColorTest.cpp", + "NativeDrawingPathTest.cpp", + "NativeDrawingPenTest.cpp", + "OH_Drawing_FontCollectionTest.cpp", + "OH_Drawing_TypographyTest.cpp", + ] + + cflags = [ + "-Wall", + "-Werror", + ] + + include_dirs = [ + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src", + "//third_party/googletest/googletest/include", + ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] +} diff --git a/graphic/graphicnapidrawingtest/NativeDrawingBitmapTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingBitmapTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..150928638c13c2279a76129ab63b43fc0a3e778a --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingBitmapTest.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_bitmap.h" +#include "c/drawing_types.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingBitmapTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingBitmapTest::SetUpTestCase() {} +void NativeDrawingBitmapTest::TearDownTestCase() {} +void NativeDrawingBitmapTest::SetUp() {} +void NativeDrawingBitmapTest::TearDown() {} + +/* + * @tc.name: NativeDrawingBitmapTest_bitmap001 + * @tc.desc: test for create drawing_bitmap and destroy drawing_bitmap. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap001, TestSize.Level1) +{ + OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); + EXPECT_EQ(bitmap == nullptr, false); + OH_Drawing_BitmapDestroy(bitmap); +} + +/* + * @tc.name: NativeDrawingBitmapTest_bitmap002 + * @tc.desc: test for drawing_bitmap build. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap002, TestSize.Level1) +{ + OH_Drawing_Bitmap* bitmap1 = OH_Drawing_BitmapCreate(); + const unsigned int width = 500; + const unsigned int height = 500; + OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ALPHA_8, ALPHA_FORMAT_PREMUL }; + OH_Drawing_BitmapBuild(bitmap1, width, height, &bitmapFormat); + EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap1)); + EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap1)); + OH_Drawing_BitmapDestroy(bitmap1); +} + +/* + * @tc.name: NativeDrawingBitmapTest_bitmap003 + * @tc.desc: test for drawing_bitmap build. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap003, TestSize.Level1) +{ + OH_Drawing_Bitmap* bitmap2 = OH_Drawing_BitmapCreate(); + const unsigned int width = 0; + const unsigned int height = 0; + OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGB_565, ALPHA_FORMAT_OPAQUE }; + OH_Drawing_BitmapBuild(bitmap2, width, height, &bitmapFormat); + EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap2)); + EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap2)); + OH_Drawing_BitmapDestroy(bitmap2); +} + +/* + * @tc.name: NativeDrawingBitmapTest_bitmap004 + * @tc.desc: test for drawing_bitmap build. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap004, TestSize.Level1) +{ + OH_Drawing_Bitmap* bitmap4 = OH_Drawing_BitmapCreate(); + const unsigned int width = 500; + const unsigned int height = 500; + OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ARGB_4444, ALPHA_FORMAT_UNPREMUL }; + OH_Drawing_BitmapBuild(bitmap4, width, height, &bitmapFormat); + EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap4)); + EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap4)); + EXPECT_EQ(OH_Drawing_BitmapGetPixels(bitmap4) == nullptr, false); + OH_Drawing_BitmapDestroy(bitmap4); +} + +/* + * @tc.name: NativeDrawingBitmapTest_bitmap005 + * @tc.desc: test for drawing_bitmap build. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap005, TestSize.Level1) +{ + OH_Drawing_Bitmap* bitmap5 = OH_Drawing_BitmapCreate(); + const unsigned int width = 500; + const unsigned int height = 500; + OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL }; + OH_Drawing_BitmapBuild(bitmap5, width, height, &bitmapFormat); + EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap5)); + EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap5)); + OH_Drawing_BitmapDestroy(bitmap5); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/NativeDrawingBrushTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingBrushTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08d36aa48c6ce1f3b9e5583383c2c9bd3e34e55d --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingBrushTest.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_brush.h" +#include "c/drawing_color.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingBrushTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingBrushTest::SetUpTestCase() {} +void NativeDrawingBrushTest::TearDownTestCase() {} +void NativeDrawingBrushTest::SetUp() {} +void NativeDrawingBrushTest::TearDown() {} + +/* + * @tc.name: NativeDrawingBrushTest_brush001 + * @tc.desc: test for create brush and destroy brush. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBrushTest, NativeDrawingBrushTest_brush001, TestSize.Level1) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + EXPECT_EQ(brush == nullptr, false); + OH_Drawing_BrushDestroy(brush); +} + +/* + * @tc.name: NativeDrawingBrushTest_brush002 + * @tc.desc: test for the set methods of brush. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingBrushTest, NativeDrawingBrushTest_brush002, TestSize.Level1) +{ + OH_Drawing_Brush* brush1 = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetAntiAlias(brush1, false); + EXPECT_EQ(OH_Drawing_BrushIsAntiAlias(brush1), false); + OH_Drawing_BrushSetColor(brush1, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); + EXPECT_EQ(OH_Drawing_BrushGetColor(brush1), 0xFFFF0000); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/NativeDrawingCanvasTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingCanvasTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b39e3111f94b866c0a2f0abd8f8b5ea3d1755380 --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingCanvasTest.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_bitmap.h" +#include "c/drawing_brush.h" +#include "c/drawing_canvas.h" +#include "c/drawing_color.h" +#include "c/drawing_path.h" +#include "c/drawing_pen.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingCanvasTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingCanvasTest::SetUpTestCase() {} +void NativeDrawingCanvasTest::TearDownTestCase() {} +void NativeDrawingCanvasTest::SetUp() {} +void NativeDrawingCanvasTest::TearDown() {} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas001 + * @tc.desc: test for create canvas and destroy canvas. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas001, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); + EXPECT_EQ(canvas == nullptr, false); + OH_Drawing_CanvasDestroy(canvas); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas002 + * @tc.desc: test for OH_Drawing_CanvasBind. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas002, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas1 = OH_Drawing_CanvasCreate(); + OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); + OH_Drawing_CanvasBind(canvas1, bitmap); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas003 + * @tc.desc: test for OH_Drawing_CanvasAttachPen & OH_Drawing_CanvasDetachPen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas003, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas2 = OH_Drawing_CanvasCreate(); + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_CanvasAttachPen(canvas2, pen); + OH_Drawing_CanvasDetachPen(canvas2); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas004 + * @tc.desc: test for OH_Drawing_CanvasAttachBrush & OH_Drawing_CanvasDetachBrush. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas004, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas3 = OH_Drawing_CanvasCreate(); + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_CanvasAttachBrush(canvas3, brush); + OH_Drawing_CanvasDetachBrush(canvas3); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas005 + * @tc.desc: test for OH_Drawing_CanvasDrawLine. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas005, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas4 = OH_Drawing_CanvasCreate(); + OH_Drawing_CanvasDrawLine(canvas4, 0, 0, 20, 20); + OH_Drawing_CanvasDrawLine(canvas4, -15.2f, -1, 0, 20); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas006 + * @tc.desc: test for OH_Drawing_CanvasDrawPath. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas006, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas5 = OH_Drawing_CanvasCreate(); + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + OH_Drawing_CanvasDrawPath(canvas5, path); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas007 + * @tc.desc: test for OH_Drawing_CanvasSave & OH_Drawing_CanvasRestore. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas007, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas6 = OH_Drawing_CanvasCreate(); + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + OH_Drawing_CanvasDrawPath(canvas6, path); + OH_Drawing_CanvasSave(canvas6); + OH_Drawing_CanvasRestore(canvas6); +} + +/* + * @tc.name: NativeDrawingCanvasTest_canvas008 + * @tc.desc: test for OH_Drawing_CanvasClear. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas008, TestSize.Level1) +{ + OH_Drawing_Canvas* canvas7 = OH_Drawing_CanvasCreate(); + OH_Drawing_CanvasClear(canvas7, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/NativeDrawingColorTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingColorTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..724fb84781579b8c8616f23e990d994ec5b10c00 --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingColorTest.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_brush.h" +#include "c/drawing_color.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingColorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingColorTest::SetUpTestCase() {} +void NativeDrawingColorTest::TearDownTestCase() {} +void NativeDrawingColorTest::SetUp() {} +void NativeDrawingColorTest::TearDown() {} + +/* + * @tc.name: NativeDrawingColorTest_color001 + * @tc.desc: test for ColorSetArgb. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingColorTest, NativeDrawingColorTest_color001, TestSize.Level1) +{ + OH_Drawing_Brush* brush1 = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetAntiAlias(brush1, false); + EXPECT_EQ(OH_Drawing_BrushIsAntiAlias(brush1), false); + OH_Drawing_BrushSetColor(brush1, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); + EXPECT_EQ(OH_Drawing_BrushGetColor(brush1), 0xFFFF0000); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/NativeDrawingPathTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingPathTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a01df5ac4bd624aa3c729aecd2f7c96528fcf270 --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingPathTest.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_path.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingPathTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingPathTest::SetUpTestCase() {} +void NativeDrawingPathTest::TearDownTestCase() {} +void NativeDrawingPathTest::SetUp() {} +void NativeDrawingPathTest::TearDown() {} + +/* + * @tc.name: NativeDrawingPathTest_path001 + * @tc.desc: test for create drawing_path. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path001, TestSize.Level1) +{ + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + EXPECT_EQ(path == nullptr, false); + OH_Drawing_PathDestroy(path); +} + +/* + * @tc.name: NativeDrawingPathTest_path002 + * @tc.desc: test for PathMoveTo func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path002, TestSize.Level1) +{ + OH_Drawing_Path* path1 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(path1, 20, 20); + OH_Drawing_PathMoveTo(path1, -1, 20.6f); + OH_Drawing_PathDestroy(path1); +} + +/* + * @tc.name: NativeDrawingPathTest_path004 + * @tc.desc: test for PathLineTo func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path003, TestSize.Level1) +{ + OH_Drawing_Path* path2 = OH_Drawing_PathCreate(); + OH_Drawing_PathLineTo(path2, 50, 40); + OH_Drawing_PathLineTo(path2, -50, 10.2f); + OH_Drawing_PathDestroy(path2); +} + +/* + * @tc.name: NativeDrawingPathTest_path005 + * @tc.desc: test for PathReset func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path004, TestSize.Level1) +{ + OH_Drawing_Path* path3 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(path3, 20, 20); + OH_Drawing_PathReset(path3); + OH_Drawing_PathDestroy(path3); +} + +/* + * @tc.name: NativeDrawingPathTest_path006 + * @tc.desc: test for PathArcTo func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path005, TestSize.Level1) +{ + OH_Drawing_Path* path4 = OH_Drawing_PathCreate(); + OH_Drawing_PathArcTo(path4, 10, 10, 20, 0, 0, 90); + OH_Drawing_PathArcTo(path4, -10, 10, 10, -10, 0, 90); + OH_Drawing_PathDestroy(path4); +} + +/* + * @tc.name: NativeDrawingPathTest_path007 + * @tc.desc: test for PathQuadTo func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path006, TestSize.Level1) +{ + OH_Drawing_Path* path5 = OH_Drawing_PathCreate(); + OH_Drawing_PathQuadTo(path5, 0, 0, 30, 30); + OH_Drawing_PathQuadTo(path5, -20.5f, -20.5f, 30, 0); + OH_Drawing_PathDestroy(path5); +} + +/* + * @tc.name: NativeDrawingPathTest_path008 + * @tc.desc: test for PathCubicTo func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path007, TestSize.Level1) +{ + OH_Drawing_Path* path6 = OH_Drawing_PathCreate(); + OH_Drawing_PathCubicTo(path6, 30, 40, 60, 0, 50, 20); + OH_Drawing_PathCubicTo(path6, -30, 40, 60, -30.6f, 50, -20); + OH_Drawing_PathDestroy(path6); +} + +/* + * @tc.name: NativeDrawingPathTest_path009 + * @tc.desc: test for PathClose func. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_path009, TestSize.Level1) +{ + OH_Drawing_Path* path7 = OH_Drawing_PathCreate(); + OH_Drawing_PathLineTo(path7, 50, 40); + OH_Drawing_PathClose(path7); + OH_Drawing_PathDestroy(path7); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/NativeDrawingPenTest.cpp b/graphic/graphicnapidrawingtest/NativeDrawingPenTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9655f543a2615090fad7a84c52fd0fb423a1ff75 --- /dev/null +++ b/graphic/graphicnapidrawingtest/NativeDrawingPenTest.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, Hardware + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "c/drawing_color.h" +#include "c/drawing_pen.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class NativeDrawingPenTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void NativeDrawingPenTest::SetUpTestCase() {} +void NativeDrawingPenTest::TearDownTestCase() {} +void NativeDrawingPenTest::SetUp() {} +void NativeDrawingPenTest::TearDown() {} + +/* + * @tc.name: NativeDrawingPenTest_pen001 + * @tc.desc: test for create drawing_pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen001, TestSize.Level1) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + EXPECT_EQ(pen == nullptr, false); + OH_Drawing_PenDestroy(pen); +} + +/* + * @tc.name: NativeDrawingPenTest_pen002 + * @tc.desc: test for the get and set methods about AntiAlias for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen002, TestSize.Level1) +{ + OH_Drawing_Pen* pen1 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetAntiAlias(pen1, true); + EXPECT_EQ(OH_Drawing_PenIsAntiAlias(pen1), true); + OH_Drawing_PenSetAntiAlias(pen1, false); + EXPECT_EQ(OH_Drawing_PenIsAntiAlias(pen1), false); + OH_Drawing_PenDestroy(pen1); +} + +/* + * @tc.name: NativeDrawingPenTest_pen003 + * @tc.desc: test for the get and set methods about the color for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen003, TestSize.Level1) +{ + OH_Drawing_Pen* pen2 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen2, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); + EXPECT_EQ(OH_Drawing_PenGetColor(pen2), 0xFFFF0000); + OH_Drawing_PenDestroy(pen2); +} + +/* + * @tc.name: NativeDrawingPenTest_pen004 + * @tc.desc: test for the get and set methods about the width for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen004, TestSize.Level1) +{ + OH_Drawing_Pen* pen3 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetWidth(pen3, 10); + EXPECT_EQ(OH_Drawing_PenGetWidth(pen3), 10); + OH_Drawing_PenDestroy(pen3); +} + +/* + * @tc.name: NativeDrawingPenTest_pen005 + * @tc.desc: test for the get and set methods about the miterLimit for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen005, TestSize.Level1) +{ + OH_Drawing_Pen* pen4 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetMiterLimit(pen4, 5); + EXPECT_EQ(OH_Drawing_PenGetMiterLimit(pen4), 5); + OH_Drawing_PenDestroy(pen4); +} + +/* + * @tc.name: NativeDrawingPenTest_pen006 + * @tc.desc: test for the get and set methods about the line cap style for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen006, TestSize.Level1) +{ + OH_Drawing_Pen* pen5 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_SQUARE_CAP); + EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_SQUARE_CAP); + OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_FLAT_CAP); + EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_FLAT_CAP); + OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP); + EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP); + OH_Drawing_PenDestroy(pen5); +} + +/* + * @tc.name: NativeDrawingPenTest_pen007 + * @tc.desc: test for the get and set methods about the line join style for a pen. + * @tc.type: FUNC + * @tc.require: AR000GTO5R + */ +HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen007, TestSize.Level1) +{ + OH_Drawing_Pen* pen6 = OH_Drawing_PenCreate(); + OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_ROUND_JOIN); + EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_ROUND_JOIN); + OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN); + EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN); + OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN); + EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN); + OH_Drawing_PenDestroy(pen6); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/OH_Drawing_FontCollectionTest.cpp b/graphic/graphicnapidrawingtest/OH_Drawing_FontCollectionTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf42fa94c927699b3b32d84c46dcb361236df07d --- /dev/null +++ b/graphic/graphicnapidrawingtest/OH_Drawing_FontCollectionTest.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "c/drawing_font_collection.h" + +#include "gtest/gtest.h" +#include "c/drawing_text_declaration.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +class OH_Drawing_FontCollectionTest : public testing::Test { +}; + +/* + * @tc.name: NativeDrawingTest001 + * @tc.desc: test for creating fontCollection + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_FontCollectionTest, OH_Drawing_FontCollectionTest001, TestSize.Level1) +{ + OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection(); + EXPECT_EQ(fontCollection == nullptr, false); + OH_Drawing_DestroyFontCollection(fontCollection); +} +} \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp b/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..59b7d05566705d246fd7a4dbeb4a132c5154b5e9 --- /dev/null +++ b/graphic/graphicnapidrawingtest/OH_Drawing_TypographyTest.cpp @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "c/drawing_bitmap.h" +#include "c/drawing_canvas.h" +#include "c/drawing_color.h" +#include "c/drawing_font_collection.h" +#include "c/drawing_text_declaration.h" +#include "c/drawing_text_typography.h" +#include "rosen_text/ui/typography.h" +#include "rosen_text/ui/typography_create.h" + +using namespace rosen; +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +class OH_Drawing_TypographyTest : public testing::Test { +}; + +static TypographyStyle* ConvertToOriginalText(OH_Drawing_TypographyStyle* style) +{ + return reinterpret_cast(style); +} + +static TextStyle* ConvertToOriginalText(OH_Drawing_TextStyle* style) +{ + return reinterpret_cast(style); +} + +/* + * @tc.name: OH_Drawing_TypographyTest001 + * @tc.desc: test for creating TypographyStyle + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest001, TestSize.Level1) +{ + OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); + EXPECT_EQ(typoStyle == nullptr, false); + OH_Drawing_DestroyTypographyStyle(typoStyle); +} + +/* + * @tc.name: OH_Drawing_TypographyTest002 + * @tc.desc: test for text direction + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest002, TestSize.Level1) +{ + OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); + OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::LTR); + OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_RTL); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::RTL); +} + +/* + * @tc.name: OH_Drawing_TypographyTest003 + * @tc.desc: test for text alignment + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest003, TestSize.Level1) +{ + OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::LEFT); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_RIGHT); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::RIGHT); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_CENTER); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::CENTER); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_JUSTIFY); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::JUSTIFY); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_START); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::START); + OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_END); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::END); +} + +/* + * @tc.name: OH_Drawing_TypographyTest004 + * @tc.desc: test for max lines + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest004, TestSize.Level1) +{ + OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); + OH_Drawing_SetTypographyTextMaxLines(typoStyle, 100); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines_, 100); + OH_Drawing_SetTypographyTextMaxLines(typoStyle, 200); + EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines_, 200); +} + +/* + * @tc.name: OH_Drawing_TypographyTest005 + * @tc.desc: test for creating text style + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest005, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + EXPECT_EQ(txtStyle == nullptr, false); + OH_Drawing_DestroyTextStyle(txtStyle); +} + +/* + * @tc.name: OH_Drawing_TypographyTest006 + * @tc.desc: test for text color + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest006, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + // black + OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00)); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFF000000); + // red + OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFFFF0000); + // blue + OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF)); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFF0000FF); +} + +/* + * @tc.name: OH_Drawing_TypographyTest007 + * @tc.desc: test for font size + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest007, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontSize(txtStyle, 80); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize_, 80); + OH_Drawing_SetTextStyleFontSize(txtStyle, 40); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize_, 40); +} + +/* + * @tc.name: OH_Drawing_TypographyTest008 + * @tc.desc: test for font weight + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest008, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W400); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_900); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W900); +} + +/* + * @tc.name: OH_Drawing_TypographyTest009 + * @tc.desc: test for baseline location + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest009, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::ALPHABETIC); + OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::IDEOGRAPHIC); +} + +/* + * @tc.name: OH_Drawing_TypographyTest010 + * @tc.desc: test for text decoration + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest010, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::NONE); + OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::UNDERLINE); + OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_OVERLINE); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::OVERLINE); + OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_LINE_THROUGH); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::LINETHROUGH); +} + +/* + * @tc.name: OH_Drawing_TypographyTest011 + * @tc.desc: test for text decoration color + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest011, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00)); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor_, 0xFF000000); + OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00)); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor_, 0xFFFF0000); +} + +/* + * @tc.name: OH_Drawing_TypographyTest012 + * @tc.desc: test for font height + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest012, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.0); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->height_, 0.0); +} + +/* + * @tc.name: OH_Drawing_TypographyTest013 + * @tc.desc: test for font families + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest013, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + const char* fontFamilies[] = {"Roboto"}; + OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies); + std::vector fontFamiliesResult = {"Roboto"}; + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontFamilies_, fontFamiliesResult); +} + +/* + * @tc.name: OH_Drawing_TypographyTest014 + * @tc.desc: test for font italic + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest014, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::NORMAL); + OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_ITALIC); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::ITALIC); +} + +/* + * @tc.name: OH_Drawing_TypographyTest015 + * @tc.desc: test for font locale + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest015, TestSize.Level1) +{ + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleLocale(txtStyle, "en"); + EXPECT_EQ(ConvertToOriginalText(txtStyle)->locale_, "en"); +} + +/* + * @tc.name: OH_Drawing_TypographyTest016 + * @tc.desc: test for typography + * @tc.type: FUNC + */ +HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest016, TestSize.Level1) +{ + OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); + OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, + OH_Drawing_CreateFontCollection()); + EXPECT_TRUE(handler != nullptr); + + OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00)); + double fontSize = 30; + OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize); + OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400); + OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC); + const char* fontFamilies[] = {"Roboto"}; + OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies); + OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle); + + const char* text = "OpenHarmony\n"; + OH_Drawing_TypographyHandlerAddText(handler, text); + OH_Drawing_TypographyHandlerPopTextStyle(handler); + + OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler); + double maxWidth = 800.0; + OH_Drawing_TypographyLayout(typography, maxWidth); + 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); + + OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate(); + OH_Drawing_CanvasBind(cCanvas, cBitmap); + OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF)); + OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]); +} +} \ No newline at end of file diff --git a/graphic/graphicnapidrawingtest/Test.json b/graphic/graphicnapidrawingtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..679d2fefac96e3b79507f54cc1763a053f2805d5 --- /dev/null +++ b/graphic/graphicnapidrawingtest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "GraphicNapiDrawingTest->/data/local/tmp/GraphicNapiDrawingTest" + ], + "type": "PushKit", + "post-push" : [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "GraphicNapiDrawingTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for GraphicNapiDrawingTest Tests" +} \ No newline at end of file