diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index cfcda3a0afa727a439202331a85a824577531bfb..219c34bc7f3525b2c6f52a62bfb1c0c10c376077 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -85,7 +85,7 @@ bool DisplayManager::CheckRectValid(const Media::Rect &rect, int32_t oriHeight, return true; } -bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) +bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const { if (!((size.width > 0) and (size.height > 0))) { if (!((size.width == 0) and (size.height == 0))) { diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index c523562cc3006786323ccb94652aeb6b00de5b49..aa6313958c92338dd88147b9f3f10f1b112a5c48 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -18,7 +18,10 @@ module_out_path = "window_manager/dm" group("unittest") { testonly = true - deps = [ ":dm_snapshot_utils_test" ] + deps = [ + ":dm_screenshot_test", + ":dm_snapshot_utils_test", + ] } ## UnitTest dm_snapshot_utils_test {{{ @@ -35,6 +38,17 @@ ohos_unittest("dm_snapshot_utils_test") { ## UnitTest dm_snapshot_utils_test }}} +## UnitTest dm_screenshot_test {{{ +ohos_unittest("dm_screenshot_test") { + module_out_path = module_out_path + + sources = [ "screenshot_test.cpp" ] + + deps = [ ":dm_unittest_common" ] +} + +## UnitTest dm_screenshot_test }}} + ## Build dm_unittest_common.a {{{ config("dm_unittest_common_public_config") { include_dirs = [ diff --git a/dm/test/unittest/screenshot_test.cpp b/dm/test/unittest/screenshot_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1b0427c4a288d7aea11a62a6eeaebedf1ebd7cc --- /dev/null +++ b/dm/test/unittest/screenshot_test.cpp @@ -0,0 +1,118 @@ +/* + * 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 + +#include "mock_display_manager_adapter.h" +#include "singleton_mocker.h" +#include "screenshot_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +constexpr int32_t TEST_IMAGE_HEIGHT = 1080; +constexpr int32_t TEST_IMAGE_WIDTH = 1920; +using Mocker = SingletonMocker; +void ScreenshotTest::SetUpTestCase() +{ +} + +void ScreenshotTest::TearDownTestCase() +{ +} + +void ScreenshotTest::SetUp() +{ +} + +void ScreenshotTest::TearDown() +{ +} + +namespace { +static std::shared_ptr CreatePixelMap() +{ + // pixel_map testing code + Media::InitializationOptions opt; + opt.size.width = TEST_IMAGE_WIDTH; + opt.size.height = TEST_IMAGE_HEIGHT; + opt.pixelFormat = Media::PixelFormat::RGBA_8888; + opt.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; + opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; + opt.editable = false; + opt.useSourceIfMatch = false; + + const int bitmapDepth = 8; // color depth + const int bpp = 4; // bytes per pixel + const int pixelValue = 125; + + const int voulumeSize = opt.size.width * opt.size.height * bpp; + auto data = (uint32_t *)malloc(voulumeSize); + if (data == nullptr) { + return nullptr; + } + + uint8_t *pic = (uint8_t *)data; + memset_s(pic, voulumeSize, pixelValue, voulumeSize); + + uint32_t colorLen = voulumeSize * bitmapDepth; + auto pixelMap = Media::PixelMap::Create(data, colorLen, opt); + if (pixelMap == nullptr) { + return nullptr; + } + std::shared_ptr pixelMap_(pixelMap.release()); + return pixelMap_; +} + +/** + * @tc.name: GetScreenshot_default + * @tc.desc: SetWindowRect/GetWindowRect + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(ScreenshotTest, GetScreenshot_default, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(0ULL)); + + DisplayId displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + + EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(nullptr)); + + ASSERT_EQ(nullptr, DisplayManager::GetInstance().GetScreenshot(displayId)); +} + +HWTEST_F(ScreenshotTest, GetScreenshot_01, Function | MediumTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(0ULL)); + DisplayId displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + + EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(CreatePixelMap())); + auto screenshot = DisplayManager::GetInstance().GetScreenshot(displayId); + ASSERT_NE(nullptr, screenshot); + + uint32_t width = screenshot->GetWidth(); + uint32_t height = screenshot->GetHeight(); + ASSERT_EQ(width, TEST_IMAGE_WIDTH); + ASSERT_EQ(height, TEST_IMAGE_HEIGHT); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/dm/test/unittest/screenshot_test.h b/dm/test/unittest/screenshot_test.h new file mode 100644 index 0000000000000000000000000000000000000000..59d4b27de5c8b234d37fe3f82361017e44d2118c --- /dev/null +++ b/dm/test/unittest/screenshot_test.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H + +#include +#include "png.h" +#include "display_manager.h" +#include "pixel_map.h" + +namespace OHOS { +namespace Rosen { +class ScreenshotTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 5f1b11362907e2459cae52f7c951b25fef0c66ed..b8797603b9007fb1f13bd8493954ac3f38e04df3 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -37,7 +37,7 @@ public: ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); - std::shared_ptr GetScreenSnapshot(DisplayId displayId, ScreenId screenId); + std::shared_ptr GetScreenSnapshot(DisplayId displayId); private: void OnAbstractScreenConnected(sptr absScreen); diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index cc4e7908970b376f144d303c659f66818b354e47..45af6bd565abdcd878a1e819b4b4e22192783321 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -70,7 +70,7 @@ RSScreenModeInfo AbstractDisplayController::GetScreenActiveMode(ScreenId id) return rsInterface_->GetScreenActiveMode(id); } -std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId, ScreenId screenId) +std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId) { if (rsInterface_ == nullptr) { return nullptr; diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 256290e13f5beea938cd11a68df6c8d5cc2bd60d..e133cf72a851a74f5cf83178fe44793fa9b872a2 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -117,9 +117,8 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) std::shared_ptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) { - ScreenId screenId = GetScreenIdFromDisplayId(displayId); std::shared_ptr screenSnapshot - = abstractDisplayController_->GetScreenSnapshot(displayId, screenId); + = abstractDisplayController_->GetScreenSnapshot(displayId); return screenSnapshot; } diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 402f3181ec43212642c3a2ade16a8731d0094631..92d60fb5f247abb264387f8359bbbe46ae1d8dd1 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -65,7 +65,7 @@ private: DisplayManager(); ~DisplayManager(); bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; - bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); + bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const; void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); void NotifyDisplayStateChanged(DisplayState state);