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 virtual ~VertexArrayManagerTest() {
32 virtual void SetUp() {
33 GpuServiceTest::SetUp();
34 manager_
.reset(new VertexArrayManager());
37 virtual void TearDown() {
39 GpuServiceTest::TearDown();
42 scoped_ptr
<VertexArrayManager
> manager_
;
45 // GCC requires these declarations, but MSVC requires they not be present
47 const uint32
VertexArrayManagerTest::kNumVertexAttribs
;
50 TEST_F(VertexArrayManagerTest
, Basic
) {
51 const GLuint kClient1Id
= 1;
52 const GLuint kService1Id
= 11;
53 const GLuint kClient2Id
= 2;
55 // Check we can create
56 manager_
->CreateVertexAttribManager(
57 kClient1Id
, kService1Id
, kNumVertexAttribs
, true);
58 // Check creation success
59 VertexAttribManager
* info1
= manager_
->GetVertexAttribManager(kClient1Id
);
60 ASSERT_TRUE(info1
!= NULL
);
61 EXPECT_EQ(kService1Id
, info1
->service_id());
63 EXPECT_TRUE(manager_
->GetClientId(info1
->service_id(), &client_id
));
64 EXPECT_EQ(kClient1Id
, client_id
);
65 // Check we get nothing for a non-existent name.
66 EXPECT_TRUE(manager_
->GetVertexAttribManager(kClient2Id
) == NULL
);
67 // Check trying to a remove non-existent name does not crash.
68 manager_
->RemoveVertexAttribManager(kClient2Id
);
69 // Check that it gets deleted when the last reference is released.
70 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id
)))
72 .RetiresOnSaturation();
73 // Check we can't get the texture after we remove it.
74 manager_
->RemoveVertexAttribManager(kClient1Id
);
75 EXPECT_TRUE(manager_
->GetVertexAttribManager(kClient1Id
) == NULL
);
78 TEST_F(VertexArrayManagerTest
, Destroy
) {
79 const GLuint kClient1Id
= 1;
80 const GLuint kService1Id
= 11;
81 VertexArrayManager manager
;
82 // Check we can create
83 manager
.CreateVertexAttribManager(
84 kClient1Id
, kService1Id
, kNumVertexAttribs
, true);
85 // Check creation success
86 VertexAttribManager
* info1
= manager
.GetVertexAttribManager(kClient1Id
);
87 ASSERT_TRUE(info1
!= NULL
);
88 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, ::testing::Pointee(kService1Id
)))
90 .RetiresOnSaturation();
91 manager
.Destroy(true);
92 // Check that resources got freed.
93 info1
= manager
.GetVertexAttribManager(kClient1Id
);
94 ASSERT_TRUE(info1
== NULL
);