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/context_group.h"
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
      9 #include "gpu/command_buffer/service/test_helper.h"
     10 #include "gpu/command_buffer/service/texture_manager.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 #include "ui/gl/gl_mock.h"
     13 
     14 using ::gfx::MockGLInterface;
     15 using ::testing::_;
     16 using ::testing::DoAll;
     17 using ::testing::HasSubstr;
     18 using ::testing::InSequence;
     19 using ::testing::MatcherCast;
     20 using ::testing::Not;
     21 using ::testing::Pointee;
     22 using ::testing::Return;
     23 using ::testing::SetArrayArgument;
     24 using ::testing::SetArgumentPointee;
     25 using ::testing::StrEq;
     26 using ::testing::StrictMock;
     27 
     28 namespace gpu {
     29 namespace gles2 {
     30 
     31 class ContextGroupTest : public testing::Test {
     32  public:
     33   ContextGroupTest() {
     34   }
     35 
     36  protected:
     37   virtual void SetUp() {
     38     gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
     39     ::gfx::GLInterface::SetGLInterface(gl_.get());
     40     decoder_.reset(new MockGLES2Decoder());
     41     group_ = scoped_refptr<ContextGroup>(
     42         new ContextGroup(NULL, NULL, NULL, NULL, NULL, true));
     43   }
     44 
     45   virtual void TearDown() {
     46     ::gfx::GLInterface::SetGLInterface(NULL);
     47     gl_.reset();
     48   }
     49 
     50   scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
     51   scoped_ptr<MockGLES2Decoder> decoder_;
     52   scoped_refptr<ContextGroup> group_;
     53 };
     54 
     55 TEST_F(ContextGroupTest, Basic) {
     56   // Test it starts off uninitialized.
     57   EXPECT_EQ(0u, group_->max_vertex_attribs());
     58   EXPECT_EQ(0u, group_->max_texture_units());
     59   EXPECT_EQ(0u, group_->max_texture_image_units());
     60   EXPECT_EQ(0u, group_->max_vertex_texture_image_units());
     61   EXPECT_EQ(0u, group_->max_fragment_uniform_vectors());
     62   EXPECT_EQ(0u, group_->max_varying_vectors());
     63   EXPECT_EQ(0u, group_->max_vertex_uniform_vectors());
     64   EXPECT_TRUE(group_->buffer_manager() == NULL);
     65   EXPECT_TRUE(group_->framebuffer_manager() == NULL);
     66   EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
     67   EXPECT_TRUE(group_->texture_manager() == NULL);
     68   EXPECT_TRUE(group_->program_manager() == NULL);
     69   EXPECT_TRUE(group_->shader_manager() == NULL);
     70 }
     71 
     72 TEST_F(ContextGroupTest, InitializeNoExtensions) {
     73   TestHelper::SetupContextGroupInitExpectations(gl_.get(),
     74       DisallowedFeatures(), "");
     75   group_->Initialize(decoder_.get(), DisallowedFeatures());
     76   EXPECT_EQ(static_cast<uint32>(TestHelper::kNumVertexAttribs),
     77             group_->max_vertex_attribs());
     78   EXPECT_EQ(static_cast<uint32>(TestHelper::kNumTextureUnits),
     79             group_->max_texture_units());
     80   EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxTextureImageUnits),
     81             group_->max_texture_image_units());
     82   EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexTextureImageUnits),
     83              group_->max_vertex_texture_image_units());
     84   EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxFragmentUniformVectors),
     85             group_->max_fragment_uniform_vectors());
     86   EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVaryingVectors),
     87             group_->max_varying_vectors());
     88   EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexUniformVectors),
     89             group_->max_vertex_uniform_vectors());
     90   EXPECT_TRUE(group_->buffer_manager() != NULL);
     91   EXPECT_TRUE(group_->framebuffer_manager() != NULL);
     92   EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
     93   EXPECT_TRUE(group_->texture_manager() != NULL);
     94   EXPECT_TRUE(group_->program_manager() != NULL);
     95   EXPECT_TRUE(group_->shader_manager() != NULL);
     96 
     97   group_->Destroy(decoder_.get(), false);
     98   EXPECT_TRUE(group_->buffer_manager() == NULL);
     99   EXPECT_TRUE(group_->framebuffer_manager() == NULL);
    100   EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
    101   EXPECT_TRUE(group_->texture_manager() == NULL);
    102   EXPECT_TRUE(group_->program_manager() == NULL);
    103   EXPECT_TRUE(group_->shader_manager() == NULL);
    104 }
    105 
    106 TEST_F(ContextGroupTest, MultipleContexts) {
    107   scoped_ptr<MockGLES2Decoder> decoder2_(new MockGLES2Decoder());
    108   TestHelper::SetupContextGroupInitExpectations(gl_.get(),
    109       DisallowedFeatures(), "");
    110   group_->Initialize(decoder_.get(), DisallowedFeatures());
    111   group_->Initialize(decoder2_.get(), DisallowedFeatures());
    112 
    113   EXPECT_TRUE(group_->buffer_manager() != NULL);
    114   EXPECT_TRUE(group_->framebuffer_manager() != NULL);
    115   EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
    116   EXPECT_TRUE(group_->texture_manager() != NULL);
    117   EXPECT_TRUE(group_->program_manager() != NULL);
    118   EXPECT_TRUE(group_->shader_manager() != NULL);
    119 
    120   group_->Destroy(decoder_.get(), false);
    121 
    122   EXPECT_TRUE(group_->buffer_manager() != NULL);
    123   EXPECT_TRUE(group_->framebuffer_manager() != NULL);
    124   EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
    125   EXPECT_TRUE(group_->texture_manager() != NULL);
    126   EXPECT_TRUE(group_->program_manager() != NULL);
    127   EXPECT_TRUE(group_->shader_manager() != NULL);
    128 
    129   group_->Destroy(decoder2_.get(), false);
    130 
    131   EXPECT_TRUE(group_->buffer_manager() == NULL);
    132   EXPECT_TRUE(group_->framebuffer_manager() == NULL);
    133   EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
    134   EXPECT_TRUE(group_->texture_manager() == NULL);
    135   EXPECT_TRUE(group_->program_manager() == NULL);
    136   EXPECT_TRUE(group_->shader_manager() == NULL);
    137 }
    138 
    139 }  // namespace gles2
    140 }  // namespace gpu
    141 
    142 
    143