summaryrefslogtreecommitdiff
path: root/lib/talloc
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-03-31 19:50:47 +0200
committerStefan Metzmacher <metze@samba.org>2011-04-08 09:28:10 +0200
commitf9fdef870e4c49d9e6c23ba085ba6dbd34ec5469 (patch)
treee199a0ce6bf1eda5d093e395f2b6d4191b5bff60 /lib/talloc
parent2146ffd764499d67e3f0576a2e78a1575cd52d9c (diff)
downloadsamba-f9fdef870e4c49d9e6c23ba085ba6dbd34ec5469.tar.gz
samba-f9fdef870e4c49d9e6c23ba085ba6dbd34ec5469.tar.bz2
samba-f9fdef870e4c49d9e6c23ba085ba6dbd34ec5469.zip
talloc/testsuite: test more talloc_pool related things
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'lib/talloc')
-rw-r--r--lib/talloc/testsuite.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index ee6256b8e1..6395e83684 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1123,6 +1123,7 @@ static bool test_pool(void)
{
void *pool;
void *p1, *p2, *p3, *p4;
+ void *p2_2;
pool = talloc_pool(NULL, 1024);
@@ -1131,6 +1132,60 @@ static bool test_pool(void)
p3 = talloc_size(p1, 50);
p4 = talloc_size(p3, 1000);
+#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+ p2_2 = talloc_realloc_size(pool, p2, 20+1);
+ torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed");
+ p2_2 = talloc_realloc_size(pool, p2, 20-1);
+ torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ p2_2 = talloc_realloc_size(pool, p2, 20-1);
+ torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+
+ talloc_free(p3);
+
+ /* this should reclaim the memory of p4 and p3 */
+ p2_2 = talloc_realloc_size(pool, p2, 400);
+ torture_assert("pool realloc 400", p2_2 == p2, "failed: pointer changed");
+
+ talloc_free(p1);
+
+ /* this should reclaim the memory of p1 */
+ p2_2 = talloc_realloc_size(pool, p2, 800);
+ torture_assert("pool realloc 800", p2_2 == p1, "failed: pointer not changed");
+ p2 = p2_2;
+
+ /* this should do a malloc */
+ p2_2 = talloc_realloc_size(pool, p2, 1800);
+ torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
+ p2 = p2_2;
+
+ /* this should reclaim the memory from the pool */
+ p3 = talloc_size(pool, 80);
+ torture_assert("pool alloc 80", p3 == p1, "failed: pointer changed");
+
+ talloc_free(p2);
+ talloc_free(p3);
+
+ p1 = talloc_size(pool, 80);
+ p2 = talloc_size(pool, 20);
+
+ talloc_free(p1);
+
+ p2_2 = talloc_realloc_size(pool, p2, 20-1);
+ torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ p2_2 = talloc_realloc_size(pool, p2, 20-1);
+ torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+
+ /* this should do a malloc */
+ p2_2 = talloc_realloc_size(pool, p2, 1800);
+ torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
+ p2 = p2_2;
+
+ /* this should reclaim the memory from the pool */
+ p3 = talloc_size(pool, 800);
+ torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed");
+
+#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+
talloc_free(pool);
return true;