ReactOS 0.4.15-dev-7961-gdcf9eb0
rope_test.cpp
Go to the documentation of this file.
1//Small header to get STLport numerous defines:
2#include <utility>
3
4#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
5# include <rope>
6
7# if !defined (_STLP_USE_NO_IOSTREAMS)
8# include <sstream>
9# endif
10#endif
11
13
14// #include <stdlib.h> // for rand etc
15
16#if defined (_STLP_USE_NAMESPACES)
17using namespace std;
18#endif
19
20//
21// TestCase class
22//
23class RopeTest : public CPPUNIT_NS::TestCase
24{
26#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) || defined (_STLP_USE_NO_IOSTREAMS)
28#endif
30#if defined (_STLP_USE_NO_IOSTREAMS)
32#endif
37#if !defined (_STLP_MEMBER_TEMPLATES)
39#endif
42
43protected:
44 void io();
45 void find1();
46 void find2();
48 void bug_report();
50};
51
53
54//
55// tests implementation
56//
58{
59#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && !defined (_STLP_USE_NO_IOSTREAMS)
60 char const* cstr = "rope test string";
61 crope rstr(cstr);
62
63 {
64 ostringstream ostr;
65 ostr << rstr;
66
67 CPPUNIT_ASSERT( ostr );
68 CPPUNIT_ASSERT( ostr.str() == cstr );
69 }
70#endif
71}
72
74{
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 );
79
80 n = r.find("ear");
81
82 CPPUNIT_ASSERT( n == (r.size() - 3) );
83#endif
84}
85
87{
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) );
92#endif
93}
94
96{
97#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
98 crope r('1');
99 char const* s = r.c_str();
100 CPPUNIT_ASSERT( '1' == s[0] && '\0' == s[1] );
101#endif
102}
103
104// Test used for a bug report from Peter Hercek
106{
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 );
120#endif
121}
122
123#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
124const char str[] = "ilcpsklryvmcpjnbpbwllsrehfmxrkecwitrsglrexvtjmxypu\
125nbqfgxmuvgfajclfvenhyuhuorjosamibdnjdbeyhkbsomblto\
126uujdrbwcrrcgbflqpottpegrwvgajcrgwdlpgitydvhedtusip\
127pyvxsuvbvfenodqasajoyomgsqcpjlhbmdahyviuemkssdslde\
128besnnngpesdntrrvysuipywatpfoelthrowhfexlwdysvspwlk\
129fblfdf";
130
131crope create_rope( int len )
132{
133 int l = len/2;
135 if(l <= 2)
136 {
137 static int j = 0;
138 for(int i = 0; i < len; ++i)
139 {
140 // char c = 'a' + rand() % ('z' - 'a');
141 result.append(1, /* c */ str[j++] );
142 j %= sizeof(str);
143 }
144 }
145 else
146 {
147 result = create_rope(len/2);
148 result.append(create_rope(len/2));
149 }
150 return result;
151}
152
153#endif
154
156{
157#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && \
158 defined (_STLP_MEMBER_TEMPLATES)
159 //
160 // Try and create a rope with a complex tree structure:
161 //
162 // srand(0);
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());
168 int pos = 0;
169 while(i != j)
170 {
172 // This initial read triggers the bug:
174 k = i;
175 int newpos = pos;
176 // Now make sure that i is incremented into the next leaf:
177 while(i != j)
178 {
179 CPPUNIT_ASSERT(*i == expected[newpos]);
180 ++i;
181 ++newpos;
182 }
183 // Back up from stored value and continue:
184 i = k;
185 ++i;
186 ++pos;
187 }
188#endif
189}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
r l[0]
Definition: byte_order.h:168
void find1()
Definition: rope_test.cpp:73
CPPUNIT_TEST(bug_report)
CPPUNIT_TEST(test_saved_rope_iterators)
void find2()
Definition: rope_test.cpp:86
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST_SUITE(RopeTest)
CPPUNIT_TEST(io)
void bug_report()
Definition: rope_test.cpp:105
void construct_from_char()
Definition: rope_test.cpp:95
CPPUNIT_TEST(find1)
CPPUNIT_TEST(find2)
CPPUNIT_TEST(construct_from_char)
void test_saved_rope_iterators()
Definition: rope_test.cpp:155
void io()
Definition: rope_test.cpp:57
_String str() const
Definition: _sstream.h:184
Definition: _rope.h:1087
const _CharT * c_str() const
Definition: _rope.c:1310
size_t size_type
Definition: _rope.h:1092
#define CPPUNIT_STOP_IGNORE
Definition: cppunit_mini.h:188
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
BOOL expected
Definition: store.c:2063
int k
Definition: mpi.c:3369
Definition: features.h:417
#define equal(x, y)
Definition: reader.cc:56
const WCHAR * str
LOCAL char * rstr(char *s1, char *s2)
Definition: tree.c:165