xref: /llvm-project/libc/test/src/stdlib/malloc_test.cpp (revision b6bc9d72f65a5086f310f321e969d96e9a559e75)
1a6213088SJoseph Huber //===-- Unittests for malloc ----------------------------------------------===//
2a6213088SJoseph Huber //
3a6213088SJoseph Huber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4a6213088SJoseph Huber // See https://llvm.org/LICENSE.txt for license information.
5a6213088SJoseph Huber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a6213088SJoseph Huber //
7a6213088SJoseph Huber //===----------------------------------------------------------------------===//
8a6213088SJoseph Huber 
9a6213088SJoseph Huber #include "src/stdlib/free.h"
10a6213088SJoseph Huber #include "src/stdlib/malloc.h"
11a6213088SJoseph Huber #include "test/UnitTest/Test.h"
12a6213088SJoseph Huber 
TEST(LlvmLibcMallocTest,Allocate)13a6213088SJoseph Huber TEST(LlvmLibcMallocTest, Allocate) {
14*b6bc9d72SGuillaume Chatelet   int *ptr = reinterpret_cast<int *>(LIBC_NAMESPACE::malloc(sizeof(int)));
15a6213088SJoseph Huber   EXPECT_NE(reinterpret_cast<void *>(ptr), static_cast<void *>(nullptr));
16a6213088SJoseph Huber   *ptr = 1;
17a6213088SJoseph Huber   EXPECT_EQ(*ptr, 1);
18*b6bc9d72SGuillaume Chatelet   LIBC_NAMESPACE::free(ptr);
19a6213088SJoseph Huber }
20