ReactOS 0.4.15-dev-8145-ga541a46
StringTest Class Reference
Inheritance diagram for StringTest:
Collaboration diagram for StringTest:

Protected Member Functions

void constructor ()
 
void trivial_char_compare ()
 
void reserve ()
 
void erase ()
 
void data ()
 
void c_str ()
 
void null_char ()
 
void insert ()
 
void replace ()
 
void resize ()
 
void short_string ()
 
void find ()
 
void bogus_edge_find ()
 
void rfind ()
 
void find_last_of ()
 
void find_last_not_of ()
 
void copy ()
 
void assign ()
 
void mt ()
 
void short_string_optim_bug ()
 
void compare ()
 
void template_expression ()
 
void te_tmp ()
 
void oper_tmp ()
 
void template_wexpression ()
 
void io ()
 
void allocator_with_state ()
 
void capacity ()
 
void concat24 ()
 

Static Protected Member Functions

static string func (const string &par)
 

Private Member Functions

 CPPUNIT_TEST_SUITE (StringTest)
 
 CPPUNIT_TEST (constructor)
 
 CPPUNIT_TEST (trivial_char_compare)
 
 CPPUNIT_TEST (reserve)
 
 CPPUNIT_TEST (assign)
 
 CPPUNIT_TEST (erase)
 
 CPPUNIT_TEST (data)
 
 CPPUNIT_TEST (c_str)
 
 CPPUNIT_TEST (null_char)
 
 CPPUNIT_TEST (insert)
 
 CPPUNIT_TEST (replace)
 
 CPPUNIT_TEST (resize)
 
 CPPUNIT_TEST (short_string)
 
 CPPUNIT_TEST (find)
 
 CPPUNIT_TEST (bogus_edge_find)
 
 CPPUNIT_TEST (rfind)
 
 CPPUNIT_TEST (find_last_of)
 
 CPPUNIT_TEST (find_last_not_of)
 
 CPPUNIT_TEST (copy)
 
 CPPUNIT_TEST (mt)
 
 CPPUNIT_TEST (short_string_optim_bug)
 
 CPPUNIT_TEST (compare)
 
 CPPUNIT_TEST (template_expression)
 
 CPPUNIT_TEST (te_tmp)
 
 CPPUNIT_TEST (oper_tmp)
 
 CPPUNIT_TEST (template_wexpression)
 
 CPPUNIT_TEST (io)
 
 CPPUNIT_TEST (allocator_with_state)
 
 CPPUNIT_TEST (capacity)
 
 CPPUNIT_TEST (concat24)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Attributes

 CPPUNIT_IGNORE
 
 CPPUNIT_STOP_IGNORE
 

Detailed Description

Definition at line 47 of file string_test.cpp.

Member Function Documentation

◆ allocator_with_state()

void StringTest::allocator_with_state ( )
protected

Definition at line 1300 of file string_test.cpp.

1301{
1302#if !(defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO))
1303
1304 char buf1[1024];
1305 StackAllocator<char> stack1(buf1, buf1 + sizeof(buf1));
1306
1307 char buf2[1024];
1308 StackAllocator<char> stack2(buf2, buf2 + sizeof(buf2));
1309
1311 {
1312 StackString str1("string stack1", stack1);
1313 StackString str1Cpy(str1);
1314
1315 StackString str2("string stack2", stack2);
1316 StackString str2Cpy(str2);
1317
1318 str1.swap(str2);
1319
1320 CPPUNIT_ASSERT( str1.get_allocator().swaped() );
1321 CPPUNIT_ASSERT( str2.get_allocator().swaped() );
1322
1323 CPPUNIT_ASSERT( str1 == str2Cpy );
1324 CPPUNIT_ASSERT( str2 == str1Cpy );
1325 CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
1326 CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
1327 }
1328 CPPUNIT_ASSERT( stack1.ok() );
1329 CPPUNIT_ASSERT( stack2.ok() );
1330 stack1.reset(); stack2.reset();
1331
1332 {
1333 StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
1334 StackString str1Cpy(str1);
1335
1336 StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
1337 StackString str2Cpy(str2);
1338
1339 str1.swap(str2);
1340
1341 CPPUNIT_ASSERT( str1.get_allocator().swaped() );
1342 CPPUNIT_ASSERT( str2.get_allocator().swaped() );
1343
1344 CPPUNIT_ASSERT( str1 == str2Cpy );
1345 CPPUNIT_ASSERT( str2 == str1Cpy );
1346 CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
1347 CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
1348 }
1349 CPPUNIT_ASSERT( stack1.ok() );
1350 CPPUNIT_ASSERT( stack2.ok() );
1351 stack1.reset(); stack2.reset();
1352
1353
1354 {
1355 StackString str1("string stack1", stack1);
1356 StackString str1Cpy(str1);
1357
1358 StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
1359 StackString str2Cpy(str2);
1360
1361 str1.swap(str2);
1362
1363 CPPUNIT_ASSERT( str1.get_allocator().swaped() );
1364 CPPUNIT_ASSERT( str2.get_allocator().swaped() );
1365
1366 CPPUNIT_ASSERT( str1 == str2Cpy );
1367 CPPUNIT_ASSERT( str2 == str1Cpy );
1368 CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
1369 CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
1370 }
1371 CPPUNIT_ASSERT( stack1.ok() );
1372 CPPUNIT_ASSERT( stack2.ok() );
1373 stack1.reset(); stack2.reset();
1374
1375
1376 {
1377 StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
1378 StackString str1Cpy(str1);
1379
1380 StackString str2("string stack2", stack2);
1381 StackString str2Cpy(str2);
1382
1383 str1.swap(str2);
1384
1385 CPPUNIT_ASSERT( str1.get_allocator().swaped() );
1386 CPPUNIT_ASSERT( str2.get_allocator().swaped() );
1387
1388 CPPUNIT_ASSERT( str1 == str2Cpy );
1389 CPPUNIT_ASSERT( str2 == str1Cpy );
1390 CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
1391 CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
1392 }
1393 CPPUNIT_ASSERT( stack1.ok() );
1394 CPPUNIT_ASSERT( stack2.ok() );
1395 stack1.reset(); stack2.reset();
1396#endif
1397}
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200

◆ assign()

void StringTest::assign ( )
protected

Definition at line 854 of file string_test.cpp.

