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, Hardware
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 
18 #include "EGL/egl_wrapper_loader.h"
19 
20 #include "egl_defs.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Rosen {
26 class EglWrapperLoaderTest : public testing::Test {
27 public:
SetUpTestCase()28     static void SetUpTestCase() {}
TearDownTestCase()29     static void TearDownTestCase() {}
SetUp()30     void SetUp() {}
TearDown()31     void TearDown() {}
32 };
33 
34 /**
35  * @tc.name: GetProcAddrFromDriver001
36  * @tc.desc:
37  * @tc.type: FUNC
38  */
HWTEST_F(EglWrapperLoaderTest,GetProcAddrFromDriver001,Level1)39 HWTEST_F(EglWrapperLoaderTest, GetProcAddrFromDriver001, Level1)
40 {
41     std::string name = std::string("");
42     auto result = EglWrapperLoader::GetInstance().GetProcAddrFromDriver(name.c_str());
43 
44     ASSERT_EQ(nullptr, result);
45 }
46 
47 /**
48  * @tc.name: GetProcAddrFromDriver002
49  * @tc.desc:
50  * @tc.type: FUNC
51  */
HWTEST_F(EglWrapperLoaderTest,GetProcAddrFromDriver002,Level2)52 HWTEST_F(EglWrapperLoaderTest, GetProcAddrFromDriver002, Level2)
53 {
54     EglWrapperDispatchTable dispatchTable;
55     EglWrapperLoader::GetInstance().Load(&dispatchTable);
56 
57     std::string name = std::string("eglGetProcAddress");
58     auto result = EglWrapperLoader::GetInstance().GetProcAddrFromDriver(name.c_str());
59 
60     ASSERT_NE(nullptr, result);
61 }
62 
63 /**
64  * @tc.name: Load001
65  * @tc.desc:
66  * @tc.type: FUNC
67  */
HWTEST_F(EglWrapperLoaderTest,Load001,Level1)68 HWTEST_F(EglWrapperLoaderTest, Load001, Level1)
69 {
70     EglWrapperDispatchTable dispatchTable;
71 
72     auto result = EglWrapperLoader::GetInstance().Load(&dispatchTable);
73     ASSERT_TRUE(result);
74 }
75 
76 /**
77  * @tc.name: Load002
78  * @tc.desc:
79  * @tc.type: FUNC
80  */
HWTEST_F(EglWrapperLoaderTest,Load002,Level2)81 HWTEST_F(EglWrapperLoaderTest, Load002, Level2)
82 {
83     auto result = EglWrapperLoader::GetInstance().Load(nullptr);
84     ASSERT_EQ(false, result);
85 }
86 
87 /**
88  * @tc.name: Load003
89  * @tc.desc:
90  * @tc.type: FUNC
91  */
HWTEST_F(EglWrapperLoaderTest,Load003,Level2)92 HWTEST_F(EglWrapperLoaderTest, Load003, Level2)
93 {
94     EglWrapperDispatchTable dispatchTable;
95 
96     auto result = EglWrapperLoader::GetInstance().Load(&dispatchTable);
97     ASSERT_TRUE(result);
98     result = EglWrapperLoader::GetInstance().Load(&dispatchTable);
99     ASSERT_TRUE(result);
100 }
101 
102 /**
103  * @tc.name: Unload001
104  * @tc.desc:
105  * @tc.type: FUNC
106  */
HWTEST_F(EglWrapperLoaderTest,Unload001,Level1)107 HWTEST_F(EglWrapperLoaderTest, Unload001, Level1)
108 {
109     EglWrapperDispatchTable dispatchTable;
110     EglWrapperLoader::GetInstance().Load(&dispatchTable);
111 
112     auto result = EglWrapperLoader::GetInstance().Unload(&dispatchTable);
113     ASSERT_TRUE(result);
114 }
115 
116 /**
117  * @tc.name: Unload002
118  * @tc.desc:
119  * @tc.type: FUNC
120  */
HWTEST_F(EglWrapperLoaderTest,Unload002,Level2)121 HWTEST_F(EglWrapperLoaderTest, Unload002, Level2)
122 {
123     auto result = EglWrapperLoader::GetInstance().Unload(nullptr);
124     ASSERT_EQ(false, result);
125 }
126 
127 /**
128  * @tc.name: Unload003
129  * @tc.desc:
130  * @tc.type: FUNC
131  */
HWTEST_F(EglWrapperLoaderTest,Unload003,Level2)132 HWTEST_F(EglWrapperLoaderTest, Unload003, Level2)
133 {
134     EglWrapperDispatchTable dispatchTable;
135     dispatchTable.isLoad = false;
136 
137     auto result = EglWrapperLoader::GetInstance().Unload(&dispatchTable);
138     ASSERT_EQ(false, result);
139 }
140 
141 /**
142  * @tc.name: LoadEgl001
143  * @tc.desc:
144  * @tc.type: FUNC
145  */
HWTEST_F(EglWrapperLoaderTest,LoadEgl001,Level1)146 HWTEST_F(EglWrapperLoaderTest, LoadEgl001, Level1)
147 {
148     EglWrapperDispatchTable dispatchTable;
149     std::string eglPath = std::string("libEGL_impl.so");
150     auto result = EglWrapperLoader::GetInstance().LoadEgl(eglPath.c_str(), &dispatchTable.egl);
151 
152     ASSERT_TRUE(result);
153 }
154 
155 /**
156  * @tc.name: LoadEgl002
157  * @tc.desc:
158  * @tc.type: FUNC
159  */
HWTEST_F(EglWrapperLoaderTest,LoadEgl002,Level2)160 HWTEST_F(EglWrapperLoaderTest, LoadEgl002, Level2)
161 {
162     std::string eglPath = std::string("");
163     auto result = EglWrapperLoader::GetInstance().LoadEgl(eglPath.c_str(), nullptr);
164 
165     ASSERT_EQ(false, result);
166 }
167 
168 /**
169  * @tc.name: LoadEgl003
170  * @tc.desc:
171  * @tc.type: FUNC
172  */
HWTEST_F(EglWrapperLoaderTest,LoadEgl003,Level2)173 HWTEST_F(EglWrapperLoaderTest, LoadEgl003, Level2)
174 {
175     EglWrapperDispatchTable dispatchTable;
176     std::string eglPath = std::string("libc.so");
177     auto result = EglWrapperLoader::GetInstance().LoadEgl(eglPath.c_str(), &dispatchTable.egl);
178 
179     ASSERT_EQ(false, result);
180 }
181 
182 /**
183  * @tc.name: LoadGl001
184  * @tc.desc:
185  * @tc.type: FUNC
186  */
HWTEST_F(EglWrapperLoaderTest,LoadGl001,Level1)187 HWTEST_F(EglWrapperLoaderTest, LoadGl001, Level1)
188 {
189     EglWrapperDispatchTable dispatchTable;
190     std::string eglPath = std::string("hilog.so");
191     auto result = EglWrapperLoader::GetInstance().LoadGl(eglPath.c_str(),
192         gGlApiNames1, (FunctionPointerType *)&dispatchTable.gl.table1);
193 
194     ASSERT_EQ(nullptr, result);
195 }
196 
197 /**
198  * @tc.name: LoadGl002
199  * @tc.desc:
200  * @tc.type: FUNC
201  */
HWTEST_F(EglWrapperLoaderTest,LoadGl002,Level2)202 HWTEST_F(EglWrapperLoaderTest, LoadGl002, Level2)
203 {
204     std::string eglPath = std::string("");
205     auto result = EglWrapperLoader::GetInstance().LoadGl(eglPath.c_str(), gGlApiNames1, nullptr);
206 
207     ASSERT_EQ(nullptr, result);
208 }
209 
210 /**
211  * @tc.name: LoadGl003
212  * @tc.desc:
213  * @tc.type: FUNC
214  */
HWTEST_F(EglWrapperLoaderTest,LoadGl003,Level2)215 HWTEST_F(EglWrapperLoaderTest, LoadGl003, Level2)
216 {
217     EglWrapperDispatchTable dispatchTable;
218     std::string eglPath = std::string("libEGL_impl.so");
219     auto result = EglWrapperLoader::GetInstance().LoadEgl(eglPath.c_str(), &dispatchTable.egl);
220     ASSERT_TRUE(result);
221 
222     std::string glPath = std::string("libGLESv1_impl.so");
223     auto ret = EglWrapperLoader::GetInstance().LoadGl(glPath.c_str(),
224         gGlApiNames1, (FunctionPointerType *)&dispatchTable.gl.table1);
225 
226     ASSERT_NE(nullptr, ret);
227 }
228 } // OHOS::Rosen
229