2 //=============================================================================
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 run_main (int, ACE_TCHAR
*[])
27 ACE_START_TEST (ACE_TEXT ("Simple_Message_Block_Test"));
30 // Checks normal stack deletes.
35 // Checks normal heap deletes.
36 ACE_Message_Block
*mb
= 0;
38 ACE_NEW_RETURN (mb
, ACE_Message_Block
, -1);
43 // Checks continuation of message blocks on the stack.
44 ACE_Message_Block
mb1 (1024);
45 ACE_Message_Block
mb2 (1024);
51 // Checks continuation of message blocks on the heap.
52 ACE_Message_Block
*mb1
;
53 ACE_Message_Block
*mb2
;
55 ACE_NEW_RETURN (mb1
, ACE_Message_Block (1024), -1);
56 ACE_NEW_RETURN (mb2
, ACE_Message_Block (1024), -1);
62 // Same set of tests but with locking_strategy set.
64 ACE_Lock_Adapter
<ACE_SYNCH_MUTEX
> mutex
;
65 ACE_Lock
*lock
= &mutex
;
68 // Checks normal stack deletes.
70 mb
.locking_strategy (lock
);
74 // Checks normal heap deletes.
75 ACE_Message_Block
*mb
= 0;
76 ACE_NEW_RETURN (mb
, ACE_Message_Block
, -1);
77 mb
->locking_strategy (lock
);
82 // Checks continuation of message blocks on the stack with one
84 ACE_Message_Block
mb1 (1024);
85 ACE_Message_Block
mb2 (1024);
87 mb1
.locking_strategy (lock
);
93 // Checks continuation of message blocks on the heap with one
95 ACE_Message_Block
*mb1
;
96 ACE_Message_Block
*mb2
;
98 ACE_NEW_RETURN (mb1
, ACE_Message_Block (1024), -1);
99 ACE_NEW_RETURN (mb2
, ACE_Message_Block (1024), -1);
101 mb1
->locking_strategy (lock
);
108 // Checks continuation of message blocks on the stack with two
110 ACE_Message_Block
mb1 (1024);
111 ACE_Message_Block
mb2 (1024);
113 mb1
.locking_strategy (lock
);
114 mb2
.locking_strategy (lock
);
120 // Checks continuation of message blocks on the heap with two
122 ACE_Message_Block
*mb1
;
123 ACE_Message_Block
*mb2
;
125 ACE_NEW_RETURN (mb1
, ACE_Message_Block (1024), -1);
126 ACE_NEW_RETURN (mb2
, ACE_Message_Block (1024), -1);
128 mb1
->locking_strategy (lock
);
129 mb2
->locking_strategy (lock
);
136 // Checks continuation of message blocks on the heap with two
137 // lock strategy where the second one is a duplicate of the
139 ACE_Message_Block
*mb1
;
140 ACE_NEW_RETURN (mb1
, ACE_Message_Block (1024), -1);
141 mb1
->locking_strategy (lock
);
143 ACE_Message_Block
*mb2
= mb1
->duplicate ();
151 // Checks continuation of message blocks on the heap with two
152 // different lock strategies
154 ACE_Lock_Adapter
<ACE_SYNCH_MUTEX
> lock1
;
155 ACE_Lock_Adapter
<ACE_SYNCH_MUTEX
> lock2
;
157 ACE_Message_Block
*mb1
;
158 ACE_Message_Block
*mb2
;
160 ACE_NEW_RETURN (mb1
, ACE_Message_Block (1024), -1);
161 ACE_NEW_RETURN (mb2
, ACE_Message_Block (1024), -1);
163 mb1
->locking_strategy (&lock1
);
164 mb2
->locking_strategy (&lock2
);
171 // Checks failure of copy when "virtual" allocation (using mark)
173 char message
[]="abcdefghijklmnop";
174 ACE_Message_Block
mb1 (ACE_OS::strlen (message
) + 1);
175 ACE_Message_Block
mb2 (ACE_OS::strlen (message
) + 1);
177 // Resize mb2 so that we mark for use less than the allocated buffer
178 if (mb2
.size (ACE_OS::strlen (message
) + 1 - 10) == -1)
180 ACE_ERROR ((LM_ERROR
,
181 ACE_TEXT ("(%P|%t) Resize test failed ..\n")));
184 // We expect this to succeed
185 if (mb1
.copy (message
, ACE_OS::strlen (message
) + 1) == -1)
187 ACE_ERROR ((LM_ERROR
,
188 ACE_TEXT ("(%P|%t) Copy test failed ..\n")));
191 // We expect this to fail
192 if (mb2
.copy (message
, ACE_OS::strlen (message
) + 1) != -1)
194 ACE_ERROR ((LM_ERROR
,
195 ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n")));
198 // We also expect this to fail
199 if (mb2
.copy (message
) != -1)
201 ACE_ERROR ((LM_ERROR
,
202 ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n")));