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 }
159
160 /**
161 * @tc.name: SetCurtainScreenUsingStatus001
162 * @tc.desc: Test CurtainScreen on.
163 * @tc.type: FUNC
164 * @tc.require: issueI993OY
165 */
166 HWTEST_F(RSInterfacesSystemTest, SetCurtainScreenUsingStatus001, Function | MediumTest | Level2)
167 {
168 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
169 rsInterfaces->SetCurtainScreenUsingStatus(true);
170 EXPECT_NE(rsInterfaces, 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* rsInterfaces = &(RSInterfaces::GetInstance());
182 rsInterfaces->SetCurtainScreenUsingStatus(false);
183 EXPECT_NE(rsInterfaces, nullptr);
184 }
185
186 /**
187 * @tc.name: SetVirtualScreenUsingStatus001
188 * @tc.desc: Virtual screen use status.
189 * @tc.type: FUNC
190 * @tc.require: issueI9ABGS
191 */
192 HWTEST_F(RSInterfacesSystemTest, SetVirtualScreenUsingStatus001, Function | MediumTest | Level2)
193 {
194 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
195 rsInterfaces->SetVirtualScreenUsingStatus(true);
196 EXPECT_NE(rsInterfaces, nullptr);
197 }
198
199 /**
200 * @tc.name: SetVirtualScreenUsingStatus002
201 * @tc.desc: Virtual screen don't use status.
202 * @tc.type: FUNC
203 * @tc.require: issueI9ABGS
204 */
205 HWTEST_F(RSInterfacesSystemTest, SetVirtualScreenUsingStatus002, Function | MediumTest | Level2)
206 {
207 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
208 rsInterfaces->SetVirtualScreenUsingStatus(false);
209 EXPECT_NE(rsInterfaces, nullptr);
210 }
211
212 /**
213 * @tc.name: SetLayerTop001
214 * @tc.desc: Test SetLayerTop interface.
215 * @tc.type: FUNC
216 * @tc.require: issueIAT8HK
217 */
218 HWTEST_F(RSInterfacesSystemTest, SetLayerTop001, Function | MediumTest | Level2)
219 {
220 std::string nodeIdStr = "123456";
221 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
222 rsInterfaces->SetLayerTop(nodeIdStr, false);
223 EXPECT_NE(rsInterfaces, nullptr);
224 }
225
226 /**
227 * @tc.name: SetLayerTop002
228 * @tc.desc: Test SetLayerTop interface.
229 * @tc.type: FUNC
230 * @tc.require: issueIAT8HK
231 */
232 HWTEST_F(RSInterfacesSystemTest, SetLayerTop002, Function | MediumTest | Level2)
233 {
234 std::string nodeIdStr = "123456";
235 RSInterfaces* rsInterfaces = &(RSInterfaces::GetInstance());
236 rsInterfaces->SetLayerTop(nodeIdStr, true);
237 EXPECT_NE(rsInterfaces, nullptr);
238 }
239 }
240 } // namespace Rosen
241 } // namespace OHOS
242