testMem.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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{
22public:
23 int aValue;
24};
25
27{
29
30public:
31 int aValue = 0;
32};
33
34void
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
55void
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
virtual void freeOne(void *)=0
virtual void * alloc()=0
MEMPROXY_CLASS(MoreToAlloc)
int aValue
Definition: testMem.cc:31
void testMemPool()
Definition: testMem.cc:35
void testMemProxy()
Definition: testMem.cc:56
#define memPoolCreate
Definition: Pool.h:325
CPPUNIT_TEST_SUITE_REGISTRATION(testMem)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors