Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3574_Regression / test.cpp
blob3f2cd268f09770f4362c21eae1d52e7712be3012
1 #include "tao/StringSeqC.h"
3 int
4 ACE_TMAIN (int, ACE_TCHAR *[])
6 char const *str = "Some string";
8 CORBA::StringSeq seq;
9 seq.length (100);
10 for (CORBA::ULong i = 0; i < seq.length (); ++i)
12 seq[i] = str;
15 // Save a pointer to the whole buffer.
16 char const * const *wholebuf = seq.get_buffer ();
18 // This call should reinitialize the the 100th element
19 // (the fact that the shrunk elements are reinitialized is TAO
20 // specific but we test for it).
21 seq.length (99);
22 // No reallocation should happen for the buffer.
23 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
24 // And set the length to the same value
25 seq.length (99);
26 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
27 // We cannot be sure that the pointer to the reinitialized 100th
28 // element is different from the old one since memory manager can
29 // return the same pointer that we've just released but it must
30 // not be 0 and it must be an empty string.
31 ACE_TEST_ASSERT (wholebuf[99] != 0);
32 ACE_TEST_ASSERT (ACE_OS::strcmp (wholebuf[99], "") == 0);
34 // Extend the sequence to the original size.
35 seq.length (100);
36 // No reallocation should happen for the buffer.
37 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
38 // And now we can test absolutely legally that the 100th
39 // element was reinitialized as CORBA spec requires.
40 ACE_TEST_ASSERT (seq[99].in () != 0);
41 ACE_TEST_ASSERT (ACE_OS::strcmp (seq[99].in (), "") == 0);
42 seq.length (101);
43 // Reallocation should happen for the buffer.
44 ACE_TEST_ASSERT (seq.get_buffer () != wholebuf);
45 ACE_TEST_ASSERT (seq[100].in () != 0);
46 ACE_TEST_ASSERT (ACE_OS::strcmp (seq[100].in (), "") == 0);
48 return 0;