Path: blob/main_old/src/common/aligned_memory_unittest.cpp
1693 views
//1// Copyright 2017 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// aligned_memory_unittests: Tests for the aligned memory allocator.6// Tests copied from Chrome: src/base/memory/aligned_memory_unittests.cc.7//89#include "common/aligned_memory.h"1011#include <memory>1213#include "gtest/gtest.h"1415#define EXPECT_ALIGNED(ptr, align) EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1))1617namespace angle18{1920// Test that dynamic allocation works as expected.21TEST(AlignedMemoryTest, DynamicAllocation)22{23void *p = AlignedAlloc(8, 8);24EXPECT_TRUE(p);25EXPECT_ALIGNED(p, 8);26AlignedFree(p);2728p = AlignedAlloc(8, 16);29EXPECT_TRUE(p);30EXPECT_ALIGNED(p, 16);31AlignedFree(p);3233p = AlignedAlloc(8, 256);34EXPECT_TRUE(p);35EXPECT_ALIGNED(p, 256);36AlignedFree(p);3738p = AlignedAlloc(8, 4096);39EXPECT_TRUE(p);40EXPECT_ALIGNED(p, 4096);41AlignedFree(p);42}4344} // namespace angle454647