Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 1 | // |
| 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 Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 9 | #include "libANGLE/Caps.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/TransformFeedback.h" |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 11 | #include "libANGLE/renderer/BufferImpl_mock.h" |
| 12 | #include "libANGLE/renderer/TransformFeedbackImpl_mock.h" |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 13 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 14 | using ::testing::_; |
| 15 | using ::testing::Return; |
| 16 | using ::testing::SetArgumentPointee; |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 17 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 18 | namespace |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 19 | { |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 20 | |
| 21 | class TransformFeedbackTest : public testing::Test |
| 22 | { |
| 23 | protected: |
| 24 | virtual void SetUp() |
| 25 | { |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 26 | // Set a reasonable number of tf attributes |
| 27 | mCaps.maxTransformFeedbackSeparateAttributes = 8; |
| 28 | |
| 29 | mImpl = new rx::MockTransformFeedbackImpl; |
| 30 | EXPECT_CALL(*mImpl, destructor()); |
| 31 | mFeedback = new gl::TransformFeedback(mImpl, 1, mCaps); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 32 | mFeedback->addRef(); |
| 33 | } |
| 34 | |
| 35 | virtual void TearDown() |
| 36 | { |
| 37 | mFeedback->release(); |
| 38 | } |
| 39 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 40 | rx::MockTransformFeedbackImpl* mImpl; |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 41 | gl::TransformFeedback* mFeedback; |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 42 | gl::Caps mCaps; |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | TEST_F(TransformFeedbackTest, DestructionDeletesImpl) |
| 46 | { |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 47 | rx::MockTransformFeedbackImpl* impl = new rx::MockTransformFeedbackImpl; |
| 48 | EXPECT_CALL(*impl, destructor()).Times(1).RetiresOnSaturation(); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 49 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 50 | gl::TransformFeedback* feedback = new gl::TransformFeedback(impl, 1, mCaps); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 51 | feedback->addRef(); |
| 52 | feedback->release(); |
| 53 | |
| 54 | // Only needed because the mock is leaked if bugs are present, |
| 55 | // which logs an error, but does not cause the test to fail. |
| 56 | // Ordinarily mocks are verified when destroyed. |
| 57 | testing::Mock::VerifyAndClear(impl); |
| 58 | } |
| 59 | |
| 60 | TEST_F(TransformFeedbackTest, SideEffectsOfStartAndStop) |
| 61 | { |
| 62 | testing::InSequence seq; |
| 63 | |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 64 | EXPECT_FALSE(mFeedback->isActive()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 65 | EXPECT_CALL(*mImpl, begin(GL_TRIANGLES)); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 66 | mFeedback->begin(GL_TRIANGLES); |
| 67 | EXPECT_TRUE(mFeedback->isActive()); |
| 68 | EXPECT_EQ(static_cast<GLenum>(GL_TRIANGLES), mFeedback->getPrimitiveMode()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 69 | EXPECT_CALL(*mImpl, end()); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 70 | mFeedback->end(); |
| 71 | EXPECT_FALSE(mFeedback->isActive()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | TEST_F(TransformFeedbackTest, SideEffectsOfPauseAndResume) |
| 75 | { |
| 76 | testing::InSequence seq; |
| 77 | |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 78 | EXPECT_FALSE(mFeedback->isActive()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 79 | EXPECT_CALL(*mImpl, begin(GL_TRIANGLES)); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 80 | mFeedback->begin(GL_TRIANGLES); |
| 81 | EXPECT_FALSE(mFeedback->isPaused()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 82 | EXPECT_CALL(*mImpl, pause()); |
| 83 | mFeedback->pause(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 84 | EXPECT_TRUE(mFeedback->isPaused()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 85 | EXPECT_CALL(*mImpl, resume()); |
| 86 | mFeedback->resume(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 87 | EXPECT_FALSE(mFeedback->isPaused()); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 88 | EXPECT_CALL(*mImpl, end()); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 89 | mFeedback->end(); |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 92 | TEST_F(TransformFeedbackTest, BufferBinding) |
| 93 | { |
| 94 | rx::MockBufferImpl *bufferImpl = new rx::MockBufferImpl; |
| 95 | gl::Buffer *buffer = new gl::Buffer(bufferImpl, 1); |
| 96 | EXPECT_CALL(*bufferImpl, destructor()).Times(1).RetiresOnSaturation(); |
| 97 | |
| 98 | static const size_t bindIndex = 0; |
| 99 | |
| 100 | rx::MockTransformFeedbackImpl *feedbackImpl = new rx::MockTransformFeedbackImpl; |
Geoff Lang | 48d33ae | 2015-04-27 11:01:44 -0400 | [diff] [blame] | 101 | EXPECT_CALL(*feedbackImpl, destructor()).Times(1).RetiresOnSaturation(); |
| 102 | |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 103 | gl::TransformFeedback *feedback = new gl::TransformFeedback(feedbackImpl, 1, mCaps); |
| 104 | |
| 105 | EXPECT_EQ(feedback->getIndexedBufferCount(), mCaps.maxTransformFeedbackSeparateAttributes); |
| 106 | |
| 107 | EXPECT_CALL(*feedbackImpl, bindGenericBuffer(_)); |
| 108 | feedback->bindGenericBuffer(buffer); |
| 109 | EXPECT_EQ(feedback->getGenericBuffer().get(), buffer); |
| 110 | |
| 111 | EXPECT_CALL(*feedbackImpl, bindIndexedBuffer(_, _)); |
| 112 | feedback->bindIndexedBuffer(bindIndex, buffer, 0, 1); |
| 113 | for (size_t i = 0; i < feedback->getIndexedBufferCount(); i++) |
| 114 | { |
| 115 | if (i == bindIndex) |
| 116 | { |
| 117 | EXPECT_EQ(feedback->getIndexedBuffer(i).get(), buffer); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | EXPECT_EQ(feedback->getIndexedBuffer(i).get(), nullptr); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | feedback->addRef(); |
| 126 | feedback->release(); |
| 127 | |
| 128 | testing::Mock::VerifyAndClear(bufferImpl); |
| 129 | } |
| 130 | |
Kenneth Russell | db8ae16 | 2014-08-25 19:02:35 -0700 | [diff] [blame] | 131 | } // namespace |