• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <malloc.h>
3 
4 using namespace testing::ext;
5 
6 class MallocFreeTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 constexpr int VALUE = 5;
12 
13 /**
14  * @tc.name: free_001
15  * @tc.desc: This test verifies that after using the malloc function for dynamic memory allocation, when calling the
16  *           free function to release memory blocks, it can correctly release memory and make the memory situation meet
17  *           expectations.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MallocFreeTest, free_001, TestSize.Level1)
21 {
22     int* memoryBlock = static_cast<int*>(malloc(sizeof(int)));
23     *memoryBlock = VALUE;
24     ASSERT_NE(memoryBlock, nullptr);
25     EXPECT_TRUE(*memoryBlock == VALUE);
26     free(memoryBlock);
27 }