1 /*
2 * Copyright (c) 2024 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 <memory>
19 #include "egl_blob_cache.h"
20
21 #include "egl_defs.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS::Rosen {
27 class EglBlobTest : public testing::Test {
28 public:
SetUpTestCase()29 static void SetUpTestCase() {}
TearDownTestCase()30 static void TearDownTestCase() {}
SetUp()31 void SetUp() {}
TearDown()32 void TearDown() {}
33 };
34
35 /**
36 * @tc.name: EglBlobInit001
37 * @tc.desc:
38 * @tc.type: FUNC
39 */
HWTEST_F(EglBlobTest,EglBlobInit001,Level1)40 HWTEST_F(EglBlobTest, EglBlobInit001, Level1)
41 {
42 BlobCache* ret = BlobCache::Get();
43 ASSERT_NE(ret, nullptr);
44 }
45
46
47 /**
48 * @tc.name: EglBlobInit002
49 * @tc.desc:
50 * @tc.type: FUNC
51 */
HWTEST_F(EglBlobTest,EglBlobInit002,Level1)52 HWTEST_F(EglBlobTest, EglBlobInit002, Level1)
53 {
54 BlobCache* ret = BlobCache::Get();
55 ASSERT_NE(ret, nullptr);
56
57 void *a = malloc(4);
58 void *b = malloc(4);
59 int* intPtr = static_cast<int*>(a);
60 int* intPtr2 = static_cast<int*>(b);
61 *intPtr = 1;
62 *intPtr2 = 2;
63 const void* key = static_cast<const void*>(a);
64 void *value = static_cast<void*>(b);
65 int d = *static_cast<int *>(value);
66 ASSERT_EQ(d, 2);
67 EGLsizeiANDROID keysize = 4;
68 EGLsizeiANDROID valuesize = 4;
69 void *value2 = malloc(4);
70 BlobCache::SetBlobFunc(key, keysize, value, valuesize);
71 BlobCache::GetBlobFunc(key, keysize, value2, valuesize);
72 int c = *static_cast<int *>(value2);
73 ASSERT_EQ(c, 2);
74 }
75
76 /**
77 * @tc.name: EglBlobInit003
78 * @tc.desc:
79 * @tc.type: FUNC
80 */
HWTEST_F(EglBlobTest,EglBlobInit003,Level1)81 HWTEST_F(EglBlobTest, EglBlobInit003, Level1)
82 {
83 BlobCache* ret = BlobCache::Get();
84 ASSERT_NE(ret, nullptr);
85
86 void *a = malloc(4);
87 void *b = malloc(4);
88 int* intPtr = static_cast<int*>(a);
89 int* intPtr2 = static_cast<int*>(b);
90 *intPtr = 1;
91 *intPtr2 = 2;
92 const void* key = static_cast<const void*>(a);
93 void *value = static_cast<void*>(b);
94 int d = *static_cast<int *>(value);
95 ASSERT_EQ(d, 2);
96 EGLsizeiANDROID keysize = 4;
97 EGLsizeiANDROID valuesize = 4;
98 EGLsizeiANDROID valuesize2 = 3;
99 void *value2 = malloc(4);
100 BlobCache::SetBlobFunc(key, keysize, value, valuesize);
101 BlobCache::GetBlobFunc(key, keysize, value2, valuesize2);
102 int c = *static_cast<int *>(value2);
103 ASSERT_EQ(c, 0);
104 }
105
106 /**
107 * @tc.name: EglBlobInit004
108 * @tc.desc:
109 * @tc.type: FUNC
110 */
HWTEST_F(EglBlobTest,EglBlobInit004,Level1)111 HWTEST_F(EglBlobTest, EglBlobInit004, Level1)
112 {
113 BlobCache* ret = BlobCache::Get();
114 ASSERT_NE(ret, nullptr);
115
116 void *a = malloc(4);
117 void *b = malloc(4);
118 int* intPtr = static_cast<int*>(a);
119 int* intPtr2 = static_cast<int*>(b);
120 *intPtr = 1;
121 *intPtr2 = 2;
122 const void* key = static_cast<const void*>(a);
123 void *value = static_cast<void*>(b);
124 int d = *static_cast<int *>(value);
125 ASSERT_EQ(d, 2);
126 EGLsizeiANDROID keysize = -1;
127 EGLsizeiANDROID valuesize = -1;
128 void *value2 = malloc(4);
129 BlobCache::SetBlobFunc(key, keysize, value, valuesize);
130 BlobCache::GetBlobFunc(key, keysize, value2, valuesize);
131 int c = *static_cast<int *>(value2);
132 ASSERT_EQ(c, 0);
133 }
134
135 /**
136 * @tc.name: EglBlobInit005
137 * @tc.desc:
138 * @tc.type: FUNC
139 */
HWTEST_F(EglBlobTest,EglBlobInit005,Level1)140 HWTEST_F(EglBlobTest, EglBlobInit005, Level1)
141 {
142 BlobCache* ret = BlobCache::Get();
143 ASSERT_NE(ret, nullptr);
144
145 void *a = malloc(4);
146 void *b = malloc(4);
147 int* intPtr = static_cast<int*>(a);
148 int* intPtr2 = static_cast<int*>(b);
149 *intPtr = 1;
150 *intPtr2 = 2;
151 const void* key = static_cast<const void*>(a);
152 void *value = static_cast<void*>(b);
153 int d = *static_cast<int *>(value);
154 ASSERT_EQ(d, 2);
155 EGLsizeiANDROID keysize = 4;
156 EGLsizeiANDROID valuesize = 4;
157 void *value2 = malloc(4);
158 BlobCache::SetBlobFunc(key, keysize, value, valuesize);
159 EGLsizeiANDROID retnum = BlobCache::GetBlobFunc(key, keysize, value2, valuesize);
160 ASSERT_EQ(retnum, 4);
161 }
162
163 } // OHOS::Rosen
164