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