| Flutter Impeller |

host_buffer_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 "flutter/testing/testing.h"
6 #include "impeller/core/host_buffer.h"
7
8 namespace impeller {
9 namespace testing {
10
11 TEST(HostBufferTest, TestInitialization) {
12 ASSERT_TRUE(HostBuffer::Create());
13 // Newly allocated buffers don't touch the heap till they have to.
14 ASSERT_EQ(HostBuffer::Create()->GetLength(), 0u);
15 ASSERT_EQ(HostBuffer::Create()->GetSize(), 0u);
16 }
17
18 TEST(HostBufferTest, CanEmplace) {
19 struct Length2 {
20 uint8_t pad[2];
21 };
22 static_assert(sizeof(Length2) == 2u);
23
24 auto buffer = HostBuffer::Create();
25
26 for (size_t i = 0; i < 12500; i++) {
27 auto view = buffer->Emplace(Length2{});
28 ASSERT_TRUE(view);
29 ASSERT_EQ(buffer->GetLength(), (i + 1) * sizeof(Length2));
30 ASSERT_EQ(view.range, Range(i * sizeof(Length2), 2u));
31 }
32 }
33
34 TEST(HostBufferTest, CanEmplaceWithAlignment) {
35 struct Length2 {
36 uint8_t pad[2];
37 };
38 static_assert(sizeof(Length2) == 2);
39 struct alignas(16) Align16 {
40 uint8_t pad[2];
41 };
42 static_assert(alignof(Align16) == 16);
43 static_assert(sizeof(Align16) == 16);
44
45 auto buffer = HostBuffer::Create();
46 ASSERT_TRUE(buffer);
47
48 {
49 auto view = buffer->Emplace(Length2{});
50 ASSERT_TRUE(view);
51 ASSERT_EQ(buffer->GetLength(), 2u);
52 ASSERT_EQ(view.range, Range(0u, 2u));
53 }
54
55 {
56 auto view = buffer->Emplace(Align16{});
57 ASSERT_TRUE(view);
58 ASSERT_EQ(view.range.offset, 16u);
59 ASSERT_EQ(view.range.length, 16u);
60 ASSERT_EQ(buffer->GetLength(), 32u);
61 }
62 {
63 auto view = buffer->Emplace(Length2{});
64 ASSERT_TRUE(view);
65 ASSERT_EQ(buffer->GetLength(), 34u);
66 ASSERT_EQ(view.range, Range(32u, 2u));
67 }
68
69 {
70 auto view = buffer->Emplace(Align16{});
71 ASSERT_TRUE(view);
72 ASSERT_EQ(view.range.offset, 48u);
73 ASSERT_EQ(view.range.length, 16u);
74 ASSERT_EQ(buffer->GetLength(), 64u);
75 }
76 }
77
78 } // namespace testing
79 } // namespace impeller
host_buffer.h
impeller::HostBuffer::Create
static std::shared_ptr< HostBuffer > Create()
Definition: host_buffer.cc:18
impeller::testing::TEST
TEST(CanvasRecorder, Save)
Definition: canvas_recorder_unittests.cc:61
impeller::Range
Definition: range.h:14
impeller
Definition: aiks_context.cc:10