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