realloc-pool unit-test
[ardour.git] / libs / pbd / test / reallocpool_test.cc
1 #include <string.h>
2 #include "reallocpool_test.h"
3 #include "pbd/reallocpool.h"
4
5 CPPUNIT_TEST_SUITE_REGISTRATION (ReallocPoolTest);
6
7 using namespace std;
8
9 ReallocPoolTest::ReallocPoolTest ()
10 {
11 }
12
13 void
14 ReallocPoolTest::testBasic ()
15 {
16         srand (0);
17         PBD::ReallocPool *m = new PBD::ReallocPool("TestPool", 256 * 1024);
18
19         for (int l = 0; l < 2 * 1024 * 1024; ++l) {
20                 void *x[32];
21                 size_t s[32];
22                 int cnt = rand() % 32;
23                 for (int i = 0; i < cnt; ++i) {
24                         s[i] = rand() % 1024;
25                         x[i] = m->malloc (s[i]);
26                 }
27                 for (int i = 0; i < cnt; ++i) {
28                         if (x[i]) {
29                                 memset (x[i], 0xa5, s[i]);
30                         }
31                 }
32                 for (int i = 0; i < cnt; ++i) {
33                         m->free (x[i]);
34                 }
35         }
36 #ifdef RAP_WITH_CALL_STATS
37         CPPUNIT_ASSERT (m->mem_used() == 0);
38 #endif
39         delete (m);
40 }