Skip to content

Commit 3fd4d0a

Browse files
[Impeller] Make glIsTexture mockable for use by the ReactorGLES.NameUntrackedHandle test (#162082)
ReactorGLES.NameUntrackedHandle calls SetDebugLabel, which invokes glIsTexture. glIsTexture should return a GLboolean. But the mock GLES resolver was mapping glIsTexture to a no-op function with a void return type. This change makes glIsTexture mockable so the test can ensure that it returns the appropriate result.
1 parent 3850ba3 commit 3fd4d0a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

engine/src/flutter/impeller/renderer/backend/gles/test/mock_gles.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,23 @@ auto const kExtensions = std::vector<const char*>{
3939
};
4040

4141
namespace {
42+
43+
template <typename T>
44+
struct function_traits;
45+
46+
template <typename C, typename Ret, typename... Args>
47+
struct function_traits<Ret (C::*)(Args...)> {
48+
using return_type = Ret;
49+
};
50+
4251
template <typename Func, typename... Args>
43-
void CallMockMethod(Func func, Args&&... args) {
52+
auto CallMockMethod(Func func, Args&&... args) {
4453
if (auto mock_gles = g_mock_gles.lock()) {
4554
if (mock_gles->GetImpl()) {
46-
(mock_gles->GetImpl()->*func)(std::forward<Args>(args)...);
55+
return (mock_gles->GetImpl()->*func)(std::forward<Args>(args)...);
4756
}
4857
}
58+
return typename function_traits<Func>::return_type();
4959
}
5060
} // namespace
5161

@@ -194,6 +204,13 @@ void mockObjectLabelKHR(GLenum identifier,
194204
static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), //
195205
decltype(glObjectLabelKHR)>::value);
196206

207+
GLboolean mockIsTexture(GLuint texture) {
208+
return CallMockMethod(&IMockGLESImpl::IsTexture, texture);
209+
}
210+
211+
static_assert(CheckSameSignature<decltype(mockGenTextures), //
212+
decltype(glGenTextures)>::value);
213+
197214
// static
198215
std::shared_ptr<MockGLES> MockGLES::Init(
199216
std::unique_ptr<MockGLESImpl> impl,
@@ -257,6 +274,8 @@ const ProcTableGLES::Resolver kMockResolverGLES = [](const char* name) {
257274
return reinterpret_cast<void*>(mockObjectLabelKHR);
258275
} else if (strcmp(name, "glGenBuffers") == 0) {
259276
return reinterpret_cast<void*>(mockGenBuffers);
277+
} else if (strcmp(name, "glIsTexture") == 0) {
278+
return reinterpret_cast<void*>(mockIsTexture);
260279
} else {
261280
return reinterpret_cast<void*>(&doNothing);
262281
}

engine/src/flutter/impeller/renderer/backend/gles/test/mock_gles.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class IMockGLESImpl {
3636
GLuint64* result) {}
3737
virtual void DeleteQueriesEXT(GLsizei size, const GLuint* queries) {}
3838
virtual void GenBuffers(GLsizei n, GLuint* buffers) {}
39+
virtual GLboolean IsTexture(GLuint texture) { return true; }
3940
};
4041

4142
class MockGLESImpl : public IMockGLESImpl {
@@ -70,6 +71,7 @@ class MockGLESImpl : public IMockGLESImpl {
7071
(GLsizei size, const GLuint* queries),
7172
(override));
7273
MOCK_METHOD(void, GenBuffers, (GLsizei n, GLuint* buffers), (override));
74+
MOCK_METHOD(GLboolean, IsTexture, (GLuint texture), (override));
7375
};
7476

7577
/// @brief Provides a mocked version of the |ProcTableGLES| class.

engine/src/flutter/impeller/renderer/backend/gles/test/reactor_unittests.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace impeller {
1717
namespace testing {
1818

1919
using ::testing::_;
20+
using ::testing::NiceMock;
2021

2122
class TestWorker : public ReactorGLES::Worker {
2223
public:
@@ -96,13 +97,14 @@ TEST(ReactorGLES, UntrackedHandle) {
9697
}
9798

9899
TEST(ReactorGLES, NameUntrackedHandle) {
99-
auto mock_gles_impl = std::make_unique<MockGLESImpl>();
100+
auto mock_gles_impl = std::make_unique<NiceMock<MockGLESImpl>>();
100101

101102
EXPECT_CALL(*mock_gles_impl, GenTextures(1, _))
102103
.WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
103104
EXPECT_CALL(*mock_gles_impl,
104105
ObjectLabelKHR(_, 1234, _, ::testing::StrEq("hello, joe!")))
105106
.Times(1);
107+
ON_CALL(*mock_gles_impl, IsTexture).WillByDefault(::testing::Return(GL_TRUE));
106108

107109
std::shared_ptr<MockGLES> mock_gles =
108110
MockGLES::Init(std::move(mock_gles_impl));

0 commit comments

Comments
 (0)