From 5eaeed3c4cd7b613cdeac33f0943413e417e7fe9 Mon Sep 17 00:00:00 2001 From: abbuu Date: Wed, 17 May 2023 15:35:45 +0800 Subject: [PATCH] Adding Drawing UT cases 02 Signed-off-by: abbuu Change-Id: I5c9328fc34c48dc5d9cc109e82c72b4ddcf42028 --- .../test/2d_graphics/unittest/effect/BUILD.gn | 3 +- .../unittest/effect/color_filter_test.cpp | 16 +- .../unittest/effect/filter_test.cpp | 38 +++- .../unittest/effect/image_filter_test.cpp | 165 ++++++++++++++++++ 4 files changed, 217 insertions(+), 5 deletions(-) create mode 100644 rosen/test/2d_graphics/unittest/effect/image_filter_test.cpp diff --git a/rosen/test/2d_graphics/unittest/effect/BUILD.gn b/rosen/test/2d_graphics/unittest/effect/BUILD.gn index 25f1aca183..a6a294fb82 100644 --- a/rosen/test/2d_graphics/unittest/effect/BUILD.gn +++ b/rosen/test/2d_graphics/unittest/effect/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -23,6 +23,7 @@ ohos_unittest("2d_graphics_effect_test") { "color_matrix_test.cpp", "color_space_test.cpp", "filter_test.cpp", + "image_filter_test.cpp", "mask_filter_test.cpp", "path_effect_test.cpp", "shader_effect_test.cpp", diff --git a/rosen/test/2d_graphics/unittest/effect/color_filter_test.cpp b/rosen/test/2d_graphics/unittest/effect/color_filter_test.cpp index 7c1a149945..4d5caaa104 100644 --- a/rosen/test/2d_graphics/unittest/effect/color_filter_test.cpp +++ b/rosen/test/2d_graphics/unittest/effect/color_filter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -134,6 +134,18 @@ HWTEST_F(ColorFilterTest, CreateSrgbGammaToLinear001, TestSize.Level1) EXPECT_FALSE(nullptr == colorFilter); } +/** + * @tc.name: CreateLumaColorFilter001 + * @tc.desc: test for creating a ColorFilter that its type is luma. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ColorFilterTest, CreateLumaColorFilter001, TestSize.Level1) +{ + auto colorFilter = ColorFilter::CreateLumaColorFilter(); + EXPECT_FALSE(nullptr == colorFilter); +} + /** * @tc.name: GetType001 * @tc.desc: @@ -307,4 +319,4 @@ HWTEST_F(ColorFilterTest, CreateInstance008, TestSize.Level1) } } // namespace Drawing } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/rosen/test/2d_graphics/unittest/effect/filter_test.cpp b/rosen/test/2d_graphics/unittest/effect/filter_test.cpp index 86be322654..e71c16e30d 100644 --- a/rosen/test/2d_graphics/unittest/effect/filter_test.cpp +++ b/rosen/test/2d_graphics/unittest/effect/filter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -83,6 +83,40 @@ HWTEST_F(FilterTest, GetterAndSetterColorFilter002, TestSize.Level1) EXPECT_FALSE(result != colorFilter); } +/* + * @tc.name: GetterAndSetterImageFilter001 + * @tc.desc: test for seting and geting imageFilter. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(FilterTest, GetterAndSetterImageFilter001, TestSize.Level1) +{ + auto filter = std::make_unique(); + ASSERT_TRUE(filter != nullptr); + auto imageFilter = ImageFilter::CreateBlurImageFilter(10.0f, 10.0f, TileMode::CLAMP, nullptr); + ASSERT_TRUE(imageFilter != nullptr); + filter->SetImageFilter(imageFilter); + auto result = filter->GetImageFilter(); + EXPECT_FALSE(result != imageFilter); +} + +/* + * @tc.name: GetterAndSetterImageFilter002 + * @tc.desc: test for seting and geting imageFilter. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(FilterTest, GetterAndSetterImageFilter002, TestSize.Level1) +{ + auto filter = std::make_unique(); + ASSERT_TRUE(filter != nullptr); + auto imageFilter = ImageFilter::CreateBlurImageFilter(20.0f, 20.0f, TileMode::CLAMP, nullptr); + ASSERT_TRUE(imageFilter != nullptr); + filter->SetImageFilter(imageFilter); + auto result = filter->GetImageFilter(); + EXPECT_FALSE(result != imageFilter); +} + /* * @tc.name: GetterAndSetterMaskFilter001 * @tc.desc: @@ -216,4 +250,4 @@ HWTEST_F(FilterTest, OverrideNotEquals002, TestSize.Level1) } } // namespace Drawing } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/rosen/test/2d_graphics/unittest/effect/image_filter_test.cpp b/rosen/test/2d_graphics/unittest/effect/image_filter_test.cpp new file mode 100644 index 0000000000..666c26facb --- /dev/null +++ b/rosen/test/2d_graphics/unittest/effect/image_filter_test.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2023 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 "effect/image_filter.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace Drawing { +class ImageFilterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void ImageFilterTest::SetUpTestCase() {} +void ImageFilterTest::TearDownTestCase() {} +void ImageFilterTest::SetUp() {} +void ImageFilterTest::TearDown() {} + +/* + * @tc.name: CreateBlurImageFilterTest001 + * @tc.desc: test for creating a filter that blurs its input by the separate X and Y sinma value. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, CreateBlurImageFilterTest001, TestSize.Level1) +{ + auto imageFilter = ImageFilter::CreateBlurImageFilter(10.0f, 10.0f, TileMode::CLAMP, nullptr); + EXPECT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: CreateColorFilterImageFilterTest001 + * @tc.desc: test for creating a filter that applies the color filter to the input filter results. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, CreateColorFilterImageFilterTest001, TestSize.Level1) +{ + auto colorFilter = ColorFilter::CreateBlendModeColorFilter(11, OHOS::Rosen::Drawing::BlendMode::CLEAR); + auto imageFilter = ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr); + EXPECT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: CreateOffsetImageFilterTest001 + * @tc.desc: test for creating a filter that offsets the input filter by the given vector. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, CreateOffsetImageFilterTest001, TestSize.Level1) +{ + auto imageFilter = ImageFilter::CreateOffsetImageFilter(10.0f, 10.0f, nullptr); + EXPECT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: CreateArithmeticImageFilterTest001 + * @tc.desc: test for creating a filter that implements a custom blend mode. + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, CreateArithmeticImageFilterTest001, TestSize.Level1) +{ + std::vector coefficients; + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + auto imageFilter = ImageFilter::CreateArithmeticImageFilter(coefficients, true, nullptr, nullptr); + EXPECT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: CreateComposeImageFilterTest001 + * @tc.desc: test for creating a filter that composes f1 with f2. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ImageFilterTest, CreateComposeImageFilterTest001, TestSize.Level1) +{ + auto imageFilter1 = ImageFilter::CreateBlurImageFilter(10.0f, 20.0f, TileMode::CLAMP, nullptr); + auto imageFilter2 = ImageFilter::CreateOffsetImageFilter(30.0f, 40.0f, nullptr); + auto imageFilter = ImageFilter::CreateComposeImageFilter(imageFilter1, imageFilter2); + EXPECT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: ImageFilterCreateTest001 + * @tc.desc: testing the ImageFilter Construction Method + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, ImageFilterCreateTest001, TestSize.Level1) +{ + auto imageFilter = std::make_shared(ImageFilter::FilterType::BLUR, 10.0f, 10.0f, nullptr); + ASSERT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: ImageFilterCreateTest002 + * @tc.desc: testing the ImageFilter Construction Method + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, ImageFilterCreateTest002, TestSize.Level1) +{ + auto colorFilter = ColorFilter::CreateBlendModeColorFilter(11, OHOS::Rosen::Drawing::BlendMode::CLEAR); + auto imageFilter = std::make_shared(ImageFilter::FilterType::COLOR, *colorFilter, nullptr); + ASSERT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: ImageFilterCreateTest003 + * @tc.desc: testing the ImageFilter Construction Method + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, ImageFilterCreateTest003, TestSize.Level1) +{ + std::vector coefficients; + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + coefficients.push_back(10.0f); + auto imageFilter = std::make_shared(ImageFilter::FilterType::ARITHMETIC, coefficients, + true, nullptr, nullptr); + ASSERT_TRUE(nullptr != imageFilter); +} + +/* + * @tc.name: ImageFilterCreateTest004 + * @tc.desc: testing the ImageFilter Construction Method + * @tc.type: FUNC + * @tc.require: I73UXK + */ +HWTEST_F(ImageFilterTest, ImageFilterCreateTest004, TestSize.Level1) +{ + auto imageFilter1 = ImageFilter::CreateBlurImageFilter(10.0f, 20.0f, TileMode::CLAMP, nullptr); + auto imageFilter2 = ImageFilter::CreateOffsetImageFilter(30.0f, 40.0f, nullptr); + auto imageFilter = std::make_shared(ImageFilter::FilterType::COMPOSE, imageFilter1, imageFilter2); + ASSERT_TRUE(nullptr != imageFilter); +} +} // namespace Drawing +} // namespace Rosen +} // namespace OHOS