blob: 589bda9f9c7cafc1db40f2e4fe4b4f320857a461 [file] [log] [blame]
Jamie Madillbdd419f2015-03-20 15:29:42 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// Unit tests for ResourceManager.
7//
8
9#include <gmock/gmock.h>
10#include <gtest/gtest.h>
11
12#include "angle_unittests_utils.h"
13#include "libANGLE/ResourceManager.h"
14
15using namespace rx;
16using namespace gl;
17
18namespace
19{
20
21class MockFactory : public NullFactory
22{
23 public:
24 MOCK_METHOD0(createBuffer, BufferImpl*());
25 MOCK_METHOD1(createTexture, TextureImpl*(GLenum));
26 MOCK_METHOD0(createRenderbuffer, RenderbufferImpl*());
27};
28
29class ResourceManagerTest : public testing::Test
30{
31 protected:
32 void SetUp() override
33 {
34 mResourceManager = new ResourceManager(&mMockFactory);
35 }
36
37 void TearDown() override
38 {
39 SafeDelete(mResourceManager);
40 }
41
42 MockFactory mMockFactory;
43 ResourceManager *mResourceManager;
44};
45
46TEST_F(ResourceManagerTest, ReallocateBoundTexture)
47{
48 EXPECT_CALL(mMockFactory, createTexture(GL_TEXTURE_2D)).Times(1).RetiresOnSaturation();
49
50 mResourceManager->checkTextureAllocation(1, GL_TEXTURE_2D);
51 GLuint newTexture = mResourceManager->createTexture();
52 EXPECT_NE(1u, newTexture);
53}
54
55TEST_F(ResourceManagerTest, ReallocateBoundBuffer)
56{
57 EXPECT_CALL(mMockFactory, createBuffer()).Times(1).RetiresOnSaturation();
58
59 mResourceManager->checkBufferAllocation(1);
60 GLuint newBuffer = mResourceManager->createBuffer();
61 EXPECT_NE(1u, newBuffer);
62}
63
64TEST_F(ResourceManagerTest, ReallocateBoundRenderbuffer)
65{
66 EXPECT_CALL(mMockFactory, createRenderbuffer()).Times(1).RetiresOnSaturation();
67
68 mResourceManager->checkRenderbufferAllocation(1);
69 GLuint newRenderbuffer = mResourceManager->createRenderbuffer();
70 EXPECT_NE(1u, newRenderbuffer);
71}
72
73}