forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
texture_unittests.cc
99 lines (79 loc) · 3.33 KB
/
texture_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/common/graphics/texture.h"
#include "flutter/flow/testing/mock_texture.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
TEST(TextureRegistryTest, UnregisterTextureCallbackTriggered) {
TextureRegistry registry;
auto mock_texture1 = std::make_shared<MockTexture>(0);
auto mock_texture2 = std::make_shared<MockTexture>(1);
registry.RegisterTexture(mock_texture1);
registry.RegisterTexture(mock_texture2);
ASSERT_EQ(registry.GetTexture(0), mock_texture1);
ASSERT_EQ(registry.GetTexture(1), mock_texture2);
ASSERT_FALSE(mock_texture1->unregistered());
ASSERT_FALSE(mock_texture2->unregistered());
registry.UnregisterTexture(0);
ASSERT_EQ(registry.GetTexture(0), nullptr);
ASSERT_TRUE(mock_texture1->unregistered());
ASSERT_FALSE(mock_texture2->unregistered());
registry.UnregisterTexture(1);
ASSERT_EQ(registry.GetTexture(1), nullptr);
ASSERT_TRUE(mock_texture1->unregistered());
ASSERT_TRUE(mock_texture2->unregistered());
}
TEST(TextureRegistryTest, GrContextCallbackTriggered) {
TextureRegistry registry;
auto mock_texture1 = std::make_shared<MockTexture>(0);
auto mock_texture2 = std::make_shared<MockTexture>(1);
registry.RegisterTexture(mock_texture1);
registry.RegisterTexture(mock_texture2);
ASSERT_FALSE(mock_texture1->gr_context_created());
ASSERT_FALSE(mock_texture2->gr_context_created());
ASSERT_FALSE(mock_texture1->gr_context_destroyed());
ASSERT_FALSE(mock_texture2->gr_context_destroyed());
registry.OnGrContextCreated();
ASSERT_TRUE(mock_texture1->gr_context_created());
ASSERT_TRUE(mock_texture2->gr_context_created());
registry.UnregisterTexture(0);
registry.OnGrContextDestroyed();
ASSERT_FALSE(mock_texture1->gr_context_destroyed());
ASSERT_TRUE(mock_texture2->gr_context_created());
}
TEST(TextureRegistryTest, RegisterTextureTwice) {
TextureRegistry registry;
auto mock_texture1 = std::make_shared<MockTexture>(0);
auto mock_texture2 = std::make_shared<MockTexture>(0);
registry.RegisterTexture(mock_texture1);
ASSERT_EQ(registry.GetTexture(0), mock_texture1);
registry.RegisterTexture(mock_texture2);
ASSERT_EQ(registry.GetTexture(0), mock_texture2);
ASSERT_FALSE(mock_texture1->unregistered());
ASSERT_FALSE(mock_texture2->unregistered());
registry.UnregisterTexture(0);
ASSERT_EQ(registry.GetTexture(0), nullptr);
ASSERT_FALSE(mock_texture1->unregistered());
ASSERT_TRUE(mock_texture2->unregistered());
}
TEST(TextureRegistryTest, ReuseSameTextureSlot) {
TextureRegistry registry;
auto mock_texture1 = std::make_shared<MockTexture>(0);
auto mock_texture2 = std::make_shared<MockTexture>(0);
registry.RegisterTexture(mock_texture1);
ASSERT_EQ(registry.GetTexture(0), mock_texture1);
registry.UnregisterTexture(0);
ASSERT_EQ(registry.GetTexture(0), nullptr);
ASSERT_TRUE(mock_texture1->unregistered());
ASSERT_FALSE(mock_texture2->unregistered());
registry.RegisterTexture(mock_texture2);
ASSERT_EQ(registry.GetTexture(0), mock_texture2);
registry.UnregisterTexture(0);
ASSERT_EQ(registry.GetTexture(0), nullptr);
ASSERT_TRUE(mock_texture1->unregistered());
ASSERT_TRUE(mock_texture2->unregistered());
}
} // namespace testing
} // namespace flutter