855{
856 string s;
857 char const* cstr = "test string for assign";
858
859 s.assign(cstr, cstr + 22);
860 CPPUNIT_ASSERT( s == "test string for assign" );
861
862 string s2("other test string");
863 s.assign(s2);
864 CPPUNIT_ASSERT( s == s2 );
865
866 static string str1;
867 static string str2;
868
869 // short string optim:
870 str1 = "123456";
871 // longer than short string:
872 str2 = "1234567890123456789012345678901234567890";
873
874 CPPUNIT_ASSERT(str1[5] == '6');
875 CPPUNIT_ASSERT(str2[29] == '0');
876}
GLdouble s
Definition: gl.h:2039
struct S2 s2

◆ bogus_edge_find()

void StringTest::bogus_edge_find ( )
protected

Definition at line 663 of file string_test.cpp.

664{
665 /* ISO/IEC 14882 2003, 21.3.6.1 basic_string::find [lib.string::find]
666 *
667 * size_type find(const basic_string<charT,traits,Allocator>& str,
668 * size_type pos = 0) const;
669 * Effects: Determines the lowest position xpos, if possible, such that
670 * both of the following conditions obtain:
671 * pos <= xpos and xpos + str.size() <= size();
672 * at(xpos+I) == str.at(I) for all elements I of the string controlled by str.
673 * Returns: xpos if the function can determine such a value for xpos. Otherwise,
674 * returns npos.
675 * Notes: Uses traits::eq().
676 *
677 * ===
678 * So, from formal point of view
679 * string s; string::size_type p = s.find( "", 0, 0 );
680 * should return 0 in p, i.e. position out-of-bound of string, so
681 * code like following is bad:
682 * string s;
683 *
684 * string::size_type p = s.find( "", 0, 0 );
685 *
686 * ...
687 *
688 * if ( p != string::npos ) { // normal
689 * char ch = s[p]; // Arghhhhhhhhhh
690 * }
691 *
692 * People near Standard commete has opinion opposite to my. Even if it looks
693 * like bogus behaviour for me, it should be fixed.
694 */
695
696 {
697 string s;
698 string::size_type p = s.find( "", 0, 0 );
699
700 /* CPPUNIT_CHECK( p == string::npos ); */
701 CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it?
702 }
703 {
704 string s( "123" );
705 string::size_type p = s.find( "", 0, 0 );
706
707 CPPUNIT_CHECK( p == 0 );
708 }
709 {
710 string s( "123" );
711 string::size_type p = s.find( "", 1, 0 );
712
713 CPPUNIT_CHECK( p == 1 );
714 }
715 {
716 string s( "" );
717 string::size_type p = s.find( "", 1, 0 );
718
719 CPPUNIT_CHECK( p == string::npos );
720 }
721 {
722 string s( "123" );
723 string::size_type p = s.find( "", 3, 0 );
724
725 CPPUNIT_CHECK( p == 3 ); // bogus result, isn't it?
726 }
727 {
728 string s;
729 string::size_type p = s.rfind( "", 0, 0 );
730
731 /* CPPUNIT_CHECK( p == string::npos ); */
732 CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it?
733 }
734 {
735 string s( "123" );
736 string::size_type p = s.rfind( "", 0, 0 );
737
738 CPPUNIT_CHECK( p == 0 );
739 }
740 {
741 string s( "123" );
742 string::size_type p = s.rfind( "", 1, 0 );
743
744 CPPUNIT_CHECK( p == 1 );
745 }
746 {
747 string s( "" );
748 string::size_type p = s.rfind( "", 1, 0 );
749
750 CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it?
751 }
752 {
753 string s( "123" );
754 string::size_type p = s.rfind( "", 3, 0 );
755
756 CPPUNIT_CHECK( p == 3 ); // bogus result, isn't it?
757 }
758}
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195
GLfloat GLfloat p
Definition: glext.h:8902

◆ c_str()

void StringTest::c_str ( )
protected

Definition at line 410 of file string_test.cpp.

411{
412 string low( "2004-01-01" );
413 string xx;
414 string yy;
415
416 CPPUNIT_ASSERT( *(yy.c_str()) == '\0' ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 1
417
418 // Blocks A and B should follow each other.
419 // Block A:
420 xx = "123456";
421 xx += low;
422 CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234562004-01-01" ) == 0 );
423 // End of block A
424
425 // Block B:
426 xx = "1234";
427 xx += ";";
428 CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234;" ) == 0 );
429 // End of block B
430}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
const _CharT * c_str() const
Definition: _string.h:949
int xx
Definition: npserver.c:29

Referenced by erase().

◆ capacity()

void StringTest::capacity ( )
protected

Definition at line 1399 of file string_test.cpp.

1400{
1401 string s;
1402
1403 CPPUNIT_CHECK( s.capacity() > 0 );
1404 CPPUNIT_CHECK( s.capacity() < s.max_size() );
1405 CPPUNIT_CHECK( s.capacity() >= s.size() );
1406
1407#ifndef _STLP_SHORT_STRING_SZ
1408# define _STLP_SHORT_STRING_SZ 16 // see stlport/stl/_string_base.h
1409#endif
1410
1411 for ( int i = 0; i < _STLP_SHORT_STRING_SZ + 2; ++i ) {
1412 s += ' ';
1413 CPPUNIT_CHECK( s.capacity() > 0 );
1414 CPPUNIT_CHECK( s.capacity() < s.max_size() );
1415 CPPUNIT_CHECK( s.capacity() >= s.size() );
1416 }
1417}
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
#define _STLP_SHORT_STRING_SZ

◆ compare()

void StringTest::compare ( )
protected

Definition at line 904 of file string_test.cpp.

905{
906 string str1("abcdef");
907 string str2;
908
909 str2 = "abcdef";
910 CPPUNIT_ASSERT( str1.compare(str2) == 0 );
911 str2 = "abcde";
912 CPPUNIT_ASSERT( str1.compare(str2) > 0 );
913 str2 = "abcdefg";
914 CPPUNIT_ASSERT( str1.compare(str2) < 0 );
915
916 CPPUNIT_ASSERT( str1.compare("abcdef") == 0 );
917 CPPUNIT_ASSERT( str1.compare("abcde") > 0 );
918 CPPUNIT_ASSERT( str1.compare("abcdefg") < 0 );
919
920 str2 = "cde";
921 CPPUNIT_ASSERT( str1.compare(2, 3, str2) == 0 );
922 str2 = "cd";
923 CPPUNIT_ASSERT( str1.compare(2, 3, str2) > 0 );
924 str2 = "cdef";
925 CPPUNIT_ASSERT( str1.compare(2, 3, str2) < 0 );
926
927 str2 = "abcdef";
928 CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 3) == 0 );
929 CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 2) > 0 );
930 CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 4) < 0 );
931
932 CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 3) == 0 );
933 CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 2) > 0 );
934 CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 4) < 0 );
935}

