Add screen manager unittest

Signed-off-by: shiyueeee <nieshiyue@huawei.com>
Change-Id: Ic3feffc4752a61214f0c91e26cc91fce404beb8a
This commit is contained in:
shiyueeee
2022-01-18 21:46:01 +08:00
parent 614e9f2a87
commit 1d4c169de5
5 changed files with 239 additions and 0 deletions
+17
View File
@@ -20,6 +20,7 @@ group("unittest") {
deps = [
":dm_display_power_unit_test",
":dm_screen_manager_test",
":dm_screenshot_test",
":dm_snapshot_utils_test",
]
@@ -61,6 +62,20 @@ ohos_unittest("dm_screenshot_test") {
## UnitTest dm_screenshot_test }}}
## UnitTest dm_screen_manager_test {{{
ohos_unittest("dm_screen_manager_test") {
module_out_path = module_out_path
sources = [
"screen_manager_test.cpp",
"screen_manager_utils.cpp",
]
deps = [ ":dm_unittest_common" ]
}
## UnitTest dm_screen_manager_test }}}
## Build dm_unittest_common.a {{{
config("dm_unittest_common_public_config") {
include_dirs = [
@@ -69,6 +84,7 @@ config("dm_unittest_common_public_config") {
"//foundation/windowmanager/snapshot",
"//foundation/windowmanager/interfaces/innerkits/dm",
"//foundation/windowmanager/utils/include",
"//foundation/graphic/standard/rosen/modules/render_service_client", # RSSurface
]
}
@@ -82,6 +98,7 @@ ohos_static_library("dm_unittest_common") {
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/windowmanager/dm:libdm",
"//foundation/windowmanager/dmserver:libdms",
"//foundation/windowmanager/snapshot:snapshot_display",
"//foundation/windowmanager/utils:libwmutil",
"//foundation/windowmanager/wm:libwm",
+93
View File
@@ -0,0 +1,93 @@
/*
* 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 "screen_manager_test.h"
#include "mock_display_manager_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
sptr<Display> ScreenManagerTest::defaultDisplay_ = nullptr;
DisplayId ScreenManagerTest::defaultDisplayId_ = DISPLAY_ID_INVALD;
uint32_t ScreenManagerTest::defaultWidth_ = 480;
uint32_t ScreenManagerTest::defaultHeight_ = 320;
void ScreenManagerTest::SetUpTestCase()
{
defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
defaultDisplayId_ = defaultDisplay_->GetId();
defaultWidth_ = defaultDisplay_->GetWidth();
defaultHeight_ = defaultDisplay_->GetHeight();
}
void ScreenManagerTest::TearDownTestCase()
{
}
void ScreenManagerTest::SetUp()
{
}
void ScreenManagerTest::TearDown()
{
}
namespace {
/**
* @tc.name: CreateAndDestory01
* @tc.desc: CreateVirtualScreen with invalid option and return invalid screen id
* @tc.type: FUNC
*/
HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1)
{
VirtualScreenOption wrongOption = {defaultName_, defaultWidth_, defaultHeight_,
defaultDensity_, nullptr, defaultFlags_};
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(SCREEN_ID_INVALD));
EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM));
ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(wrongOption);
DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id);
ASSERT_EQ(SCREEN_ID_INVALD, id);
ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, ret);
}
/**
* @tc.name: CreateAndDestory02
* @tc.desc: CreateVirtualScreen with valid option and return valid screen id
* @tc.type: FUNC
*/
HWTEST_F(ScreenManagerTest, CreateAndDestory02, Function | SmallTest | Level1)
{
ScreenManagerUtils utils;
ASSERT_TRUE(utils.CreateSurface());
VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_,
defaultDensity_, utils.psurface_, defaultFlags_};
ScreenId validId = 0;
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(validId));
EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK));
ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id);
ASSERT_EQ(validId, id);
ASSERT_EQ(DMError::DM_OK, ret);
}
}
} // namespace Rosen
} // namespace OHOS
+42
View File
@@ -0,0 +1,42 @@
/*
* 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 FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H
#define FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H
#include <gtest/gtest.h>
#include "screen_manager_utils.h"
namespace OHOS {
namespace Rosen {
class ScreenManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
const std::string defaultName_ = "virtualScreen01";
const float defaultDensity_ = 2.0;
const int32_t defaultFlags_ = 0;
static sptr<Display> defaultDisplay_;
static DisplayId defaultDisplayId_;
static uint32_t defaultWidth_;
static uint32_t defaultHeight_;
};
} // namespace Rosen
} // namespace OHOS
#endif // FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H
+41
View File
@@ -0,0 +1,41 @@
/*
* 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 "screen_manager_utils.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenManagerUtils"};
}
bool ScreenManagerUtils::CreateSurface()
{
csurface_ = Surface::CreateSurfaceAsConsumer();
if (csurface_ == nullptr) {
WLOGFE("csurface create failed");
return false;
}
auto producer = csurface_->GetProducer();
psurface_ = Surface::CreateSurfaceAsProducer(producer);
if (psurface_ == nullptr) {
WLOGFE("csurface create failed");
return false;
}
return true;
}
} // namespace ROSEN
} // namespace OHOS
+46
View File
@@ -0,0 +1,46 @@
/*
* 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 FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H
#define FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H
#include <securec.h>
#include "display.h"
#include "display_manager.h"
#include "dm_common.h"
#include "screen.h"
#include "screen_manager.h"
#include "window_manager_hilog.h"
#include "unique_fd.h"
#include "core/ui/rs_surface_node.h"
#include "core/ui/rs_display_node.h"
namespace OHOS {
namespace Rosen {
class ScreenManagerUtils {
public:
bool CreateSurface();
const std::string defaultName_ = "virtualScreen01";
sptr<Surface> csurface_ = nullptr; // cosumer surface
sptr<Surface> psurface_ = nullptr; // producer surface
const float defaultDensity_ = 2.0;
const int32_t defaultFlags_ = 0;
};
} // namespace Rosen
} // namespace OHOS
#endif // FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H