[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.
This commit is contained in:
Jason Simmons 2025-01-23 11:00:01 -08:00 committed by GitHub
parent 3850ba32e0
commit 3fd4d0a61c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View File

@ -39,13 +39,23 @@ auto const kExtensions = std::vector<const char*>{
}; };
namespace { namespace {
template <typename T>
struct function_traits;
template <typename C, typename Ret, typename... Args>
struct function_traits<Ret (C::*)(Args...)> {
using return_type = Ret;
};
template <typename Func, typename... Args> template <typename Func, typename... Args>
void CallMockMethod(Func func, Args&&... args) { auto CallMockMethod(Func func, Args&&... args) {
if (auto mock_gles = g_mock_gles.lock()) { if (auto mock_gles = g_mock_gles.lock()) {
if (mock_gles->GetImpl()) { if (mock_gles->GetImpl()) {
(mock_gles->GetImpl()->*func)(std::forward<Args>(args)...); return (mock_gles->GetImpl()->*func)(std::forward<Args>(args)...);
} }
} }
return typename function_traits<Func>::return_type();
} }
} // namespace } // namespace
@ -194,6 +204,13 @@ void mockObjectLabelKHR(GLenum identifier,
static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), // static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), //
decltype(glObjectLabelKHR)>::value); decltype(glObjectLabelKHR)>::value);
GLboolean mockIsTexture(GLuint texture) {
return CallMockMethod(&IMockGLESImpl::IsTexture, texture);
}
static_assert(CheckSameSignature<decltype(mockGenTextures), //
decltype(glGenTextures)>::value);
// static // static
std::shared_ptr<MockGLES> MockGLES::Init( std::shared_ptr<MockGLES> MockGLES::Init(
std::unique_ptr<MockGLESImpl> impl, std::unique_ptr<MockGLESImpl> impl,
@ -257,6 +274,8 @@ const ProcTableGLES::Resolver kMockResolverGLES = [](const char* name) {
return reinterpret_cast<void*>(mockObjectLabelKHR); return reinterpret_cast<void*>(mockObjectLabelKHR);
} else if (strcmp(name, "glGenBuffers") == 0) { } else if (strcmp(name, "glGenBuffers") == 0) {
return reinterpret_cast<void*>(mockGenBuffers); return reinterpret_cast<void*>(mockGenBuffers);
} else if (strcmp(name, "glIsTexture") == 0) {
return reinterpret_cast<void*>(mockIsTexture);
} else { } else {
return reinterpret_cast<void*>(&doNothing); return reinterpret_cast<void*>(&doNothing);
} }

View File

@ -36,6 +36,7 @@ class IMockGLESImpl {
GLuint64* result) {} GLuint64* result) {}
virtual void DeleteQueriesEXT(GLsizei size, const GLuint* queries) {} virtual void DeleteQueriesEXT(GLsizei size, const GLuint* queries) {}
virtual void GenBuffers(GLsizei n, GLuint* buffers) {} virtual void GenBuffers(GLsizei n, GLuint* buffers) {}
virtual GLboolean IsTexture(GLuint texture) { return true; }
}; };
class MockGLESImpl : public IMockGLESImpl { class MockGLESImpl : public IMockGLESImpl {
@ -70,6 +71,7 @@ class MockGLESImpl : public IMockGLESImpl {
(GLsizei size, const GLuint* queries), (GLsizei size, const GLuint* queries),
(override)); (override));
MOCK_METHOD(void, GenBuffers, (GLsizei n, GLuint* buffers), (override)); MOCK_METHOD(void, GenBuffers, (GLsizei n, GLuint* buffers), (override));
MOCK_METHOD(GLboolean, IsTexture, (GLuint texture), (override));
}; };
/// @brief Provides a mocked version of the |ProcTableGLES| class. /// @brief Provides a mocked version of the |ProcTableGLES| class.

View File

@ -17,6 +17,7 @@ namespace impeller {
namespace testing { namespace testing {
using ::testing::_; using ::testing::_;
using ::testing::NiceMock;
class TestWorker : public ReactorGLES::Worker { class TestWorker : public ReactorGLES::Worker {
public: public:
@ -96,13 +97,14 @@ TEST(ReactorGLES, UntrackedHandle) {
} }
TEST(ReactorGLES, NameUntrackedHandle) { TEST(ReactorGLES, NameUntrackedHandle) {
auto mock_gles_impl = std::make_unique<MockGLESImpl>(); auto mock_gles_impl = std::make_unique<NiceMock<MockGLESImpl>>();
EXPECT_CALL(*mock_gles_impl, GenTextures(1, _)) EXPECT_CALL(*mock_gles_impl, GenTextures(1, _))
.WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; }); .WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
EXPECT_CALL(*mock_gles_impl, EXPECT_CALL(*mock_gles_impl,
ObjectLabelKHR(_, 1234, _, ::testing::StrEq("hello, joe!"))) ObjectLabelKHR(_, 1234, _, ::testing::StrEq("hello, joe!")))
.Times(1); .Times(1);
ON_CALL(*mock_gles_impl, IsTexture).WillByDefault(::testing::Return(GL_TRUE));
std::shared_ptr<MockGLES> mock_gles = std::shared_ptr<MockGLES> mock_gles =
MockGLES::Init(std::move(mock_gles_impl)); MockGLES::Init(std::move(mock_gles_impl));