ReactOS  0.4.13-dev-698-g77671f0
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 
12 #include "cppunit/cppunit_proxy.h"
13 
14 // #include <stdlib.h> // for rand etc
15 
16 #if defined (_STLP_USE_NAMESPACES)
17 using namespace std;
18 #endif
19 
20 //
21 // TestCase class
22 //
23 class 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
33  CPPUNIT_TEST(find1);
34  CPPUNIT_TEST(find2);
35  CPPUNIT_TEST(construct_from_char);
36  CPPUNIT_TEST(bug_report);
37 #if !defined (_STLP_MEMBER_TEMPLATES)
39 #endif
40  CPPUNIT_TEST(test_saved_rope_iterators);
42 
43 protected:
44  void io();
45  void find1();
46  void find2();
47  void construct_from_char();
48  void bug_report();
49  void test_saved_rope_iterators();
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" );
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)
124 const char str[] = "ilcpsklryvmcpjnbpbwllsrehfmxrkecwitrsglrexvtjmxypu\
125 nbqfgxmuvgfajclfvenhyuhuorjosamibdnjdbeyhkbsomblto\
126 uujdrbwcrrcgbflqpottpegrwvgajcrgwdlpgitydvhedtusip\
127 pyvxsuvbvfenodqasajoyomgsqcpjlhbmdahyviuemkssdslde\
128 besnnngpesdntrrvysuipywatpfoelthrowhfexlwdysvspwlk\
129 fblfdf";
130 
131 crope create_rope( int len )
132 {
133  int l = len/2;
134  crope result;
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:
173  CPPUNIT_ASSERT(*i);
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 }
Definition: _rope.h:91
void find1()
Definition: rope_test.cpp:73
size_t size_type
Definition: _rope.h:1092
basic_ostringstream< char, char_traits< char >, allocator< char > > ostringstream
Definition: _iosfwd.h:127
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define equal(x, y)
Definition: reader.cc:56
static const size_t npos
Definition: _string_npos.h:26
GLdouble n
Definition: glext.h:7729
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
void bug_report()
Definition: rope_test.cpp:105
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
void test_saved_rope_iterators()
Definition: rope_test.cpp:155
const WCHAR * str
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
void io()
Definition: rope_test.cpp:57
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
r l[0]
Definition: byte_order.h:167
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define CPPUNIT_STOP_IGNORE
Definition: cppunit_mini.h:188
CPPUNIT_TEST_SUITE_REGISTRATION(RopeTest)
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
void construct_from_char()
Definition: rope_test.cpp:95
LOCAL char * rstr(char *s1, char *s2)
Definition: tree.c:165
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void find2()
Definition: rope_test.cpp:86
#define CPPUNIT_IGNORE
Definition: cppunit_mini.h:185
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
GLuint64EXT * result
Definition: glext.h:11304
int k
Definition: mpi.c:3369
const _CharT * c_str() const
Definition: _rope.c:1310
BOOL expected
Definition: store.c:2063