Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Message_Block_Large_Copy_Test.cpp
blob44fb9bf15f6f904203409f9153509fe3a284d69d
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 *[])
103 int rc = 0;
105 ACE_START_TEST (ACE_TEXT ("Message_Block_Large_Copy_Test"));
108 // Message_Block size() and Length() of 24,000,000
109 const size_t MSG_BLOCK_COUNT = 8000;
110 const size_t MSG_BLOCK_SIZE = 3000;
111 const size_t MSG_BLOCK_TOTAL = MSG_BLOCK_COUNT * MSG_BLOCK_SIZE;
113 ACE_ERROR ((LM_DEBUG,
114 ACE_TEXT ("(%P|%t) %u blocks %u bytes each, total %u\n"),
115 MSG_BLOCK_COUNT,
116 MSG_BLOCK_SIZE,
117 MSG_BLOCK_TOTAL));
119 char block[MSG_BLOCK_SIZE];
120 ACE_OS::memset (block, 'A', MSG_BLOCK_SIZE);
122 size_t duplicate_total = run_duplicate_test (
123 MSG_BLOCK_COUNT,
124 block,
125 MSG_BLOCK_SIZE);
126 if (duplicate_total != MSG_BLOCK_TOTAL )
128 ACE_ERROR ((LM_ERROR,
129 ACE_TEXT ("(%P|%t) duplicate(): returned total of %u\n"),
130 duplicate_total));
131 rc = 1;
134 size_t clone_total = run_clone_test (
135 MSG_BLOCK_COUNT,
136 block,
137 MSG_BLOCK_SIZE);
138 if (clone_total != MSG_BLOCK_TOTAL )
140 ACE_ERROR ((LM_ERROR,
141 ACE_TEXT ("(%P|%t) clone(): returned total of %u \n"),
142 clone_total));
143 rc = 1;
147 ACE_END_TEST;
148 return rc;