xref: /aosp_15_r20/external/angle/src/tests/angle_unittests_utils.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // angle_unittests_utils.h:
7*8975f5c5SAndroid Build Coastguard Worker //   Helpers for mocking and unit testing.
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #ifndef TESTS_ANGLE_UNITTESTS_UTILS_H_
10*8975f5c5SAndroid Build Coastguard Worker #define TESTS_ANGLE_UNITTESTS_UTILS_H_
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Surface.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/ContextImpl.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/EGLImplFactory.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/GLImplFactory.h"
16*8975f5c5SAndroid Build Coastguard Worker 
17*8975f5c5SAndroid Build Coastguard Worker namespace rx
18*8975f5c5SAndroid Build Coastguard Worker {
19*8975f5c5SAndroid Build Coastguard Worker 
20*8975f5c5SAndroid Build Coastguard Worker // Useful when mocking a part of the GLImplFactory class
21*8975f5c5SAndroid Build Coastguard Worker class NullFactory : public GLImplFactory
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker   public:
NullFactory()24*8975f5c5SAndroid Build Coastguard Worker     NullFactory() {}
25*8975f5c5SAndroid Build Coastguard Worker 
26*8975f5c5SAndroid Build Coastguard Worker     // Shader creation
createCompiler()27*8975f5c5SAndroid Build Coastguard Worker     CompilerImpl *createCompiler() override { return nullptr; }
createShader(const gl::ShaderState & data)28*8975f5c5SAndroid Build Coastguard Worker     ShaderImpl *createShader(const gl::ShaderState &data) override { return nullptr; }
createProgram(const gl::ProgramState & data)29*8975f5c5SAndroid Build Coastguard Worker     ProgramImpl *createProgram(const gl::ProgramState &data) override { return nullptr; }
createProgramExecutable(const gl::ProgramExecutable * executable)30*8975f5c5SAndroid Build Coastguard Worker     ProgramExecutableImpl *createProgramExecutable(const gl::ProgramExecutable *executable) override
31*8975f5c5SAndroid Build Coastguard Worker     {
32*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
33*8975f5c5SAndroid Build Coastguard Worker     }
34*8975f5c5SAndroid Build Coastguard Worker 
35*8975f5c5SAndroid Build Coastguard Worker     // Framebuffer creation
createFramebuffer(const gl::FramebufferState & data)36*8975f5c5SAndroid Build Coastguard Worker     FramebufferImpl *createFramebuffer(const gl::FramebufferState &data) override
37*8975f5c5SAndroid Build Coastguard Worker     {
38*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
39*8975f5c5SAndroid Build Coastguard Worker     }
40*8975f5c5SAndroid Build Coastguard Worker 
41*8975f5c5SAndroid Build Coastguard Worker     // Texture creation
createTexture(const gl::TextureState & data)42*8975f5c5SAndroid Build Coastguard Worker     TextureImpl *createTexture(const gl::TextureState &data) override { return nullptr; }
43*8975f5c5SAndroid Build Coastguard Worker 
44*8975f5c5SAndroid Build Coastguard Worker     // Renderbuffer creation
createRenderbuffer(const gl::RenderbufferState & state)45*8975f5c5SAndroid Build Coastguard Worker     RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override
46*8975f5c5SAndroid Build Coastguard Worker     {
47*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
48*8975f5c5SAndroid Build Coastguard Worker     }
49*8975f5c5SAndroid Build Coastguard Worker 
50*8975f5c5SAndroid Build Coastguard Worker     // Buffer creation
createBuffer(const gl::BufferState & state)51*8975f5c5SAndroid Build Coastguard Worker     BufferImpl *createBuffer(const gl::BufferState &state) override { return nullptr; }
52*8975f5c5SAndroid Build Coastguard Worker 
53*8975f5c5SAndroid Build Coastguard Worker     // Vertex Array creation
createVertexArray(const gl::VertexArrayState & data)54*8975f5c5SAndroid Build Coastguard Worker     VertexArrayImpl *createVertexArray(const gl::VertexArrayState &data) override
55*8975f5c5SAndroid Build Coastguard Worker     {
56*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
57*8975f5c5SAndroid Build Coastguard Worker     }
58*8975f5c5SAndroid Build Coastguard Worker 
59*8975f5c5SAndroid Build Coastguard Worker     // Query and Fence creation
createQuery(gl::QueryType type)60*8975f5c5SAndroid Build Coastguard Worker     QueryImpl *createQuery(gl::QueryType type) override { return nullptr; }
createFenceNV()61*8975f5c5SAndroid Build Coastguard Worker     FenceNVImpl *createFenceNV() override { return nullptr; }
createSync()62*8975f5c5SAndroid Build Coastguard Worker     SyncImpl *createSync() override { return nullptr; }
63*8975f5c5SAndroid Build Coastguard Worker 
64*8975f5c5SAndroid Build Coastguard Worker     // Transform Feedback creation
createTransformFeedback(const gl::TransformFeedbackState & state)65*8975f5c5SAndroid Build Coastguard Worker     TransformFeedbackImpl *createTransformFeedback(const gl::TransformFeedbackState &state) override
66*8975f5c5SAndroid Build Coastguard Worker     {
67*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
68*8975f5c5SAndroid Build Coastguard Worker     }
69*8975f5c5SAndroid Build Coastguard Worker 
70*8975f5c5SAndroid Build Coastguard Worker     // Sampler object creation
createSampler(const gl::SamplerState & state)71*8975f5c5SAndroid Build Coastguard Worker     SamplerImpl *createSampler(const gl::SamplerState &state) override { return nullptr; }
72*8975f5c5SAndroid Build Coastguard Worker 
73*8975f5c5SAndroid Build Coastguard Worker     // Program Pipeline creation
createProgramPipeline(const gl::ProgramPipelineState & data)74*8975f5c5SAndroid Build Coastguard Worker     ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override
75*8975f5c5SAndroid Build Coastguard Worker     {
76*8975f5c5SAndroid Build Coastguard Worker         return nullptr;
77*8975f5c5SAndroid Build Coastguard Worker     }
78*8975f5c5SAndroid Build Coastguard Worker 
createSemaphore()79*8975f5c5SAndroid Build Coastguard Worker     SemaphoreImpl *createSemaphore() override { return nullptr; }
80*8975f5c5SAndroid Build Coastguard Worker 
createOverlay(const gl::OverlayState & state)81*8975f5c5SAndroid Build Coastguard Worker     OverlayImpl *createOverlay(const gl::OverlayState &state) override { return nullptr; }
82*8975f5c5SAndroid Build Coastguard Worker };
83*8975f5c5SAndroid Build Coastguard Worker 
84*8975f5c5SAndroid Build Coastguard Worker // A class with all the factory methods mocked.
85*8975f5c5SAndroid Build Coastguard Worker class MockGLFactory : public GLImplFactory
86*8975f5c5SAndroid Build Coastguard Worker {
87*8975f5c5SAndroid Build Coastguard Worker   public:
88*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createContext, ContextImpl *(const gl::State &));
89*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD0(createCompiler, CompilerImpl *());
90*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createShader, ShaderImpl *(const gl::ShaderState &));
91*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createProgram, ProgramImpl *(const gl::ProgramState &));
92*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createProgramExecutable, ProgramExecutableImpl *(const gl::ProgramExecutable *));
93*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createProgramPipeline, ProgramPipelineImpl *(const gl::ProgramPipelineState &));
94*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createFramebuffer, FramebufferImpl *(const gl::FramebufferState &));
95*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD0(createMemoryObject, MemoryObjectImpl *());
96*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createTexture, TextureImpl *(const gl::TextureState &));
97*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createRenderbuffer, RenderbufferImpl *(const gl::RenderbufferState &));
98*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createBuffer, BufferImpl *(const gl::BufferState &));
99*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createVertexArray, VertexArrayImpl *(const gl::VertexArrayState &));
100*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createQuery, QueryImpl *(gl::QueryType type));
101*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD0(createFenceNV, FenceNVImpl *());
102*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD0(createSync, SyncImpl *());
103*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createTransformFeedback,
104*8975f5c5SAndroid Build Coastguard Worker                  TransformFeedbackImpl *(const gl::TransformFeedbackState &));
105*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createSampler, SamplerImpl *(const gl::SamplerState &));
106*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD0(createSemaphore, SemaphoreImpl *());
107*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createOverlay, OverlayImpl *(const gl::OverlayState &));
108*8975f5c5SAndroid Build Coastguard Worker };
109*8975f5c5SAndroid Build Coastguard Worker 
110*8975f5c5SAndroid Build Coastguard Worker class MockEGLFactory : public EGLImplFactory
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker   public:
113*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD3(createWindowSurface,
114*8975f5c5SAndroid Build Coastguard Worker                  SurfaceImpl *(const egl::SurfaceState &,
115*8975f5c5SAndroid Build Coastguard Worker                                EGLNativeWindowType,
116*8975f5c5SAndroid Build Coastguard Worker                                const egl::AttributeMap &));
117*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD2(createPbufferSurface,
118*8975f5c5SAndroid Build Coastguard Worker                  SurfaceImpl *(const egl::SurfaceState &, const egl::AttributeMap &));
119*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD4(createPbufferFromClientBuffer,
120*8975f5c5SAndroid Build Coastguard Worker                  SurfaceImpl *(const egl::SurfaceState &,
121*8975f5c5SAndroid Build Coastguard Worker                                EGLenum,
122*8975f5c5SAndroid Build Coastguard Worker                                EGLClientBuffer,
123*8975f5c5SAndroid Build Coastguard Worker                                const egl::AttributeMap &));
124*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD3(createPixmapSurface,
125*8975f5c5SAndroid Build Coastguard Worker                  SurfaceImpl *(const egl::SurfaceState &,
126*8975f5c5SAndroid Build Coastguard Worker                                NativePixmapType,
127*8975f5c5SAndroid Build Coastguard Worker                                const egl::AttributeMap &));
128*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD4(createImage,
129*8975f5c5SAndroid Build Coastguard Worker                  ImageImpl *(const egl::ImageState &,
130*8975f5c5SAndroid Build Coastguard Worker                              const gl::Context *,
131*8975f5c5SAndroid Build Coastguard Worker                              EGLenum,
132*8975f5c5SAndroid Build Coastguard Worker                              const egl::AttributeMap &));
133*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD5(createContext,
134*8975f5c5SAndroid Build Coastguard Worker                  ContextImpl *(const gl::State &,
135*8975f5c5SAndroid Build Coastguard Worker                                gl::ErrorSet *,
136*8975f5c5SAndroid Build Coastguard Worker                                const egl::Config *,
137*8975f5c5SAndroid Build Coastguard Worker                                const gl::Context *,
138*8975f5c5SAndroid Build Coastguard Worker                                const egl::AttributeMap &));
139*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD2(createStreamProducerD3DTexture,
140*8975f5c5SAndroid Build Coastguard Worker                  StreamProducerImpl *(egl::Stream::ConsumerType, const egl::AttributeMap &));
141*8975f5c5SAndroid Build Coastguard Worker     MOCK_METHOD1(createShareGroup, ShareGroupImpl *(const egl::ShareGroupState &));
142*8975f5c5SAndroid Build Coastguard Worker };
143*8975f5c5SAndroid Build Coastguard Worker 
144*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
145*8975f5c5SAndroid Build Coastguard Worker 
146*8975f5c5SAndroid Build Coastguard Worker #endif  // TESTS_ANGLE_UNITTESTS_UTILS_H_
147