]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testMem.cc
94e1a86cce7df46a05f4db115d759720089b0dc5
2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
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.
10 #include "mem/forward.h"
12 #include "tests/testMem.h"
13 #include "unitTestMain.h"
18 CPPUNIT_TEST_SUITE_REGISTRATION( testMem
);
20 class SomethingToAlloc
28 MEMPROXY_CLASS(MoreToAlloc
);
35 testMem::testMemPool()
37 MemAllocator
*Pool
= memPoolCreate("Test Pool", sizeof(SomethingToAlloc
));
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
);
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
);
56 testMem::testMemProxy()
58 auto *something
= new MoreToAlloc
;
59 CPPUNIT_ASSERT(something
);
60 CPPUNIT_ASSERT_EQUAL(something
->aValue
, 0);
61 something
->aValue
= 5;
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);