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: ScreenManager03
88 * @tc.desc: Mirror virtualScreen
89 * @tc.type: FUNC
90 */
91 HWTEST_F(RSInterfacesSystemTest, ScreenManager03, Function | MediumTest | Level2)
92 {
93 RSInterfacesTestUtils utils;
94 ASSERT_TRUE(utils.CreateSurface());
95 defaultOption_.surface_ = utils.pSurface_;
96 defaultOption_.isForShot_ = false;
97
98 ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
99 sleep(TEST_SLEEP_S);
100
101 std::vector<ScreenId> mirrorIds;
102 mirrorIds.push_back(virtualScreenId);
103 ScreenId screenGroupId;
104 ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds, screenGroupId);
105
106 uint32_t virtualScreenSkipFrameInterval = 2;
107 auto ids = RSInterfaces::GetInstance().GetAllScreenIds();
108 ScreenId rsId = ids.front();
109
110 int32_t ret = RSInterfaces::GetInstance().SetScreenSkipFrameInterval(rsId, virtualScreenSkipFrameInterval);
111 ASSERT_EQ(ret, StatusCode::SUCCESS);
112 std::cout << "VirtualScreen is created now" << std::endl;
113 sleep(30 * TEST_SLEEP_S);
114
115 auto res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
116 ASSERT_EQ(DMError::DM_OK, res);
117 }
118
119 /**
120 * @tc.name: SetFocusAppInfo
121 * @tc.desc: Set focus AppInfo
122 * @tc.type: FUNC
123 */
124 HWTEST_F(RSInterfacesSystemTest, SetFocusAppInfo, Function | MediumTest | Level2)
125 {
126 FocusAppInfo info;
127
128 int32_t ret = RSInterfaces::GetInstance().SetFocusAppInfo(info);
129 ASSERT_EQ(ret, StatusCode::SUCCESS);
130 }
131
132 /**
133 * @tc.name: ShowWatermark
134 * @tc.desc: Test ShowWatermark interface.
135 * @tc.type: FUNC
136 * @tc.require: issueI6HP8P
137 */
138 HWTEST_F(RSInterfacesSystemTest, ShowWatermark, Function | MediumTest | Level2)
139 {
140 const uint32_t color[8] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
141 uint32_t colorLength = sizeof(color) / sizeof(color[0]);
142 const int32_t offset = 0;
143 Media::InitializationOptions opts;
144 opts.size.width = 3;
145 opts.size.height = 2;
146 opts.pixelFormat = Media::PixelFormat::RGBA_8888;
147 opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
148 int32_t stride = opts.size.width;
149 std::unique_ptr<Media::PixelMap> pixelMap1 = Media::PixelMap::Create(color, colorLength, offset, stride, opts);
150 RSInterfaces::GetInstance().ShowWatermark(std::move(pixelMap1), true);
151 sleep(TEST_SLEEP_S);
152 (void)system("snapshot_display -i 0");
153 sleep(3 * TEST_SLEEP_S);
154 RSInterfaces::GetInstance().ShowWatermark(nullptr, false);
155 sleep(TEST_SLEEP_S);
156 (void)system("snapshot_display -i 0");
157 sleep(3 * TEST_SLEEP_S);
158 EXPECT_TRUE(RSInterfaces::GetInstance().renderServiceClient_ != nullptr);
159 }
160
161 /**
162 * @tc.name: SetCurtainScreenUsingStatus001
163 * @tc.desc: Test CurtainScreen on.
164 * @tc.type: FUNC
165 * @tc.require: issueI993OY
166 */
167 HWTEST_F(RSInterfacesSystemTest, SetCurtainScreenUsingStatus001, Function | MediumTest | Level2)
168 {
169 RSInterfaces::GetInstance().SetCurtainScreenUsingStatus(true);
170 EXPECT_TRUE(RSInterfaces::GetInstance().renderServiceClient_ != nullptr);
171 }
172
173 /**
174 * @tc.name: SetCurtainScreenUsingStatus002
175 * @tc.desc: Test CurtainScreen off.
176 * @tc.type: FUNC
177 * @tc.require: issueI993OY
178 */
179 HWTEST_F(RSInterfacesSystemTest, SetCurtainScreenUsingStatus002, Function | MediumTest | Level2)
180 {
181 RSInterfaces::GetInstance().SetCurtainScreenUsingStatus(false);
182 EXPECT_TRUE(RSInterfaces::GetInstance().renderServiceClient_ != nullptr);
183 }
184
185 /**
186 * @tc.name: SetVirtualScreenUsingStatus001
187 * @tc.desc: Virtual screen use status.
188 * @tc.type: FUNC
189 * @tc.require: issueI9ABGS
190 */
191 HWTEST_F(RSInterfacesSystemTest, SetVirtualScreenUsingStatus001, Function | MediumTest | Level2)
192 {
193 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
194 rsInterfaces->SetVirtualScreenUsingStatus(true);
195 EXPECT_TRUE(rsInterfaces != nullptr);
196 }
197
198 /**
199 * @tc.name: SetVirtualScreenUsingStatus002
200 * @tc.desc: Virtual screen don't use status.
201 * @tc.type: FUNC
202 * @tc.require: issueI9ABGS
203 */
204 HWTEST_F(RSInterfacesSystemTest, SetVirtualScreenUsingStatus002, Function | MediumTest | Level2)
205 {
206 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
207 rsInterfaces->SetVirtualScreenUsingStatus(false);
208 EXPECT_TRUE(rsInterfaces != nullptr);
209 }
210
211 /**
212 * @tc.name: SetFreeMultiWindowStatus001
213 * @tc.desc: tablet free multi-window don't use status.
214 * @tc.type: FUNC
215 * @tc.require: issueIANPC2
216 */
217 HWTEST_F(RSInterfacesSystemTest, SetFreeMultiWindowStatus001, Function | MediumTest | Level2)
218 {
219 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
220 rsInterfaces->SetFreeMultiWindowStatus(false);
221 EXPECT_TRUE(rsInterfaces != nullptr);
222 }
223
224 /**
225 * @tc.name: SetFreeMultiWindowStatus002
226 * @tc.desc: tablet free multi-window use status.
227 * @tc.type: FUNC
228 * @tc.require: issueIANPC2
229 */
230 HWTEST_F(RSInterfacesSystemTest, SetFreeMultiWindowStatus002, Function | MediumTest | Level2)
231 {
232 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
233 rsInterfaces->SetFreeMultiWindowStatus(true);
234 EXPECT_TRUE(rsInterfaces != nullptr);
235 }
236
237 /**
238 * @tc.name: SetLayerTop001
239 * @tc.desc: Test SetLayerTop interface.
240 * @tc.type: FUNC
241 * @tc.require: issueIAT8HK
242 */
243 HWTEST_F(RSInterfacesSystemTest, SetLayerTop001, Function | MediumTest | Level2)
244 {
245 std::string nodeIdStr = "123456";
246 RSInterfaces::GetInstance().SetLayerTop(nodeIdStr, false);
247 EXPECT_TRUE(RSInterfaces::GetInstance().renderServiceClient_ != nullptr);
248 }
249
250 /**
251 * @tc.name: SetLayerTop002
252 * @tc.desc: Test SetLayerTop interface.
253 * @tc.type: FUNC
254 * @tc.require: issueIAT8HK
255 */
256 HWTEST_F(RSInterfacesSystemTest, SetLayerTop002, Function | MediumTest | Level2)
257 {
258 std::string nodeIdStr = "123456";
259 RSInterfaces::GetInstance().SetLayerTop(nodeIdStr, true);
260 EXPECT_TRUE(RSInterfaces::GetInstance().renderServiceClient_ != nullptr);
261 }
262 }
263 } // namespace Rosen
264 } // namespace OHOS
265