1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#include <gtest/gtest.h> 17e0dac50fSopenharmony_ci#include "display_manager.h" 18e0dac50fSopenharmony_ci#include "display_manager_proxy.h" 19e0dac50fSopenharmony_ci#include "screen_manager.h" 20e0dac50fSopenharmony_ci#include "screen_manager_utils.h" 21e0dac50fSopenharmony_ci#include "mock_display_manager_adapter.h" 22e0dac50fSopenharmony_ci#include "singleton_mocker.h" 23e0dac50fSopenharmony_ci#include "screen_manager.cpp" 24e0dac50fSopenharmony_ci#include "window_manager_hilog.h" 25e0dac50fSopenharmony_ci#include "scene_board_judgement.h" 26e0dac50fSopenharmony_ci 27e0dac50fSopenharmony_ciusing namespace testing; 28e0dac50fSopenharmony_ciusing namespace testing::ext; 29e0dac50fSopenharmony_ci 30e0dac50fSopenharmony_cinamespace OHOS { 31e0dac50fSopenharmony_cinamespace Rosen { 32e0dac50fSopenharmony_ciusing Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>; 33e0dac50fSopenharmony_ciclass DmMockScreenListener : public ScreenManager::IScreenListener { 34e0dac50fSopenharmony_cipublic: 35e0dac50fSopenharmony_ci void OnConnect(ScreenId) override {} 36e0dac50fSopenharmony_ci void OnDisconnect(ScreenId) override {} 37e0dac50fSopenharmony_ci void OnChange(ScreenId) override {} 38e0dac50fSopenharmony_ci}; 39e0dac50fSopenharmony_ci 40e0dac50fSopenharmony_ciclass TestScreenGroupListener : public ScreenManager::IScreenGroupListener { 41e0dac50fSopenharmony_cipublic: 42e0dac50fSopenharmony_ci void OnChange(const std::vector<ScreenId>&, ScreenGroupChangeEvent) override {}; 43e0dac50fSopenharmony_ci}; 44e0dac50fSopenharmony_ci 45e0dac50fSopenharmony_ciclass TestIVirtualScreenGroupListener : public ScreenManager::IVirtualScreenGroupListener { 46e0dac50fSopenharmony_cipublic: 47e0dac50fSopenharmony_ci void OnMirrorChange(const ChangeInfo& info) override {}; 48e0dac50fSopenharmony_ci}; 49e0dac50fSopenharmony_ciclass ScreenManagerTest : public testing::Test { 50e0dac50fSopenharmony_cipublic: 51e0dac50fSopenharmony_ci static void SetUpTestCase(); 52e0dac50fSopenharmony_ci static void TearDownTestCase(); 53e0dac50fSopenharmony_ci virtual void SetUp() override; 54e0dac50fSopenharmony_ci virtual void TearDown() override; 55e0dac50fSopenharmony_ci 56e0dac50fSopenharmony_ci const std::string defaultName_ = "virtualScreen01"; 57e0dac50fSopenharmony_ci const float defaultDensity_ = 2.0; 58e0dac50fSopenharmony_ci const int32_t defaultFlags_ = 0; 59e0dac50fSopenharmony_ci const ScreenId testVirtualScreenId_ = 2; 60e0dac50fSopenharmony_ci const uint32_t testVirtualScreenWidth_ = 1920; 61e0dac50fSopenharmony_ci const uint32_t testVirtualScreenHeight_ = 1080; 62e0dac50fSopenharmony_ci static sptr<Display> defaultDisplay_; 63e0dac50fSopenharmony_ci static uint32_t defaultWidth_; 64e0dac50fSopenharmony_ci static uint32_t defaultHeight_; 65e0dac50fSopenharmony_ci}; 66e0dac50fSopenharmony_cisptr<Display> ScreenManagerTest::defaultDisplay_ = nullptr; 67e0dac50fSopenharmony_ciuint32_t ScreenManagerTest::defaultWidth_ = 480; 68e0dac50fSopenharmony_ciuint32_t ScreenManagerTest::defaultHeight_ = 320; 69e0dac50fSopenharmony_ci 70e0dac50fSopenharmony_civoid ScreenManagerTest::SetUpTestCase() 71e0dac50fSopenharmony_ci{ 72e0dac50fSopenharmony_ci defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay(); 73e0dac50fSopenharmony_ci defaultWidth_ = defaultDisplay_->GetWidth(); 74e0dac50fSopenharmony_ci defaultHeight_ = defaultDisplay_->GetHeight(); 75e0dac50fSopenharmony_ci} 76e0dac50fSopenharmony_ci 77e0dac50fSopenharmony_civoid ScreenManagerTest::TearDownTestCase() 78e0dac50fSopenharmony_ci{ 79e0dac50fSopenharmony_ci} 80e0dac50fSopenharmony_ci 81e0dac50fSopenharmony_civoid ScreenManagerTest::SetUp() 82e0dac50fSopenharmony_ci{ 83e0dac50fSopenharmony_ci} 84e0dac50fSopenharmony_ci 85e0dac50fSopenharmony_civoid ScreenManagerTest::TearDown() 86e0dac50fSopenharmony_ci{ 87e0dac50fSopenharmony_ci} 88e0dac50fSopenharmony_ci 89e0dac50fSopenharmony_cinamespace { 90e0dac50fSopenharmony_ci/** 91e0dac50fSopenharmony_ci * @tc.name: CreateAndDestroy01 92e0dac50fSopenharmony_ci * @tc.desc: CreateVirtualScreen with invalid option and return invalid screen id 93e0dac50fSopenharmony_ci * @tc.type: FUNC 94e0dac50fSopenharmony_ci */ 95e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, CreateAndDestroy01, Function | SmallTest | Level1) 96e0dac50fSopenharmony_ci{ 97e0dac50fSopenharmony_ci VirtualScreenOption wrongOption = {defaultName_, defaultWidth_, defaultHeight_, 98e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 99e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 100e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), CreateVirtualScreen(_, _)).Times(1).WillOnce(Return(SCREEN_ID_INVALID)); 101e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM)); 102e0dac50fSopenharmony_ci ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(wrongOption); 103e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id); 104e0dac50fSopenharmony_ci ASSERT_EQ(SCREEN_ID_INVALID, id); 105e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, ret); 106e0dac50fSopenharmony_ci} 107e0dac50fSopenharmony_ci 108e0dac50fSopenharmony_ci/** 109e0dac50fSopenharmony_ci * @tc.name: CreateAndDestroy02 110e0dac50fSopenharmony_ci * @tc.desc: CreateVirtualScreen with valid option and return valid screen id 111e0dac50fSopenharmony_ci * @tc.type: FUNC 112e0dac50fSopenharmony_ci */ 113e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, CreateAndDestroy02, Function | SmallTest | Level1) 114e0dac50fSopenharmony_ci{ 115e0dac50fSopenharmony_ci ScreenManagerUtils utils; 116e0dac50fSopenharmony_ci ASSERT_TRUE(utils.CreateSurface()); 117e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 118e0dac50fSopenharmony_ci defaultDensity_, utils.psurface_, defaultFlags_}; 119e0dac50fSopenharmony_ci ScreenId validId = 0; 120e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 121e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), CreateVirtualScreen(_, _)).Times(1).WillOnce(Return(validId)); 122e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK)); 123e0dac50fSopenharmony_ci ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 124e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id); 125e0dac50fSopenharmony_ci ASSERT_EQ(validId, id); 126e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 127e0dac50fSopenharmony_ci} 128e0dac50fSopenharmony_ci 129e0dac50fSopenharmony_ci/** 130e0dac50fSopenharmony_ci * @tc.name: MakeExpand_001 131e0dac50fSopenharmony_ci * @tc.desc: Create a virtual screen as expansion of default screen, return default screen id 132e0dac50fSopenharmony_ci * @tc.type: FUNC 133e0dac50fSopenharmony_ci */ 134e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeExpand_001, Function | SmallTest | Level1) 135e0dac50fSopenharmony_ci{ 136e0dac50fSopenharmony_ci ScreenManagerUtils utils; 137e0dac50fSopenharmony_ci ASSERT_TRUE(utils.CreateSurface()); 138e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 139e0dac50fSopenharmony_ci defaultDensity_, utils.psurface_, defaultFlags_}; 140e0dac50fSopenharmony_ci ScreenId validId = 0; // default srceenId(0) 141e0dac50fSopenharmony_ci ScreenId virtualScreenId = 1; // VirtualScreen is the second screen(1) 142e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 143e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), CreateVirtualScreen(_, _)).Times(1).WillOnce(Return(virtualScreenId)); 144e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK)); 145e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), MakeExpand(_, _, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 146e0dac50fSopenharmony_ci ScreenId vScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 147e0dac50fSopenharmony_ci std::vector<ExpandOption> options = {{validId, 0, 0}, {vScreenId, defaultWidth_, 0}}; 148e0dac50fSopenharmony_ci ScreenId expansionId; 149e0dac50fSopenharmony_ci ScreenManager::GetInstance().MakeExpand(options, expansionId); 150e0dac50fSopenharmony_ci ASSERT_EQ(expansionId, validId); 151e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(vScreenId); 152e0dac50fSopenharmony_ci ASSERT_EQ(vScreenId, virtualScreenId); 153e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 154e0dac50fSopenharmony_ci} 155e0dac50fSopenharmony_ci 156e0dac50fSopenharmony_ci/** 157e0dac50fSopenharmony_ci * @tc.name: MakeExpand_002 158e0dac50fSopenharmony_ci * @tc.desc: Makepand with empty ExpandOption, return SCREEN_ID_INVALID 159e0dac50fSopenharmony_ci * @tc.type: FUNC 160e0dac50fSopenharmony_ci */ 161e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeExpand_002, Function | SmallTest | Level1) 162e0dac50fSopenharmony_ci{ 163e0dac50fSopenharmony_ci ScreenId invalidId = SCREEN_ID_INVALID; 164e0dac50fSopenharmony_ci std::vector<ExpandOption> options = {}; 165e0dac50fSopenharmony_ci ScreenId expansionId = SCREEN_ID_INVALID; 166e0dac50fSopenharmony_ci ScreenManager::GetInstance().MakeExpand(options, expansionId); 167e0dac50fSopenharmony_ci ASSERT_EQ(expansionId, invalidId); 168e0dac50fSopenharmony_ci} 169e0dac50fSopenharmony_ci 170e0dac50fSopenharmony_ci/** 171e0dac50fSopenharmony_ci * @tc.name: MakeExpand_003 172e0dac50fSopenharmony_ci * @tc.desc: Makepand with ExpandOption.size() > MAX_SCREEN_SIZE, return SCREEN_ID_INVALID 173e0dac50fSopenharmony_ci * @tc.type: FUNC 174e0dac50fSopenharmony_ci */ 175e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeExpand_003, Function | SmallTest | Level1) 176e0dac50fSopenharmony_ci{ 177e0dac50fSopenharmony_ci std::vector<ExpandOption> options = {}; 178e0dac50fSopenharmony_ci for (uint32_t i = 0; i < 33; ++i){ // MAX_SCREEN_SIZE + 1 179e0dac50fSopenharmony_ci ExpandOption option; 180e0dac50fSopenharmony_ci option.screenId_ = i; 181e0dac50fSopenharmony_ci options.emplace_back(option); 182e0dac50fSopenharmony_ci } 183e0dac50fSopenharmony_ci ScreenId screemGroupId; 184e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().MakeExpand(options, screemGroupId); 185e0dac50fSopenharmony_ci EXPECT_EQ(error, DMError::DM_ERROR_INVALID_PARAM); 186e0dac50fSopenharmony_ci} 187e0dac50fSopenharmony_ci 188e0dac50fSopenharmony_ci/** 189e0dac50fSopenharmony_ci * @tc.name: SetSurface01 190e0dac50fSopenharmony_ci * @tc.desc: SetVirtualScreenSurface with valid option and return success 191e0dac50fSopenharmony_ci * @tc.type: FUNC 192e0dac50fSopenharmony_ci */ 193e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetSurface01, Function | SmallTest | Level1) 194e0dac50fSopenharmony_ci{ 195e0dac50fSopenharmony_ci ScreenManagerUtils utils; 196e0dac50fSopenharmony_ci ASSERT_TRUE(utils.CreateSurface()); 197e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 198e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 199e0dac50fSopenharmony_ci ScreenId validId = 0; 200e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 201e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), CreateVirtualScreen(_, _)).Times(1).WillOnce(Return(validId)); 202e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), SetVirtualScreenSurface(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 203e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK)); 204e0dac50fSopenharmony_ci ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 205e0dac50fSopenharmony_ci DMError surfaceRes = ScreenManager::GetInstance().SetVirtualScreenSurface(id, utils.psurface_); 206e0dac50fSopenharmony_ci DMError destroyRes = ScreenManager::GetInstance().DestroyVirtualScreen(id); 207e0dac50fSopenharmony_ci ASSERT_EQ(validId, id); 208e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, surfaceRes); 209e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, destroyRes); 210e0dac50fSopenharmony_ci} 211e0dac50fSopenharmony_ci 212e0dac50fSopenharmony_ci/** 213e0dac50fSopenharmony_ci * @tc.name: SetSurface02 214e0dac50fSopenharmony_ci * @tc.desc: SetVirtualScreenSurface with invalid option and return failed 215e0dac50fSopenharmony_ci * @tc.type: FUNC 216e0dac50fSopenharmony_ci */ 217e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetSurface02, Function | SmallTest | Level1) 218e0dac50fSopenharmony_ci{ 219e0dac50fSopenharmony_ci ScreenManagerUtils utils; 220e0dac50fSopenharmony_ci ASSERT_TRUE(utils.CreateSurface()); 221e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 222e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 223e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 224e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), CreateVirtualScreen(_, _)).Times(1).WillOnce(Return(SCREEN_ID_INVALID)); 225e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), SetVirtualScreenSurface(_, _)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM)); 226e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM)); 227e0dac50fSopenharmony_ci ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 228e0dac50fSopenharmony_ci DMError surfaceRes = ScreenManager::GetInstance().SetVirtualScreenSurface(id, utils.psurface_); 229e0dac50fSopenharmony_ci DMError destroyRes = ScreenManager::GetInstance().DestroyVirtualScreen(id); 230e0dac50fSopenharmony_ci ASSERT_EQ(SCREEN_ID_INVALID, id); 231e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, surfaceRes); 232e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, destroyRes); 233e0dac50fSopenharmony_ci} 234e0dac50fSopenharmony_ci 235e0dac50fSopenharmony_ci/** 236e0dac50fSopenharmony_ci * @tc.name: OnScreenConnect01 237e0dac50fSopenharmony_ci * @tc.desc: OnScreenConnect 238e0dac50fSopenharmony_ci * @tc.type: FUNC 239e0dac50fSopenharmony_ci */ 240e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, OnScreenConnect01, Function | SmallTest | Level1) 241e0dac50fSopenharmony_ci{ 242e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 243e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 244e0dac50fSopenharmony_ci sptr<ScreenManager::IScreenListener> listener = new DmMockScreenListener(); 245e0dac50fSopenharmony_ci ScreenManager::GetInstance().RegisterScreenListener(listener); 246e0dac50fSopenharmony_ci auto screenManagerListener = ScreenManager::GetInstance().pImpl_->screenManagerListener_; 247e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener, nullptr); 248e0dac50fSopenharmony_ci screenManagerListener->OnScreenConnect(nullptr); 249e0dac50fSopenharmony_ci sptr<ScreenInfo> screenInfo = new ScreenInfo(); 250e0dac50fSopenharmony_ci screenInfo->SetScreenId(SCREEN_ID_INVALID); 251e0dac50fSopenharmony_ci screenManagerListener->OnScreenConnect(screenInfo); 252e0dac50fSopenharmony_ci screenInfo->SetScreenId(0); 253e0dac50fSopenharmony_ci screenManagerListener->OnScreenConnect(screenInfo); 254e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener->pImpl_, nullptr); 255e0dac50fSopenharmony_ci screenManagerListener->pImpl_ = nullptr; 256e0dac50fSopenharmony_ci screenManagerListener->OnScreenConnect(screenInfo); 257e0dac50fSopenharmony_ci ScreenManager::GetInstance().pImpl_->screenManagerListener_ = nullptr; 258e0dac50fSopenharmony_ci} 259e0dac50fSopenharmony_ci 260e0dac50fSopenharmony_ci/** 261e0dac50fSopenharmony_ci * @tc.name: OnScreenDisconnect01 262e0dac50fSopenharmony_ci * @tc.desc: OnScreenDisconnect 263e0dac50fSopenharmony_ci * @tc.type: FUNC 264e0dac50fSopenharmony_ci */ 265e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, OnScreenDisconnect01, Function | SmallTest | Level1) 266e0dac50fSopenharmony_ci{ 267e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 268e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 269e0dac50fSopenharmony_ci sptr<ScreenManager::IScreenListener> listener = new DmMockScreenListener(); 270e0dac50fSopenharmony_ci ScreenManager::GetInstance().RegisterScreenListener(listener); 271e0dac50fSopenharmony_ci auto screenManagerListener = ScreenManager::GetInstance().pImpl_->screenManagerListener_; 272e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener, nullptr); 273e0dac50fSopenharmony_ci screenManagerListener->OnScreenDisconnect(SCREEN_ID_INVALID); 274e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener->pImpl_, nullptr); 275e0dac50fSopenharmony_ci screenManagerListener->OnScreenDisconnect(0); 276e0dac50fSopenharmony_ci screenManagerListener->pImpl_ = nullptr; 277e0dac50fSopenharmony_ci screenManagerListener->OnScreenDisconnect(0); 278e0dac50fSopenharmony_ci ScreenManager::GetInstance().pImpl_->screenManagerListener_ = nullptr; 279e0dac50fSopenharmony_ci} 280e0dac50fSopenharmony_ci 281e0dac50fSopenharmony_ci/** 282e0dac50fSopenharmony_ci * @tc.name: OnScreenChange01 283e0dac50fSopenharmony_ci * @tc.desc: OnScreenChange 284e0dac50fSopenharmony_ci * @tc.type: FUNC 285e0dac50fSopenharmony_ci */ 286e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, OnScreenChange01, Function | SmallTest | Level1) 287e0dac50fSopenharmony_ci{ 288e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 289e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 290e0dac50fSopenharmony_ci sptr<ScreenManager::IScreenListener> listener = new DmMockScreenListener(); 291e0dac50fSopenharmony_ci ScreenManager::GetInstance().RegisterScreenListener(listener); 292e0dac50fSopenharmony_ci auto screenManagerListener = ScreenManager::GetInstance().pImpl_->screenManagerListener_; 293e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener, nullptr); 294e0dac50fSopenharmony_ci screenManagerListener->OnScreenChange(nullptr, ScreenChangeEvent::UPDATE_ORIENTATION); 295e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener->pImpl_, nullptr); 296e0dac50fSopenharmony_ci sptr<ScreenInfo> screenInfo = new ScreenInfo(); 297e0dac50fSopenharmony_ci screenManagerListener->OnScreenChange(screenInfo, ScreenChangeEvent::UPDATE_ORIENTATION); 298e0dac50fSopenharmony_ci screenManagerListener->pImpl_ = nullptr; 299e0dac50fSopenharmony_ci screenManagerListener->OnScreenChange(screenInfo, ScreenChangeEvent::UPDATE_ORIENTATION); 300e0dac50fSopenharmony_ci ScreenManager::GetInstance().pImpl_->screenManagerListener_ = nullptr; 301e0dac50fSopenharmony_ci} 302e0dac50fSopenharmony_ci 303e0dac50fSopenharmony_ci/** 304e0dac50fSopenharmony_ci * @tc.name: OnScreenGroupChange01 305e0dac50fSopenharmony_ci * @tc.desc: OnScreenGroupChange 306e0dac50fSopenharmony_ci * @tc.type: FUNC 307e0dac50fSopenharmony_ci */ 308e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, OnScreenGroupChange01, Function | SmallTest | Level1) 309e0dac50fSopenharmony_ci{ 310e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 311e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 312e0dac50fSopenharmony_ci sptr<ScreenManager::IScreenListener> listener = new DmMockScreenListener(); 313e0dac50fSopenharmony_ci ScreenManager::GetInstance().RegisterScreenListener(listener); 314e0dac50fSopenharmony_ci auto screenManagerListener = ScreenManager::GetInstance().pImpl_->screenManagerListener_; 315e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener, nullptr); 316e0dac50fSopenharmony_ci std::string trigger; 317e0dac50fSopenharmony_ci std::vector<sptr<ScreenInfo>> screenInfos; 318e0dac50fSopenharmony_ci ScreenGroupChangeEvent groupEvent = ScreenGroupChangeEvent::CHANGE_GROUP; 319e0dac50fSopenharmony_ci screenManagerListener->OnScreenGroupChange(trigger, screenInfos, groupEvent); 320e0dac50fSopenharmony_ci ASSERT_NE(screenManagerListener->pImpl_, nullptr); 321e0dac50fSopenharmony_ci sptr<ScreenInfo> screenInfo = new ScreenInfo(); 322e0dac50fSopenharmony_ci screenInfo->SetScreenId(1); 323e0dac50fSopenharmony_ci sptr<ScreenInfo> screenInfo2 = new ScreenInfo(); 324e0dac50fSopenharmony_ci screenInfos.emplace_back(screenInfo); 325e0dac50fSopenharmony_ci screenInfos.emplace_back(screenInfo2); 326e0dac50fSopenharmony_ci screenManagerListener->OnScreenGroupChange(trigger, screenInfos, groupEvent); 327e0dac50fSopenharmony_ci screenManagerListener->pImpl_ = nullptr; 328e0dac50fSopenharmony_ci screenManagerListener->OnScreenGroupChange(trigger, screenInfos, groupEvent); 329e0dac50fSopenharmony_ci ScreenManager::GetInstance().pImpl_->screenManagerListener_ = nullptr; 330e0dac50fSopenharmony_ci} 331e0dac50fSopenharmony_ci/** 332e0dac50fSopenharmony_ci * @tc.name: RemoveVirtualScreenFromGroup 333e0dac50fSopenharmony_ci * @tc.desc: for interface coverage & check func RemoveVirtualScreenFromGroup 334e0dac50fSopenharmony_ci * @tc.type: FUNC 335e0dac50fSopenharmony_ci */ 336e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, RemoveVirtualScreenFromGroup, Function | SmallTest | Level1) 337e0dac50fSopenharmony_ci{ 338e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 339e0dac50fSopenharmony_ci std::vector<ScreenId> testScreens(33, 1); 340e0dac50fSopenharmony_ci auto result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens); 341e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, result); 342e0dac50fSopenharmony_ci 343e0dac50fSopenharmony_ci testScreens.clear(); 344e0dac50fSopenharmony_ci result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens); 345e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, result); 346e0dac50fSopenharmony_ci 347e0dac50fSopenharmony_ci testScreens.emplace_back(static_cast<ScreenId>(1)); 348e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RemoveVirtualScreenFromGroup(_)).Times(1); 349e0dac50fSopenharmony_ci result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens); 350e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 351e0dac50fSopenharmony_ci} 352e0dac50fSopenharmony_ci/** 353e0dac50fSopenharmony_ci * @tc.name: SetScreenRotationLocked 354e0dac50fSopenharmony_ci * @tc.desc: for interface coverage & check SetScreenRotationLocked 355e0dac50fSopenharmony_ci * @tc.type: FUNC 356e0dac50fSopenharmony_ci */ 357e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetScreenRotationLocked, Function | SmallTest | Level1) 358e0dac50fSopenharmony_ci{ 359e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 360e0dac50fSopenharmony_ci 361e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), SetScreenRotationLocked(_)).Times(1); 362e0dac50fSopenharmony_ci auto result = ScreenManager::GetInstance().SetScreenRotationLocked(true); 363e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 364e0dac50fSopenharmony_ci} 365e0dac50fSopenharmony_ci 366e0dac50fSopenharmony_ci/** 367e0dac50fSopenharmony_ci * @tc.name: IsScreenRotationLocked 368e0dac50fSopenharmony_ci * @tc.desc: for interface coverage & check IsScreenRotationLocked 369e0dac50fSopenharmony_ci * @tc.type: FUNC 370e0dac50fSopenharmony_ci */ 371e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, IsScreenRotationLocked, Function | SmallTest | Level1) 372e0dac50fSopenharmony_ci{ 373e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 374e0dac50fSopenharmony_ci 375e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), IsScreenRotationLocked(_)).Times(1).WillOnce(Return(DMError::DM_OK)); 376e0dac50fSopenharmony_ci bool result; 377e0dac50fSopenharmony_ci DMError ret; 378e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().IsScreenRotationLocked(result); 379e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 380e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), IsScreenRotationLocked(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_NULLPTR)); 381e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().IsScreenRotationLocked(result); 382e0dac50fSopenharmony_ci ASSERT_TRUE(DMError::DM_OK != ret); 383e0dac50fSopenharmony_ci} 384e0dac50fSopenharmony_ci 385e0dac50fSopenharmony_ci/** 386e0dac50fSopenharmony_ci * @tc.name: RegisterScreenGroupListener 387e0dac50fSopenharmony_ci * @tc.desc: for interface coverage and 388e0dac50fSopenharmony_ci * check RegisterScreenGroupListener & UnregisterScreenGroupListener 389e0dac50fSopenharmony_ci * @tc.type: FUNC 390e0dac50fSopenharmony_ci */ 391e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, RegisterScreenGroupListener, Function | SmallTest | Level1) 392e0dac50fSopenharmony_ci{ 393e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 394e0dac50fSopenharmony_ci auto& screenManager = ScreenManager::GetInstance(); 395e0dac50fSopenharmony_ci auto result = screenManager.RegisterScreenGroupListener(nullptr); 396e0dac50fSopenharmony_ci ASSERT_TRUE(DMError::DM_OK != result); 397e0dac50fSopenharmony_ci 398e0dac50fSopenharmony_ci sptr<ScreenManager::IScreenGroupListener> listener = new (std::nothrow)TestScreenGroupListener(); 399e0dac50fSopenharmony_ci if (screenManager.pImpl_->screenManagerListener_ == nullptr) { 400e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 401e0dac50fSopenharmony_ci } 402e0dac50fSopenharmony_ci result = screenManager.RegisterScreenGroupListener(listener); 403e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 404e0dac50fSopenharmony_ci 405e0dac50fSopenharmony_ci result = screenManager.UnregisterScreenGroupListener(nullptr); 406e0dac50fSopenharmony_ci ASSERT_TRUE(DMError::DM_OK != result); 407e0dac50fSopenharmony_ci 408e0dac50fSopenharmony_ci auto sizeScreen = screenManager.pImpl_->screenListeners_.size(); 409e0dac50fSopenharmony_ci auto sizeScreenGroup = screenManager.pImpl_->screenGroupListeners_.size(); 410e0dac50fSopenharmony_ci auto sizeVirtualScreen = screenManager.pImpl_->virtualScreenGroupListeners_.size(); 411e0dac50fSopenharmony_ci if (sizeScreenGroup > 1) { 412e0dac50fSopenharmony_ci result = screenManager.UnregisterScreenGroupListener(listener); 413e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 414e0dac50fSopenharmony_ci } else if (sizeScreenGroup == 1) { 415e0dac50fSopenharmony_ci if (sizeScreen == 0 && sizeVirtualScreen == 0) { 416e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), UnregisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 417e0dac50fSopenharmony_ci } 418e0dac50fSopenharmony_ci result = screenManager.UnregisterScreenGroupListener(listener); 419e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 420e0dac50fSopenharmony_ci } 421e0dac50fSopenharmony_ci} 422e0dac50fSopenharmony_ci/** 423e0dac50fSopenharmony_ci * @tc.name: RegisterVirtualScreenGroupListener 424e0dac50fSopenharmony_ci * @tc.desc: for interface coverage and 425e0dac50fSopenharmony_ci * check RegisterVirtualScreenGroupListener & UnregisterVirtualScreenGroupListener 426e0dac50fSopenharmony_ci * @tc.type: FUNC 427e0dac50fSopenharmony_ci */ 428e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, RegisterVirtualScreenGroupListener, Function | SmallTest | Level1) 429e0dac50fSopenharmony_ci{ 430e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 431e0dac50fSopenharmony_ci auto& screenManager = ScreenManager::GetInstance(); 432e0dac50fSopenharmony_ci auto result = screenManager.RegisterVirtualScreenGroupListener(nullptr); 433e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, result); 434e0dac50fSopenharmony_ci 435e0dac50fSopenharmony_ci sptr<ScreenManager::IVirtualScreenGroupListener> listener = new (std::nothrow)TestIVirtualScreenGroupListener(); 436e0dac50fSopenharmony_ci if (screenManager.pImpl_->screenManagerListener_ == nullptr) { 437e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 438e0dac50fSopenharmony_ci } 439e0dac50fSopenharmony_ci result = screenManager.RegisterVirtualScreenGroupListener(listener); 440e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 441e0dac50fSopenharmony_ci 442e0dac50fSopenharmony_ci result = screenManager.UnregisterVirtualScreenGroupListener(nullptr); 443e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, result); 444e0dac50fSopenharmony_ci 445e0dac50fSopenharmony_ci auto sizeScreen = screenManager.pImpl_->screenListeners_.size(); 446e0dac50fSopenharmony_ci auto sizeScreenGroup = screenManager.pImpl_->screenGroupListeners_.size(); 447e0dac50fSopenharmony_ci auto sizeVirtualScreen = screenManager.pImpl_->virtualScreenGroupListeners_.size(); 448e0dac50fSopenharmony_ci 449e0dac50fSopenharmony_ci if (sizeVirtualScreen > 1) { 450e0dac50fSopenharmony_ci result = screenManager.UnregisterVirtualScreenGroupListener(listener); 451e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 452e0dac50fSopenharmony_ci } else if (sizeVirtualScreen == 1) { 453e0dac50fSopenharmony_ci if (sizeScreen == 0 && sizeScreenGroup == 0) { 454e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), UnregisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 455e0dac50fSopenharmony_ci } 456e0dac50fSopenharmony_ci result = screenManager.UnregisterVirtualScreenGroupListener(listener); 457e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 458e0dac50fSopenharmony_ci } 459e0dac50fSopenharmony_ci} 460e0dac50fSopenharmony_ci 461e0dac50fSopenharmony_ci/** 462e0dac50fSopenharmony_ci * @tc.name: StopExpand_001 463e0dac50fSopenharmony_ci * @tc.desc: StopExpand_001 id 464e0dac50fSopenharmony_ci * @tc.type: FUNC 465e0dac50fSopenharmony_ci */ 466e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, StopExpand_001, Function | SmallTest | Level1) 467e0dac50fSopenharmony_ci{ 468e0dac50fSopenharmony_ci std::vector<ScreenId> screenIds; 469e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().StopExpand(screenIds)); 470e0dac50fSopenharmony_ci std::vector<ScreenId> expandScreenIds {0, 1, 2, 3, 4, 5}; 471e0dac50fSopenharmony_ci DMError err = SingletonContainer::Get<ScreenManagerAdapter>().StopExpand(expandScreenIds); 472e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, err); 473e0dac50fSopenharmony_ci} 474e0dac50fSopenharmony_ci 475e0dac50fSopenharmony_ci/** 476e0dac50fSopenharmony_ci * @tc.name: StopMirror 477e0dac50fSopenharmony_ci * @tc.desc: StopMirror id 478e0dac50fSopenharmony_ci * @tc.type: FUNC 479e0dac50fSopenharmony_ci */ 480e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, StopMirror, Function | SmallTest | Level1) 481e0dac50fSopenharmony_ci{ 482e0dac50fSopenharmony_ci ScreenManagerUtils utils; 483e0dac50fSopenharmony_ci ASSERT_TRUE(utils.CreateSurface()); 484e0dac50fSopenharmony_ci std::vector<ScreenId> screenIds; 485e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().StopMirror(screenIds)); 486e0dac50fSopenharmony_ci std::vector<ScreenId> mirrorScreenIds1 {0, 1, 2, 3, 4, 5}; 487e0dac50fSopenharmony_ci DMError err = SingletonContainer::Get<ScreenManagerAdapter>().StopMirror(mirrorScreenIds1); 488e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, err); 489e0dac50fSopenharmony_ci std::vector<ScreenId> mirrorScreenIds2 {}; 490e0dac50fSopenharmony_ci err = SingletonContainer::Get<ScreenManagerAdapter>().StopMirror(mirrorScreenIds2); 491e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, err); 492e0dac50fSopenharmony_ci} 493e0dac50fSopenharmony_ci 494e0dac50fSopenharmony_ci/** 495e0dac50fSopenharmony_ci * @tc.name: RegisterVirtualScreenGroupListener02 496e0dac50fSopenharmony_ci * @tc.desc: RegisterVirtualScreenGroupListener02 fun 497e0dac50fSopenharmony_ci * @tc.type: FUNC 498e0dac50fSopenharmony_ci */ 499e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, RegisterVirtualScreenGroupListener02, Function | SmallTest | Level1) 500e0dac50fSopenharmony_ci{ 501e0dac50fSopenharmony_ci std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 502e0dac50fSopenharmony_ci auto& screenManager = ScreenManager::GetInstance(); 503e0dac50fSopenharmony_ci auto result = screenManager.RegisterVirtualScreenGroupListener(nullptr); 504e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, result); 505e0dac50fSopenharmony_ci sptr<ScreenManager::IVirtualScreenGroupListener> listener = new (std::nothrow)TestIVirtualScreenGroupListener(); 506e0dac50fSopenharmony_ci if (screenManager.pImpl_->screenManagerListener_ == nullptr) { 507e0dac50fSopenharmony_ci EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 508e0dac50fSopenharmony_ci } 509e0dac50fSopenharmony_ci result = ScreenManager::GetInstance().RegisterVirtualScreenGroupListener(listener); 510e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, result); 511e0dac50fSopenharmony_ci} 512e0dac50fSopenharmony_ci 513e0dac50fSopenharmony_ci/** 514e0dac50fSopenharmony_ci * @tc.name: SetVirtualScreenFlag01 515e0dac50fSopenharmony_ci * @tc.desc: SetVirtualScreenFlag01 cast flag 516e0dac50fSopenharmony_ci * @tc.type: FUNC 517e0dac50fSopenharmony_ci */ 518e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetVirtualScreenFlag01, Function | SmallTest | Level1) 519e0dac50fSopenharmony_ci{ 520e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 521e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 522e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 523e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().SetVirtualScreenFlag(screenId, VirtualScreenFlag::CAST); 524e0dac50fSopenharmony_ci if (!SceneBoardJudgement::IsSceneBoardEnabled()) { 525e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_DEVICE_NOT_SUPPORT, ret); 526e0dac50fSopenharmony_ci } else { 527e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 528e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 529e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 530e0dac50fSopenharmony_ci } 531e0dac50fSopenharmony_ci} 532e0dac50fSopenharmony_ci 533e0dac50fSopenharmony_ci/** 534e0dac50fSopenharmony_ci * @tc.name: SetVirtualScreenFlag02 535e0dac50fSopenharmony_ci * @tc.desc: SetVirtualScreenFlag02 max flag 536e0dac50fSopenharmony_ci * @tc.type: FUNC 537e0dac50fSopenharmony_ci */ 538e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetVirtualScreenFlag02, Function | SmallTest | Level1) 539e0dac50fSopenharmony_ci{ 540e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 541e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 542e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 543e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().SetVirtualScreenFlag(screenId, VirtualScreenFlag::MAX); 544e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, ret); 545e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 546e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 547e0dac50fSopenharmony_ci} 548e0dac50fSopenharmony_ci 549e0dac50fSopenharmony_ci/** 550e0dac50fSopenharmony_ci * @tc.name: GetVirtualScreenFlag01 551e0dac50fSopenharmony_ci * @tc.desc: GetVirtualScreenFlag01 get cast 552e0dac50fSopenharmony_ci * @tc.type: FUNC 553e0dac50fSopenharmony_ci */ 554e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, GetVirtualScreenFlag01, Function | SmallTest | Level1) 555e0dac50fSopenharmony_ci{ 556e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 557e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 558e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 559e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().SetVirtualScreenFlag(screenId, VirtualScreenFlag::CAST); 560e0dac50fSopenharmony_ci if (!SceneBoardJudgement::IsSceneBoardEnabled()) { 561e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_DEVICE_NOT_SUPPORT, ret); 562e0dac50fSopenharmony_ci } else { 563e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 564e0dac50fSopenharmony_ci VirtualScreenFlag screenFlag = ScreenManager::GetInstance().GetVirtualScreenFlag(screenId); 565e0dac50fSopenharmony_ci ASSERT_EQ(VirtualScreenFlag::CAST, screenFlag); 566e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 567e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 568e0dac50fSopenharmony_ci } 569e0dac50fSopenharmony_ci} 570e0dac50fSopenharmony_ci 571e0dac50fSopenharmony_ci/** 572e0dac50fSopenharmony_ci * @tc.name: SetVirtualMirrorScreenScaleMode01 573e0dac50fSopenharmony_ci * @tc.desc: SetVirtualMirrorScreenScaleMode01 fun 574e0dac50fSopenharmony_ci * @tc.type: FUNC 575e0dac50fSopenharmony_ci */ 576e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetVirtualMirrorScreenScaleMode01, Function | SmallTest | Level1) 577e0dac50fSopenharmony_ci{ 578e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 579e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 580e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 581e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().SetVirtualMirrorScreenScaleMode(screenId, 582e0dac50fSopenharmony_ci ScreenScaleMode::FILL_MODE); 583e0dac50fSopenharmony_ci if (!SceneBoardJudgement::IsSceneBoardEnabled()) { 584e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_DEVICE_NOT_SUPPORT, ret); 585e0dac50fSopenharmony_ci } else { 586e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 587e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 588e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 589e0dac50fSopenharmony_ci } 590e0dac50fSopenharmony_ci} 591e0dac50fSopenharmony_ci 592e0dac50fSopenharmony_ci/** 593e0dac50fSopenharmony_ci * @tc.name: SetVirtualMirrorScreenScaleMode02 594e0dac50fSopenharmony_ci * @tc.desc: SetVirtualMirrorScreenScaleMode02 fun 595e0dac50fSopenharmony_ci * @tc.type: FUNC 596e0dac50fSopenharmony_ci */ 597e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, SetVirtualMirrorScreenScaleMode02, Function | SmallTest | Level1) 598e0dac50fSopenharmony_ci{ 599e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 600e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 601e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 602e0dac50fSopenharmony_ci DMError ret = ScreenManager::GetInstance().SetVirtualMirrorScreenScaleMode(screenId, 603e0dac50fSopenharmony_ci ScreenScaleMode::UNISCALE_MODE); 604e0dac50fSopenharmony_ci if (!SceneBoardJudgement::IsSceneBoardEnabled()) { 605e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_DEVICE_NOT_SUPPORT, ret); 606e0dac50fSopenharmony_ci } else { 607e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 608e0dac50fSopenharmony_ci ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 609e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 610e0dac50fSopenharmony_ci } 611e0dac50fSopenharmony_ci} 612e0dac50fSopenharmony_ci 613e0dac50fSopenharmony_ci/** 614e0dac50fSopenharmony_ci * @tc.name: IsCaptured02 615e0dac50fSopenharmony_ci * @tc.desc: IsCaptured02 fun 616e0dac50fSopenharmony_ci * @tc.type: FUNC 617e0dac50fSopenharmony_ci */ 618e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, IsCaptured02, Function | SmallTest | Level1) 619e0dac50fSopenharmony_ci{ 620e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 621e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 622e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 623e0dac50fSopenharmony_ci bool isCapture = DisplayManager::GetInstance().IsCaptured(); 624e0dac50fSopenharmony_ci if (!SceneBoardJudgement::IsSceneBoardEnabled()) { 625e0dac50fSopenharmony_ci ASSERT_FALSE(isCapture); 626e0dac50fSopenharmony_ci } else { 627e0dac50fSopenharmony_ci ASSERT_TRUE(isCapture); 628e0dac50fSopenharmony_ci auto ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 629e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 630e0dac50fSopenharmony_ci } 631e0dac50fSopenharmony_ci} 632e0dac50fSopenharmony_ci 633e0dac50fSopenharmony_ci/** 634e0dac50fSopenharmony_ci * @tc.name: IsCaptured03 635e0dac50fSopenharmony_ci * @tc.desc: IsCaptured03 fun 636e0dac50fSopenharmony_ci * @tc.type: FUNC 637e0dac50fSopenharmony_ci */ 638e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, IsCaptured03, Function | SmallTest | Level1) 639e0dac50fSopenharmony_ci{ 640e0dac50fSopenharmony_ci VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, 641e0dac50fSopenharmony_ci defaultDensity_, nullptr, defaultFlags_}; 642e0dac50fSopenharmony_ci ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); 643e0dac50fSopenharmony_ci auto ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); 644e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_OK, ret); 645e0dac50fSopenharmony_ci bool isCapture = DisplayManager::GetInstance().IsCaptured(); 646e0dac50fSopenharmony_ci ASSERT_FALSE(isCapture); 647e0dac50fSopenharmony_ci} 648e0dac50fSopenharmony_ci 649e0dac50fSopenharmony_ci/** 650e0dac50fSopenharmony_ci * @tc.name: UnregisterScreenListener 651e0dac50fSopenharmony_ci * @tc.desc: UnregisterScreenListener fun 652e0dac50fSopenharmony_ci * @tc.type: FUNC 653e0dac50fSopenharmony_ci */ 654e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, UnregisterScreenListener, Function | SmallTest | Level1) 655e0dac50fSopenharmony_ci{ 656e0dac50fSopenharmony_ci auto ret = ScreenManager::GetInstance().UnregisterScreenListener(nullptr); 657e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret); 658e0dac50fSopenharmony_ci} 659e0dac50fSopenharmony_ci 660e0dac50fSopenharmony_ci/** 661e0dac50fSopenharmony_ci * @tc.name: RegisterScreenListener 662e0dac50fSopenharmony_ci * @tc.desc: RegisterScreenListener fun 663e0dac50fSopenharmony_ci * @tc.type: FUNC 664e0dac50fSopenharmony_ci */ 665e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, RegisterScreenListener, Function | SmallTest | Level1) 666e0dac50fSopenharmony_ci{ 667e0dac50fSopenharmony_ci auto ret = ScreenManager::GetInstance().RegisterScreenListener(nullptr); 668e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret); 669e0dac50fSopenharmony_ci} 670e0dac50fSopenharmony_ci 671e0dac50fSopenharmony_ci/** 672e0dac50fSopenharmony_ci * @tc.name: UnregisterVirtualScreenGroupListener 673e0dac50fSopenharmony_ci * @tc.desc: UnregisterVirtualScreenGroupListener fun 674e0dac50fSopenharmony_ci * @tc.type: FUNC 675e0dac50fSopenharmony_ci */ 676e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, UnregisterVirtualScreenGroupListener, Function | SmallTest | Level1) 677e0dac50fSopenharmony_ci{ 678e0dac50fSopenharmony_ci auto ret = ScreenManager::GetInstance().UnregisterVirtualScreenGroupListener(nullptr); 679e0dac50fSopenharmony_ci ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret); 680e0dac50fSopenharmony_ci} 681e0dac50fSopenharmony_ci 682e0dac50fSopenharmony_ci/** 683e0dac50fSopenharmony_ci * @tc.name: MakeUniqueScreen_001 684e0dac50fSopenharmony_ci * @tc.desc: MakeUniqueScreen_001 fun 685e0dac50fSopenharmony_ci * @tc.type: FUNC 686e0dac50fSopenharmony_ci */ 687e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeUniqueScreen_001, Function | SmallTest | Level1) 688e0dac50fSopenharmony_ci{ 689e0dac50fSopenharmony_ci std::vector<ScreenId> screenIds; 690e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().MakeUniqueScreen(screenIds); 691e0dac50fSopenharmony_ci ASSERT_EQ(error, DMError::DM_ERROR_INVALID_PARAM); 692e0dac50fSopenharmony_ci} 693e0dac50fSopenharmony_ci 694e0dac50fSopenharmony_ci/** 695e0dac50fSopenharmony_ci * @tc.name: MakeUniqueScreen_002 696e0dac50fSopenharmony_ci * @tc.desc: MakeUniqueScreen_002 fun 697e0dac50fSopenharmony_ci * @tc.type: FUNC 698e0dac50fSopenharmony_ci */ 699e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeUniqueScreen_002, Function | SmallTest | Level1) 700e0dac50fSopenharmony_ci{ 701e0dac50fSopenharmony_ci std::vector<ScreenId> screenIds; 702e0dac50fSopenharmony_ci for (uint32_t i = 0; i < 33; ++i){ // MAX_SCREEN_SIZE + 1 703e0dac50fSopenharmony_ci screenIds.emplace_back(i); 704e0dac50fSopenharmony_ci } 705e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().MakeUniqueScreen(screenIds); 706e0dac50fSopenharmony_ci ASSERT_EQ(error, DMError::DM_ERROR_INVALID_PARAM); 707e0dac50fSopenharmony_ci} 708e0dac50fSopenharmony_ci 709e0dac50fSopenharmony_ci/** 710e0dac50fSopenharmony_ci * @tc.name: MakeUniqueScreen_003 711e0dac50fSopenharmony_ci * @tc.desc: MakeUniqueScreen_003 fun 712e0dac50fSopenharmony_ci * @tc.type: FUNC 713e0dac50fSopenharmony_ci */ 714e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeUniqueScreen_003, Function | SmallTest | Level1) 715e0dac50fSopenharmony_ci{ 716e0dac50fSopenharmony_ci std::vector<ScreenId> screenIds; 717e0dac50fSopenharmony_ci for (uint32_t i = 0; i < 32; ++i){ // MAX_SCREEN_SIZE 718e0dac50fSopenharmony_ci screenIds.emplace_back(i); 719e0dac50fSopenharmony_ci } 720e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().MakeUniqueScreen(screenIds); 721e0dac50fSopenharmony_ci ASSERT_NE(error, DMError::DM_ERROR_INVALID_PARAM); 722e0dac50fSopenharmony_ci} 723e0dac50fSopenharmony_ci 724e0dac50fSopenharmony_ci/** 725e0dac50fSopenharmony_ci * @tc.name: MakeMirror_001 726e0dac50fSopenharmony_ci * @tc.desc: MakeMirror_001 fun 727e0dac50fSopenharmony_ci * @tc.type: FUNC 728e0dac50fSopenharmony_ci */ 729e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, MakeMirror_001, Function | SmallTest | Level1) 730e0dac50fSopenharmony_ci{ 731e0dac50fSopenharmony_ci std::vector<ScreenId> mirrorScreenId; 732e0dac50fSopenharmony_ci for (uint32_t i = 0; i < 33; ++i){ // MAX_SCREEN_SIZE + 1 733e0dac50fSopenharmony_ci mirrorScreenId.emplace_back(i); 734e0dac50fSopenharmony_ci } 735e0dac50fSopenharmony_ci ScreenId ScreenGroupId; 736e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().MakeMirror(1, mirrorScreenId, ScreenGroupId); 737e0dac50fSopenharmony_ci ASSERT_EQ(error, DMError::DM_ERROR_INVALID_PARAM); 738e0dac50fSopenharmony_ci} 739e0dac50fSopenharmony_ci 740e0dac50fSopenharmony_ci/** 741e0dac50fSopenharmony_ci * @tc.name: StopExpand 742e0dac50fSopenharmony_ci * @tc.desc: StopExpand fun 743e0dac50fSopenharmony_ci * @tc.type: FUNC 744e0dac50fSopenharmony_ci */ 745e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, StopExpand, Function | SmallTest | Level1) 746e0dac50fSopenharmony_ci{ 747e0dac50fSopenharmony_ci std::vector<ScreenId> expandScreenIds; 748e0dac50fSopenharmony_ci for (uint32_t i = 0; i < 33; ++i){ // MAX_SCREEN_SIZE + 1 749e0dac50fSopenharmony_ci expandScreenIds.emplace_back(i); 750e0dac50fSopenharmony_ci } 751e0dac50fSopenharmony_ci DMError error = ScreenManager::GetInstance().StopExpand(expandScreenIds); 752e0dac50fSopenharmony_ci ASSERT_EQ(error, DMError::DM_OK); 753e0dac50fSopenharmony_ci} 754e0dac50fSopenharmony_ci 755e0dac50fSopenharmony_ci/** 756e0dac50fSopenharmony_ci * @tc.name: GetScreenInfoSrting 757e0dac50fSopenharmony_ci * @tc.desc: GetScreenInfoSrting fun 758e0dac50fSopenharmony_ci * @tc.type: FUNC 759e0dac50fSopenharmony_ci */ 760e0dac50fSopenharmony_ciHWTEST_F(ScreenManagerTest, GetScreenInfoSrting, Function | SmallTest | Level1) 761e0dac50fSopenharmony_ci{ 762e0dac50fSopenharmony_ci sptr<ScreenInfo> screenInfo = nullptr; 763e0dac50fSopenharmony_ci auto result =ScreenManager::GetInstance().pImpl_->GetScreenInfoSrting(screenInfo); 764e0dac50fSopenharmony_ci EXPECT_EQ(result, ""); 765e0dac50fSopenharmony_ci} 766e0dac50fSopenharmony_ci} 767e0dac50fSopenharmony_ci} // namespace Rosen 768e0dac50fSopenharmony_ci} // namespace OHOS