xref: /aosp_15_r20/external/pigweed/pw_allocator/allocator_as_pool_test.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_allocator/allocator_as_pool.h"
16 
17 #include <cstdint>
18 
19 #include "pw_allocator/layout.h"
20 #include "pw_allocator/testing.h"
21 #include "pw_unit_test/framework.h"
22 
23 namespace {
24 
25 // Test fxitures.
26 
27 using ::pw::allocator::AllocatorAsPool;
28 using ::pw::allocator::Layout;
29 using AllocatorForTest = ::pw::allocator::test::AllocatorForTest<256>;
30 
31 struct U64 {
32   std::byte bytes[8];
33 };
34 
35 class AllocatorAsPoolTest : public ::testing::Test {
36  public:
AllocatorAsPoolTest()37   AllocatorAsPoolTest() : allocator_(), pool_(allocator_, Layout::Of<U64>()) {}
38 
39  protected:
40   AllocatorForTest allocator_;
41   AllocatorAsPool pool_;
42 };
43 
44 // Unit tests.
45 
TEST_F(AllocatorAsPoolTest,Capabilities)46 TEST_F(AllocatorAsPoolTest, Capabilities) {
47   EXPECT_EQ(pool_.capabilities(), allocator_.capabilities());
48 }
49 
TEST_F(AllocatorAsPoolTest,AllocateDeallocate)50 TEST_F(AllocatorAsPoolTest, AllocateDeallocate) {
51   void* ptr = pool_.Allocate();
52   ASSERT_NE(ptr, nullptr);
53   pool_.Deallocate(ptr);
54 }
55 
56 }  // namespace
57