1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // gtest
17 #include <gtest/gtest.h>
18 #include "future.h"
19 #include "rs_interfaces_test_utils.h"
20 #include "screen.h"
21 #include "transaction/rs_interfaces.h"
22 #include "transaction/rs_transaction.h"
23 #include "window.h"
24 #include "window_option.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 class RSInterfacesSystemTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 static sptr<Display> defaultDisplay_;
38 static DisplayId defaultDisplayId_;
39 static ScreenId defaultScreenId_;
40 static std::string defaultName_;
41 static uint32_t defaultWidth_;
42 static uint32_t defaultHeight_;
43 static float defaultDensity_;
44 static int32_t defaultFlags_;
45 static VirtualScreenOption defaultOption_;
46 static constexpr uint32_t TEST_SLEEP_S = 1; // test sleep time
47 };
48
49 sptr<Display> RSInterfacesSystemTest::defaultDisplay_ = nullptr;
50 DisplayId RSInterfacesSystemTest::defaultDisplayId_ = DISPLAY_ID_INVALID;
51 ScreenId RSInterfacesSystemTest::defaultScreenId_ = INVALID_SCREEN_ID;
52 std::string RSInterfacesSystemTest::defaultName_ = "virtualScreen01";
53 uint32_t RSInterfacesSystemTest::defaultWidth_ = 480;
54 uint32_t RSInterfacesSystemTest::defaultHeight_ = 320;
55 float RSInterfacesSystemTest::defaultDensity_ = 2.0;
56 int32_t RSInterfacesSystemTest::defaultFlags_ = 0;
57 VirtualScreenOption RSInterfacesSystemTest::defaultOption_ = {
58 defaultName_, defaultWidth_, defaultHeight_, defaultDensity_, nullptr, defaultFlags_
59 };
60 const std::string defaultCmd_ = "/system/bin/snapshot_display -i ";
61
SetUpTestCase()62 void RSInterfacesSystemTest::SetUpTestCase()
63 {
64 defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
65 defaultDisplayId_ = defaultDisplay_->GetId();
66 defaultScreenId_ = defaultDisplay_->GetScreenId();
67 defaultWidth_ = defaultDisplay_->GetWidth();
68 defaultHeight_ = defaultDisplay_->GetHeight();
69 defaultOption_.width_ = defaultWidth_;
70 defaultOption_.height_ = defaultHeight_;
71 }
72
TearDownTestCase()73 void RSInterfacesSystemTest::TearDownTestCase()
74 {
75 }
76
SetUp()77 void RSInterfacesSystemTest::SetUp()
78 {
79 }
80
TearDown()81 void RSInterfacesSystemTest::TearDown()
82 {
83 }
84
85 namespace {
86 /**
87 * @tc.name: ScreenManager01
88 * @tc.desc: Modify expand virtualScreen resolution
89 * @tc.type: FUNC
90 */
91 HWTEST_F(RSInterfacesSystemTest, ScreenManager01, Function | MediumTest | Level2)
92 {
93 uint32_t resolutionFirstWidth = 1920;
94 uint32_t resolutionFirstHeight = 1080;
95 uint32_t resolutionLastWidth = 720;
96 uint32_t resolutionLastHeight = 1280;
97
98 RSInterfacesTestUtils utils;
99 ASSERT_TRUE(utils.CreateSurface());
100 defaultOption_.surface_ = utils.pSurface_;
101 defaultOption_.isForShot_ = false;
102
103 ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
104 sleep(TEST_SLEEP_S);
105
106 std::vector<ExpandOption> options = {{defaultScreenId_, 0, 0}, {virtualScreenId, defaultWidth_, 0}};
107 ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
108
109 sleep(TEST_SLEEP_S);
110 ASSERT_NE(SCREEN_ID_INVALID, expansionId);
111
112 auto ids = RSInterfaces::GetInstance().GetAllScreenIds();
113 ScreenId rsId = ids.front();
114 auto resolution = RSInterfaces::GetInstance().GetVirtualScreenResolution(rsId);
115 ASSERT_EQ(resolution.GetVirtualScreenWidth(), defaultWidth_);
116 ASSERT_EQ(resolution.GetVirtualScreenHeight(), defaultHeight_);
117
118 RSInterfaces::GetInstance().SetVirtualScreenResolution(rsId, resolutionFirstWidth, resolutionFirstHeight);
119 resolution = RSInterfaces::GetInstance().GetVirtualScreenResolution(rsId);
120 ASSERT_EQ(resolution.GetVirtualScreenWidth(), resolutionFirstWidth);
121 ASSERT_EQ(resolution.GetVirtualScreenHeight(), resolutionFirstHeight);
122
123 RSInterfaces::GetInstance().SetVirtualScreenResolution(rsId, resolutionLastWidth, resolutionLastHeight);
124 resolution = RSInterfaces::GetInstance().GetVirtualScreenResolution(rsId);
125 ASSERT_EQ(resolution.GetVirtualScreenWidth(), resolutionLastWidth);
126 ASSERT_EQ(resolution.GetVirtualScreenHeight(), resolutionLastHeight);
127
128 auto res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
129 ASSERT_EQ(DMError::DM_OK, res);
130 }
131
132 /**
133 * @tc.name: ScreenManager02
134 * @tc.desc: The main screen resolution can be changed by the mirrorscreen.
135 * @tc.type: FUNC
136 */
137 HWTEST_F(RSInterfacesSystemTest, ScreenManager02, Function | MediumTest | Level2)
138 {
139 uint32_t resolutionFirstWidth = 2000;
140 uint32_t resolutionFirstHeight = 1500;
141
142 RSInterfacesTestUtils utils;
143 ASSERT_TRUE(utils.CreateSurface());
144 defaultOption_.surface_ = utils.pSurface_;
145 defaultOption_.isForShot_ = false;
146
147 ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
148 sleep(TEST_SLEEP_S);
149
150 std::vector<ScreenId> mirrorIds;
151 mirrorIds.push_back(virtualScreenId);
152 ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
153 sleep(TEST_SLEEP_S);
154 ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
155
156 auto ids = RSInterfaces::GetInstance().GetAllScreenIds();
157 ScreenId rsId = ids.front();
158 auto resolution = RSInterfaces::GetInstance().GetVirtualScreenResolution(rsId);
159 ASSERT_EQ(resolution.GetVirtualScreenWidth(), defaultWidth_);
160 ASSERT_EQ(resolution.GetVirtualScreenHeight(), defaultHeight_);
161
162 RSInterfaces::GetInstance().SetVirtualScreenResolution(rsId, resolutionFirstWidth, resolutionFirstHeight);
163 resolution = RSInterfaces::GetInstance().GetVirtualScreenResolution(rsId);
164 ScreenId mainId = RSInterfaces::GetInstance().GetDefaultScreenId();
165 RSScreenModeInfo screenModeInfo = RSInterfaces::GetInstance().GetScreenActiveMode(mainId);
166 ASSERT_EQ(resolution.GetVirtualScreenWidth(), resolutionFirstWidth);
167 ASSERT_EQ(resolution.GetVirtualScreenHeight(), resolutionFirstHeight);
168 ASSERT_NE(static_cast<uint32_t>(screenModeInfo.GetScreenWidth()), resolutionFirstWidth);
169 ASSERT_NE(static_cast<uint32_t>(screenModeInfo.GetScreenHeight()), resolutionFirstHeight);
170
171 auto res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
172 ASSERT_EQ(DMError::DM_OK, res);
173 }
174
175 /**
176 * @tc.name: ScreenManager03
177 * @tc.desc: Mirror virtualScreen
178 * @tc.type: FUNC
179 */
180 HWTEST_F(RSInterfacesSystemTest, ScreenManager03, Function | MediumTest | Level2)
181 {
182 RSInterfacesTestUtils utils;
183 ASSERT_TRUE(utils.CreateSurface());
184 defaultOption_.surface_ = utils.pSurface_;
185 defaultOption_.isForShot_ = false;
186
187 ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
188 sleep(TEST_SLEEP_S);
189
190 std::vector<ScreenId> mirrorIds;
191 mirrorIds.push_back(virtualScreenId);
192 ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
193
194 uint32_t virtualScreenSkipFrameInterval = 2;
195 auto ids = RSInterfaces::GetInstance().GetAllScreenIds();
196 ScreenId rsId = ids.front();
197
198 int32_t ret = RSInterfaces::GetInstance().SetScreenSkipFrameInterval(rsId, virtualScreenSkipFrameInterval);
199 ASSERT_EQ(ret, StatusCode::SUCCESS);
200 std::cout << "VirtualScreen is created now" << std::endl;
201 sleep(30 * TEST_SLEEP_S);
202
203 auto res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
204 ASSERT_EQ(DMError::DM_OK, res);
205 }
206
207 /**
208 * @tc.name: SetFocusAppInfo
209 * @tc.desc: Set focus AppInfo
210 * @tc.type: FUNC
211 */
212 HWTEST_F(RSInterfacesSystemTest, SetFocusAppInfo, Function | MediumTest | Level2)
213 {
214 FocusAppInfo info;
215
216 int32_t ret = RSInterfaces::GetInstance().SetFocusAppInfo(info);
217 ASSERT_EQ(ret, StatusCode::SUCCESS);
218 }
219 }
220 } // namespace Rosen
221 } // namespace OHOS
222