diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 4b4e565eb2d762141f0f27f6bddf407ed93b00bc..4d234bda82c11dae907f9ecfb73ad8796b3fc4d6 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -17,6 +17,7 @@ group("unittest") { deps += [ "ans_callback_stub_test:unittest", + "ans_image_util_test:unittest", "ans_manager_death_recipient_test:unittest", "ans_subscriber_proxy_test:unittest", ] diff --git a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..366fadf47e3cd1f7cf7f0a044ca1e977b91ab5ff --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn @@ -0,0 +1,62 @@ +# 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("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_image_util_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "${core_path}/common/include", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + "../mock", + ] + + sources = [ + "${core_path}/common/src/ans_log_wrapper.cpp", + "${core_path}/src/ans_image_util.cpp", + "../mock/mock_image_packer.cpp", + "../mock/mock_image_source.cpp", + "../mock/mock_pixel_map.cpp", + "ans_image_util_unit_test.cpp", + ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_image_util_test" ] +} diff --git a/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..718f1272734813506c1f84143c7d89c273efcba5 --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp @@ -0,0 +1,658 @@ + /* + * 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 + +#define private public +#define protected public +#include "ans_image_util.h" +#include "image_packer.h" +#include "pixel_map.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +extern void MockImagePackerGetSupportedFormats(uint32_t mockRet); +extern void MockImagePackerStartPacking(const uint8_t* mockRet); +extern void MockImagePackerFinalizePacking(uint32_t mockRet); +extern void MockResetImagePackerState(); + +extern void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode); +extern void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode); +extern void MockImageSourceGetSupportedFormats(uint32_t mockRet); +extern void MockResetImageSourceState(); + +extern void MockPixelMapGetByteCount(int32_t mockRet); +extern void MockResetPixelMapState(); + +class AnsImageUtilUnitTest : public testing::Test { +public: + AnsImageUtilUnitTest() {} + + virtual ~AnsImageUtilUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsImageUtilUnitTest::SetUpTestCase() {} + +void AnsImageUtilUnitTest::TearDownTestCase() {} + +void AnsImageUtilUnitTest::SetUp() {} + +void AnsImageUtilUnitTest::TearDown() {} + +/* + * @tc.name: PackImageTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_FALSE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: PackImageTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string format = ":"; + std::string res = imageUtil->PackImage(nullptr, format); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string res = imageUtil->PackImage(pixelMap, ""); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_TRUE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: UnPackImageTest_0100 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0200 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = ""; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0300 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0400 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0500 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0600 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: PackImage2FileTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_TRUE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0200, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = nullptr; + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0300, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = ""; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = ""; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0500 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0500, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0100 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0200 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = ""; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0300 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = ""; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + + +/* + * @tc.name: CreatePixelMapTest_0400 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0500 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0600 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: CreatePixelMapTest_0700 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0700, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0800 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0800, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: BinToHexTest_0100 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = "12112221"; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_NE("", res); +} + +/* + * @tc.name: BinToHexTest_0200 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = ""; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0100 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "12112221"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_NE("", res); +} + +/* + * @tc.name: HexToBinTest_0200 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = ""; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0300 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0400 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0400, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123x"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/mock/mock_i_remote_object.h b/frameworks/core/test/unittest/mock/mock_i_remote_object.h index d37235cd5a949d0c734be9be28b348901fba3ce5..5a2392a1d29dd9e836d2b16597357fbbf5c0aad5 100644 --- a/frameworks/core/test/unittest/mock/mock_i_remote_object.h +++ b/frameworks/core/test/unittest/mock/mock_i_remote_object.h @@ -1,78 +1,82 @@ -/* - * 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 "gmock/gmock.h" - -#include "iremote_broker.h" -#include "iremote_object.h" - -namespace OHOS { -namespace Notification { -class MockIRemoteObject : public IRemoteObject { -public: - MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} - - ~MockIRemoteObject() {} - - int32_t GetObjectRefCount() override - { - return 0; - } - - MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - - bool IsProxyObject() const override - { - return true; - } - - bool CheckObjectLegality() const override - { - return true; - } - - bool AddDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool RemoveDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool Marshalling(Parcel &parcel) const override - { - return true; - } - - sptr AsInterface() override - { - return nullptr; - } - - int Dump(int fd, const std::vector &args) override - { - return 0; - } - - std::u16string GetObjectDescriptor() const - { - std::u16string descriptor = std::u16string(); - return descriptor; - } -}; -} // namespace Notification -} // namespace OHOS +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H +#define BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H + +#include "gmock/gmock.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Notification { +class MockIRemoteObject : public IRemoteObject { +public: + MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} + + ~MockIRemoteObject() {} + + int32_t GetObjectRefCount() override + { + return 0; + } + + MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; +} // namespace Notification +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_packer.cpp b/frameworks/core/test/unittest/mock/mock_image_packer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8063acfc93e5c74128f5369fd26004665bc906f4 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_packer.cpp @@ -0,0 +1,139 @@ +/* + * 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 "image_packer.h" +#include "mock_image_related_class.h" +#include "securec.h" + +namespace { +const uint8_t COUNT = 64; +uint32_t g_mockImagePackerGetSupportedFormatsRet = 0; +const uint8_t *g_mockImagePackerStartPackingRet = nullptr; +uint32_t g_mockImagePackerFinalizePackingRet = 16; +} + +void MockImagePackerGetSupportedFormats(uint32_t mockRet) +{ + g_mockImagePackerGetSupportedFormatsRet = mockRet; +} + +void MockImagePackerStartPacking(const uint8_t *mockRet) +{ + g_mockImagePackerStartPackingRet = mockRet; +} + +void MockImagePackerFinalizePacking(uint32_t mockRet) +{ + g_mockImagePackerFinalizePackingRet = mockRet; +} + +void MockResetImagePackerState() +{ + g_mockImagePackerGetSupportedFormatsRet = 0; + g_mockImagePackerStartPackingRet = nullptr; + g_mockImagePackerFinalizePackingRet = 16; // 16 :initial test result +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; +using namespace MultimediaPlugin; + +uint32_t ImagePacker::GetSupportedFormats(std::set &formats) +{ + return g_mockImagePackerGetSupportedFormatsRet; +} + +uint32_t ImagePacker::StartPackingImpl(const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(uint8_t *outputData, uint32_t maxSize, const PackOption &option) +{ + memcpy_s(outputData, COUNT, g_mockImagePackerStartPackingRet, COUNT); + return 0; +} + +uint32_t ImagePacker::StartPacking(const std::string &filePath, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(const int &fd, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(std::ostream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPackingAdapter(PackerStream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(PixelMap &pixelMap) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source, uint32_t index) +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking() +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking(int64_t &packedSize) +{ + packedSize = g_mockImagePackerFinalizePackingRet; + return 0; +} + +bool ImagePacker::GetEncoderPlugin(const PackOption &option) +{ + return true; +} + +void ImagePacker::CopyOptionsToPlugin(const PackOption &opts, PlEncodeOptions &plOpts) +{} + +void ImagePacker::FreeOldPackerStream() +{} + +bool ImagePacker::IsPackOptionValid(const PackOption &option) +{ + return true; +} + +// class reference need explicit constructor and destructor, otherwise unique_ptr use unnormal +ImagePacker::ImagePacker() +{} + +ImagePacker::~ImagePacker() +{} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_image_related_class.h b/frameworks/core/test/unittest/mock/mock_image_related_class.h new file mode 100644 index 0000000000000000000000000000000000000000..3d34c4cf76e7d5233eb484a3c500b8acac2138f9 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_related_class.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H +#define BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H + +namespace OHOS { +namespace Media { +class SourceStream {}; +class PackerStream {}; +} // namespace Media + +namespace ImagePlugin { +class AbsImageEncoder {}; +class AbsImageDecoder {}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_source.cpp b/frameworks/core/test/unittest/mock/mock_image_source.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57314557bfaa1e5278d90054c2e566d397c59648 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_source.cpp @@ -0,0 +1,373 @@ +/* + * Copyright (C) 2021 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. + */ + +#define private public +#define protected public +#include "image_source.h" +#undef private +#undef protected +#include "mock_image_related_class.h" + +namespace { +bool g_mockImageSourceCreateImageSourceRet = true; +uint32_t g_mockImageSourceCreateImageSourceErrorCode = 0; +bool g_mockImageSourceCreatePixelMapRet = true; +uint32_t g_mockImageSourceCreatePixelMapErrorCode = 0; +uint32_t g_mockImageSourceGetSupportedFormatsRet = 0; +} + +void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreateImageSourceRet = mockRet; + g_mockImageSourceCreateImageSourceErrorCode = errorCode; +} + +void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreatePixelMapRet = mockRet; + g_mockImageSourceCreatePixelMapErrorCode = errorCode; +} + +void MockImageSourceGetSupportedFormats(uint32_t mockRet) +{ + g_mockImageSourceGetSupportedFormatsRet = mockRet; +} + +void MockResetImageSourceState() +{ + g_mockImageSourceCreateImageSourceRet = true; + g_mockImageSourceCreateImageSourceErrorCode = 0; + g_mockImageSourceCreatePixelMapRet = true; + g_mockImageSourceCreatePixelMapErrorCode = 0; +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; + +uint32_t ImageSource::GetSupportedFormats(std::set &formats) +{ + return g_mockImageSourceGetSupportedFormatsRet; +} + +std::unique_ptr ImageSource::CreateImageSource(std::unique_ptr is, + const SourceOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const uint8_t *data, uint32_t size, + const SourceOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const std::string &pathName, const SourceOptions &opts, + uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const int fd, const SourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalImageSource(const IncrementalSourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +void ImageSource::Reset() +{} + +std::unique_ptr ImageSource::CreatePixelMapEx(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreatePixelMapErrorCode; + if (g_mockImageSourceCreatePixelMapRet) { + PixelMap *pixelMap = new (std::nothrow) PixelMap(); + return std::unique_ptr(pixelMap); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreatePixelMap(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalPixelMap(uint32_t index, const DecodeOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::PromoteDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + ImageDecodingState &state, uint8_t &decodeProgress) +{ + return 0; +} + +void ImageSource::DetachIncrementalDecoding(PixelMap &pixelMap) +{} + +uint32_t ImageSource::UpdateData(const uint8_t *data, uint32_t size, bool isCompleted) +{ + return 0; +} + +DecodeEvent ImageSource::GetDecodeEvent() +{ + return decodeEvent_; +} + +uint32_t ImageSource::GetImageInfo(uint32_t index, ImageInfo &imageInfo) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const std::string &path) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const int fd) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, uint8_t *data, uint32_t size) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value) +{ + return 0; +} + +const SourceInfo &ImageSource::GetSourceInfo(uint32_t &errorCode) +{ + return sourceInfo_; +} + +void ImageSource::RegisterListener(PeerListener *listener) +{} + +void ImageSource::UnRegisterListener(PeerListener *listener) +{} + +void ImageSource::AddDecodeListener(DecodeListener *listener) +{} + +void ImageSource::RemoveDecodeListener(DecodeListener *listener) +{} + +ImageSource::~ImageSource() +{} + +bool ImageSource::IsStreamCompleted() +{ + return true; +} + +ImageSource::ImageSource(std::unique_ptr &&stream, const SourceOptions &opts) +{} + +ImageSource::FormatAgentMap ImageSource::InitClass() +{ + FormatAgentMap tempAgentMap; + return tempAgentMap; +} + +uint32_t ImageSource::CheckEncodedFormat(AbsImageFormatAgent &agent) +{ + return 0; +} + +uint32_t ImageSource::CheckFormatHint(const std::string &formatHint, FormatAgentMap::iterator &formatIter) +{ + return 0; +} + +uint32_t ImageSource::GetEncodedFormat(const std::string &formatHint, std::string &format) +{ + return 0; +} + +uint32_t ImageSource::OnSourceRecognized(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::OnSourceUnresolved() +{ + return 0; +} + +uint32_t ImageSource::DecodeSourceInfo(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::DecodeImageInfo(uint32_t index, ImageStatusMap::iterator &iter) +{ + return 0; +} + +uint32_t ImageSource::InitMainDecoder() +{ + return 0; +} + +AbsImageDecoder *ImageSource::CreateDecoder(uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::SetDecodeOptions(std::unique_ptr &decoder, uint32_t index, + const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo) +{ + return 0; +} + +uint32_t ImageSource::UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo, + PixelMap &pixelMap) +{ + return 0; +} + +void ImageSource::CopyOptionsToPlugin(const DecodeOptions &opts, PixelDecodeOptions &plOpts) +{} + +void ImageSource::CopyOptionsToProcOpts(const DecodeOptions &opts, DecodeOptions &procOpts, PixelMap &pixelMap) +{} + +ImageSource::ImageStatusMap::iterator ImageSource::GetValidImageStatus(uint32_t index, uint32_t &errorCode) +{ + return imageStatusMap_.find(index); +} + +uint32_t ImageSource::AddIncrementalContext(PixelMap &pixelMap, IncrementalRecordMap::iterator &iterator) +{ + return 0; +} + +uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + IncrementalDecodingContext &recordContext) +{ + return 0; +} + +const NinePatchInfo &ImageSource::GetNinePatchInfo() const +{ + return ninePatchInfo_; +} + +void ImageSource::SetMemoryUsagePreference(const MemoryUsagePreference preference) +{} + +MemoryUsagePreference ImageSource::GetMemoryUsagePreference() +{ + return preference_; +} + +uint32_t ImageSource::GetRedactionArea(const int &fd, const int &redactionType, + std::vector> &ranges) +{ + return 0; +} + +void ImageSource::SetIncrementalSource(const bool isIncrementalSource) +{ + isIncrementalSource_ = isIncrementalSource; +} + +bool ImageSource::IsIncrementalSource() +{ + return isIncrementalSource_; +} + +FinalOutputStep ImageSource::GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch) +{ + return FinalOutputStep::NO_CHANGE; +} + +bool ImageSource::HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch) +{ + return true; +} + +bool ImageSource::ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight) +{ + return false; +} + +bool ImageSource::ImageConverChange(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo) +{ + return true; +} + +std::unique_ptr ImageSource::DecodeBase64(const uint8_t *data, uint32_t size) +{ + return DecodeBase64(""); +} + +std::unique_ptr ImageSource::DecodeBase64(const std::string &data) +{ + return nullptr; +} + +bool ImageSource::IsSpecialYUV() +{ + return true; +} + +bool ImageSource::ConvertYUV420ToRGBA(uint8_t *data, uint32_t size, + bool isSupportOdd, bool isAddUV, uint32_t &errorCode) +{ + return true; +} + +std::unique_ptr ImageSource::CreatePixelMapForYUV(uint32_t &errorCode) +{ + return nullptr; +} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_pixel_map.cpp b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1bd9daa2a00144b276d6b92835748745dd7b5077 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2021 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 "pixel_map.h" + +namespace { +int32_t g_mockPixelMapGetByteCountRet = 128; +} + +void MockPixelMapGetByteCount(int32_t mockRet) +{ + g_mockPixelMapGetByteCountRet = mockRet; +} + +void MockResetPixelMapState() +{ + g_mockPixelMapGetByteCountRet = 128; // 128 :initial test result +} +namespace OHOS { +namespace Media { +PixelMap::~PixelMap() +{} + +void PixelMap::FreePixelMap() __attribute__((no_sanitize("cfi"))) +{} + +void PixelMap::ReleaseSharedMemory(void *addr, void *context, uint32_t size) +{} + +void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, CustomFreePixelMap func) +{} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, + const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, int32_t offset, + int32_t stride, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::CheckParams(const uint32_t *colors, uint32_t colorLength, int32_t offset, int32_t stride, + const InitializationOptions &opts) +{ + return true; +} + +std::unique_ptr PixelMap::Create(const InitializationOptions &opts) +{ + return nullptr; +} + +void PixelMap::UpdatePixelsAlpha(const AlphaType &alphaType, const PixelFormat &pixelFormat, uint8_t *dstPixels, + PixelMap dstPixelMap) +{} + +std::unique_ptr PixelMap::Create(PixelMap &source, const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(PixelMap &source, const Rect &srcRect, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageInfo, const ImageInfo &dstImageInfo, + const Rect &srcRect, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::ScalePixelMap(const Size &targetSize, const Size &dstSize, const ScaleMode &scaleMode, + PixelMap &dstPixelMap) +{ + return true; +} + +void PixelMap::InitDstImageInfo(const InitializationOptions &opts, const ImageInfo &srcImageInfo, + ImageInfo &dstImageInfo) +{} + +bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::IsSameSize(const Size &src, const Size &dst) +{ + return true; +} + +bool PixelMap::GetPixelFormatDetail(const PixelFormat format) +{ + return true; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info) +{ + return 0; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused) +{ + return 0; +} + +const uint8_t *PixelMap::GetPixel8(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint16_t *PixelMap::GetPixel16(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint32_t *PixelMap::GetPixel32(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint8_t *PixelMap::GetPixel(int32_t x, int32_t y) +{ + return nullptr; +} + +bool PixelMap::GetARGB32Color(int32_t x, int32_t y, uint32_t &color) +{ + return true; +} + +bool PixelMap::ALPHA8ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB565ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::ARGB8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGBA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::BGRA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +int32_t PixelMap::GetPixelBytes() +{ + return 0; +} + +int32_t PixelMap::GetRowBytes() +{ + return 0; +} + +int32_t PixelMap::GetByteCount() +{ + return g_mockPixelMapGetByteCountRet; +} + +int32_t PixelMap::GetWidth() +{ + return 0; +} + +int32_t PixelMap::GetHeight() +{ + return 0; +} + +int32_t PixelMap::GetBaseDensity() +{ + return 0; +} + +void PixelMap::GetImageInfo(ImageInfo &imageInfo) +{} + +PixelFormat PixelMap::GetPixelFormat() +{ + return imageInfo_.pixelFormat; +} + +ColorSpace PixelMap::GetColorSpace() +{ + return imageInfo_.colorSpace; +} + +AlphaType PixelMap::GetAlphaType() +{ + return imageInfo_.alphaType; +} + +const uint8_t *PixelMap::GetPixels() +{ + return data_; +} + +uint8_t PixelMap::GetARGB32ColorA(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorR(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorG(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorB(uint32_t color) +{ + return 0; +} + +bool PixelMap::IsSameImage(const PixelMap &other) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, uint8_t *dst) +{ + return 0; +} + +bool PixelMap::CheckPixelsInput(const uint8_t *dst, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, const uint32_t &offset, const uint32_t &stride, + const Rect ®ion, uint8_t *dst) +{ + return 0; +} + +uint32_t PixelMap::ReadPixel(const Position &pos, uint32_t &dst) +{ + return 0; +} + +uint32_t PixelMap::ResetConfig(const Size &size, const PixelFormat &format) +{ + return 0; +} + +bool PixelMap::SetAlphaType(const AlphaType &alphaType) +{ + return true; +} + +uint32_t PixelMap::WritePixel(const Position &pos, const uint32_t &color) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize) +{ + return 0; +} + +bool PixelMap::WritePixels(const uint32_t &color) +{ + return true; +} + +AllocatorType PixelMap::GetAllocatorType() +{ + return allocatorType_; +} + +void *PixelMap::GetFd() const +{ + return context_; +} + +void PixelMap::ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size) +{} + +bool PixelMap::WriteImageData(Parcel &parcel, size_t size) const +{ + return true; +} + +uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) +{ + return nullptr; +} + +bool PixelMap::WriteFileDescriptor(Parcel &parcel, int fd) +{ + return true; +} + +int PixelMap::ReadFileDescriptor(Parcel &parcel) +{ + return 0; +} + +bool PixelMap::WriteImageInfo(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::Marshalling(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::ReadImageInfo(Parcel &parcel, ImageInfo &imgInfo) +{ + return true; +} + +PixelMap *PixelMap::Unmarshalling(Parcel &parcel) +{ + return nullptr; +} + +uint32_t PixelMap::SetAlpha(const float percent) +{ + return 0; +} + +void PixelMap::scale(float xAxis, float yAxis) +{} + +void PixelMap::translate(float xAxis, float yAxis) +{} + +void PixelMap::rotate(float degrees) +{} + +void PixelMap::flip(bool xAxis, bool yAxis) +{} + +uint32_t PixelMap::crop(const Rect &rect) +{ + return 0; +} +} // namespace Media +} // namespace OHOS