fix ref_free_steal test
authorStefan Metzmacher <metze@samba.org>
Tue, 14 Jul 2009 10:00:22 +0000 (12:00 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 14 Jul 2009 10:00:22 +0000 (12:00 +0200)
lib/talloc/testsuite.c

index 6057fc11c5fea4317495957d0596c9f2a37d5cbe..9b79bfacac6d5cc1601e8b979be32cb3f8786f34 100644 (file)
@@ -913,7 +913,6 @@ static bool test_ref_free_steal(void)
        void *root, *p1, *p2, *p3, *ref, *r1;
 
        printf("test: ref_free_self\n# SINGLE REFERENCE FREE SELF FREE\n");
-       talloc_erase_no_owner_context();
 
        root = talloc_named_const(NULL, 0, "root");
        p1 = talloc_named_const(root, 1, "p1");
@@ -936,13 +935,28 @@ static bool test_ref_free_steal(void)
        /* r1 should have ref reference to p2 still */
        talloc_report_full(NULL, stderr);
        CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 1);
 
-       /* if we talloc_steal p2 to p3, r1 should still have a reference
-          (unless it had been made the parent like in old talloc */
+       /* if we talloc_steal p2 to p3, we should get an abort() */
        fprintf(stderr, "Steal p2 to p3\n");
+       test_abort_start();
        talloc_steal(p3, p2);
+       torture_assert(__FUNCTION__,
+                      test_abort_count == 1,
+                      "talloc_steal() didn't abort");
+       test_abort_stop();
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 1);
+
+       /* but we can reference p2 to p3 */
+       fprintf(stderr, "Steal p2 to p3\n");
+       talloc_reference(p3, p2);
+
        talloc_report_full(NULL, stderr);
-       //CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 2);
 
        /* now we free p3 and r1 should still have a reference */
        fprintf(stderr, "free p3\n");
@@ -956,9 +970,11 @@ static bool test_ref_free_steal(void)
        talloc_free(r1);
 
        talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 3);
        CHECK_BLOCKS(__FUNCTION__, root, 1);
 
        talloc_free(root);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 2);
        printf("success: ref1\n");
        return true;
 }