◆ concat24()

void StringTest::concat24 ( )
protected

Definition at line 1419 of file string_test.cpp.

1420{
1421 string s = string( "123456789012345678901234" ) + string( "123456789012345678901234" );
1422
1423 CPPUNIT_CHECK( s.length() == 48 );
1424 CPPUNIT_CHECK( s[23] == '4' );
1425 CPPUNIT_CHECK( s[24] == '1' );
1426 CPPUNIT_CHECK( s[47] == '4' );
1427}

◆ constructor()

void StringTest::constructor ( )
protected

Definition at line 169 of file string_test.cpp.

170{
171#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
172 try {
173 string s((size_t)-1, 'a');
175 }
176 catch (length_error const&) {
177 }
178 catch (...) {
179 //Expected exception is length_error:
181 }
182#endif
183}
#define CPPUNIT_FAIL
Definition: cppunit_mini.h:206

◆ copy()

void StringTest::copy ( )
protected

Definition at line 823 of file string_test.cpp.

824{
825 string s("foo");
826 char dest[4];
827 dest[0] = dest[1] = dest[2] = dest[3] = 1;
828 s.copy(dest, 4);
829 int pos = 0;
830 CPPUNIT_ASSERT( dest[pos++] == 'f' );
831 CPPUNIT_ASSERT( dest[pos++] == 'o' );
832 CPPUNIT_ASSERT( dest[pos++] == 'o' );
833 CPPUNIT_ASSERT( dest[pos++] == 1 );
834
835 dest[0] = dest[1] = dest[2] = dest[3] = 1;
836 s.copy(dest, 4, 2);
837 pos = 0;
838 CPPUNIT_ASSERT( dest[pos++] == 'o' );
839 CPPUNIT_ASSERT( dest[pos++] == 1 );
840
841#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
842 try {
843 s.copy(dest, 4, 5);
845 }
846 catch (out_of_range const&) {
847 }
848 catch ( ... ) {
850 }
851#endif
852}
static char * dest
Definition: rtl.c:135

◆ CPPUNIT_TEST() [1/29]

StringTest::CPPUNIT_TEST ( allocator_with_state  )
private

◆ CPPUNIT_TEST() [2/29]

StringTest::CPPUNIT_TEST ( assign  )
private

◆ CPPUNIT_TEST() [3/29]

StringTest::CPPUNIT_TEST ( bogus_edge_find  )
private

◆ CPPUNIT_TEST() [4/29]

StringTest::CPPUNIT_TEST ( c_str  )
private

◆ CPPUNIT_TEST() [5/29]

StringTest::CPPUNIT_TEST ( capacity  )
private

◆ CPPUNIT_TEST() [6/29]

StringTest::CPPUNIT_TEST ( compare  )
private

◆ CPPUNIT_TEST() [7/29]

StringTest::CPPUNIT_TEST ( concat24  )
private

◆ CPPUNIT_TEST() [8/29]

StringTest::CPPUNIT_TEST ( constructor  )
private

◆ CPPUNIT_TEST() [9/29]

StringTest::CPPUNIT_TEST ( copy  )
private

◆ CPPUNIT_TEST() [10/29]

StringTest::CPPUNIT_TEST ( data  )
private

◆ CPPUNIT_TEST() [11/29]

StringTest::CPPUNIT_TEST ( erase  )
private

◆ CPPUNIT_TEST() [12/29]

StringTest::CPPUNIT_TEST ( find  )
private

◆ CPPUNIT_TEST() [13/29]

StringTest::CPPUNIT_TEST ( find_last_not_of  )
private

◆ CPPUNIT_TEST() [14/29]

StringTest::CPPUNIT_TEST ( find_last_of  )
private

◆ CPPUNIT_TEST() [15/29]

StringTest::CPPUNIT_TEST ( insert  )
private

◆ CPPUNIT_TEST() [16/29]

StringTest::CPPUNIT_TEST ( io  )
private

◆ CPPUNIT_TEST() [17/29]

StringTest::CPPUNIT_TEST ( mt  )
private

◆ CPPUNIT_TEST() [18/29]

StringTest::CPPUNIT_TEST ( null_char  )
private

◆ CPPUNIT_TEST() [19/29]

StringTest::CPPUNIT_TEST ( oper_tmp  )
private

◆ CPPUNIT_TEST() [20/29]

StringTest::CPPUNIT_TEST ( replace  )
private

◆ CPPUNIT_TEST() [21/29]

StringTest::CPPUNIT_TEST ( reserve  )
private

◆ CPPUNIT_TEST() [22/29]

StringTest::CPPUNIT_TEST ( resize  )
private

◆ CPPUNIT_TEST() [23/29]

StringTest::CPPUNIT_TEST ( rfind  )
private

◆ CPPUNIT_TEST() [24/29]

StringTest::CPPUNIT_TEST ( short_string  )
private

◆ CPPUNIT_TEST() [25/29]

StringTest::CPPUNIT_TEST ( short_string_optim_bug  )
private

◆ CPPUNIT_TEST() [26/29]

StringTest::CPPUNIT_TEST ( te_tmp  )
private

◆ CPPUNIT_TEST() [27/29]

StringTest::CPPUNIT_TEST ( template_expression  )
private

◆ CPPUNIT_TEST() [28/29]

StringTest::CPPUNIT_TEST ( template_wexpression  )
private

◆ CPPUNIT_TEST() [29/29]

StringTest::CPPUNIT_TEST ( trivial_char_compare  )
private

◆ CPPUNIT_TEST_SUITE()

