Home | History | Annotate | Download | only in service
      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/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"
     14 
     15 using ::testing::Pointee;
     16 using ::testing::_;
     17 
     18 namespace gpu {
     19 namespace gles2 {
     20 
     21 class VertexArrayManagerTest : public GpuServiceTest {
     22  public:
     23   static const uint32 kNumVertexAttribs = 8;
     24 
     25   VertexArrayManagerTest() {
     26   }
     27 
     28   virtual ~VertexArrayManagerTest() {
     29   }
     30 
     31  protected:
     32   virtual void SetUp() {
     33     GpuServiceTest::SetUp();
     34     manager_.reset(new VertexArrayManager());
     35   }
     36 
     37   virtual void TearDown() {
     38     manager_.reset();
     39     GpuServiceTest::TearDown();
     40   }
     41 
     42   scoped_ptr<VertexArrayManager> manager_;
     43 };
     44 
     45 // GCC requires these declarations, but MSVC requires they not be present
     46 #ifndef COMPILER_MSVC
     47 const uint32 VertexArrayManagerTest::kNumVertexAttribs;
     48 #endif
     49 
     50 TEST_F(VertexArrayManagerTest, Basic) {
     51   const GLuint kClient1Id = 1;
     52   const GLuint kService1Id = 11;
     53   const GLuint kClient2Id = 2;
     54 
     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());
     62   GLuint client_id = 0;
     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)))
     71       .Times(1)
     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);
     76 }
     77 
     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)))
     89       .Times(1)
     90       .RetiresOnSaturation();
     91   manager.Destroy(true);
     92   // Check that resources got freed.
     93   info1 = manager.GetVertexAttribManager(kClient1Id);
     94   ASSERT_TRUE(info1 == NULL);
     95 }
     96 
     97 }  // namespace gles2
     98 }  // namespace gpu
     99 
    100 
    101