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 #include <gtest/gtest.h>
17 #include <hilog/log.h>
18
19 #include "platform/common/rs_system_properties.h"
20 #include "render_context.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS::Rosen {
25 class RenderContextTest : public testing::Test {
26 public:
27 static constexpr HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0, "RenderContextTest" };
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void RenderContextTest::SetUpTestCase() {}
TearDownTestCase()35 void RenderContextTest::TearDownTestCase() {}
SetUp()36 void RenderContextTest::SetUp() {}
TearDown()37 void RenderContextTest::TearDown() {}
38
39 /**
40 * @tc.name: CreateEGLSurfaceTest001
41 * @tc.desc: Verify the CreateEGLSurfaceTest001 of RenderContextTest
42 * @tc.type: FUNC
43 */
44 HWTEST_F(RenderContextTest, CreateEGLSurfaceTest001, Function | SmallTest | Level2)
45 {
46 #ifdef ACE_ENABLE_GL
47 if (RSSystemProperties::IsUseVulkan()) {
48 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
49 return;
50 }
51 // start CreateEGLSurfaceTest001 test
52 RenderContext renderContext;
53 EGLSurface eglSurface = renderContext.CreateEGLSurface(nullptr);
54 EXPECT_EQ(eglSurface, EGL_NO_SURFACE);
55 #endif
56 }
57
58 /**
59 * @tc.name: CreateEGLSurfaceTest002
60 * @tc.desc: Verify the CreateEGLSurfaceTest002 of RenderContextTest
61 * @tc.type: FUNC
62 */
63 HWTEST_F(RenderContextTest, CreateEGLSurfaceTest002, Function | SmallTest | Level2)
64 {
65 #ifdef ACE_ENABLE_GL
66 if (RSSystemProperties::IsUseVulkan()) {
67 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
68 return;
69 }
70 // start CreateEGLSurfaceTest002 test
71 RenderContext renderContext;
72 renderContext.InitializeEglContext();
73 EGLSurface eglSurface = renderContext.CreateEGLSurface(nullptr);
74 EXPECT_EQ(eglSurface, EGL_NO_SURFACE);
75 #endif
76 }
77
78 /**
79 * @tc.name: SetUpGrContextTest
80 * @tc.desc: Verify the SetUpGrContextTest of RenderContextTest
81 * @tc.type: FUNC
82 */
83 HWTEST_F(RenderContextTest, SetUpGrContextTest, Function | SmallTest | Level2)
84 {
85 #ifdef ACE_ENABLE_GL
86 if (RSSystemProperties::IsUseVulkan()) {
87 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
88 return;
89 }
90 // start SetUpGrContextTest test
91 RenderContext renderContext;
92 bool grContext = renderContext.SetUpGpuContext();
93 EXPECT_EQ(grContext, false);
94 #endif
95 }
96
97 /**
98 * @tc.name: AcquireSurfaceTest
99 * @tc.desc: Verify the AcquireSurfaceTest of RenderContextTest
100 * @tc.type: FUNC
101 */
102 HWTEST_F(RenderContextTest, AcquireSurfaceTest, Function | SmallTest | Level2)
103 {
104 #ifdef ACE_ENABLE_GL
105 if (RSSystemProperties::IsUseVulkan()) {
106 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
107 return;
108 }
109 // start AcquireSurfaceTest test
110 RenderContext renderContext;
111 auto surface = renderContext.AcquireSurface(0, 0);
112 EXPECT_TRUE(surface == nullptr);
113 #endif
114 }
115
116 /**
117 * @tc.name: QueryEglBufferAgeTest001
118 * @tc.desc: Verify the QueryEglBufferAgeTest001 of RenderContextTest
119 * @tc.type: FUNC
120 */
121 HWTEST_F(RenderContextTest, QueryEglBufferAgeTest001, Function | SmallTest | Level2)
122 {
123 #ifdef ACE_ENABLE_GL
124 if (RSSystemProperties::IsUseVulkan()) {
125 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
126 return;
127 }
128 // start QueryEglBufferAgeTest001 test
129 RenderContext renderContext;
130 EGLint bufferAge = renderContext.QueryEglBufferAge();
131 EXPECT_EQ(bufferAge, EGL_UNKNOWN);
132 #endif
133 }
134
135 /**
136 * @tc.name: QueryEglBufferAgeTest002
137 * @tc.desc: Verify the QueryEglBufferAgeTest002 of RenderContextTest
138 * @tc.type: FUNC
139 */
140 HWTEST_F(RenderContextTest, QueryEglBufferAgeTest002, Function | SmallTest | Level2)
141 {
142 #ifdef ACE_ENABLE_GL
143 if (RSSystemProperties::IsUseVulkan()) {
144 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
145 return;
146 }
147 // start QueryEglBufferAgeTest002 test
148 RenderContext renderContext;
149 EGLint bufferAge = renderContext.QueryEglBufferAge();
150 EXPECT_EQ(bufferAge, EGL_UNKNOWN);
151 #endif
152 }
153
154 /**
155 * @tc.name: ClearRedundantResourcesTest001
156 * @tc.desc: Verify the ClearRedundantResourcesTest002 of RenderContextTest
157 * @tc.type: FUNC
158 */
HWTEST_F(RenderContextTest,ClearRedundantResourcesTest001,Level1)159 HWTEST_F(RenderContextTest, ClearRedundantResourcesTest001, Level1)
160 {
161 #ifdef ACE_ENABLE_GL
162 if (RSSystemProperties::IsUseVulkan()) {
163 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
164 return;
165 }
166 // start ClearRedundantResourcesTest001 test
167 RenderContext renderContext;
168 renderContext.InitializeEglContext();
169 renderContext.ClearRedundantResources();
170 #endif
171 }
172
173 /**
174 * @tc.name: DamageFrameTest001
175 * @tc.desc: Verify the DamageFrameTest001 of RenderContextTest
176 * @tc.type: FUNC
177 */
HWTEST_F(RenderContextTest,DamageFrameTest001,Level1)178 HWTEST_F(RenderContextTest, DamageFrameTest001, Level1)
179 {
180 #ifdef ACE_ENABLE_GL
181 if (RSSystemProperties::IsUseVulkan()) {
182 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
183 return;
184 }
185 // start DamageFrameTest001 test
186 RenderContext renderContext;
187 renderContext.InitializeEglContext();
188 renderContext.DamageFrame(0, 0, 0, 0);
189 #endif
190 }
191
192 /**
193 * @tc.name: MakeSelfCurrentTest001
194 * @tc.desc: Verify the MakeSelfCurrentTest001 of RenderContextTest
195 * @tc.type: FUNC
196 */
HWTEST_F(RenderContextTest,MakeSelfCurrentTest001,Level1)197 HWTEST_F(RenderContextTest, MakeSelfCurrentTest001, Level1)
198 {
199 #ifdef ACE_ENABLE_GL
200 if (RSSystemProperties::IsUseVulkan()) {
201 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
202 return;
203 }
204 // start MakeSelfCurrentTest001 test
205 RenderContext renderContext;
206 renderContext.InitializeEglContext();
207 renderContext.MakeSelfCurrent();
208 #endif
209 }
210
211 /**
212 * @tc.name: ColorSpaceTest001
213 * @tc.desc: Verify the SetColorSpaceTest and GetColorSpaceTest of RenderContextTest
214 * @tc.type: FUNC
215 */
HWTEST_F(RenderContextTest,ColorSpaceTest001,Level1)216 HWTEST_F(RenderContextTest, ColorSpaceTest001, Level1)
217 {
218 #ifdef ACE_ENABLE_GL
219 if (RSSystemProperties::IsUseVulkan()) {
220 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
221 return;
222 }
223 // start ColorSpaceTest001 test
224 RenderContext renderContext;
225 renderContext.SetColorSpace(GRAPHIC_COLOR_GAMUT_DISPLAY_P3);
226 ASSERT_EQ(renderContext.GetColorSpace(), GRAPHIC_COLOR_GAMUT_DISPLAY_P3);
227 #endif
228 }
229
230 /**
231 * @tc.name: PixelFormatTest001
232 * @tc.desc: Verify the SetPixelFormatTest and GetPixelFormat of RenderContextTest
233 * @tc.type: FUNC
234 */
HWTEST_F(RenderContextTest,PixelFormatTest001,Level1)235 HWTEST_F(RenderContextTest, PixelFormatTest001, Level1)
236 {
237 #ifdef ACE_ENABLE_GL
238 if (RSSystemProperties::IsUseVulkan()) {
239 GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
240 return;
241 }
242 // start PixelFormatTest001 test
243 RenderContext renderContext;
244 renderContext.SetPixelFormat(GRAPHIC_PIXEL_FMT_RGBA_1010102);
245 ASSERT_EQ(renderContext.GetPixelFormat(), GRAPHIC_PIXEL_FMT_RGBA_1010102);
246 #endif
247 }
248 } // namespace OHOS::Rosen