StringTest::CPPUNIT_TEST_SUITE ( StringTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

StringTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ data()

void StringTest::data ( )
protected

Definition at line 375 of file string_test.cpp.

376{
377 string xx;
378
379 CPPUNIT_ASSERT( xx.data() != 0 ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 3
380#if 0
381 /* This test really not required: in ISO-IEC-14882:1998(E) paragraph 3 stated:
382 * '... and can have zero added to it', again: 'CAN', but not 'MUST'.
383 * That's why I am comment this test. But I don't remove it due to I had
384 * unevident problem with misinterpretation of data() return (i.e. data()
385 * and c_str() provide different functionality!) and expect that this is
386 * more-or-less common pitfall.
387 * - ptr
388 */
389 string low( "2004-01-01" );
390 // Blocks A and B should follow each other.
391 // Block A:
392 xx = "123456";
393 xx += low;
394 if ( strcmp( xx.data(), "1234562004-01-01" ) != 0 ) {
395 return -1;
396 }
397 // End of block A
398
399 // Block B:
400 xx = "1234";
401 xx += ";";
402
403 if ( strcmp( xx.data(), "1234;" ) != 0 ) {
404 return -1;
405 }
406 // End of block B
407#endif
408}

◆ erase()

void StringTest::erase ( )
protected

Definition at line 325 of file string_test.cpp.

326{
327 char const* c_str = "Hello, World!";
328 string str(c_str);
330
331 str.erase(str.begin() + 1, str.end() - 1); // Erase all but first and last.
332
333 size_t i;
334 for (i = 0; i < str.size(); ++i) {
335 switch ( i ) {
336 case 0:
337 CPPUNIT_ASSERT( str[i] == 'H' );
338 break;
339 case 1:
340 CPPUNIT_ASSERT( str[i] == '!' );
341 break;
342 default:
344 }
345 }
346
347 str.insert(1, c_str);
348 str.erase(str.begin()); // Erase first element.
349 str.erase(str.end() - 1); // Erase last element.
351 str.clear(); // Erase all.
352 CPPUNIT_ASSERT( str.empty() );
353
354 str = c_str;
356
357 str.erase(1, str.size() - 1); // Erase all but first and last.
358 for (i = 0; i < str.size(); i++) {
359 switch ( i ) {
360 case 0:
361 CPPUNIT_ASSERT( str[i] == 'H' );
362 break;
363 case 1:
364 CPPUNIT_ASSERT( str[i] == '!' );
365 break;
366 default:
368 }
369 }
370
371 str.erase(1);
372 CPPUNIT_ASSERT( str == "H" );
373}
void c_str()
const WCHAR * str

◆ find()

void StringTest::find ( )
protected

Definition at line 638 of file string_test.cpp.

639{
640 string s("one two three one two three");
641 CPPUNIT_ASSERT( s.find("one") == 0 );
642 CPPUNIT_ASSERT( s.find('t') == 4 );
643 CPPUNIT_ASSERT( s.find('t', 5) == 8 );
644 //We are trying to get a const reference to the npos string static member to
645 //force the compiler to allocate memory for this variable. It is used to reveal
646 //a bug of STLport which was simply declaring npos without instanciating it.
647#if defined (STLPORT) && defined (_STLP_STATIC_CONST_INIT_BUG)
648 string::size_type const& npos_local = string::npos;
649#else
650# define npos_local string::npos
651#endif
652 CPPUNIT_ASSERT( s.find("four") == npos_local );
653 CPPUNIT_ASSERT( s.find("one", string::npos) == npos_local );
654
655 CPPUNIT_ASSERT( s.find_first_of("abcde") == 2 );
656
657 CPPUNIT_ASSERT( s.find_first_not_of("enotw ") == 9 );
658
659 string empty;
660 CPPUNIT_ASSERT( s.substr(s.find(empty), empty.size()) == empty );
661}
static const WCHAR empty[]
Definition: main.c:47
#define npos_local

◆ find_last_not_of()

void StringTest::find_last_not_of ( )
protected

Definition at line 799 of file string_test.cpp.

800{
801 // 21.3.6.6
802 string s("one two three one two three");
803
804 CPPUNIT_ASSERT( s.find_last_not_of("ehortw ") == 15 );
805
806 string test( "aba" );
807
808 CPPUNIT_CHECK( test.find_last_not_of( "a", 2, 1 ) == 1 );
809 CPPUNIT_CHECK( test.find_last_not_of( "b", 2, 1 ) == 2 );
810 CPPUNIT_CHECK( test.find_last_not_of( "a", 1, 1 ) == 1 );
811 CPPUNIT_CHECK( test.find_last_not_of( "b", 1, 1 ) == 0 );
812 CPPUNIT_CHECK( test.find_last_not_of( "a", 0, 1 ) == string::npos );
813 CPPUNIT_CHECK( test.find_last_not_of( "b", 0, 1 ) == 0 );
814
815 CPPUNIT_CHECK( test.find_last_not_of( 'a', 2 ) == 1 );
816 CPPUNIT_CHECK( test.find_last_not_of( 'b', 2 ) == 2 );
817 CPPUNIT_CHECK( test.find_last_not_of( 'a', 1 ) == 1 );
818 CPPUNIT_CHECK( test.find_last_not_of( 'b', 1 ) == 0 );
819 CPPUNIT_CHECK( test.find_last_not_of( 'a', 0 ) == string::npos );
820 CPPUNIT_CHECK( test.find_last_not_of( 'b', 0 ) == 0 );
821}
#define test
Definition: rosglue.h:37

◆ find_last_of()

void StringTest::find_last_of ( )
protected

Definition at line 781 of file string_test.cpp.

782{
783 // 21.3.6.4
784 string s("one two three one two three");
785
786 CPPUNIT_ASSERT( s.find_last_of("abcde") == 26 );
787
788 string test( "aba" );
789
790 CPPUNIT_CHECK( test.find_last_of( "a", 2, 1 ) == 2 );
791 CPPUNIT_CHECK( test.find_last_of( "a", 1, 1 ) == 0 );
792 CPPUNIT_CHECK( test.find_last_of( "a", 0, 1 ) == 0 );
793
794 CPPUNIT_CHECK( test.find_last_of( 'a', 2 ) == 2 );
795 CPPUNIT_CHECK( test.find_last_of( 'a', 1 ) == 0 );
796 CPPUNIT_CHECK( test.find_last_of( 'a', 0 ) == 0 );
797}

◆ func()

static string StringTest::func ( const string par)
inlinestaticprotected

Definition at line 140 of file string_test.cpp.

140 {
141 string tmp( par );
142 return tmp;
143 }

◆ insert()

void StringTest::insert ( )
protected

Definition at line 454 of file string_test.cpp.

455{
456 string strorg = "This is test string for string calls";
457 string str;
458 /*
459 * In case of reallocation there is no auto reference problem
460 * so we reserve a big enough string to be sure to test this
461 * particular point.
462 */
463 str.reserve(100);
464 str = strorg;
465
466 //test self insertion:
467 str.insert(10, str.c_str() + 5, 15);
468 CPPUNIT_ASSERT( str == "This is teis test string st string for string calls" );
469
470 str = strorg;
471 str.insert(15, str.c_str() + 5, 25);
472 CPPUNIT_ASSERT( str == "This is test stis test string for stringring for string calls" );
473
474 str = strorg;
475 str.insert(0, str.c_str() + str.size() - 4, 4);
476 CPPUNIT_ASSERT( str == "allsThis is test string for string calls" );
477
478 str = strorg;
479 str.insert(0, str.c_str() + str.size() / 2 - 1, str.size() / 2 + 1);
480 CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
481
482 str = strorg;
483 string::iterator b = str.begin();
484 string::const_iterator s = str.begin() + str.size() / 2 - 1;
485 string::const_iterator e = str.end();
486 str.insert( b, s, e );
487 CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
488
489 str = strorg;
490 str.insert(str.begin(), str.begin() + str.size() / 2 - 1, str.end());
491 CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
492
493#ifdef _STLP_MEMBER_TEMPLATES
494 vector<int> int_vect;
495 //Just a compile time test:
496 str.insert(str.end(), int_vect.begin(), int_vect.end());
497#endif
498
499 string str0;
500 str0.insert(str0.begin(), 5, '0');
501 CPPUNIT_ASSERT( str0 == "00000" );
502
503 string str1;
504 {
505 string::size_type pos = 0, nb = 2;
506 str1.insert(pos, nb, '1');
507 }
508 CPPUNIT_ASSERT( str1 == "11" );
509
510 str0.insert(0, str1);
511 CPPUNIT_ASSERT( str0 == "1100000" );
512
513 string str2("2345");
514 str0.insert(str0.size(), str2, 1, 2);
515 CPPUNIT_ASSERT( str0 == "110000034" );
516
517 str1.insert(str1.begin() + 1, 2, '2');
518 CPPUNIT_ASSERT( str1 == "1221" );
519
520 str1.insert(2, "333333", 3);
521 CPPUNIT_ASSERT( str1 == "1233321" );
522
523 str1.insert(4, "4444");
524 CPPUNIT_ASSERT( str1 == "12334444321" );
525
526 str1.insert(str1.begin() + 6, '5');
527 CPPUNIT_ASSERT( str1 == "123344544321" );
528}
_Self & insert(size_type __pos, const _Self &__s)
Definition: _string.h:608
size_type size() const
Definition: _string.h:400
iterator begin()
Definition: _string.h:385
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define e
Definition: ke_i.h:82
iterator end()
Definition: _vector.h:184
iterator begin()
Definition: _vector.h:182

◆ io()

void StringTest::io ( )
protected

Definition at line 1272 of file string_test.cpp.

1273{
1274#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
1275 string str("STLport");
1276 {
1277 ostringstream ostr;
1278 ostr << str;
1279 CPPUNIT_ASSERT( ostr.good() );
1280 CPPUNIT_ASSERT( ostr.str() == str );
1281 }
1282 {
1283 istringstream istr(str);
1284 string istr_content;
1285 istr >> istr_content;
1286 CPPUNIT_ASSERT( !istr.fail() && istr.eof() );
1287 CPPUNIT_ASSERT( istr_content == str );
1288 }
1289 {
1290 istringstream istr(str);
1291 istr.width(3);
1292 string istr_content;
1293 istr >> istr_content;
1294 CPPUNIT_ASSERT( !istr.fail() && !istr.eof() );
1295 CPPUNIT_ASSERT( istr_content == "STL" );
1296 }
1297#endif
1298}
_String str() const
Definition: _sstream.h:184
bool good() const
Definition: _ios_base.h:172

◆ mt()

void StringTest::mt ( )
protected

Definition at line 210 of file string_test.cpp.

211{
212#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API)
213 const int nth = 2;
214# if defined (USE_PTHREAD_API)
215 pthread_t t[nth];
216
217 for ( int i = 0; i < nth; ++i ) {
218 pthread_create( &t[i], 0, f, 0 );
219 }
220
221 for ( int i = 0; i < nth; ++i ) {
222 pthread_join( t[i], 0 );
223 }
224# endif // PTHREAD
225
226# if defined (USE_WINDOWS_API)
227 //DWORD start = GetTickCount();
228
229 HANDLE t[nth];
230
231 int i; // VC6 not support in-loop scope of cycle var
232 for ( i = 0; i < nth; ++i ) {
233 t[i] = CreateThread(NULL, 0, f, 0, 0, NULL);
234 }
235
237 // On some platforms (evc3/evc4) WaitForMultipleObjects() with fWaitAll == TRUE
238 // is not supported. We then wait with a loop on each thread:
239 for ( i = 0; i < nth; ++i ) {
241 }
242 }
243
244 /*
245 DWORD duration = GetTickCount() - start;
246 ostringstream ostr;
247 ostr << "Duration: " << duration << endl;
248 CPPUNIT_MESSAGE(ostr.str().c_str());
249 */
250# endif
251#endif
252}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define INFINITE
Definition: serial.h:102
GLdouble GLdouble t
Definition: gl.h:2047
GLfloat f
Definition: glext.h:7540
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define WAIT_FAILED
Definition: winbase.h:413

◆ null_char()

void StringTest::null_char ( )
protected

Definition at line 432 of file string_test.cpp.

433{
434 // ISO/IEC 14882:1998(E), ISO/IEC 14882:2003(E), 21.3.4 ('... the const version')
435 const string s( "123456" );
436
437 CPPUNIT_CHECK( s[s.size()] == '\0' );
438
439#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
440 try {
441 //Check is only here to avoid warning about value of expression not used
442 CPPUNIT_CHECK( s.at(s.size()) == '\0' );
444 }
445 catch (out_of_range const&) {
446 CPPUNIT_ASSERT( true );
447 }
448 catch ( ... ) {
450 }
451#endif
452}

◆ oper_tmp()

void StringTest::oper_tmp ( )
protected

Definition at line 1149 of file string_test.cpp.

1150{
1151 string s1( "path1" );
1152 string s2( ".ext" );
1153
1154 string& rs1 = s1;
1155 string& rs2 = s2;
1156
1157 CPPUNIT_CHECK( (mypath( string( "/root" ) ) / (rs1 + rs2)).str() == "/root/path1.ext" );
1158}
struct S1 s1

◆ replace()

void StringTest::replace ( )
protected

Definition at line 530 of file string_test.cpp.

531{
532 /*
533 * This test case is for the non template basic_string::replace method,
534 * this is why we play with the const iterators and reference to guaranty
535 * that the right method is called.
536 */
537 const string v( "78" );
538 string s( "123456" );
539 string const& cs = s;
540
541 string::iterator i = s.begin() + 1;
542 s.replace(i, i + 3, v.begin(), v.end());
543 CPPUNIT_ASSERT( s == "17856" );
544
545 s = "123456";
546 i = s.begin() + 1;
547 s.replace(i, i + 1, v.begin(), v.end());
548 CPPUNIT_ASSERT( s == "1783456" );
549
550 s = "123456";
551 i = s.begin() + 1;
552 string::const_iterator ci = s.begin() + 1;
553 s.replace(i, i + 3, ci + 3, cs.end());
554 CPPUNIT_ASSERT( s == "15656" );
555
556 s = "123456";
557 i = s.begin() + 1;
558 ci = s.begin() + 1;
559 s.replace(i, i + 3, ci, ci + 2);
560 CPPUNIT_ASSERT( s == "12356" );
561
562 s = "123456";
563 i = s.begin() + 1;
564 ci = s.begin() + 1;
565 s.replace(i, i + 3, ci + 1, cs.end());
566 CPPUNIT_ASSERT( s == "1345656" );
567
568 s = "123456";
569 i = s.begin();
570 ci = s.begin() + 1;
571 s.replace(i, i, ci, ci + 1);
572 CPPUNIT_CHECK( s == "2123456" );
573
574 s = "123456";
575 s.replace(s.begin() + 4, s.end(), cs.begin(), cs.end());
576 CPPUNIT_ASSERT( s == "1234123456" );
577
578 /*
579 * This is the test for the template replace method.
580 */
581 s = "123456";
582 string::iterator b = s.begin() + 4;
583 string::iterator e = s.end();
584 string::const_iterator rb = s.begin();
585 string::const_iterator re = s.end();
586 s.replace(b, e, rb, re);
587 CPPUNIT_ASSERT( s == "1234123456" );
588
589 s = "123456";
590 s.replace(s.begin() + 4, s.end(), s.begin(), s.end());
591 CPPUNIT_ASSERT( s == "1234123456" );
592
593 string strorg("This is test string for string calls");
594 string str = strorg;
595 str.replace(5, 15, str.c_str(), 10);
596 CPPUNIT_ASSERT( str == "This This is tefor string calls" );
597
598 str = strorg;
599 str.replace(5, 5, str.c_str(), 10);
600 CPPUNIT_ASSERT( str == "This This is test string for string calls" );
601
602#if (defined (STLPORT) && defined(_STLP_MEMBER_TEMPLATES)) || ( !defined (STLPORT) && !defined(__GNUC__) )
603 deque<char> cdeque;
604 cdeque.push_back('I');
605 str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end());
606 CPPUNIT_ASSERT( str == "Is test string for string calls" );
607#endif
608}
Definition: _deque.h:404
iterator end()
Definition: _deque.h:433
void push_back(const value_type &__t=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _deque.h:668
iterator begin()
Definition: _deque.h:432
const GLdouble * v
Definition: gl.h:2040
#define cs
Definition: i386-dis.c:442

◆ reserve()

void StringTest::reserve ( )
protected

Definition at line 193 of file string_test.cpp.

194{
195 string s;
196#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
197 try {
198 s.reserve(s.max_size() + 1);
200 }
201 catch (length_error const&) {
202 }
203 catch (...) {
204 //Expected exception is length_error:
206 }
207#endif
208}

◆ resize()

void StringTest::resize ( )
protected

Definition at line 610 of file string_test.cpp.

611{
612 string s;
613
614 s.resize(0);
615
616 CPPUNIT_ASSERT( *s.c_str() == 0 );
617
618 s = "1234567";
619
620 s.resize(0);
621 CPPUNIT_ASSERT( *s.c_str() == 0 );
622
623 s = "1234567";
624 s.resize(1);
625 CPPUNIT_ASSERT( s.size() == 1 );
626 CPPUNIT_ASSERT( *s.c_str() == '1' );
627 CPPUNIT_ASSERT( *(s.c_str() + 1) == 0 );
628
629 s = "1234567";
630 s.resize(10);
631 CPPUNIT_ASSERT( s.size() == 10 );
632 CPPUNIT_ASSERT( s[6] == '7' );
633 CPPUNIT_ASSERT( s[7] == 0 );
634 CPPUNIT_ASSERT( s[8] == 0 );
635 CPPUNIT_ASSERT( s[9] == 0 );
636}

◆ rfind()

void StringTest::rfind ( )
protected

Definition at line 760 of file string_test.cpp.

761{
762 // 21.3.6.2
763 string s("one two three one two three");
764
765 CPPUNIT_ASSERT( s.rfind("two") == 18 );
766 CPPUNIT_ASSERT( s.rfind("two", 0) == string::npos );
767 CPPUNIT_ASSERT( s.rfind("two", 11) == 4 );
768 CPPUNIT_ASSERT( s.rfind('w') == 19 );
769
770 string test( "aba" );
771
772 CPPUNIT_CHECK( test.rfind( "a", 2, 1 ) == 2 );
773 CPPUNIT_CHECK( test.rfind( "a", 1, 1 ) == 0 );
774 CPPUNIT_CHECK( test.rfind( "a", 0, 1 ) == 0 );
775
776 CPPUNIT_CHECK( test.rfind( 'a', 2 ) == 2 );
777 CPPUNIT_CHECK( test.rfind( 'a', 1 ) == 0 );
778 CPPUNIT_CHECK( test.rfind( 'a', 0 ) == 0 );
779}

◆ short_string()

void StringTest::short_string ( )
protected

Definition at line 254 of file string_test.cpp.

255{
256 string const ref_short_str1("str1"), ref_short_str2("str2");
257 string short_str1(ref_short_str1), short_str2(ref_short_str2);
258 string const ref_long_str1("str 1");
259 string const ref_long_str2("str 2");
260 string long_str1(ref_long_str1), long_str2(ref_long_str2);
261
262 CPPUNIT_ASSERT(short_str1 == ref_short_str1);
263 CPPUNIT_ASSERT(long_str1 == ref_long_str1);
264
265 {
266 string str1(short_str1);
267 str1 = long_str1;
268 CPPUNIT_ASSERT(str1 == ref_long_str1);
269 }
270
271 {
272 string str1(long_str1);
273 str1 = short_str1;
274 CPPUNIT_ASSERT(str1 == ref_short_str1);
275 }
276
277 {
278 short_str1.swap(short_str2);
279 CPPUNIT_ASSERT((short_str1 == ref_short_str2) && (short_str2 == ref_short_str1));
280 short_str1.swap(short_str2);
281 }
282
283 {
284 long_str1.swap(long_str2);
285 CPPUNIT_ASSERT((long_str1 == ref_long_str2) && (long_str2 == ref_long_str1));
286 long_str1.swap(long_str2);
287 }
288
289 {
290 short_str1.swap(long_str1);
291 CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
292 short_str1.swap(long_str1);
293 }
294
295 {
296 long_str1.swap(short_str1);
297 CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
298 long_str1.swap(short_str1);
299 }
300
301 {
302 string a(256, 'a');
303 string b(256, 'b');
304 const char* as = a.c_str();
305 const char* bs = b.c_str();
306 swap(a, b);
307 CPPUNIT_ASSERT( a.c_str() == bs );
308 CPPUNIT_ASSERT( b.c_str() == as );
309 }
310
311 {
312 //This is to test move constructor
313 vector<string> str_vect;
314 str_vect.push_back(short_str1);
315 str_vect.push_back(long_str1);
316 str_vect.push_back(short_str2);
317 str_vect.push_back(long_str2);
318 CPPUNIT_ASSERT((str_vect[0] == ref_short_str1) &&
319 (str_vect[1] == ref_long_str1) &&
320 (str_vect[2] == ref_short_str2) &&
321 (str_vect[3] == ref_long_str2));
322 }
323}
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
#define swap(a, b)
Definition: qsort.c:63
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379

◆ short_string_optim_bug()

void StringTest::short_string_optim_bug ( )
protected

Definition at line 889 of file string_test.cpp.

890{
891 string teststr("shortest");
892
893 bool short_string_optim_bug_helper(string teststr);
894
896}
bool short_string_optim_bug_helper(string teststr)

◆ te_tmp()

void StringTest::te_tmp ( )
protected

Definition at line 1116 of file string_test.cpp.

1117{
1118#if !defined (TE_TMP_TEST_IGNORED)
1119 superstring s;
1120 string more( "more" );
1121 string less( "less" );
1122
1123 superstring r = s / (more + less);
1124#endif
1125}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

◆ template_expression()

void StringTest::template_expression ( )
protected

Definition at line 950 of file string_test.cpp.

951{
952 string one("one"), two("two"), three("three");
953 string space(1, ' ');
954
955 // check availability of [un]equality operators
956 {
957 // string-string
958 one == two;
959 one != two;
960 // string-literal
961 one == "two";
962 one != "two";
963 // literal-string
964 "one" == two;
965 "one" != two;
966 // strsum-string
967 (one + two) == three;
968 (one + two) != three;
969 // string-strsum
970 one == (two + three);
971 one != (two + three);
972 // strsum-literal
973 (one + two) == "three";
974 (one + two) != "three";
975 // literal-strsum
976 "one" == (two + three);
977 "one" != (two + three);
978 // strsum-strsum
979 (one + two) == (two + three);
980 (one + two) != (two + three);
981 }
982
983 {
984 string result(one + ' ' + two + ' ' + three);
985 CPPUNIT_CHECK( result == "one two three" );
986 }
987
988 {
989 string result(one + ' ' + two + ' ' + three, 4);
990 CPPUNIT_CHECK( result == "two three" );
991 }
992
993 {
994 string result(one + ' ' + two + ' ' + three, 4, 3);
995 CPPUNIT_CHECK( result == "two" );
996 }
997
998 //2 members expressions:
999 CPPUNIT_CHECK( (' ' + one) == " one" );
1000 CPPUNIT_CHECK( (one + ' ') == "one " );
1001 CPPUNIT_CHECK( (one + " two") == "one two" );
1002 CPPUNIT_CHECK( ("one " + two) == "one two" );
1003 CPPUNIT_CHECK( (one + space) == "one " );
1004
1005 //3 members expressions:
1006 CPPUNIT_CHECK( ((one + space) + "two") == "one two" );
1007 CPPUNIT_CHECK( ("one" + (space + two)) == "one two" );
1008 CPPUNIT_CHECK( ((one + space) + two) == "one two" );
1009 CPPUNIT_CHECK( (one + (space + two)) == "one two" );
1010 CPPUNIT_CHECK( ((one + space) + 't') == "one t" );
1011 CPPUNIT_CHECK( ('o' + (space + two)) == "o two" );
1012
1013 //4 members expressions:
1014 CPPUNIT_CHECK( ((one + space) + (two + space)) == "one two " );
1015
1016 //special operators
1017 {
1018 string result;
1019 result = one + space + two;
1020 CPPUNIT_CHECK( result == "one two" );
1021
1022 result += space + three;
1023 CPPUNIT_CHECK( result == "one two three" );
1024 }
1025
1026 //special append method
1027 {
1028 string result;
1029 //Use reserve to avoid reallocation and really test auto-referencing problems:
1030 result.reserve(64);
1031
1032 result.append(one + space + two);
1033 CPPUNIT_CHECK( result == "one two" );
1034
1035 result.append(space + result + space + three);
1036 CPPUNIT_CHECK( result == "one two one two three" );
1037
1038 result = "one two";
1039 result.append(space + three, 1, 2);
1040 CPPUNIT_ASSERT( result == "one twoth" );
1041
1042 result.append(space + result);
1043 CPPUNIT_CHECK( result == "one twoth one twoth" );
1044 }
1045
1046 //special assign method
1047 {
1048 string result;
1049 //Use reserve to avoid reallocation and really test auto-referencing problems:
1050 result.reserve(64);
1051
1052 result.assign(one + space + two + space + three);
1053 CPPUNIT_CHECK( result == "one two three" );
1054
1055 result.assign(one + space + two + space + three, 3, 5);
1056 CPPUNIT_CHECK( result == " two " );
1057
1058 result.assign(one + result + three);
1059 CPPUNIT_CHECK( result == "one two three" );
1060 }
1061
1062 {
1063 CPPUNIT_CHECK( !(one + ' ' + two).empty() );
1064
1065 char result = (one + ' ' + two)[3];
1066 CPPUNIT_CHECK( result == ' ' );
1067
1068 result = (one + ' ' + two).at(3);
1069 CPPUNIT_CHECK( result == ' ' );
1070
1071#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1072 try {
1073 result = (one + ' ' + two).at(10);
1075 }
1076 catch (out_of_range const&) {
1077 CPPUNIT_ASSERT( result == ' ' );
1078 }
1079 catch (...) {
1081 }
1082#endif
1083 }
1084
1085 /*
1086 mystring a("ing");
1087 //gcc failed to compile following expression when template expressions are activated.
1088 //MSVC sees no problem. gcc limitation or MSVC is too cool ??
1089 mystring b = "str" + a;
1090 */
1091}
GLuint64EXT * result
Definition: glext.h:11304
static double two
Definition: jn_yn.c:52
int one
Definition: sehframes.cpp:28

