Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3574_Regression / test.cpp
bloba949254b5ec554bf4ee76ee677a0ee7155dc7e8c
1 #include "tao/StringSeqC.h"
3 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x660) && (__BORLANDC__ <= 0x760)
4 # pragma option push -w-8011
5 #endif
7 int
8 ACE_TMAIN (int, ACE_TCHAR *[])
10 char const *str = "Some string";
12 CORBA::StringSeq seq;
13 seq.length (100);
14 for (CORBA::ULong i = 0; i < seq.length (); ++i)
16 seq[i] = str;
19 // Save a pointer to the whole buffer.
20 char const * const *wholebuf = seq.get_buffer ();
22 // This call should reinitialize the the 100th element
23 // (the fact that the shrunk elements are reinitialized is TAO
24 // specific but we test for it).
25 seq.length (99);
26 // No reallocation should happen for the buffer.
27 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
28 // And set the length to the same value
29 seq.length (99);
30 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
31 // We cannot be sure that the pointer to the reinitialized 100th
32 // element is different from the old one since memory manager can
33 // return the same pointer that we've just released but it must
34 // not be 0 and it must be an empty string.
35 ACE_TEST_ASSERT (wholebuf[99] != 0);
36 ACE_TEST_ASSERT (ACE_OS::strcmp (wholebuf[99], "") == 0);
38 // Extend the sequence to the original size.
39 seq.length (100);
40 // No reallocation should happen for the buffer.
41 ACE_TEST_ASSERT (seq.get_buffer () == wholebuf);
42 // And now we can test absolutely legally that the 100th
43 // element was reinitialized as CORBA spec requires.
44 ACE_TEST_ASSERT (seq[99].in () != 0);
45 ACE_TEST_ASSERT (ACE_OS::strcmp (seq[99].in (), "") == 0);
46 seq.length (101);
47 // Reallocation should happen for the buffer.
48 ACE_TEST_ASSERT (seq.get_buffer () != wholebuf);
49 ACE_TEST_ASSERT (seq[100].in () != 0);
50 ACE_TEST_ASSERT (ACE_OS::strcmp (seq[100].in (), "") == 0);
52 return 0;
55 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x660) && (__BORLANDC__ <= 0x760)
56 # pragma option pop
57 #endif