test/test_basic_mempool.cpp

changeset 572
f0f99dd06d9f
parent 571
f83583a0bbac
     1.1 --- a/test/test_basic_mempool.cpp	Wed Aug 03 17:27:55 2022 +0200
     1.2 +++ b/test/test_basic_mempool.cpp	Mon Aug 08 17:12:00 2022 +0200
     1.3 @@ -32,19 +32,17 @@
     1.4  
     1.5  class CxBasicMempool : public ::testing::Test {
     1.6  protected:
     1.7 -    CxTestingAllocator testingAllocator;
     1.8      CxMempool *pool = nullptr;
     1.9  
    1.10      void TearDown() override {
    1.11          if (pool != nullptr) {
    1.12              cxMempoolDestroy(pool);
    1.13          }
    1.14 -        EXPECT_TRUE(testingAllocator.verify());
    1.15      }
    1.16  };
    1.17  
    1.18  TEST_F(CxBasicMempool, Create) {
    1.19 -    pool = cxBasicMempoolCreateSimple(16);
    1.20 +    pool = cxBasicMempoolCreate(16);
    1.21      ASSERT_NE(pool->allocator, nullptr);
    1.22      ASSERT_NE(pool->cl, nullptr);
    1.23      EXPECT_NE(pool->cl->destroy, nullptr);
    1.24 @@ -56,41 +54,35 @@
    1.25      EXPECT_NE(pool->allocator->cl->free, nullptr);
    1.26  
    1.27      auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
    1.28 -    EXPECT_EQ(basic_pool->allocator, cxDefaultAllocator);
    1.29      EXPECT_EQ(basic_pool->size, 16);
    1.30      EXPECT_EQ(basic_pool->ndata, 0);
    1.31      EXPECT_NE(basic_pool->data, nullptr);
    1.32  }
    1.33  
    1.34  TEST_F(CxBasicMempool, malloc) {
    1.35 -    pool = cxBasicMempoolCreate(4, &testingAllocator);
    1.36 +    pool = cxBasicMempoolCreate(4);
    1.37      auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
    1.38      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.39      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.40 -    EXPECT_EQ(testingAllocator.alloc_total, 2);
    1.41      EXPECT_EQ(basic_pool->ndata, 2);
    1.42      EXPECT_EQ(basic_pool->size, 4);
    1.43      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.44      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.45 -    EXPECT_EQ(testingAllocator.alloc_total, 4);
    1.46      EXPECT_EQ(basic_pool->ndata, 4);
    1.47      EXPECT_EQ(basic_pool->size, 4);
    1.48      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.49      EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
    1.50 -    EXPECT_EQ(testingAllocator.alloc_total, 6);
    1.51      EXPECT_EQ(basic_pool->ndata, 6);
    1.52      EXPECT_GE(basic_pool->size, 6);
    1.53 -    EXPECT_TRUE(testingAllocator.used());
    1.54  }
    1.55  
    1.56  TEST_F(CxBasicMempool, calloc) {
    1.57 -    pool = cxBasicMempoolCreate(4, &testingAllocator);
    1.58 +    pool = cxBasicMempoolCreate(4);
    1.59  
    1.60      auto test = (int *) cxCalloc(pool->allocator, 2, sizeof(int));
    1.61      ASSERT_NE(test, nullptr);
    1.62      EXPECT_EQ(test[0], 0);
    1.63      EXPECT_EQ(test[1], 0);
    1.64 -    EXPECT_TRUE(testingAllocator.used());
    1.65  }
    1.66  
    1.67  static unsigned test_destructor_called = 0;
    1.68 @@ -100,7 +92,7 @@
    1.69  }
    1.70  
    1.71  TEST_F(CxBasicMempool, destructor) {
    1.72 -    pool = cxBasicMempoolCreate(4, &testingAllocator);
    1.73 +    pool = cxBasicMempoolCreate(4);
    1.74      auto data = cxMalloc(pool->allocator, sizeof(int));
    1.75      *((int *) data) = 13;
    1.76      cxMempoolSetDestructor(pool, data, test_destructor);
    1.77 @@ -116,7 +108,7 @@
    1.78  }
    1.79  
    1.80  TEST_F(CxBasicMempool, realloc) {
    1.81 -    pool = cxBasicMempoolCreate(4, &testingAllocator);
    1.82 +    pool = cxBasicMempoolCreate(4);
    1.83      auto data = cxMalloc(pool->allocator, sizeof(int));
    1.84      *((int *) data) = 13;
    1.85      cxMempoolSetDestructor(pool, data, test_destructor);
    1.86 @@ -138,7 +130,7 @@
    1.87  
    1.88  
    1.89  TEST_F(CxBasicMempool, free) {
    1.90 -    pool = cxBasicMempoolCreate(4, &testingAllocator);
    1.91 +    pool = cxBasicMempoolCreate(4);
    1.92      auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
    1.93  
    1.94      void *mem1;

mercurial