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/gpu_service_test.h"
11 #include "gpu/command_buffer/service/test_helper.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h"
15 using ::testing::Pointee
;
21 class VertexArrayManagerTest
: public GpuServiceTest
{
23 static const uint32 kNumVertexAttribs
= 8;
25 VertexArrayManagerTest() {
28 ~VertexArrayManagerTest() override
{}
31 void SetUp() override
{
32 GpuServiceTest::SetUpWithGLVersion("2.1", "GL_ARB_vertex_array_object");
33 manager_
.reset(new VertexArrayManager());
36 void TearDown() override
{
38 GpuServiceTest::TearDown();
41 scoped_ptr
<VertexArrayManager
> manager_
;
44 // GCC requires these declarations, but MSVC requires they not be present
46 const uint32
VertexArrayManagerTest::kNumVertexAttribs
;
49 TEST_F(VertexArrayManagerTest
, Basic
) {
50 const GLuint kClient1Id
= 1;
51 const GLuint kService1Id
= 11;
52 const GLuint kClient2Id
= 2;
54 // Check we can create
55 manager_
->CreateVertexAttribManager(
56 kClient1Id
, kService1Id
, kNumVertexAttribs
, true);
57 // Check creation success
58 VertexAttribManager
* info1
= manager_
->GetVertexAttribManager(kClient1Id
);
59 ASSERT_TRUE(info1
!= NULL
);
60 EXPECT_EQ(kService1Id
, info1
->service_id());
62 EXPECT_TRUE(manager_
->GetClientId(info1
->service_id(), &client_id
));
63 EXPECT_EQ(kClient1Id
, client_id
);
64 // Check we get nothing for a non-existent name.
65 EXPECT_TRUE(manager_
->GetVertexAttribManager(kClient2Id
) == NULL
);
66 // Check trying to a remove non-existent name does not crash.
67 manager_
->RemoveVertexAttribManager(kClient2Id
);
68 // Check that it gets deleted when the last reference is released.
69 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id
)))
71 .RetiresOnSaturation();
72 // Check we can't get the texture after we remove it.
73 manager_
->RemoveVertexAttribManager(kClient1Id
);
74 EXPECT_TRUE(manager_
->GetVertexAttribManager(kClient1Id
) == NULL
);
77 TEST_F(VertexArrayManagerTest
, Destroy
) {
78 const GLuint kClient1Id
= 1;
79 const GLuint kService1Id
= 11;
80 VertexArrayManager manager
;
81 // Check we can create
82 manager
.CreateVertexAttribManager(
83 kClient1Id
, kService1Id
, kNumVertexAttribs
, true);
84 // Check creation success
85 VertexAttribManager
* info1
= manager
.GetVertexAttribManager(kClient1Id
);
86 ASSERT_TRUE(info1
!= NULL
);
87 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id
)))
89 .RetiresOnSaturation();
90 manager
.Destroy(true);
91 // Check that resources got freed.
92 info1
= manager
.GetVertexAttribManager(kClient1Id
);
93 ASSERT_TRUE(info1
== NULL
);