blob: 4aafd3d0985998d2843cc9ec3be8e3b2a1d3f2d4 [file] [log] [blame]
Kenneth Russelldb8ae162014-08-25 19:02:35 -07001//
2// Copyright (c) 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"
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/TransformFeedback.h"
10#include "libANGLE/renderer/TransformFeedbackImpl.h"
Kenneth Russelldb8ae162014-08-25 19:02:35 -070011
12namespace {
13
14class MockTransformFeedbackImpl : public rx::TransformFeedbackImpl
15{
16 public:
17 virtual ~MockTransformFeedbackImpl() { destroy(); }
18
19 MOCK_METHOD1(begin, void(GLenum primitiveMode));
20 MOCK_METHOD0(end, void());
21 MOCK_METHOD0(pause, void());
22 MOCK_METHOD0(resume, void());
23
24 MOCK_METHOD0(destroy, void());
25};
26
27class TransformFeedbackTest : public testing::Test
28{
29 protected:
30 virtual void SetUp()
31 {
32 mImpl = new MockTransformFeedbackImpl;
33 EXPECT_CALL(*mImpl, destroy());
34 mFeedback = new gl::TransformFeedback(mImpl, 1);
35 mFeedback->addRef();
36 }
37
38 virtual void TearDown()
39 {
40 mFeedback->release();
41 }
42
43 MockTransformFeedbackImpl* mImpl;
44 gl::TransformFeedback* mFeedback;
45};
46
47TEST_F(TransformFeedbackTest, DestructionDeletesImpl)
48{
49 MockTransformFeedbackImpl* impl = new MockTransformFeedbackImpl;
50 EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
51
52 gl::TransformFeedback* feedback = new gl::TransformFeedback(impl, 1);
53 feedback->addRef();
54 feedback->release();
55
56 // Only needed because the mock is leaked if bugs are present,
57 // which logs an error, but does not cause the test to fail.
58 // Ordinarily mocks are verified when destroyed.
59 testing::Mock::VerifyAndClear(impl);
60}
61
62TEST_F(TransformFeedbackTest, SideEffectsOfStartAndStop)
63{
64 testing::InSequence seq;
65
66 EXPECT_EQ(GL_FALSE, mFeedback->isStarted());
67 EXPECT_CALL(*mImpl, begin(GL_TRIANGLES));
68 mFeedback->start(GL_TRIANGLES);
69 EXPECT_EQ(GL_TRUE, mFeedback->isStarted());
Kenneth Russelle0a2d1c2014-10-06 17:45:59 -070070 EXPECT_EQ(static_cast<GLenum>(GL_TRIANGLES), mFeedback->getDrawMode());
Kenneth Russelldb8ae162014-08-25 19:02:35 -070071 EXPECT_CALL(*mImpl, end());
72 mFeedback->stop();
73 EXPECT_EQ(GL_FALSE, mFeedback->isStarted());
74}
75
76TEST_F(TransformFeedbackTest, SideEffectsOfPauseAndResume)
77{
78 testing::InSequence seq;
79
80 EXPECT_FALSE(mFeedback->isStarted());
81 EXPECT_CALL(*mImpl, begin(GL_TRIANGLES));
82 mFeedback->start(GL_TRIANGLES);
83 EXPECT_EQ(GL_FALSE, mFeedback->isPaused());
84 EXPECT_CALL(*mImpl, pause());
85 mFeedback->pause();
86 EXPECT_EQ(GL_TRUE, mFeedback->isPaused());
87 EXPECT_CALL(*mImpl, resume());
88 mFeedback->resume();
89 EXPECT_EQ(GL_FALSE, mFeedback->isPaused());
90 EXPECT_CALL(*mImpl, end());
91 mFeedback->stop();
92}
93
94} // namespace