Edit

kc3-lang/angle/tests/angle_implementation_unit_tests/TransformFeedback_unittest.cpp

Branch :

  • Show log

    Commit

  • Author : Kenneth Russell
    Date : 2014-08-25 19:02:35
    Hash : db8ae16b
    Message : Refactored TransformFeedback for multi-platform ANGLE and added tests. Added angle_implementation_unit_tests target designed for testing the cross-platform code in libGLESv2, and libGLESv2_static target as a dependency. The goal is to incorporate these tests into Chromium's angle_unittests target on all platforms; however, more work is needed to make libGLESv2's common code compile on non-Windows platforms, so this is an intermediate step. BUG=angle:719 Change-Id: Ifc44a779352294e857d6e913d9b997a60674c443 Reviewed-on: https://chromium-review.googlesource.com/214105 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Kenneth Russell <kbr@chromium.org>

  • tests/angle_implementation_unit_tests/TransformFeedback_unittest.cpp
  • //
    // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "gmock/gmock.h"
    #include "gtest/gtest.h"
    #include "libGLESv2/TransformFeedback.h"
    #include "libGLESv2/renderer/TransformFeedbackImpl.h"
    
    namespace {
    
    class MockTransformFeedbackImpl : public rx::TransformFeedbackImpl
    {
      public:
        virtual ~MockTransformFeedbackImpl() { destroy(); }
    
        MOCK_METHOD1(begin, void(GLenum primitiveMode));
        MOCK_METHOD0(end, void());
        MOCK_METHOD0(pause, void());
        MOCK_METHOD0(resume, void());
    
        MOCK_METHOD0(destroy, void());
    };
    
    class TransformFeedbackTest : public testing::Test
    {
      protected:
        virtual void SetUp()
        {
            mImpl = new MockTransformFeedbackImpl;
            EXPECT_CALL(*mImpl, destroy());
            mFeedback = new gl::TransformFeedback(mImpl, 1);
            mFeedback->addRef();
        }
    
        virtual void TearDown()
        {
            mFeedback->release();
        }
    
        MockTransformFeedbackImpl* mImpl;
        gl::TransformFeedback* mFeedback;
    };
    
    TEST_F(TransformFeedbackTest, DestructionDeletesImpl)
    {
        MockTransformFeedbackImpl* impl = new MockTransformFeedbackImpl;
        EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
    
        gl::TransformFeedback* feedback = new gl::TransformFeedback(impl, 1);
        feedback->addRef();
        feedback->release();
    
        // Only needed because the mock is leaked if bugs are present,
        // which logs an error, but does not cause the test to fail.
        // Ordinarily mocks are verified when destroyed.
        testing::Mock::VerifyAndClear(impl);
    }
    
    TEST_F(TransformFeedbackTest, SideEffectsOfStartAndStop)
    {
        testing::InSequence seq;
    
        EXPECT_EQ(GL_FALSE, mFeedback->isStarted());
        EXPECT_CALL(*mImpl, begin(GL_TRIANGLES));
        mFeedback->start(GL_TRIANGLES);
        EXPECT_EQ(GL_TRUE, mFeedback->isStarted());
        EXPECT_EQ(GL_TRIANGLES, mFeedback->getDrawMode());
        EXPECT_CALL(*mImpl, end());
        mFeedback->stop();
        EXPECT_EQ(GL_FALSE, mFeedback->isStarted());
    }
    
    TEST_F(TransformFeedbackTest, SideEffectsOfPauseAndResume)
    {
        testing::InSequence seq;
    
        EXPECT_FALSE(mFeedback->isStarted());
        EXPECT_CALL(*mImpl, begin(GL_TRIANGLES));
        mFeedback->start(GL_TRIANGLES);
        EXPECT_EQ(GL_FALSE, mFeedback->isPaused());
        EXPECT_CALL(*mImpl, pause());
        mFeedback->pause();
        EXPECT_EQ(GL_TRUE, mFeedback->isPaused());
        EXPECT_CALL(*mImpl, resume());
        mFeedback->resume();
        EXPECT_EQ(GL_FALSE, mFeedback->isPaused());
        EXPECT_CALL(*mImpl, end());
        mFeedback->stop();
    }
    
    } // namespace