• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <malloc.h>
3 
4 using namespace testing::ext;
5 
6 class MallocMallocusablesizeTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 constexpr size_t INITIALSIZE = 100;
12 constexpr int SIZE = 2;
13 
14 /**
15  * @tc.name: malloc_usable_size_001
16  * @tc.desc: This test verifies malloc_usable_size function can correctly return the available space size after
17  *           reallocating memory, and verify that the realloc function can successfully reallocate memory while
18  *           retaining the original data.
19  * @tc.type: FUNC
20  */
21 HWTEST_F(MallocMallocusablesizeTest, malloc_usable_size_001, TestSize.Level1)
22 {
23     void* p = malloc(INITIALSIZE);
24     ASSERT_NE(p, nullptr);
25     p = realloc(p, INITIALSIZE * SIZE);
26     ASSERT_NE(p, nullptr);
27     size_t ret = malloc_usable_size(p);
28     EXPECT_GE(ret, INITIALSIZE * SIZE);
29     free(p);
30 }