Compile fixes
[ACE_TAO.git] / ACE / tests / Message_Block_Large_Copy_Test.cpp
blob3107b3ea07944fa58bdb9dfffc32db9476b8e2b5
2 //=============================================================================
3 /**
4 * @file Message_Block_Large_Copy_Test.cpp
6 * This test program tests large Message Block duplication and cloning.
8 * @author Phillip LaBanca <labancap@ociweb.com>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Message_Block.h"
15 #include "ace/OS_NS_string.h"
17 size_t
18 run_duplicate_test (const size_t msg_block_count,
19 const char * block,
20 const size_t msg_block_size)
22 size_t rc = 0;
24 ACE_Message_Block* mb_top = new ACE_Message_Block ();
25 ACE_Message_Block* mb = mb_top;
27 for (size_t j = 0; j != msg_block_count; ++j)
29 ACE_Message_Block* next = new ACE_Message_Block (block, msg_block_size);
30 next->wr_ptr (msg_block_size);
31 mb->cont (next);
32 mb = next;
35 ACE_Message_Block* mb_test = mb_top->duplicate ();
36 if (mb_test != 0)
38 rc = mb_test->total_size();
39 ACE_ERROR ((LM_DEBUG,
40 ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
41 mb_top->reference_count ()));
42 ACE_ERROR ((LM_DEBUG,
43 ACE_TEXT ("(%P|%t) duplicated: %@ %d %d\n"),
44 mb_test,
45 mb_test->total_size(),
46 mb_test->total_length()));
47 mb_test-> release();
50 ACE_ERROR ((LM_DEBUG,
51 ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
52 mb_top->reference_count ()));
54 mb_top-> release ();
55 return rc;
58 size_t
59 run_clone_test (const size_t msg_block_count,
60 const char * block,
61 const size_t msg_block_size)
63 size_t rc = 0;
65 ACE_Message_Block* mb_top = new ACE_Message_Block ();
66 ACE_Message_Block* mb = mb_top;
68 for (size_t j = 0; j != msg_block_count; ++j)
70 ACE_Message_Block* next = new ACE_Message_Block (block, msg_block_size);
71 next->wr_ptr (msg_block_size);
72 mb->cont (next);
73 mb = next;
76 ACE_Message_Block* mb_test = mb_top->clone ();
77 if (mb_test != 0)
79 rc = mb_test->total_size();
80 ACE_ERROR ((LM_DEBUG,
81 ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
82 mb_top->reference_count ()));
83 ACE_ERROR ((LM_DEBUG,
84 ACE_TEXT ("(%P|%t) cloned: %@ %d %d\n"),
85 mb_test,
86 mb_test->total_size(),
87 mb_test->total_length()));
88 mb_test-> release();
91 ACE_ERROR ((LM_DEBUG,
92 ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
93 mb_top->reference_count ()));
95 mb_top-> release();
96 return rc;
99 int
100 run_main (int , ACE_TCHAR *[])
102 int rc = 0;
104 ACE_START_TEST (ACE_TEXT ("Message_Block_Large_Copy_Test"));
106 // Message_Block size() and Length() of 24,000,000
107 const size_t MSG_BLOCK_COUNT = 8000;
108 const size_t MSG_BLOCK_SIZE = 3000;
109 const size_t MSG_BLOCK_TOTAL = MSG_BLOCK_COUNT * MSG_BLOCK_SIZE;
111 ACE_ERROR ((LM_DEBUG,
112 ACE_TEXT ("(%P|%t) %u blocks %u bytes each, total %u\n"),
113 MSG_BLOCK_COUNT,
114 MSG_BLOCK_SIZE,
115 MSG_BLOCK_TOTAL));
117 char block[MSG_BLOCK_SIZE];
118 ACE_OS::memset (block, 'A', MSG_BLOCK_SIZE);
120 size_t duplicate_total = run_duplicate_test (
121 MSG_BLOCK_COUNT,
122 block,
123 MSG_BLOCK_SIZE);
124 if (duplicate_total != MSG_BLOCK_TOTAL )
126 ACE_ERROR ((LM_ERROR,
127 ACE_TEXT ("(%P|%t) duplicate(): returned total of %u\n"),
128 duplicate_total));
129 rc = 1;
132 size_t clone_total = run_clone_test (
133 MSG_BLOCK_COUNT,
134 block,
135 MSG_BLOCK_SIZE);
136 if (clone_total != MSG_BLOCK_TOTAL )
138 ACE_ERROR ((LM_ERROR,
139 ACE_TEXT ("(%P|%t) clone(): returned total of %u \n"),
140 clone_total));
141 rc = 1;
145 ACE_END_TEST;
146 return rc;