1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "gpu/command_buffer/service/vertex_array_manager.h" 6 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 7 8 #include "base/memory/scoped_ptr.h" 9 #include "gpu/command_buffer/service/feature_info.h" 10 #include "gpu/command_buffer/service/test_helper.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "ui/gl/gl_mock.h" 13 14 using ::testing::Pointee; 15 using ::testing::_; 16 17 namespace gpu { 18 namespace gles2 { 19 20 class VertexArrayManagerTest : public testing::Test { 21 public: 22 static const uint32 kNumVertexAttribs = 8; 23 24 VertexArrayManagerTest() { 25 } 26 27 virtual ~VertexArrayManagerTest() { 28 } 29 30 protected: 31 virtual void SetUp() { 32 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); 33 ::gfx::GLInterface::SetGLInterface(gl_.get()); 34 35 manager_ = new VertexArrayManager(); 36 } 37 38 virtual void TearDown() { 39 delete manager_; 40 ::gfx::GLInterface::SetGLInterface(NULL); 41 gl_.reset(); 42 } 43 44 // Use StrictMock to make 100% sure we know how GL will be called. 45 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; 46 VertexArrayManager* manager_; 47 }; 48 49 // GCC requires these declarations, but MSVC requires they not be present 50 #ifndef COMPILER_MSVC 51 const uint32 VertexArrayManagerTest::kNumVertexAttribs; 52 #endif 53 54 TEST_F(VertexArrayManagerTest, Basic) { 55 const GLuint kClient1Id = 1; 56 const GLuint kService1Id = 11; 57 const GLuint kClient2Id = 2; 58 59 // Check we can create 60 manager_->CreateVertexAttribManager( 61 kClient1Id, kService1Id, kNumVertexAttribs); 62 // Check creation success 63 VertexAttribManager* info1 = manager_->GetVertexAttribManager(kClient1Id); 64 ASSERT_TRUE(info1 != NULL); 65 EXPECT_EQ(kService1Id, info1->service_id()); 66 GLuint client_id = 0; 67 EXPECT_TRUE(manager_->GetClientId(info1->service_id(), &client_id)); 68 EXPECT_EQ(kClient1Id, client_id); 69 // Check we get nothing for a non-existent name. 70 EXPECT_TRUE(manager_->GetVertexAttribManager(kClient2Id) == NULL); 71 // Check trying to a remove non-existent name does not crash. 72 manager_->RemoveVertexAttribManager(kClient2Id); 73 // Check that it gets deleted when the last reference is released. 74 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id))) 75 .Times(1) 76 .RetiresOnSaturation(); 77 // Check we can't get the texture after we remove it. 78 manager_->RemoveVertexAttribManager(kClient1Id); 79 EXPECT_TRUE(manager_->GetVertexAttribManager(kClient1Id) == NULL); 80 } 81 82 TEST_F(VertexArrayManagerTest, Destroy) { 83 const GLuint kClient1Id = 1; 84 const GLuint kService1Id = 11; 85 VertexArrayManager manager; 86 // Check we can create 87 manager.CreateVertexAttribManager(kClient1Id, kService1Id, kNumVertexAttribs); 88 // Check creation success 89 VertexAttribManager* info1 = manager.GetVertexAttribManager(kClient1Id); 90 ASSERT_TRUE(info1 != NULL); 91 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id))) 92 .Times(1) 93 .RetiresOnSaturation(); 94 manager.Destroy(true); 95 // Check that resources got freed. 96 info1 = manager.GetVertexAttribManager(kClient1Id); 97 ASSERT_TRUE(info1 == NULL); 98 } 99 100 } // namespace gles2 101 } // namespace gpu 102 103 104