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(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(createDefaultFramebuffer,
34 rx::FramebufferImpl *(const gl::Context *, const gl::FramebufferState &data));
35 MOCK_METHOD1(swap, egl::Error(const gl::Context *));
36 MOCK_METHOD3(swapWithDamage, egl::Error(const gl::Context *, const EGLint *, EGLint));
37 MOCK_METHOD5(postSubBuffer, egl::Error(const gl::Context *, EGLint, EGLint, EGLint, EGLint));
38 MOCK_METHOD2(querySurfacePointerANGLE, egl::Error(EGLint, void **));
39 MOCK_METHOD3(bindTexImage, egl::Error(const gl::Context *context, gl::Texture *, EGLint));
40 MOCK_METHOD2(releaseTexImage, egl::Error(const gl::Context *context, EGLint));
41 MOCK_METHOD3(getSyncValues, egl::Error(EGLuint64KHR *, EGLuint64KHR *, EGLuint64KHR *));
42 MOCK_METHOD2(getMscRate, egl::Error(EGLint *, EGLint *));
43 MOCK_METHOD1(setSwapInterval, void(EGLint));
44 MOCK_CONST_METHOD0(getWidth, EGLint());
45 MOCK_CONST_METHOD0(getHeight, EGLint());
46 MOCK_CONST_METHOD0(isPostSubBufferSupported, EGLint(void));
47 MOCK_CONST_METHOD0(getSwapBehavior, EGLint(void));
48 MOCK_METHOD5(getAttachmentRenderTarget,
49 angle::Result(const gl::Context *,
50 GLenum,
51 const gl::ImageIndex &,
52 GLsizei,
53 rx::FramebufferAttachmentRenderTarget **));
54
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, &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