diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-16 23:21:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:08:55 -0500 |
commit | 7b79694eadc288592729567c3caa7c70f6662760 (patch) | |
tree | e33deb9389d3268095cf90ead49b44c359e1b8ea /source4/lib/talloc/testsuite.c | |
parent | 0a5fd5421c02cb4df21eec30bf216df65cd7641b (diff) | |
download | samba-7b79694eadc288592729567c3caa7c70f6662760.tar.gz samba-7b79694eadc288592729567c3caa7c70f6662760.tar.bz2 samba-7b79694eadc288592729567c3caa7c70f6662760.zip |
r4790: added type checking helper macros in talloc. These take advantage of
the type names that talloc already keeps around for pointers, and
allows the user to type check void* private pointers. It can also be
used to implement polymorphism in C, as I'm sure someone would have
pointed out to me sooner or later :-)
(This used to be commit c283e1a3efac3a92e29a35856e20eb61ef4c221e)
Diffstat (limited to 'source4/lib/talloc/testsuite.c')
-rw-r--r-- | source4/lib/talloc/testsuite.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index bc1c18fdc1..4a1074e045 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -609,6 +609,48 @@ static BOOL test_realloc_child(void) return True; } + +/* + test type checking +*/ +static BOOL test_type(void) +{ + void *root; + struct el1 { + int count; + }; + struct el2 { + int count; + }; + struct el1 *el1; + + printf("TESTING talloc type checking\n"); + + root = talloc_new(NULL); + + el1 = talloc(root, struct el1); + + el1->count = 1; + + if (talloc_get_type(el1, struct el1) != el1) { + printf("type check failed on el1\n"); + return False; + } + if (talloc_get_type(el1, struct el2) != NULL) { + printf("type check failed on el1 with el2\n"); + return False; + } + talloc_set_type(el1, struct el2); + if (talloc_get_type(el1, struct el2) != el1) { + printf("type set failed on el1 with el2\n"); + return False; + } + + talloc_free(root); + + return True; +} + /* test steal */ @@ -664,13 +706,13 @@ static BOOL test_steal(void) } /* - test ldb alloc fn + test talloc_realloc_fn */ -static BOOL test_ldb(void) +static BOOL test_realloc_fn(void) { void *root, *p1; - printf("TESTING LDB\n"); + printf("TESTING talloc_realloc_fn\n"); root = talloc_new(NULL); @@ -774,7 +816,8 @@ BOOL torture_local_talloc(void) ret &= test_realloc_child(); ret &= test_steal(); ret &= test_unref_reparent(); - ret &= test_ldb(); + ret &= test_realloc_fn(); + ret &= test_type(); if (ret) { ret &= test_speed(); } |