1 //
2 // Copyright 2014 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
7 #include "gmock/gmock.h"
8 #include "gtest/gtest.h"
9
10 #include "libANGLE/AttributeMap.h"
11 #include "libANGLE/Config.h"
12 #include "libANGLE/State.h"
13 #include "libANGLE/Surface.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/FramebufferImpl_mock.h"
16 #include "libANGLE/renderer/SurfaceImpl.h"
17 #include "tests/angle_unittests_utils.h"
18
19 using namespace rx;
20 using namespace testing;
21
22 namespace
23 {
24
25 class MockSurfaceImpl : public rx::SurfaceImpl
26 {
27 public:
MockSurfaceImpl()28 MockSurfaceImpl() : SurfaceImpl(mockState), mockState({1}, nullptr, egl::AttributeMap()) {}
~MockSurfaceImpl()29 virtual ~MockSurfaceImpl() { destructor(); }
30
31 MOCK_METHOD1(destroy, void(const egl::Display *));
32 MOCK_METHOD1(initialize, egl::Error(const egl::Display *));
33 MOCK_METHOD2(swap, egl::Error(const gl::Context *, SurfaceSwapFeedback *));
34 MOCK_METHOD4(swapWithDamage,
35 egl::Error(const gl::Context *, const EGLint *, EGLint, SurfaceSwapFeedback *));
36 MOCK_METHOD5(postSubBuffer, egl::Error(const gl::Context *, EGLint, EGLint, EGLint, EGLint));
37 MOCK_METHOD2(querySurfacePointerANGLE, egl::Error(EGLint, void **));
38 MOCK_METHOD3(bindTexImage, egl::Error(const gl::Context *context, gl::Texture *, EGLint));
39 MOCK_METHOD2(releaseTexImage, egl::Error(const gl::Context *context, EGLint));
40 MOCK_METHOD3(getSyncValues, egl::Error(EGLuint64KHR *, EGLuint64KHR *, EGLuint64KHR *));
41 MOCK_METHOD2(getMscRate, egl::Error(EGLint *, EGLint *));
42 MOCK_METHOD2(setSwapInterval, void(const egl::Display *, EGLint));
43 MOCK_CONST_METHOD0(getWidth, EGLint());
44 MOCK_CONST_METHOD0(getHeight, EGLint());
45 MOCK_CONST_METHOD0(isPostSubBufferSupported, EGLint(void));
46 MOCK_CONST_METHOD0(getSwapBehavior, EGLint(void));
47 MOCK_METHOD5(getAttachmentRenderTarget,
48 angle::Result(const gl::Context *,
49 GLenum,
50 const gl::ImageIndex &,
51 GLsizei,
52 rx::FramebufferAttachmentRenderTarget **));
53 MOCK_METHOD2(attachToFramebuffer, egl::Error(const gl::Context *, gl::Framebuffer *));
54 MOCK_METHOD2(detachFromFramebuffer, egl::Error(const gl::Context *, gl::Framebuffer *));
55 MOCK_METHOD0(destructor, void());
56
57 egl::SurfaceState mockState;
58 };
59
TEST(SurfaceTest,DestructionDeletesImpl)60 TEST(SurfaceTest, DestructionDeletesImpl)
61 {
62 NiceMock<MockEGLFactory> factory;
63
64 MockSurfaceImpl *impl = new MockSurfaceImpl;
65 EXPECT_CALL(factory, createWindowSurface(_, _, _)).WillOnce(Return(impl));
66
67 egl::Config config;
68 egl::Surface *surface = new egl::WindowSurface(
69 &factory, {1}, &config, static_cast<EGLNativeWindowType>(0), egl::AttributeMap(), false);
70
71 EXPECT_CALL(*impl, destroy(_)).Times(1).RetiresOnSaturation();
72 EXPECT_CALL(*impl, destructor()).Times(1).RetiresOnSaturation();
73
74 EXPECT_FALSE(surface->onDestroy(nullptr).isError());
75
76 // Only needed because the mock is leaked if bugs are present,
77 // which logs an error, but does not cause the test to fail.
78 // Ordinarily mocks are verified when destroyed.
79 Mock::VerifyAndClear(impl);
80 }
81
82 } // namespace
83