Index: gpu/command_buffer/service/texture_manager_unittest.cc |
=================================================================== |
--- gpu/command_buffer/service/texture_manager_unittest.cc (revision 51426) |
+++ gpu/command_buffer/service/texture_manager_unittest.cc (working copy) |
@@ -3,8 +3,12 @@ |
// found in the LICENSE file. |
#include "gpu/command_buffer/service/texture_manager.h" |
+#include "base/scoped_ptr.h" |
+#include "app/gfx/gl/gl_mock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using ::testing::Pointee; |
+ |
namespace gpu { |
namespace gles2 { |
@@ -19,13 +23,23 @@ |
: manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { |
} |
+ ~TextureManagerTest() { |
+ manager_.Destroy(false); |
+ } |
+ |
protected: |
virtual void SetUp() { |
+ gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
+ ::gfx::GLInterface::SetGLInterface(gl_.get()); |
} |
virtual void TearDown() { |
+ ::gfx::GLInterface::SetGLInterface(NULL); |
+ gl_.reset(); |
} |
+ // Use StrictMock to make 100% sure we know how GL will be called. |
+ scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
TextureManager manager_; |
}; |
@@ -60,6 +74,24 @@ |
EXPECT_TRUE(manager_.GetTextureInfo(kClient1Id) == NULL); |
} |
+TEST_F(TextureManagerTest, Destroy) { |
+ const GLuint kClient1Id = 1; |
+ const GLuint kService1Id = 11; |
+ EXPECT_FALSE(manager_.HaveUnrenderableTextures()); |
+ // Check we can create texture. |
+ manager_.CreateTextureInfo(kClient1Id, kService1Id); |
+ // Check texture got created. |
+ TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id); |
+ ASSERT_TRUE(info1 != NULL); |
+ EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id))) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ manager_.Destroy(true); |
+ // Check that resources got freed. |
+ info1 = manager_.GetTextureInfo(kClient1Id); |
+ ASSERT_TRUE(info1 == NULL); |
+} |
+ |
TEST_F(TextureManagerTest, MaxValues) { |
// Check we get the right values for the max sizes. |
EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D)); |
@@ -126,17 +158,26 @@ |
TextureInfoTest() |
: manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { |
} |
+ ~TextureInfoTest() { |
+ manager_.Destroy(false); |
+ } |
protected: |
virtual void SetUp() { |
+ gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
+ ::gfx::GLInterface::SetGLInterface(gl_.get()); |
manager_.CreateTextureInfo(kClient1Id, kService1Id); |
info_ = manager_.GetTextureInfo(kClient1Id); |
ASSERT_TRUE(info_ != NULL); |
} |
virtual void TearDown() { |
+ ::gfx::GLInterface::SetGLInterface(NULL); |
+ gl_.reset(); |
} |
+ // Use StrictMock to make 100% sure we know how GL will be called. |
+ scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
TextureManager manager_; |
TextureManager::TextureInfo* info_; |
}; |