diff --git a/services/common/databuffer/src/data_buffer.cpp b/services/common/databuffer/src/data_buffer.cpp index 12ac906b2d378602750bbb41df255013f85a77e2..d35d1eb7a905f7a457920cff72d2338b4803250a 100644 --- a/services/common/databuffer/src/data_buffer.cpp +++ b/services/common/databuffer/src/data_buffer.cpp @@ -120,7 +120,7 @@ std::vector DataBuffer::GetDirtyRectVec() int32_t DataBuffer::GetData(int32_t offset, int32_t datasize, uint8_t* &output) { - if (offset + datasize > capacity_ || output == nullptr) { + if (static_cast(offset + datasize) > capacity_ || output == nullptr) { DHLOGE("DataBuffer GetData parameter invalid."); return ERR_DH_SCREEN_INPUT_PARAM_INVALID; } diff --git a/services/common/imageJpeg/src/jpeg_image_processor.cpp b/services/common/imageJpeg/src/jpeg_image_processor.cpp index 5fa6337c30a11f92d22360fe154a896a627f5f40..40a6d0f894609cd1e19641d86b239362a0c20a2b 100644 --- a/services/common/imageJpeg/src/jpeg_image_processor.cpp +++ b/services/common/imageJpeg/src/jpeg_image_processor.cpp @@ -282,7 +282,7 @@ void JpegImageProcessor::DecompressJpegToNV12(size_t jpegSize, uint8_t *inputDat #endif while (cinfo.output_scanline < cinfo.output_height) { (void)jpeg_read_scanlines(&cinfo, buffer, 1); - for (int j = 0 ; j < cinfo.output_width ; j++) { + for (unsigned int j = 0 ; j < cinfo.output_width ; j++) { #ifdef LIBYUV rgb[rgbIndex++] = buffer[0][j * RGB_CHROMA + TWO]; rgb[rgbIndex++] = buffer[0][j * RGB_CHROMA + 1]; diff --git a/services/common/test/unittest/BUILD.gn b/services/common/test/unittest/BUILD.gn index 95b6e68d985fcb89a7894fbdbddb0b98464b0f5f..19d5d5d9daf4c6282c77daf7c259e636bed3f67b 100644 --- a/services/common/test/unittest/BUILD.gn +++ b/services/common/test/unittest/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 @@ -15,6 +15,8 @@ group("service_common_test") { testonly = true deps = [ "databuffer:data_buffer_test", + "decision_center:screen_decision_center_test", + "imageJpeg:jpeg_image_processor_test", "utils:utils_test", ] } diff --git a/services/common/test/unittest/databuffer/BUILD.gn b/services/common/test/unittest/databuffer/BUILD.gn index 0a323b9ef95a4c2251d5e7c84430653a7fe26db0..9dfd4e9c44d0ec9cd68f8018af85f166708de5cf 100644 --- a/services/common/test/unittest/databuffer/BUILD.gn +++ b/services/common/test/unittest/databuffer/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 diff --git a/services/common/test/unittest/databuffer/data_buffer_test.cpp b/services/common/test/unittest/databuffer/data_buffer_test.cpp index b1828d2beb4a444e168935abd6aace86e9162a1f..d6afac5adbf05c0ca137a34c3d1a04e1ea083795 100644 --- a/services/common/test/unittest/databuffer/data_buffer_test.cpp +++ b/services/common/test/unittest/databuffer/data_buffer_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 @@ -15,6 +15,7 @@ #define private public #include "data_buffer_test.h" +#include "dscreen_errcode.h" #undef private using namespace testing::ext; @@ -55,5 +56,71 @@ HWTEST_F(DataBufferTest, Data_001, TestSize.Level1) uint8_t *actual = dataBuffer_->Data(); EXPECT_NE(nullptr, actual); } + +/** + * @tc.name: ResetCapcity_001 + * @tc.desc: Verify the ResetCapcity function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DataBufferTest, ResetCapcity_001, TestSize.Level1) +{ + dataBuffer_->ResetCapcity(10); + EXPECT_EQ(10, dataBuffer_->Capacity()); +} + +/** + * @tc.name: ResetCapcity_002 + * @tc.desc: Verify the ResetCapcity function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DataBufferTest, ResetCapcity_002, TestSize.Level1) +{ + dataBuffer_->ResetCapcity(0); + EXPECT_EQ(1, dataBuffer_->Capacity()); +} + +/** + * @tc.name: AddData_001 + * @tc.desc: Verify the AddData function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DataBufferTest, AddData_001, TestSize.Level1) +{ + unsigned char *inputData = nullptr; + dataBuffer_->AddData(10, inputData); + EXPECT_EQ(1, dataBuffer_->Capacity()); +} + +/** + * @tc.name: AddData_002 + * @tc.desc: Verify the AddData function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DataBufferTest, AddData_002, TestSize.Level1) +{ + unsigned char *inputData = new unsigned char[10] {0}; + dataBuffer_->ResetCapcity(20); + dataBuffer_->SetSize(0); + dataBuffer_->AddData(10, inputData); + EXPECT_EQ(10, dataBuffer_->Capacity()); + delete [] inputData; +} + +/** + * @tc.name: GetData_001 + * @tc.desc: Verify the GetData function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DataBufferTest, GetData_001, TestSize.Level1) +{ + uint8_t *outputData = new uint8_t[10] {0}; + EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, dataBuffer_->GetData(10, 10, outputData)); + delete [] outputData; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/common/test/unittest/databuffer/data_buffer_test.h b/services/common/test/unittest/databuffer/data_buffer_test.h index b9bf80ffbf682642d4ee094ff3b34184d6859b22..8e1d9e2bdf0369af196be5bbdd37bf226b8c6349 100644 --- a/services/common/test/unittest/databuffer/data_buffer_test.h +++ b/services/common/test/unittest/databuffer/data_buffer_test.h @@ -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 diff --git a/services/common/test/unittest/decision_center/BUILD.gn b/services/common/test/unittest/decision_center/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b5c26e9491a7b08c9c5aa5a9e9a7f271f5008a1f --- /dev/null +++ b/services/common/test/unittest/decision_center/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +module_out_path = "distributed_screen/services/screen_decision_center_test" + +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/decision_center/include", + "${services_path}/common/imageJpeg/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/screentransport/screensourceprocessor/include", + ] +} + +## UnitTest screen_decision_center_test +ohos_unittest("ScreenDecisionCenterTest") { + module_out_path = module_out_path + + sources = [ "${services_path}/common/test/unittest/decision_center/screen_decision_center_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] + + external_deps = [ + "graphic_standard:surface", + "multimedia_player_framework:media_client", + ] +} + +group("screen_decision_center_test") { + testonly = true + deps = [ ":ScreenDecisionCenterTest" ] +} diff --git a/services/common/test/unittest/decision_center/screen_decision_center_test.cpp b/services/common/test/unittest/decision_center/screen_decision_center_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fc7967687e250355a3914c141d352b754468ec7 --- /dev/null +++ b/services/common/test/unittest/decision_center/screen_decision_center_test.cpp @@ -0,0 +1,217 @@ +/* + * 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. + */ +#define private public +#include "screen_decision_center_test.h" +#include "dscreen_errcode.h" +#include "surface_type.h" +#include "iconsumer_surface.h" +#include "iimage_source_processor.h" +#include "iimage_source_processor_listener.h" +#include "jpeg_image_processor.h" +#undef private +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenDecisionCenterTest::SetUpTestCase(void) {} + +void ScreenDecisionCenterTest::TearDownTestCase(void) {} + +void ScreenDecisionCenterTest::SetUp(void) +{ + param_.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + param_.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + param_.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + param_.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + param_.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + decision = std::make_shared(param_); +} + +void ScreenDecisionCenterTest::TearDown(void) {} + +/** + * @tc.name: IsDirtyRectValid_001 + * @tc.desc: Verify the IsDirtyRectValid function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, IsDirtyRectValid_001, TestSize.Level1) +{ + std::vector damages; + int32_t ret = decision->IsDirtyRectValid(damages); + EXPECT_EQ(false, ret); +} + +/** + * @tc.name: IsDirtyRectValid_002 + * @tc.desc: Verify the IsDirtyRectValid function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, IsDirtyRectValid_002, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {-1, -1, 0, 0}; + damages.push_back(damage); + int32_t ret = decision->IsDirtyRectValid(damages); + EXPECT_EQ(false, ret); +} + +/** + * @tc.name: IsDirtyRectValid_003 + * @tc.desc: Verify the IsDirtyRectValid function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, IsDirtyRectValid_003, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {1, 2, 1, 2}; + damages.push_back(damage); + int32_t ret = decision->IsDirtyRectValid(damages); + EXPECT_EQ(false, ret); +} + +/** + * @tc.name: IsDirtyRectValid_004 + * @tc.desc: Verify the IsDirtyRectValid function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, IsDirtyRectValid_004, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {2560, 2772, 2, 2}; + damages.push_back(damage); + int32_t ret = decision->IsDirtyRectValid(damages); + EXPECT_EQ(false, ret); +} + +/** + * @tc.name: IsDirtyRectValid_005 + * @tc.desc: Verify the IsDirtyRectValid function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, IsDirtyRectValid_005, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {2, 2, 2, 2}; + damages.push_back(damage); + int32_t ret = decision->IsDirtyRectValid(damages); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: JudgeDirtyThreshold_001 + * @tc.desc: Verify the JudgeDirtyThreshold function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, JudgeDirtyThreshold_001, TestSize.Level1) +{ + std::vector damages; + int32_t ret = decision->JudgeDirtyThreshold(damages); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: JudgeDirtyThreshold_002 + * @tc.desc: Verify the JudgeDirtyThreshold function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, JudgeDirtyThreshold_002, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {2, 2, 2, 2}; + damages.push_back(damage); + int32_t ret = decision->JudgeDirtyThreshold(damages); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: JudgeDirtyThreshold_003 + * @tc.desc: Verify the JudgeDirtyThreshold function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, JudgeDirtyThreshold_003, TestSize.Level1) +{ + std::vector damages; + OHOS::Rect damage = {0, 0, 2600, 2780}; + damages.push_back(damage); + int32_t ret = decision->JudgeDirtyThreshold(damages); + EXPECT_EQ(false, ret); +} + +/** + * @tc.name: LimitTime_001 + * @tc.desc: Verify the LimitTime function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, LimitTime_001, TestSize.Level1) +{ + decision->sendFullTime_ = time(nullptr); + int32_t ret = decision->LimitTime(0); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: InputBufferImage_001 + * @tc.desc: Verify the InputBufferImage function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, InputBufferImage_001, TestSize.Level1) +{ + std::vector damages; + sptr surfaceBuffer = nullptr; + int32_t ret = decision->InputBufferImage(surfaceBuffer, damages); + EXPECT_EQ(ERR_DH_SCREEN_SURFACE_BUFFER_INVALIED, ret); +} + +/** + * @tc.name: ConfigureDecisionCenter_001 + * @tc.desc: Verify the ConfigureDecisionCenter function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, ConfigureDecisionCenter_001, TestSize.Level1) +{ + std::shared_ptr listener = nullptr; + std::shared_ptr imageProcessor = nullptr; + int32_t ret = decision->ConfigureDecisionCenter(listener, imageProcessor); + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret); +} + +/** + * @tc.name: SetJpegSurface_001 + * @tc.desc: Verify the SetJpegSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenDecisionCenterTest, SetJpegSurface_001, TestSize.Level1) +{ + decision->imageJpeg_ = std::make_shared(param_); + sptr jpegSurface = IConsumerSurface::Create(); + int32_t ret = decision->SetJpegSurface(jpegSurface); + EXPECT_EQ(DH_SUCCESS, ret); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/common/test/unittest/decision_center/screen_decision_center_test.h b/services/common/test/unittest/decision_center/screen_decision_center_test.h new file mode 100644 index 0000000000000000000000000000000000000000..36bd4761e15a0f3ea2650f29d1dfd05c1b8a4f67 --- /dev/null +++ b/services/common/test/unittest/decision_center/screen_decision_center_test.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef SCREEN_DECISION_CENTER_TEST_H +#define SCREEN_DECISION_CENTER_TEST_H + +#include +#include "screen_decision_center.h" +#include "video_param.h" +namespace OHOS { +namespace DistributedHardware { +class ScreenDecisionCenterTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + VideoParam param_; + std::shared_ptr decision = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/common/test/unittest/imageJpeg/BUILD.gn b/services/common/test/unittest/imageJpeg/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..417517d76e5d0ccee4b82f9c63901775975ef841 --- /dev/null +++ b/services/common/test/unittest/imageJpeg/BUILD.gn @@ -0,0 +1,53 @@ +# 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. + +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +module_out_path = "distributed_screen/services/jpeg_image_processor_test" + +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/imageJpeg/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/screentransport/screensourceprocessor/include", + ] +} + +## UnitTest jpeg_image_processor_test +ohos_unittest("JpegImageProcessorTest") { + module_out_path = module_out_path + + sources = [ "${services_path}/common/test/unittest/imageJpeg/jpeg_image_processor_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] + + external_deps = [ + "graphic_standard:surface", + "multimedia_player_framework:media_client", + ] +} + +group("jpeg_image_processor_test") { + testonly = true + deps = [ ":JpegImageProcessorTest" ] +} diff --git a/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.cpp b/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b26eb6d1631edafe35086fee89861953e0c89cba --- /dev/null +++ b/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.cpp @@ -0,0 +1,120 @@ +/* + * 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. + */ +#define private public +#include "jpeg_image_processor_test.h" +#include "data_buffer.h" +#include "dscreen_errcode.h" +#include "iconsumer_surface.h" +#include "surface_type.h" +#undef private +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenImageJpegTest::SetUpTestCase(void) {} + +void ScreenImageJpegTest::TearDownTestCase(void) {} + +void ScreenImageJpegTest::SetUp(void) +{ + param_.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + param_.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + param_.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + param_.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + param_.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + jpeg_ = std::make_shared(param_); +} + +void ScreenImageJpegTest::TearDown(void) {} + +/** + * @tc.name: SetOutputSurface_001 + * @tc.desc: Verify the SetOutputSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenImageJpegTest, SetOutputSurface_001, TestSize.Level1) +{ + sptr jpegSurface = IConsumerSurface::Create(); + int32_t ret = jpeg_->SetOutputSurface(jpegSurface); + EXPECT_EQ(DH_SUCCESS, ret); +} + +/** + * @tc.name: SetOutputSurface_002 + * @tc.desc: Verify the SetOutputSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenImageJpegTest, SetOutputSurface_002, TestSize.Level1) +{ + int32_t ret = jpeg_->SetOutputSurface(nullptr); + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret); +} + +/** + * @tc.name: FillDirtyImages2Surface_001 + * @tc.desc: Verify the FillDirtyImages2Surface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenImageJpegTest, FillDirtyImages2Surface_001, TestSize.Level1) +{ + jpeg_->imageSurface_ = nullptr; + std::shared_ptr dataBuffer = std::make_shared(10); + DirtyRect rect = {20, 20, 20, 20, 20}; + dataBuffer->AddDirtyRect(rect); + int32_t ret = jpeg_->FillDirtyImages2Surface(dataBuffer, nullptr); + EXPECT_EQ(ERR_DH_SCREEN_SURFACE_INVALIED, ret); +} + +/** + * @tc.name: FillDirtyImages2Surface_002 + * @tc.desc: Verify the FillDirtyImages2Surface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenImageJpegTest, FillDirtyImages2Surface_002, TestSize.Level1) +{ + sptr consumerSurface = IConsumerSurface::Create(); + sptr prodecer = consumerSurface->GetProducer(); + jpeg_->imageSurface_ = Surface::CreateSurfaceAsProducer(prodecer); + std::shared_ptr dataBuffer = std::make_shared(20); + DirtyRect rect = {2600, 2800, 20, 20, 20}; + dataBuffer->AddDirtyRect(rect); + uint8_t *lastFrame = new uint8_t[20] {0}; + int32_t ret = jpeg_->FillDirtyImages2Surface(dataBuffer, lastFrame); + delete [] lastFrame; + EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret); +} + +/** + * @tc.name: ReplaceDamage2LastFrame_001 + * @tc.desc: Verify the ReplaceDamage2LastFrame function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenImageJpegTest, ReplaceDamage2LastFrame_001, TestSize.Level1) +{ + uint8_t *lastframe = new uint8_t[28385280] {125}; + uint8_t *dirtyImageData = new uint8_t[1600] {125}; + DirtyRect rect = {20, 20, 20, 24, 20}; + int32_t ret = jpeg_->ReplaceDamage2LastFrame(lastframe, dirtyImageData, rect); + EXPECT_EQ(DH_SUCCESS, ret); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.h b/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..96c4841a1634f34f546126c68fcec2439516ea3f --- /dev/null +++ b/services/common/test/unittest/imageJpeg/jpeg_image_processor_test.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef SCREEN_IMAGE_JPEG_TEST_H +#define SCREEN_IMAGE_JPEG_TEST_H + +#include +#include "jpeg_image_processor.h" +#include "video_param.h" +namespace OHOS { +namespace DistributedHardware { +class ScreenImageJpegTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + VideoParam param_; + std::shared_ptr jpeg_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 687c25271c63243749f75700ed6b824200761f23..4a8691266755104b3044c26ad13eb91d784dfbec 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -135,7 +135,7 @@ void ImageSinkDecoder::OffsetProcess(sptr surfaceBuffer, sptrGetStride(); int32_t chromaOffset = configParam_.GetVideoWidth() * configParam_.GetVideoHeight(); - for (int32_t yh = 0 ; yh < configParam_.GetVideoHeight() ; yh++) { + for (unsigned int yh = 0 ; yh < configParam_.GetVideoHeight() ; yh++) { int32_t ret = memcpy_s(windowSurfaceAddr + dstDataOffset, chromaOffset - dstDataOffset, surfaceAddr + srcDataOffset, configParam_.GetVideoWidth()); if (ret != EOK) { @@ -148,7 +148,7 @@ void ImageSinkDecoder::OffsetProcess(sptr surfaceBuffer, sptrGetStride(); - if (alignedWidth == configParam_.GetVideoWidth() && alignedHeight_ == configParam_.GetVideoHeight()) { + if (static_cast(alignedWidth) == configParam_.GetVideoWidth() && + static_cast(alignedHeight_) == configParam_.GetVideoHeight()) { NormalProcess(surfaceBuffer, windowSurfaceBuffer); } else { OffsetProcess(surfaceBuffer, windowSurfaceBuffer); diff --git a/services/screentransport/test/unittest/BUILD.gn b/services/screentransport/test/unittest/BUILD.gn index a5e48ee7489a0e18185a43bb2968607f29f6668b..51bdfe13ede7eee30fac77e23e4321f9d3d6505d 100644 --- a/services/screentransport/test/unittest/BUILD.gn +++ b/services/screentransport/test/unittest/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 @@ -18,6 +18,7 @@ group("screen_transport_test") { "screensinkprocessor:sink_processor_test", "screensinktrans:sink_trans_test", "screensourceprocessor:source_processor_test", + "screensourcetrans:source_trans_test", "screentranstestutils:screen_callback_test", ] } diff --git a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn index 57855fb92ae6d7633282714052cb51690ba8cd15..00c3791dfdaa65cb5f3ecb0edcfb521675244d72 100644 --- a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn +++ b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("SourceTransTest") { external_deps = [ "c_utils:utils", + "graphic_standard:surface", "multimedia_player_framework:media_client", ] }