summaryrefslogtreecommitdiff
path: root/ACE/tests/Message_Block_Large_Copy_Test.cpp
blob: 3107b3ea07944fa58bdb9dfffc32db9476b8e2b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

//=============================================================================
/**
 *  @file    Message_Block_Large_Copy_Test.cpp
 *
 *  This test program tests large Message Block duplication and cloning.
 *
 *  @author Phillip LaBanca <labancap@ociweb.com>
 */
//=============================================================================


#include "test_config.h"
#include "ace/Message_Block.h"
#include "ace/OS_NS_string.h"

size_t
run_duplicate_test (const size_t msg_block_count,
                    const char * block,
                    const size_t msg_block_size)
{
    size_t rc = 0;

    ACE_Message_Block* mb_top = new ACE_Message_Block ();
    ACE_Message_Block* mb = mb_top;

    for (size_t j = 0; j != msg_block_count; ++j)
    {
      ACE_Message_Block* next = new ACE_Message_Block (block, msg_block_size);
      next->wr_ptr (msg_block_size);
      mb->cont (next);
      mb = next;
    }

    ACE_Message_Block* mb_test = mb_top->duplicate ();
    if (mb_test != 0)
    {
      rc = mb_test->total_size();
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
                  mb_top->reference_count ()));
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) duplicated: %@ %d %d\n"),
                  mb_test,
                  mb_test->total_size(),
                  mb_test->total_length()));
      mb_test-> release();
    }

    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
                mb_top->reference_count ()));

    mb_top-> release ();
    return rc;
}

size_t
run_clone_test (const size_t msg_block_count,
                const char * block,
                const size_t msg_block_size)
{
    size_t rc = 0;

    ACE_Message_Block* mb_top = new ACE_Message_Block ();
    ACE_Message_Block* mb = mb_top;

    for (size_t j = 0; j != msg_block_count; ++j)
    {
      ACE_Message_Block* next = new ACE_Message_Block (block, msg_block_size);
      next->wr_ptr (msg_block_size);
      mb->cont (next);
      mb = next;
    }

    ACE_Message_Block* mb_test = mb_top->clone ();
    if (mb_test != 0)
    {
      rc = mb_test->total_size();
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
                  mb_top->reference_count ()));
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) cloned: %@ %d %d\n"),
                  mb_test,
                  mb_test->total_size(),
                  mb_test->total_length()));
      mb_test-> release();
    }

    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) %u top reference_count ()\n"),
                mb_top->reference_count ()));

    mb_top-> release();
    return rc;
}

int
run_main (int , ACE_TCHAR *[])
{
  int rc = 0;

  ACE_START_TEST (ACE_TEXT ("Message_Block_Large_Copy_Test"));
  {
    // Message_Block size() and Length() of 24,000,000
    const size_t MSG_BLOCK_COUNT = 8000;
    const size_t MSG_BLOCK_SIZE  = 3000;
    const size_t MSG_BLOCK_TOTAL = MSG_BLOCK_COUNT * MSG_BLOCK_SIZE;

    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) %u blocks %u bytes each, total %u\n"),
                MSG_BLOCK_COUNT,
                MSG_BLOCK_SIZE,
                MSG_BLOCK_TOTAL));

    char block[MSG_BLOCK_SIZE];
    ACE_OS::memset (block, 'A', MSG_BLOCK_SIZE);

    size_t duplicate_total = run_duplicate_test (
      MSG_BLOCK_COUNT,
      block,
      MSG_BLOCK_SIZE);
    if (duplicate_total != MSG_BLOCK_TOTAL )
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT ("(%P|%t) duplicate(): returned total of %u\n"),
        duplicate_total));
      rc = 1;
    }

    size_t clone_total = run_clone_test (
      MSG_BLOCK_COUNT,
      block,
      MSG_BLOCK_SIZE);
    if (clone_total != MSG_BLOCK_TOTAL )
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT ("(%P|%t) clone(): returned total of %u \n"),
        clone_total));
      rc = 1;
    }

  }
  ACE_END_TEST;
  return rc;
}