xref: /third_party/gn/src/util/aligned_alloc_unittest.cc
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/gn/src/util/
16d528ed9Sopenharmony_ci// Copyright 2022 The Chromium Authors. All rights reserved.
26d528ed9Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
36d528ed9Sopenharmony_ci// found in the LICENSE file.
46d528ed9Sopenharmony_ci
56d528ed9Sopenharmony_ci#include "util/aligned_alloc.h"
66d528ed9Sopenharmony_ci#include "util/test/test.h"
76d528ed9Sopenharmony_ci
86d528ed9Sopenharmony_ciusing AlignedAllocPtrSize = AlignedAlloc<sizeof(void*)>;
96d528ed9Sopenharmony_ciusing AlignedAlloc32 = AlignedAlloc<32>;
106d528ed9Sopenharmony_ci
116d528ed9Sopenharmony_ciTEST(AlignedAllocTest, PtrSized) {
126d528ed9Sopenharmony_ci  void* ptr = AlignedAllocPtrSize::Alloc(2 * sizeof(void*));
136d528ed9Sopenharmony_ci  ASSERT_TRUE(ptr);
146d528ed9Sopenharmony_ci  ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr) % sizeof(void*), 0u);
156d528ed9Sopenharmony_ci  AlignedAllocPtrSize::Free(ptr);
166d528ed9Sopenharmony_ci}
176d528ed9Sopenharmony_ci
186d528ed9Sopenharmony_ciTEST(AlignedAllocTest, Align32) {
196d528ed9Sopenharmony_ci  void* ptr = AlignedAlloc32::Alloc(64);
206d528ed9Sopenharmony_ci  ASSERT_TRUE(ptr);
216d528ed9Sopenharmony_ci  ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr) % 32u, 0u);
226d528ed9Sopenharmony_ci  AlignedAlloc32::Free(ptr);
236d528ed9Sopenharmony_ci}
24

Indexes created Thu Nov 07 10:32:03 CST 2024