Update contrib.
1 //Small header to get STLport numerous defines:
4 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
7 # if !defined (_STLP_USE_NO_IOSTREAMS)
12 #include "cppunit/cppunit_proxy.h"
14 // #include <stdlib.h> // for rand etc
16 #if defined (_STLP_USE_NAMESPACES)
23 class RopeTest : public CPPUNIT_NS::TestCase
25 CPPUNIT_TEST_SUITE(RopeTest);
26 #if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) || defined (_STLP_USE_NO_IOSTREAMS)
30 #if defined (_STLP_USE_NO_IOSTREAMS)
35 CPPUNIT_TEST(construct_from_char);
36 CPPUNIT_TEST(bug_report);
37 #if !defined (_STLP_MEMBER_TEMPLATES)
40 CPPUNIT_TEST(test_saved_rope_iterators);
41 CPPUNIT_TEST_SUITE_END();
47 void construct_from_char();
49 void test_saved_rope_iterators();
52 CPPUNIT_TEST_SUITE_REGISTRATION(RopeTest);
55 // tests implementation
59 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && !defined (_STLP_USE_NO_IOSTREAMS)
60 char const* cstr = "rope test string";
67 CPPUNIT_ASSERT( ostr );
68 CPPUNIT_ASSERT( ostr.str() == cstr );
73 void RopeTest::find1()
75 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
76 crope r("Fuzzy Wuzzy was a bear");
77 crope::size_type n = r.find( "hair" );
78 CPPUNIT_ASSERT( n == crope::npos );
82 CPPUNIT_ASSERT( n == (r.size() - 3) );
86 void RopeTest::find2()
88 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
89 crope r("Fuzzy Wuzzy was a bear");
90 crope::size_type n = r.find( 'e' );
91 CPPUNIT_ASSERT( n == (r.size() - 3) );
95 void RopeTest::construct_from_char()
97 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
99 char const* s = r.c_str();
100 CPPUNIT_ASSERT( '1' == s[0] && '\0' == s[1] );
104 // Test used for a bug report from Peter Hercek
105 void RopeTest::bug_report()
107 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
108 //first create a rope bigger than crope::_S_copy_max = 23
109 // so that any string addition is added to a new leaf
110 crope evilRope("12345678901234567890123_");
111 //crope* pSevenCharRope( new TRope("1234567") );
112 crope sevenCharRope0("12345678");
113 crope sevenCharRope1("1234567");
114 // add _Rope_RopeRep<c,a>::_S_alloc_granularity-1 = 7 characters
115 evilRope += "1234567"; // creates a new leaf
116 crope sevenCharRope2("1234567");
117 // add one more character to the leaf
118 evilRope += '8'; // here is the write beyond the allocated memory
119 CPPUNIT_ASSERT( strcmp(sevenCharRope2.c_str(), "1234567") == 0 );
123 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
124 const char str[] = "ilcpsklryvmcpjnbpbwllsrehfmxrkecwitrsglrexvtjmxypu\
125 nbqfgxmuvgfajclfvenhyuhuorjosamibdnjdbeyhkbsomblto\
126 uujdrbwcrrcgbflqpottpegrwvgajcrgwdlpgitydvhedtusip\
127 pyvxsuvbvfenodqasajoyomgsqcpjlhbmdahyviuemkssdslde\
128 besnnngpesdntrrvysuipywatpfoelthrowhfexlwdysvspwlk\
131 crope create_rope( int len )
138 for(int i = 0; i < len; ++i)
140 // char c = 'a' + rand() % ('z' - 'a');
141 result.append(1, /* c */ str[j++] );
147 result = create_rope(len/2);
148 result.append(create_rope(len/2));
155 void RopeTest::test_saved_rope_iterators()
157 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && \
158 defined (_STLP_MEMBER_TEMPLATES)
160 // Try and create a rope with a complex tree structure:
163 crope r = create_rope(300);
164 string expected(r.begin(), r.end());
165 CPPUNIT_ASSERT(expected.size() == r.size());
166 CPPUNIT_ASSERT(equal(expected.begin(), expected.end(), r.begin()));
167 crope::const_iterator i(r.begin()), j(r.end());
171 crope::const_iterator k;
172 // This initial read triggers the bug:
176 // Now make sure that i is incremented into the next leaf:
179 CPPUNIT_ASSERT(*i == expected[newpos]);
183 // Back up from stored value and continue: