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.
5 #include "gpu/command_buffer/service/vertex_array_manager.h"
6 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
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"
14 using ::testing::Pointee;
20 class VertexArrayManagerTest : public testing::Test {
22 static const uint32 kNumVertexAttribs = 8;
24 VertexArrayManagerTest() {
27 virtual ~VertexArrayManagerTest() {
31 virtual void SetUp() {
32 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
33 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
35 manager_ = new VertexArrayManager();
38 virtual void TearDown() {
40 ::gfx::MockGLInterface::SetGLInterface(NULL);
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_;
49 // GCC requires these declarations, but MSVC requires they not be present
51 const uint32 VertexArrayManagerTest::kNumVertexAttribs;
54 TEST_F(VertexArrayManagerTest, Basic) {
55 const GLuint kClient1Id = 1;
56 const GLuint kService1Id = 11;
57 const GLuint kClient2Id = 2;
59 // Check we can create
60 manager_->CreateVertexAttribManager(
61 kClient1Id, kService1Id, kNumVertexAttribs, true);
62 // Check creation success
63 VertexAttribManager* info1 = manager_->GetVertexAttribManager(kClient1Id);
64 ASSERT_TRUE(info1 != NULL);
65 EXPECT_EQ(kService1Id, info1->service_id());
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)))
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);
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(
88 kClient1Id, kService1Id, kNumVertexAttribs, true);
89 // Check creation success
90 VertexAttribManager* info1 = manager.GetVertexAttribManager(kClient1Id);
91 ASSERT_TRUE(info1 != NULL);
92 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id)))
94 .RetiresOnSaturation();
95 manager.Destroy(true);
96 // Check that resources got freed.
97 info1 = manager.GetVertexAttribManager(kClient1Id);
98 ASSERT_TRUE(info1 == NULL);