| Flutter Impeller |

pool_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "gtest/gtest.h"
6
7 #include "impeller/renderer/pool.h"
8
9 namespace impeller {
10 namespace testing {
11
12 namespace {
13 class Foobar {
14 public:
15 static std::shared_ptr<Foobar> Create() { return std::make_shared<Foobar>(); }
16
17 size_t GetSize() const { return size_; }
18
19 void SetSize(size_t size) { size_ = size; }
20
21 void Reset() { is_reset_ = true; }
22
23 bool GetIsReset() const { return is_reset_; }
24
25 void SetIsReset(bool is_reset) { is_reset_ = is_reset; }
26
27 private:
28 size_t size_;
29 bool is_reset_ = false;
30 };
31 } // namespace
32
33 TEST(PoolTest, Simple) {
34 Pool<Foobar> pool(1'000);
35 {
36 auto grabbed = pool.Grab();
37 grabbed->SetSize(123);
38 pool.Recycle(grabbed);
39 EXPECT_EQ(pool.GetSize(), 123u);
40 }
41 auto grabbed = pool.Grab();
42 EXPECT_EQ(grabbed->GetSize(), 123u);
43 EXPECT_TRUE(grabbed->GetIsReset());
44 EXPECT_EQ(pool.GetSize(), 0u);
45 }
46
47 TEST(PoolTest, Overload) {
48 Pool<Foobar> pool(1'000);
49 {
50 std::vector<std::shared_ptr<Foobar>> values;
51 for (int i = 0; i < 20; i++) {
52 values.push_back(pool.Grab());
53 }
54 for (auto value : values) {
55 value->SetSize(100);
56 pool.Recycle(value);
57 }
58 }
59 EXPECT_EQ(pool.GetSize(), 1'000u);
60 }
61
62 } // namespace testing
63 } // namespace impeller
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition: canvas_unittests.cc:18
pool.h
impeller::Pool
A thread-safe pool with a limited byte size.
Definition: pool.h:15
impeller
Definition: aiks_context.cc:10