summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_3574_Regression/test.cpp
blob: 0e2c361dfa38a973a300ac27da62457c3202e7af (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
// $Id$

#include "tao/StringSeqC.h"

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  char const *str = "Some string";

  CORBA::StringSeq seq;
  seq.length (100);
  for (CORBA::ULong i = 0; i < seq.length (); ++i)
    {
      seq[i] = str;
    }

  // Save a pointer to the whole buffer.
  char const * const *wholebuf = seq.get_buffer ();

  // This call should reinitialize the the 100th element
  // (the fact that the shrunk elements are reinitialized is TAO
  // specific but we test for it).
  seq.length (99);
  // No reallocation should happen for the buffer.
  ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
  // And set the length to the same value
  seq.length (99);
  ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
  // We cannot be sure that the pointer to the reinitialized 100th
  // element is different from the old one since memory manager can
  // return the same pointer that we've just released but it must
  // not be 0 and it must be an empty string.
  ACE_TEST_ASSERT (wholebuf[99] != 0);
  ACE_TEST_ASSERT (ACE_OS::strcmp (wholebuf[99], "") == 0);

  // Extend the sequence to the original size.
  seq.length (100);
  // No reallocation should happen for the buffer.
  ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
  // And now we can test absolutely legally that the 100th
  // element was reinitialized as CORBA spec requires.
  ACE_TEST_ASSERT (seq[99].in () != 0);
  ACE_TEST_ASSERT (ACE_OS::strcmp (seq[99].in (), "") == 0);
  seq.length (101);
  // Reallocation should happen for the buffer.
  ACE_TEST_ASSERT (seq.get_buffer () != wholebuf);
  ACE_TEST_ASSERT (seq[100].in () != 0);
  ACE_TEST_ASSERT (ACE_OS::strcmp (seq[100].in (), "") == 0);

  return 0;
}