2 //=============================================================================
4 * @file Intrusive_Auto_Ptr_Test.cpp
6 * This test verifies the functionality of the <ACE_Intrusive_Auto_Ptr>
9 * @author Iliyan Jeliazkov <iliyan@ociweb.com>
11 //=============================================================================
14 #include "test_config.h"
15 #include "ace/Intrusive_Auto_Ptr.h"
16 #include "ace/Thread_Manager.h"
24 explicit One (int refcount
) : ref(refcount
)
34 bool has_refs (int howmany
)
36 return this->ref
== howmany
;
39 static bool was_released ()
44 static void intrusive_add_ref (One
*);
45 static void intrusive_remove_ref (One
*);
48 bool One::released
= true;
51 One::intrusive_add_ref (One
*one
) {
56 One::intrusive_remove_ref (One
*one
) {
62 int run_main (int, ACE_TCHAR
*[])
64 ACE_START_TEST (ACE_TEXT ("Intrusive_Auto_Ptr_Test"));
67 One
*theone (new One(0));
70 ACE_TEST_ASSERT (theone
->has_refs (0));
71 ACE_TEST_ASSERT (!One::was_released ());
73 ACE_Intrusive_Auto_Ptr
<One
> ip2(theone
);
76 ACE_TEST_ASSERT (theone
->has_refs (1));
77 ACE_TEST_ASSERT (!One::was_released ());
79 ACE_Intrusive_Auto_Ptr
<One
> ip2(theone
);
80 ACE_TEST_ASSERT (theone
->has_refs (2));
81 ACE_TEST_ASSERT (!One::was_released ());
84 ACE_TEST_ASSERT (theone
->has_refs (1));
85 ACE_TEST_ASSERT (!One::was_released ());
88 ACE_TEST_ASSERT (One::was_released());
90 // Test assigning zero.
93 ACE_TEST_ASSERT (theone
->has_refs (0));
94 ACE_TEST_ASSERT (!One::was_released ());
96 // Transfer object to instrusive auto ptr.
97 // The reference is expected to increment to 1.
98 ACE_Intrusive_Auto_Ptr
<One
> ip2(theone
);
100 ACE_TEST_ASSERT (theone
->has_refs (1));
101 ACE_TEST_ASSERT (!One::was_released ());
103 // Assign a zero instrusive auto ptr.
104 // The reference is expected to decrement to 0, so that the object is
105 // expected to be released.
106 ACE_Intrusive_Auto_Ptr
<One
> ip3
;
108 ACE_TEST_ASSERT (One::was_released ());