◆ template_wexpression()

void StringTest::template_wexpression ( )
protected

Definition at line 1160 of file string_test.cpp.

1161{
1162#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
1163# if !defined (__CYGWIN__) || defined (STLPORT)
1164 wstring one(L"one"), two(L"two"), three(L"three");
1165 wstring space(L" ");
1166
1167 {
1168 wstring result(one + L' ' + two + L' ' + three);
1169 CPPUNIT_CHECK( result == L"one two three" );
1170 }
1171
1172 {
1173 wstring result(one + L' ' + two + L' ' + three, 4);
1174 CPPUNIT_CHECK( result == L"two three" );
1175 }
1176
1177 {
1178 wstring result(one + L' ' + two + L' ' + three, 4, 3);
1179 CPPUNIT_CHECK( result == L"two" );
1180 }
1181
1182 //2 members expressions:
1183 CPPUNIT_CHECK( (L' ' + one) == L" one" );
1184 CPPUNIT_CHECK( (one + L' ') == L"one " );
1185 CPPUNIT_CHECK( (one + L" two") == L"one two" );
1186 CPPUNIT_CHECK( (L"one " + two) == L"one two" );
1187 CPPUNIT_CHECK( (one + space) == L"one " );
1188
1189 //3 members expressions:
1190 CPPUNIT_CHECK( ((one + space) + L"two") == L"one two" );
1191 CPPUNIT_CHECK( (L"one" + (space + two)) == L"one two" );
1192 CPPUNIT_CHECK( ((one + space) + two) == L"one two" );
1193 CPPUNIT_CHECK( (one + (space + two)) == L"one two" );
1194 CPPUNIT_CHECK( ((one + space) + L't') == L"one t" );
1195 CPPUNIT_CHECK( (L'o' + (space + two)) == L"o two" );
1196
1197 //4 members expressions:
1198 CPPUNIT_CHECK( ((one + space) + (two + space)) == L"one two " );
1199
1200 //special operators
1201 {
1202 wstring result;
1203 result = one + space + two;
1204 CPPUNIT_CHECK( result == L"one two" );
1205
1206 result += space + three;
1207 CPPUNIT_CHECK( result == L"one two three" );
1208 }
1209
1210 //special append method
1211 {
1212 wstring result;
1213 //Use reserve to avoid reallocation and really test auto-referencing problems:
1214 result.reserve(64);
1215
1216 result.append(one + space + two);
1217 CPPUNIT_CHECK( result == L"one two" );
1218
1219 result.append(space + result + space + three);
1220 CPPUNIT_CHECK( result == L"one two one two three" );
1221
1222 result = L"one two";
1223 result.append(space + three, 1, 2);
1224 CPPUNIT_ASSERT( result == L"one twoth" );
1225
1226 result.append(space + result);
1227 CPPUNIT_CHECK( result == L"one twoth one twoth" );
1228 }
1229
1230 //special assign method
1231 {
1232 wstring result;
1233 //Use reserve to avoid reallocation and really test auto-referencing problems:
1234 result.reserve(64);
1235
1236 result.assign(one + space + two + space + three);
1237 CPPUNIT_CHECK( result == L"one two three" );
1238
1239 result.assign(one + space + two + space + three, 3, 5);
1240 CPPUNIT_CHECK( result == L" two " );
1241
1242 result.assign(one + result + three);
1243 CPPUNIT_CHECK( result == L"one two three" );
1244 }
1245
1246 {
1247 CPPUNIT_CHECK( !(one + L' ' + two).empty() );
1248
1249 wchar_t result = (one + L' ' + two)[3];
1250 CPPUNIT_CHECK( result == L' ' );
1251
1252 result = (one + L' ' + two).at(3);
1253 CPPUNIT_CHECK( result == L' ' );
1254
1255# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1256 try {
1257 result = (one + L' ' + two).at(10);
1259 }
1260 catch (out_of_range const&) {
1261 CPPUNIT_ASSERT( result == L' ' );
1262 }
1263 catch (...) {
1265 }
1266# endif
1267 }
1268# endif
1269#endif
1270}
#define L(x)
Definition: ntvdm.h:50

◆ trivial_char_compare()

void StringTest::trivial_char_compare ( )
protected

Definition at line 185 of file string_test.cpp.

186{
187 string s( "message" );
188
189 CPPUNIT_CHECK( s == "message" );
190 CPPUNIT_CHECK( "message" == s );
191}

Member Data Documentation

◆ CPPUNIT_IGNORE

StringTest::CPPUNIT_IGNORE
private

Definition at line 69 of file string_test.cpp.

◆ CPPUNIT_STOP_IGNORE

StringTest::CPPUNIT_STOP_IGNORE
private

Definition at line 72 of file string_test.cpp.


The documentation for this class was generated from the following file: