Doxygen changes
[ACE_TAO.git] / ACE / tests / Simple_Message_Block_Test.cpp
blob0023f88a4a3591e702fa87a49953bf687a009efb
2 //=============================================================================
3 /**
4 * @file Simple_Message_Block_Test.cpp
6 * This test program is a torture test that illustrates how
7 * ACE_Message_Block reference counting works, how and when locks
8 * are used, how memory is managed, and how continuation chains
9 * of message blocks are made. Ideally used with purify :-)
11 * @author Irfan Pyarali <irfan@cs.wustl.edu>
13 //=============================================================================
16 #include "test_config.h"
17 #include "ace/Message_Block.h"
18 #include "ace/Synch_Traits.h"
19 #include "ace/Lock_Adapter_T.h"
20 #include "ace/OS_NS_string.h"
21 #include "ace/Thread_Mutex.h"
25 int
26 run_main (int, ACE_TCHAR *[])
28 ACE_START_TEST (ACE_TEXT ("Simple_Message_Block_Test"));
31 // Checks normal stack deletes.
32 ACE_Message_Block mb;
36 // Checks normal heap deletes.
37 ACE_Message_Block *mb = 0;
39 ACE_NEW_RETURN (mb, ACE_Message_Block, -1);
40 mb->release ();
44 // Checks continuation of message blocks on the stack.
45 ACE_Message_Block mb1 (1024);
46 ACE_Message_Block mb2 (1024);
48 mb1.cont (&mb2);
52 // Checks continuation of message blocks on the heap.
53 ACE_Message_Block *mb1;
54 ACE_Message_Block *mb2;
56 ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1);
57 ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1);
59 mb1->cont (mb2);
60 mb1->release ();
63 // Same set of tests but with locking_strategy set.
65 ACE_Lock_Adapter <ACE_SYNCH_MUTEX> mutex;
66 ACE_Lock *lock = &mutex;
69 // Checks normal stack deletes.
70 ACE_Message_Block mb;
71 mb.locking_strategy (lock);
75 // Checks normal heap deletes.
76 ACE_Message_Block *mb = 0;
77 ACE_NEW_RETURN (mb, ACE_Message_Block, -1);
78 mb->locking_strategy (lock);
79 mb->release ();
83 // Checks continuation of message blocks on the stack with one
84 // lock strategy.
85 ACE_Message_Block mb1 (1024);
86 ACE_Message_Block mb2 (1024);
88 mb1.locking_strategy (lock);
90 mb1.cont (&mb2);
94 // Checks continuation of message blocks on the heap with one
95 // lock strategy.
96 ACE_Message_Block *mb1;
97 ACE_Message_Block *mb2;
99 ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1);
100 ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1);
102 mb1->locking_strategy (lock);
104 mb1->cont (mb2);
105 mb1->release ();
109 // Checks continuation of message blocks on the stack with two
110 // lock strategy.
111 ACE_Message_Block mb1 (1024);
112 ACE_Message_Block mb2 (1024);
114 mb1.locking_strategy (lock);
115 mb2.locking_strategy (lock);
117 mb1.cont (&mb2);
121 // Checks continuation of message blocks on the heap with two
122 // lock strategy
123 ACE_Message_Block *mb1;
124 ACE_Message_Block *mb2;
126 ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1);
127 ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1);
129 mb1->locking_strategy (lock);
130 mb2->locking_strategy (lock);
132 mb1->cont (mb2);
133 mb1->release ();
137 // Checks continuation of message blocks on the heap with two
138 // lock strategy where the second one is a duplicate of the
139 // first
140 ACE_Message_Block *mb1;
141 ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1);
142 mb1->locking_strategy (lock);
144 ACE_Message_Block *mb2 = mb1->duplicate ();
146 mb1->cont (mb2);
147 mb1->release ();
152 // Checks continuation of message blocks on the heap with two
153 // different lock strategies
155 ACE_Lock_Adapter <ACE_SYNCH_MUTEX> lock1;
156 ACE_Lock_Adapter <ACE_SYNCH_MUTEX> lock2;
158 ACE_Message_Block *mb1;
159 ACE_Message_Block *mb2;
161 ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1);
162 ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1);
164 mb1->locking_strategy (&lock1);
165 mb2->locking_strategy (&lock2);
167 mb1->cont (mb2);
168 mb1->release ();
172 // Checks failure of copy when "virtual" allocation (using mark)
173 // is too small
174 char message[]="abcdefghijklmnop";
175 ACE_Message_Block mb1 (ACE_OS::strlen (message) + 1);
176 ACE_Message_Block mb2 (ACE_OS::strlen (message) + 1);
178 // Resize mb2 so that we mark for use less than the allocated buffer
179 if (mb2.size (ACE_OS::strlen (message) + 1 - 10) == -1)
181 ACE_ERROR ((LM_ERROR,
182 ACE_TEXT ("(%P|%t) Resize test failed ..\n")));
185 // We expect this to succeed
186 if (mb1.copy (message, ACE_OS::strlen (message) + 1) == -1)
188 ACE_ERROR ((LM_ERROR,
189 ACE_TEXT ("(%P|%t) Copy test failed ..\n")));
192 // We expect this to fail
193 if (mb2.copy (message, ACE_OS::strlen (message) + 1) != -1)
195 ACE_ERROR ((LM_ERROR,
196 ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n")));
199 // We also expect this to fail
200 if (mb2.copy (message) != -1)
202 ACE_ERROR ((LM_ERROR,
203 ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n")));
206 ACE_END_TEST;
207 return 0;