| 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 values.reserve(20);
52 for (int i = 0; i < 20; i++) {
53 values.push_back(pool.Grab());
54 }
55 for (const auto& value : values) {
56 value->SetSize(100);
57 pool.Recycle(value);
58 }
59 }
60 EXPECT_EQ(pool.GetSize(), 1'000u);
61 }
62
63 } // namespace testing
64 } // namespace impeller
impeller::Pool
A thread-safe pool with a limited byte size.
Definition: pool.h:17
impeller::Pool::Grab
std::shared_ptr< T > Grab()
Definition: pool.h:21
impeller::Pool::GetSize
uint32_t GetSize() const
Definition: pool.h:43
impeller::Pool::Recycle
void Recycle(std::shared_ptr< T > object)
Definition: pool.h:32
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161
impeller::testing::TEST
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: allocation_size_unittests.cc:10
impeller
Definition: allocation.cc:12
pool.h