Flutter Engine
 
Loading...
Searching...
No Matches
dl_storage_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
6
8
9namespace flutter {
10namespace testing {
11
12TEST(DisplayListStorage, DefaultConstructed) {
13 DisplayListStorage storage;
14 EXPECT_EQ(storage.base(), nullptr);
15 EXPECT_EQ(storage.size(), 0u);
16 EXPECT_EQ(storage.capacity(), 0u);
17}
18
20 DisplayListStorage storage;
21 EXPECT_NE(storage.allocate(10u), nullptr);
22 EXPECT_NE(storage.base(), nullptr);
23 EXPECT_EQ(storage.size(), 10u);
24 EXPECT_EQ(storage.capacity(), DisplayListStorage::kDLPageSize);
25}
26
28 DisplayListStorage original;
29 EXPECT_NE(original.allocate(10u), nullptr);
30
31 DisplayListStorage moved = std::move(original);
32
33 // NOLINTBEGIN(bugprone-use-after-move)
34 // NOLINTBEGIN(clang-analyzer-cplusplus.Move)
35 EXPECT_EQ(original.base(), nullptr);
36 EXPECT_EQ(original.size(), 0u);
37 EXPECT_EQ(original.capacity(), 0u);
38 // NOLINTEND(clang-analyzer-cplusplus.Move)
39 // NOLINTEND(bugprone-use-after-move)
40
41 EXPECT_NE(moved.base(), nullptr);
42 EXPECT_EQ(moved.size(), 10u);
43 EXPECT_EQ(moved.capacity(), DisplayListStorage::kDLPageSize);
44}
45
46TEST(DisplayListStorage, NextPowerOfTwoSize) {
57
58 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(127), 128u);
59 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(255), 256u);
60 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(511), 512u);
61 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(1023), 1024u);
62 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(2047), 2048u);
63 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(4095), 4096u);
64 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(8191), 8192u);
65 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(16383), 16384u);
66 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(32767), 32768u);
67 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(65535), 65536u);
68 EXPECT_EQ(DisplayListStorage::NextPowerOfTwoSize(131071), 131072u);
69 // It probably works...
70}
71
72} // namespace testing
73} // namespace flutter
uint8_t * base()
Returns a pointer to the base of the storage.
Definition dl_storage.h:23
static size_t NextPowerOfTwoSize(size_t x)
Compute the next power of two from [x].
Definition dl_storage.cc:14
size_t size() const
Returns the currently allocated size.
Definition dl_storage.h:27
uint8_t * allocate(size_t needed)
Definition dl_storage.cc:39
size_t capacity() const
Returns the maximum currently allocated space.
Definition dl_storage.h:30
static const constexpr size_t kDLPageSize
Definition dl_storage.h:17
Describes an allocation on the heap.
Definition allocation.h:22
TEST(NativeAssetsManagerTest, NoAvailableAssets)