1// Copyright 2022 The Chromium 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 "util/aligned_alloc.h"
6#include "util/test/test.h"
7
8using AlignedAllocPtrSize = AlignedAlloc<sizeof(void*)>;
9using AlignedAlloc32 = AlignedAlloc<32>;
10
11TEST(AlignedAllocTest, PtrSized) {
12  void* ptr = AlignedAllocPtrSize::Alloc(2 * sizeof(void*));
13  ASSERT_TRUE(ptr);
14  ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr) % sizeof(void*), 0u);
15  AlignedAllocPtrSize::Free(ptr);
16}
17
18TEST(AlignedAllocTest, Align32) {
19  void* ptr = AlignedAlloc32::Alloc(64);
20  ASSERT_TRUE(ptr);
21  ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr) % 32u, 0u);
22  AlignedAlloc32::Free(ptr);
23}
24