1 /*
2 * Copyright (c) 2021 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 #include "gtest/gtest.h"
17 #include "common/rs_common_def.h"
18 #include "ui/rs_display_node.h"
19 #include "transaction/rs_transaction.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class RSDisplayModeTest : public testing::Test {
27 public:
28 uint64_t screenId1 = 10; // To extinguish between the original screenIds and test screenIds
29 uint64_t screenId2 = 11;
30 static constexpr uint32_t TEST_SLEEP_S = 1;
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void RSDisplayModeTest::SetUpTestCase() {}
TearDownTestCase()38 void RSDisplayModeTest::TearDownTestCase() {}
SetUp()39 void RSDisplayModeTest::SetUp() {}
TearDown()40 void RSDisplayModeTest::TearDown() {}
41
42 /**
43 * @tc.name: CreateExpand
44 * @tc.desc: Create expand display node
45 * @tc.type:FUNC
46 * @tc.require: issueI5CAAF
47 */
48 HWTEST_F(RSDisplayModeTest, CreateExpand, Function | MediumTest | Level2)
49 {
50 /**
51 * step1. create RSDisplayNode
52 */
53 RSDisplayNodeConfig config = {screenId1, false, 0};
54 RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
55 ASSERT_TRUE(displayNode != nullptr);
56
57 auto isMirrorDisplay = displayNode->IsMirrorDisplay();
58 EXPECT_EQ(isMirrorDisplay, false);
59
60 /**
61 * step2. flush commands
62 */
63 RSTransaction::FlushImplicitTransaction();
64
65 /**
66 * step3. delete nodes
67 */
68 sleep(TEST_SLEEP_S);
69 displayNode->RemoveFromTree();
70 }
71
72 /**
73 * @tc.name: CreateMirror
74 * @tc.desc: Create mirror display node
75 * @tc.type:FUNC
76 * @tc.require: issueI5CAAF
77 */
78 HWTEST_F(RSDisplayModeTest, CreateMirror, Function | MediumTest | Level2)
79 {
80 /**
81 * step1. create RSDisplayNode
82 */
83 RSDisplayNodeConfig configSrc = {screenId1, false, 0};
84 RSDisplayNode::SharedPtr displayNodeSrc = RSDisplayNode::Create(configSrc);
85 ASSERT_TRUE(displayNodeSrc != nullptr);
86
87 RSDisplayNodeConfig config = {screenId2, true, displayNodeSrc->GetId()};
88 RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
89 ASSERT_TRUE(displayNode != nullptr);
90
91 auto isMirrorDisplay = displayNode->IsMirrorDisplay();
92 EXPECT_EQ(isMirrorDisplay, true);
93
94 /**
95 * step2. flush commands
96 */
97 RSTransaction::FlushImplicitTransaction();
98
99 /**
100 * step3. delete nodes
101 */
102 sleep(TEST_SLEEP_S);
103 displayNodeSrc->RemoveFromTree();
104 displayNode->RemoveFromTree();
105 }
106
107 /**
108 * @tc.name: SetDisplayNodeMirrorConfigExpand
109 * @tc.desc: Modify display mode type to expand display
110 * @tc.type:FUNC
111 * @tc.require: issueI5CAAF
112 */
113 HWTEST_F(RSDisplayModeTest, SetDisplayNodeMirrorConfigExpand, Function | MediumTest | Level2)
114 {
115 /**
116 * step1. create RSDisplayNode
117 */
118 RSDisplayNodeConfig configSrc = {screenId1, false, 0};
119 RSDisplayNode::SharedPtr displayNodeSrc = RSDisplayNode::Create(configSrc);
120 ASSERT_TRUE(displayNodeSrc != nullptr);
121
122 RSDisplayNodeConfig config = {screenId2, true, screenId1};
123 RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
124 ASSERT_TRUE(displayNode != nullptr);
125 auto isMirrorDisplay = displayNode->IsMirrorDisplay();
126 EXPECT_EQ(isMirrorDisplay, true);
127
128 /**
129 * step2. set display mode
130 */
131 RSDisplayNodeConfig configNew = {screenId2, false, 0};
132 displayNode->SetDisplayNodeMirrorConfig(configNew);
133 isMirrorDisplay = displayNode->IsMirrorDisplay();
134 EXPECT_EQ(isMirrorDisplay, false);
135
136 /**
137 * step3. flush commands
138 */
139 RSTransaction::FlushImplicitTransaction();
140
141 /**
142 * step4. delete nodes
143 */
144 sleep(TEST_SLEEP_S);
145 displayNodeSrc->RemoveFromTree();
146 displayNode->RemoveFromTree();
147 }
148
149 /**
150 * @tc.name: SetDisplayNodeMirrorConfigMirror
151 * @tc.desc: Modify display mode type to mirror display
152 * @tc.type:FUNC
153 * @tc.require: issueI5CAAF
154 */
155 HWTEST_F(RSDisplayModeTest, SetDisplayNodeMirrorConfigMirror, Function | MediumTest | Level2)
156 {
157 /**
158 * step1. create RSDisplayNode
159 */
160 RSDisplayNodeConfig configSrc = {screenId1, false, 0};
161 RSDisplayNode::SharedPtr displayNodeSrc = RSDisplayNode::Create(configSrc);
162 ASSERT_TRUE(displayNodeSrc != nullptr);
163
164 RSDisplayNodeConfig config = {screenId2, false, 0};
165 RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
166 ASSERT_TRUE(displayNode != nullptr);
167 auto isMirrorDisplay = displayNode->IsMirrorDisplay();
168 EXPECT_EQ(isMirrorDisplay, false);
169
170 /**
171 * step2. set display mode
172 */
173 RSDisplayNodeConfig configNew = {screenId2, true, displayNodeSrc->GetId()};
174 displayNode->SetDisplayNodeMirrorConfig(configNew);
175 isMirrorDisplay = displayNode->IsMirrorDisplay();
176 EXPECT_EQ(isMirrorDisplay, true);
177
178 /**
179 * step3. flush commands
180 */
181 RSTransaction::FlushImplicitTransaction();
182
183 /**
184 * step4. delete nodes
185 */
186 sleep(TEST_SLEEP_S);
187 displayNodeSrc->RemoveFromTree();
188 displayNode->RemoveFromTree();
189 }
190 } // namespace Rosen
191 } // namespace OHOS