Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Intrusive_Auto_Ptr_Test.cpp
blob68e665d0e13ed43d2d50a9cf97d509c93bd140b8
2 //=============================================================================
3 /**
4 * @file Intrusive_Auto_Ptr_Test.cpp
6 * This test verifies the functionality of the <ACE_Intrusive_Auto_Ptr>
7 * implementation.
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"
18 class One {
19 static bool released;
21 int ref;
23 public:
24 explicit One (int refcount) : ref(refcount)
26 released = false;
29 ~One ()
31 released = true;
34 bool has_refs (int howmany)
36 return this->ref == howmany;
39 static bool was_released ()
41 return released;
44 static void intrusive_add_ref (One *);
45 static void intrusive_remove_ref (One *);
48 bool One::released = true;
50 void
51 One::intrusive_add_ref (One *one) {
52 one->ref++;
55 void
56 One::intrusive_remove_ref (One *one) {
57 one->ref--;
58 if (one->ref == 0)
59 delete 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.
91 theone = new One(0);
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;
107 ip2 = ip3;
108 ACE_TEST_ASSERT (One::was_released ());
111 ACE_END_TEST;
112 return 0;