testMem.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "mem/forward.h"
11 #include "mem/Pool.h"
12 #include "tests/testMem.h"
13 #include "unitTestMain.h"
14 
15 #include <iostream>
16 #include <stdexcept>
17 
19 
21 {
22 public:
23  int aValue;
24 };
25 
27 {
29 
30 public:
31  int aValue = 0;
32 };
33 
34 void
36 {
37  MemAllocator *Pool = memPoolCreate("Test Pool", sizeof(SomethingToAlloc));
38  CPPUNIT_ASSERT(Pool);
39 
40  auto *something = static_cast<SomethingToAlloc *>(Pool->alloc());
41  CPPUNIT_ASSERT(something);
42  CPPUNIT_ASSERT_EQUAL(something->aValue, 0);
43  something->aValue = 5;
44  Pool->freeOne(something);
45 
46  // Pool should use the FreeList to allocate next object
47  auto *otherthing = static_cast<SomethingToAlloc *>(Pool->alloc());
48  CPPUNIT_ASSERT_EQUAL(otherthing, something);
49  CPPUNIT_ASSERT_EQUAL(otherthing->aValue, 0);
50  Pool->freeOne(otherthing);
51 
52  delete Pool;
53 }
54 
55 void
57 {
58  auto *something = new MoreToAlloc;
59  CPPUNIT_ASSERT(something);
60  CPPUNIT_ASSERT_EQUAL(something->aValue, 0);
61  something->aValue = 5;
62  delete something;
63 
64  // The MEMPROXY pool should use its FreeList to allocate next object
65  auto *otherthing = new MoreToAlloc;
66  CPPUNIT_ASSERT_EQUAL(otherthing, something);
67  CPPUNIT_ASSERT_EQUAL(otherthing->aValue, 0);
68 }
69 
CPPUNIT_TEST_SUITE_REGISTRATION(testMem)
void testMemProxy()
Definition: testMem.cc:56
virtual void freeOne(void *)=0
void testMemPool()
Definition: testMem.cc:35
#define memPoolCreate
Definition: Pool.h:325
int aValue
Definition: testMem.cc:31
MEMPROXY_CLASS(MoreToAlloc)
virtual void * alloc()=0

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors