2007-06-20 03:47:51 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2004-05-21 03:55:13 -04:00
|
|
|
// Name: tests/strings/stdstrings.cpp
|
|
|
|
// Purpose: wxString unit test
|
|
|
|
// Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
|
|
|
|
// Created: 2004-05-07
|
|
|
|
// Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-22 00:00:19 -05:00
|
|
|
#include "testprec.h"
|
2004-05-21 03:55:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2016-07-14 10:36:24 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Constructors", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1(wxT("abcdefgh")),
|
|
|
|
s2(wxT("abcdefghijklm"), 8),
|
|
|
|
s3(wxT("abcdefghijklm")),
|
|
|
|
s4(8, wxT('a'));
|
|
|
|
wxString s5(s1),
|
|
|
|
s6(s3, 0, 8),
|
|
|
|
s7(s3.begin(), s3.begin() + 8);
|
|
|
|
wxString s8(s1, 4, 8);
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("abcdefgh") );
|
|
|
|
CHECK( s2 == s1 );
|
|
|
|
CHECK( s4 == wxT("aaaaaaaa") );
|
|
|
|
CHECK( s5 == wxT("abcdefgh") );
|
|
|
|
CHECK( s6 == s1 );
|
|
|
|
CHECK( s7 == s1 );
|
|
|
|
CHECK( s8 == wxT("efgh") );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
2007-06-20 03:47:51 -04:00
|
|
|
const char *pc = s1.c_str();
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxString(pc + 1, pc + 4) == "bcd" );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
|
|
|
const wchar_t *pw = s2.c_str();
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxString(pw, pw + 1) == "a" );
|
2022-12-01 10:06:24 -05:00
|
|
|
|
|
|
|
#ifdef wxHAS_RVALUE_REF
|
|
|
|
wxString s9(std::move(s1));
|
|
|
|
CHECK( s9 == wxT("abcdefgh"));
|
|
|
|
wxString s10(std::move(s3), 8);
|
|
|
|
CHECK( s10 == wxT("abcdefgh"));
|
|
|
|
#endif
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Iterators", "[stdstring]")
|
2007-06-28 08:49:58 -04:00
|
|
|
{
|
|
|
|
// test compilation of default iterators ctors:
|
|
|
|
wxString::iterator i1;
|
|
|
|
wxString::const_iterator i2;
|
|
|
|
wxString::reverse_iterator i3;
|
|
|
|
wxString::const_reverse_iterator i4;
|
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::IteratorsCmp", "[stdstring]")
|
2010-10-21 15:22:33 -04:00
|
|
|
{
|
|
|
|
wxString s("foobar");
|
|
|
|
wxString::iterator i = s.begin();
|
|
|
|
wxString::const_iterator ci = s.begin();
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( i == ci );
|
|
|
|
CHECK( i >= ci );
|
|
|
|
CHECK( i <= ci );
|
|
|
|
CHECK( ci == i );
|
|
|
|
CHECK( ci >= i );
|
|
|
|
CHECK( ci <= i );
|
2010-10-21 15:22:33 -04:00
|
|
|
|
|
|
|
ci++;
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( i != ci );
|
|
|
|
CHECK( i < ci );
|
|
|
|
CHECK( !(i > ci) );
|
2010-10-21 15:22:33 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( ci != i );
|
|
|
|
CHECK( ci > i );
|
|
|
|
CHECK( !(ci < i) );
|
2010-10-21 15:22:33 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Append", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8;
|
|
|
|
|
2007-04-05 17:55:29 -04:00
|
|
|
s1 = s2 = s3 = s4 = s5 = s6 = wxT("abc");
|
2004-05-21 03:55:13 -04:00
|
|
|
s1.append(wxT("def"));
|
|
|
|
s2.append(wxT("defgh"), 3);
|
|
|
|
s3.append(wxString(wxT("abcdef")), 3, 6);
|
|
|
|
s4.append(s1);
|
|
|
|
s5.append(3, wxT('a'));
|
2007-03-29 12:14:26 -04:00
|
|
|
s5.append(2, 'x');
|
|
|
|
s5.append(1, (unsigned char)'y');
|
2004-05-21 03:55:13 -04:00
|
|
|
s6.append(s1.begin() + 3, s1.end());
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("abcdef") );
|
|
|
|
CHECK( s2 == wxT("abcdef") );
|
|
|
|
CHECK( s3 == wxT("abcdef") );
|
|
|
|
CHECK( s4 == wxT("abcabcdef") );
|
|
|
|
CHECK( s5 == wxT("abcaaaxxy") );
|
|
|
|
CHECK( s6 == wxT("abcdef") );
|
2005-04-08 19:44:59 -04:00
|
|
|
|
2007-04-05 17:55:29 -04:00
|
|
|
const char *pc = s1.c_str() + 2;
|
|
|
|
s7.append(pc, pc + 4);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s7 == "cdef" );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
|
|
|
const wchar_t *pw = s2.c_str() + 2;
|
|
|
|
s8.append(pw, pw + 4);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s8 == "cdef" );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
2005-04-08 19:44:59 -04:00
|
|
|
s7 = s8 = wxString(wxT("null\0time"), 9);
|
|
|
|
|
|
|
|
s7.append(wxT("def"));
|
|
|
|
s8.append(wxT("defgh"), 3);
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s7 == wxString(wxT("null\0timedef"), 12) );
|
|
|
|
CHECK( s8 == wxString(wxT("null\0timedef"), 12) );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Assign", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
2022-12-01 10:06:24 -05:00
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8, s9;
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2022-12-01 10:06:24 -05:00
|
|
|
s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = wxT("abc");
|
2004-05-21 03:55:13 -04:00
|
|
|
s1.assign(wxT("def"));
|
|
|
|
s2.assign(wxT("defgh"), 3);
|
|
|
|
s3.assign(wxString(wxT("abcdef")), 3, 6);
|
|
|
|
s4.assign(s1);
|
|
|
|
s5.assign(3, wxT('a'));
|
|
|
|
s6.assign(s1.begin() + 1, s1.end());
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("def") );
|
|
|
|
CHECK( s2 == wxT("def") );
|
|
|
|
CHECK( s3 == wxT("def") );
|
|
|
|
CHECK( s4 == wxT("def") );
|
|
|
|
CHECK( s5 == wxT("aaa") );
|
|
|
|
CHECK( s6 == wxT("ef") );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
2007-06-20 03:47:51 -04:00
|
|
|
const char *pc = s1.c_str();
|
2007-04-05 17:55:29 -04:00
|
|
|
s7.assign(pc, pc + 2);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s7 == "de" );
|
2007-04-05 17:55:29 -04:00
|
|
|
|
|
|
|
const wchar_t *pw = s1.c_str();
|
|
|
|
s8.assign(pw + 2, pw + 3);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s8 == "f" );
|
2007-08-20 08:30:06 -04:00
|
|
|
|
|
|
|
s1.assign(s1, 1, 1);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == "e" );
|
2022-12-01 10:06:24 -05:00
|
|
|
|
|
|
|
#ifdef wxHAS_RVALUE_REF
|
|
|
|
s9.assign(std::move(s2));
|
|
|
|
CHECK(s9 == wxT("def"));
|
|
|
|
s2 = wxT("qwerty");
|
|
|
|
CHECK(s2 == wxT("qwerty"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Self-assignment
|
|
|
|
s9 = wxT("def");
|
|
|
|
wxString& s9ref = s9;
|
|
|
|
s9ref.assign(s9);
|
|
|
|
CHECK(s9 == wxT("def"));
|
|
|
|
// Self-move may change the value, but shouldn't crash
|
|
|
|
// and reassignment should work
|
|
|
|
#ifdef wxHAS_RVALUE_REF
|
|
|
|
s9ref.assign(std::move(s9));
|
|
|
|
s9 = "qwerty";
|
|
|
|
CHECK(s9 == wxT("qwerty"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("StdString::AssignOp", "[stdstring]")
|
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8;
|
|
|
|
s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = wxT("abc");
|
|
|
|
|
|
|
|
// operator=
|
|
|
|
s1 = wxT("def");
|
|
|
|
CHECK(s1 == wxT("def"));
|
|
|
|
|
|
|
|
s2 = s1;
|
|
|
|
CHECK(s2 == wxT("def"));
|
|
|
|
|
|
|
|
const char* pc = s1.c_str();
|
|
|
|
s3 = pc;
|
|
|
|
CHECK(s3 == wxT("def"));
|
|
|
|
|
|
|
|
const wchar_t* pw = s1.c_str();
|
|
|
|
s4 = pw;
|
|
|
|
CHECK(s4 == wxT("def"));
|
|
|
|
|
|
|
|
#ifdef wxHAS_RVALUE_REF
|
|
|
|
s5 = std::move(s1);
|
|
|
|
CHECK(s5 == wxT("def"));
|
|
|
|
s1 = wxT("qwerty");
|
|
|
|
CHECK(s1 == wxT("qwerty"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// swap
|
|
|
|
s6 = wxT("def");
|
|
|
|
std::swap(s6, s7);
|
|
|
|
CHECK(s6 == wxT("abc"));
|
|
|
|
CHECK(s7 == wxT("def"));
|
|
|
|
swap(s6, s7);
|
|
|
|
CHECK(s6 == wxT("def"));
|
|
|
|
CHECK(s7 == wxT("abc"));
|
|
|
|
s6.swap(s7);
|
|
|
|
CHECK(s6 == wxT("abc"));
|
|
|
|
CHECK(s7 == wxT("def"));
|
|
|
|
|
|
|
|
// Self-assignment
|
|
|
|
wxString& s8ref = s8;
|
|
|
|
s8ref = s8;
|
|
|
|
CHECK(s8 == wxT("abc"));
|
|
|
|
// Self-move may change the value, but shouldn't crash
|
|
|
|
// and reassignment should work
|
|
|
|
#ifdef wxHAS_RVALUE_REF
|
|
|
|
s8ref = std::move(s8);
|
|
|
|
#endif
|
|
|
|
s8 = "qwerty";
|
|
|
|
CHECK(s8 == wxT("qwerty"));
|
|
|
|
// Self-swap
|
|
|
|
std::swap(s8, s8ref);
|
|
|
|
CHECK(s8 == wxT("qwerty"));
|
|
|
|
swap(s8, s8ref);
|
|
|
|
CHECK(s8 == wxT("qwerty"));
|
|
|
|
s8.swap(s8ref);
|
|
|
|
CHECK(s8 == wxT("qwerty"));
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Compare", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8;
|
|
|
|
|
|
|
|
s1 = wxT("abcdefgh");
|
|
|
|
s2 = wxT("abcdefgh");
|
|
|
|
s3 = wxT("abc");
|
|
|
|
s4 = wxT("abcdefghi");
|
|
|
|
s5 = wxT("aaa");
|
|
|
|
s6 = wxT("zzz");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.compare(s2) == 0 );
|
|
|
|
CHECK( s1.compare(s3) > 0 );
|
|
|
|
CHECK( s1.compare(s4) < 0 );
|
|
|
|
CHECK( s1.compare(s5) > 0 );
|
|
|
|
CHECK( s1.compare(s6) < 0 );
|
|
|
|
CHECK( s1.compare(1, 12, s1) > 0);
|
|
|
|
CHECK( s1.compare(wxT("abcdefgh")) == 0);
|
|
|
|
CHECK( s1.compare(1, 7, wxT("bcdefgh")) == 0);
|
|
|
|
CHECK( s1.compare(1, 7, wxT("bcdefgh"), 7) == 0);
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Erase", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7;
|
|
|
|
|
|
|
|
s1 = wxT("abcdefgh");
|
|
|
|
s2 = wxT("abcdefgh");
|
|
|
|
s3 = wxT("abc");
|
|
|
|
s4 = wxT("abcdefghi");
|
|
|
|
s5 = wxT("aaa");
|
|
|
|
s6 = wxT("zzz");
|
|
|
|
s7 = wxT("zabcdefg");
|
|
|
|
|
|
|
|
s1.erase(1, 1);
|
|
|
|
s2.erase(4, 12);
|
|
|
|
wxString::iterator it = s3.erase(s3.begin() + 1);
|
|
|
|
wxString::iterator it2 = s4.erase(s4.begin() + 4, s4.begin() + 6);
|
|
|
|
wxString::iterator it3 = s7.erase(s7.begin() + 4, s7.begin() + 8);
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("acdefgh") );
|
|
|
|
CHECK( s2 == wxT("abcd") );
|
|
|
|
CHECK( s3 == wxT("ac") );
|
|
|
|
CHECK( s4 == wxT("abcdghi") );
|
|
|
|
CHECK( s7 == wxT("zabc") );
|
|
|
|
CHECK( *it == wxT('c') );
|
|
|
|
CHECK( *it2 == wxT('g') );
|
|
|
|
CHECK( it3 == s7.end() );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Find", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
// 0 1 2
|
|
|
|
// 01234567890123456789012345
|
|
|
|
wxString s1 = wxT("abcdefgABCDEFGabcABCabcABC");
|
|
|
|
wxString s2 = wxT("gAB");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find(wxT('A')) == 7u );
|
|
|
|
CHECK( s1.find(wxT('A'), 7) == 7u );
|
|
|
|
CHECK( s1.find(wxT('Z')) == wxString::npos );
|
|
|
|
CHECK( s1.find(wxT('C'), 22) == 25u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find(wxT("gAB")) == 6u );
|
|
|
|
CHECK( s1.find(wxT("gAB"), 7) == wxString::npos );
|
|
|
|
CHECK( s1.find(wxT("gAB"), 6) == 6u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find(wxT("gABZZZ"), 2, 3) == 6u );
|
|
|
|
CHECK( s1.find(wxT("gABZZZ"), 7, 3) == wxString::npos );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find(s2) == 6u );
|
|
|
|
CHECK( s1.find(s2, 7) == wxString::npos );
|
|
|
|
CHECK( s1.find(s2, 6) == 6u );
|
2006-04-15 11:03:57 -04:00
|
|
|
|
2004-10-07 04:53:48 -04:00
|
|
|
// 0 1 2
|
|
|
|
// 0123456 78901234567 8901234567
|
|
|
|
//wxString _s1 = wxT("abcdefg\0ABCDEFGabc\0ABCabcABC");
|
|
|
|
//wxString _s2 = wxT("g\0AB");
|
|
|
|
wxString _s1 = wxT("abcdefgABCDEFGabcABCabcABC");
|
|
|
|
wxString _s2 = wxT("gAB");
|
2006-04-15 11:03:57 -04:00
|
|
|
|
2004-10-07 04:53:48 -04:00
|
|
|
_s1.insert(7, 1, '\0');
|
|
|
|
_s1.insert(18, 1, '\0');
|
|
|
|
_s2.insert(1, 1, '\0');
|
2006-04-15 11:03:57 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( _s1.find(wxT('A')) == 8u );
|
|
|
|
CHECK( _s1.find(wxT('A'), 8) == 8u );
|
|
|
|
CHECK( _s1.find(wxT('Z')) == wxString::npos );
|
|
|
|
CHECK( _s1.find(wxT('C'), 22) == 27u );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( _s1.find(wxT("AB")) == 8u );
|
|
|
|
CHECK( _s1.find(wxT("AB"), 26) == wxString::npos );
|
|
|
|
CHECK( _s1.find(wxT("AB"), 23) == 25u );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( _s1.find(wxT("ABZZZ"), 2, 2) == 8u );
|
|
|
|
CHECK( _s1.find(wxT("ABZZZ"), 26, 2) == wxString::npos );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( _s1.find(_s2) == 6u );
|
|
|
|
CHECK( _s1.find(_s2, 7) == wxString::npos );
|
|
|
|
CHECK( _s1.find(_s2, 6) == 6u );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::FindFirst", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
// 0 1 2 3
|
|
|
|
// 01234567890123456789012345678901234
|
|
|
|
wxString s1 = wxT("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
|
|
|
|
wxString s2 = wxT("aaaaaa");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_first_not_of(wxT('a')) == 6u );
|
|
|
|
CHECK( s1.find_first_not_of(wxT('a'), 7) == 7u );
|
|
|
|
CHECK( s2.find_first_not_of(wxT('a')) == wxString::npos );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_first_not_of(wxT("abde"), 4) == 7u );
|
|
|
|
CHECK( s1.find_first_not_of(wxT("abde"), 7) == 7u );
|
|
|
|
CHECK( s1.find_first_not_of(wxT("abcdefghijkl")) == wxString::npos );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_first_not_of(wxT("abcdefghi"), 0, 4) == 9u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_first_of(wxT('c')) == 7u );
|
|
|
|
CHECK( s1.find_first_of(wxT('v')) == wxString::npos );
|
|
|
|
CHECK( s1.find_first_of(wxT('c'), 10) == 24u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_first_of(wxT("ijkl")) == 13u );
|
|
|
|
CHECK( s1.find_first_of(wxT("ddcfg"), 17) == 24u );
|
|
|
|
CHECK( s1.find_first_of(wxT("ddcfga"), 17, 5) == 24u );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::FindLast", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
// 0 1 2 3
|
|
|
|
// 01234567890123456789012345678901234
|
|
|
|
wxString s1 = wxT("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
|
|
|
|
wxString s2 = wxT("aaaaaa");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s2.find_last_not_of(wxT('a')) == wxString::npos );
|
|
|
|
CHECK( s1.find_last_not_of(wxT('d')) == 33u );
|
|
|
|
CHECK( s1.find_last_not_of(wxT('d'), 25) == 24u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_not_of(wxT("bcd")) == 22u );
|
|
|
|
CHECK( s1.find_last_not_of(wxT("abc"), 24) == 16u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_not_of(wxT("abcdefghijklmnopqrstuv"), 24, 3) == 16u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s2.find_last_of(wxT('c')) == wxString::npos );
|
|
|
|
CHECK( s1.find_last_of(wxT('a')) == 22u );
|
|
|
|
CHECK( s1.find_last_of(wxT('b'), 24) == 23u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_of(wxT("ijklm")) == 16u );
|
|
|
|
CHECK( s1.find_last_of(wxT("ijklma"), 33, 4) == 16u );
|
|
|
|
CHECK( s1.find_last_of(wxT("a"), 17) == 17u );
|
2004-10-07 12:50:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0 1 2 3
|
|
|
|
// 012345 67890123456789 01234567890123456
|
|
|
|
// wxString s1 = wxT("aaaaaa\0bcdefghlkjiaa\0aaaabcdbcdbcdbcd");
|
|
|
|
// wxString s2 = wxT("aaaaaa\0");
|
|
|
|
s1.insert(6,1,'\0');
|
|
|
|
s1.insert(20,1,'\0');
|
|
|
|
s2.insert(6,1,'\0');
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s2.find_last_not_of(wxT('a')) == 6u );
|
|
|
|
CHECK( s1.find_last_not_of(wxT('d')) == 35u );
|
|
|
|
CHECK( s1.find_last_not_of(wxT('d'), 27) == 26u );
|
2004-10-07 12:50:24 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_not_of(wxT("bcd")) == 24u );
|
|
|
|
CHECK( s1.find_last_not_of(wxT("abc"), 26) == 20u );
|
2004-10-07 12:50:24 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_not_of(wxT("abcdefghijklmnopqrstuv"), 26, 3) == 20u );
|
2004-10-07 12:50:24 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s2.find_last_of(wxT('c')) == wxString::npos );
|
|
|
|
CHECK( s1.find_last_of(wxT('a')) == 24u );
|
|
|
|
CHECK( s1.find_last_of(wxT('b'), 26) == 25u );
|
2004-10-07 12:50:24 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.find_last_of(wxT("ijklm")) == 17u );
|
|
|
|
CHECK( s1.find_last_of(wxT("ijklma"), 35, 4) == 17u );
|
|
|
|
CHECK( s1.find_last_of(wxT("a"), 18) == 18u );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::StartsEndsWith", "[stdstring]")
|
2019-07-30 03:01:24 -04:00
|
|
|
{
|
|
|
|
const wxString s(wxT("Hello, world!"));
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s.starts_with(wxT("Hello")) == true );
|
|
|
|
CHECK( s.starts_with(wxT("Hello, ")) == true );
|
|
|
|
CHECK( s.starts_with(wxT("Hello, world!")) == true );
|
|
|
|
CHECK( s.starts_with(wxT("Hello, world!!!")) == false );
|
|
|
|
CHECK( s.starts_with(wxT("")) == true );
|
|
|
|
CHECK( s.starts_with(wxT("Goodbye")) == false );
|
|
|
|
CHECK( s.starts_with(wxT("Hi")) == false );
|
|
|
|
|
|
|
|
CHECK( s.ends_with(wxT("Hello, world!")) == true );
|
|
|
|
CHECK( s.ends_with(wxT("world!")) == true );
|
|
|
|
CHECK( s.ends_with(wxT("Hello")) == false );
|
|
|
|
CHECK( s.ends_with(wxT("!")) == true );
|
|
|
|
CHECK( s.ends_with(wxT("")) == true );
|
|
|
|
CHECK( s.ends_with(wxT("very long string")) == false );
|
|
|
|
CHECK( s.ends_with(wxT("?")) == false );
|
|
|
|
CHECK( s.ends_with(wxT("Hello, world")) == false );
|
|
|
|
CHECK( s.ends_with(wxT("Gello, world!")) == false );
|
2019-07-30 03:01:24 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Insert", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
|
|
|
|
|
|
|
|
s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = wxT("aaaa");
|
|
|
|
s9 = s10 = wxT("cdefg");
|
|
|
|
|
|
|
|
s1.insert(1, wxT("cc") );
|
|
|
|
s2.insert(2, wxT("cdef"), 3);
|
|
|
|
s3.insert(2, s10);
|
|
|
|
s4.insert(2, s10, 3, 7);
|
|
|
|
s5.insert(1, 2, wxT('c'));
|
|
|
|
s6.insert(s6.begin() + 3, wxT('X'));
|
|
|
|
s7.insert(s7.begin(), s9.begin(), s9.end() - 1);
|
|
|
|
s8.insert(s8.begin(), 2, wxT('c'));
|
2009-07-23 16:30:22 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("accaaa") );
|
|
|
|
CHECK( s2 == wxT("aacdeaa") );
|
|
|
|
CHECK( s3 == wxT("aacdefgaa") );
|
|
|
|
CHECK( s4 == wxT("aafgaa") );
|
|
|
|
CHECK( s5 == wxT("accaaa") );
|
|
|
|
CHECK( s6 == wxT("aaaXa") );
|
|
|
|
CHECK( s7 == wxT("cdefaaaa") );
|
|
|
|
CHECK( s8 == wxT("ccaaaa") );
|
2009-07-23 16:30:22 -04:00
|
|
|
|
2004-05-21 03:55:13 -04:00
|
|
|
s1 = s2 = s3 = wxT("aaaa");
|
|
|
|
s1.insert(0, wxT("ccc"), 2);
|
|
|
|
s2.insert(4, wxT("ccc"), 2);
|
2009-07-23 16:30:22 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("ccaaaa") );
|
|
|
|
CHECK( s2 == wxT("aaaacc") );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Replace", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4, s5, s6, s7, s8, s9;
|
|
|
|
|
|
|
|
s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = wxT("QWERTYUIOP");
|
|
|
|
s9 = wxT("werty");
|
|
|
|
|
|
|
|
s1.replace(3, 4, wxT("rtyu"));
|
|
|
|
s1.replace(8, 7, wxT("opopop"));
|
|
|
|
s2.replace(10, 12, wxT("WWWW"));
|
|
|
|
s3.replace(1, 5, s9);
|
|
|
|
s4.replace(1, 4, s9, 0, 4);
|
|
|
|
s5.replace(1, 2, s9, 1, 12);
|
|
|
|
s6.replace(0, 123, s9, 0, 123);
|
|
|
|
s7.replace(2, 7, s9);
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("QWErtyuIopopop") );
|
|
|
|
CHECK( s2 == wxT("QWERTYUIOPWWWW") );
|
|
|
|
CHECK( s3 == wxT("QwertyUIOP") );
|
|
|
|
CHECK( s4 == wxT("QwertYUIOP") );
|
|
|
|
CHECK( s5 == wxT("QertyRTYUIOP") );
|
|
|
|
CHECK( s6 == s9 );
|
|
|
|
CHECK( s7 == wxT("QWwertyP") );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::RFind", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
// 0 1 2
|
|
|
|
// 01234567890123456789012345
|
|
|
|
wxString s1 = wxT("abcdefgABCDEFGabcABCabcABC");
|
|
|
|
wxString s2 = wxT("gAB");
|
|
|
|
wxString s3 = wxT("ab");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT('A')) == 23u );
|
|
|
|
CHECK( s1.rfind(wxT('A'), 7) == 7u );
|
|
|
|
CHECK( s1.rfind(wxT('Z')) == wxString::npos );
|
|
|
|
CHECK( s1.rfind(wxT('C'), 22) == 19u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT("cAB")) == 22u );
|
|
|
|
CHECK( s1.rfind(wxT("cAB"), 15) == wxString::npos );
|
|
|
|
CHECK( s1.rfind(wxT("cAB"), 21) == 16u );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT("gABZZZ"), 7, 3) == 6u );
|
|
|
|
CHECK( s1.rfind(wxT("gABZZZ"), 5, 3) == wxString::npos );
|
2004-05-21 03:55:13 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(s2) == 6u );
|
|
|
|
CHECK( s1.rfind(s2, 5) == wxString::npos );
|
|
|
|
CHECK( s1.rfind(s2, 6) == 6u );
|
|
|
|
CHECK( s1.rfind(s3, 1) == 0u );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
// 0 1 2
|
|
|
|
// 01234 56789012 345678901234567
|
|
|
|
// wxString s1 = wxT("abcde\0fgABCDE\0FGabcABCabcABC");
|
|
|
|
// wxString s2 = wxT("gAB");
|
|
|
|
// wxString s3 = wxT("ab");
|
2006-04-15 11:03:57 -04:00
|
|
|
|
2004-10-07 04:53:48 -04:00
|
|
|
s1.insert(5,1,'\0');
|
|
|
|
s1.insert(13,1,'\0');
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT('A')) == 25u );
|
|
|
|
CHECK( s1.rfind(wxT('A'), 8) == 8u );
|
|
|
|
CHECK( s1.rfind(wxT('Z')) == wxString::npos );
|
|
|
|
CHECK( s1.rfind(wxT('C'), 22) == 21u );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT("cAB")) == 24u );
|
|
|
|
CHECK( s1.rfind(wxT("cAB"), 15) == wxString::npos );
|
|
|
|
CHECK( s1.rfind(wxT("cAB"), 21) == 18u );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.rfind(wxT("gABZZZ"), 8, 3) == 7u );
|
|
|
|
CHECK( s1.rfind(wxT("gABZZZ"), 5, 3) == wxString::npos );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Resize", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1, s2, s3, s4;
|
|
|
|
|
|
|
|
s1 = s2 = s3 = s4 = wxT("abcABCdefDEF");
|
|
|
|
|
|
|
|
s1.resize( 12 );
|
|
|
|
s2.resize( 10 );
|
|
|
|
s3.resize( 14, wxT(' ') );
|
|
|
|
s4.resize( 14, wxT('W') );
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == wxT("abcABCdefDEF") );
|
|
|
|
CHECK( s2 == wxT("abcABCdefD") );
|
|
|
|
CHECK( s3 == wxT("abcABCdefDEF ") );
|
|
|
|
CHECK( s4 == wxT("abcABCdefDEFWW") );
|
2007-08-30 14:13:29 -04:00
|
|
|
|
2010-11-10 08:53:49 -05:00
|
|
|
#if wxUSE_UNICODE
|
2007-08-30 14:13:29 -04:00
|
|
|
wxString s =
|
|
|
|
wxString::FromUTF8("\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82");
|
|
|
|
s.resize(3);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s == wxString::FromUTF8("\xd0\x9f\xd1\x80\xd0\xb8") );
|
2010-11-10 08:53:49 -05:00
|
|
|
#endif // wxUSE_UNICODE
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Riter", "[stdstring]")
|
2006-04-15 11:03:57 -04:00
|
|
|
{
|
|
|
|
const wxString s(wxT("fozbar"));
|
|
|
|
|
|
|
|
wxString::const_reverse_iterator ri(s.rbegin());
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxT('r') == *ri );
|
|
|
|
CHECK( wxT('a') == *++ri );
|
|
|
|
CHECK( wxT('r') == *--ri );
|
2006-04-15 11:03:57 -04:00
|
|
|
|
|
|
|
ri = s.rend();
|
|
|
|
ri--;
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxT('f') == *ri );
|
2006-04-15 11:03:57 -04:00
|
|
|
|
|
|
|
--ri;
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxT('o') == *ri );
|
2006-04-15 11:03:57 -04:00
|
|
|
|
|
|
|
wxString::const_iterator i = ri.base();
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( wxT('z') == *i );
|
2006-04-15 11:03:57 -04:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Substr", "[stdstring]")
|
2004-05-21 03:55:13 -04:00
|
|
|
{
|
|
|
|
wxString s1 = wxT("abcdefgABCDEFG");
|
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.substr( 0, 14 ) == s1 );
|
|
|
|
CHECK( s1.substr( 1, 13 ) == wxT("bcdefgABCDEFG") );
|
|
|
|
CHECK( s1.substr( 1, 20 ) == wxT("bcdefgABCDEFG") );
|
|
|
|
CHECK( s1.substr( 14, 30 ) == wxT("") );
|
2004-10-07 04:53:48 -04:00
|
|
|
|
|
|
|
s1.insert(3,1,'\0');
|
|
|
|
s1.insert(8,1,'\0');
|
|
|
|
s1.insert(13,1,'\0');
|
|
|
|
|
|
|
|
wxString s2 = wxT("bcdefgABCDEFG");
|
|
|
|
s2.insert(2,1,'\0');
|
|
|
|
s2.insert(7,1,'\0');
|
|
|
|
s2.insert(12,1,'\0');
|
2006-04-15 11:03:57 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1.substr( 0, 17 ) == s1 );
|
|
|
|
CHECK( s1.substr( 1, 17 ) == s2 );
|
|
|
|
CHECK( s1.substr( 1, 20 ) == s2 );
|
|
|
|
CHECK( s1.substr( 17, 30 ) == wxT("") );
|
2004-05-21 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2007-04-17 11:32:05 -04:00
|
|
|
#if wxUSE_STD_STRING
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Conversion", "[stdstring]")
|
2007-04-17 11:32:05 -04:00
|
|
|
{
|
|
|
|
std::string strStd("std::string value");
|
|
|
|
wxStdWideString strStdWide(L"std::wstring value");
|
|
|
|
|
|
|
|
wxString s1(strStd);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s1 == "std::string value" );
|
2007-04-17 11:32:05 -04:00
|
|
|
|
|
|
|
wxString s2(strStdWide);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s2 == "std::wstring value" );
|
2007-04-17 11:32:05 -04:00
|
|
|
|
|
|
|
wxString s3;
|
|
|
|
s3 = strStd;
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s3 == "std::string value" );
|
2007-04-17 11:32:05 -04:00
|
|
|
s3 = strStdWide;
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s3 == "std::wstring value" );
|
2007-04-17 11:32:05 -04:00
|
|
|
|
|
|
|
wxString s4("hello");
|
2007-06-20 03:47:51 -04:00
|
|
|
|
2010-04-11 07:08:49 -04:00
|
|
|
// notice that implicit wxString -> std::string conversion is only
|
|
|
|
// available in wxUSE_STL case, because it conflicts with conversion to
|
|
|
|
// const char*/wchar_t*
|
2018-02-08 03:05:21 -05:00
|
|
|
#if wxUSE_STL && wxUSE_UNSAFE_WXSTRING_CONV
|
2007-04-17 11:32:05 -04:00
|
|
|
std::string s5 = s4;
|
2010-04-11 07:08:49 -04:00
|
|
|
#else
|
|
|
|
std::string s5 = s4.ToStdString();
|
|
|
|
#endif
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s5 == "hello" );
|
2007-04-17 11:32:05 -04:00
|
|
|
|
2010-04-11 07:08:49 -04:00
|
|
|
#if wxUSE_STL
|
2007-04-17 11:32:05 -04:00
|
|
|
wxStdWideString s6 = s4;
|
2010-04-11 07:08:49 -04:00
|
|
|
#else
|
|
|
|
wxStdWideString s6 = s4.ToStdWstring();
|
2007-06-20 03:47:51 -04:00
|
|
|
#endif
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s6 == "hello" );
|
2007-06-20 03:47:51 -04:00
|
|
|
|
2017-02-24 09:37:37 -05:00
|
|
|
#if wxUSE_UNSAFE_WXSTRING_CONV
|
2007-06-20 03:47:51 -04:00
|
|
|
std::string s7(s4);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s7 == "hello" );
|
2017-02-24 09:37:37 -05:00
|
|
|
#endif
|
2007-06-20 03:47:51 -04:00
|
|
|
|
|
|
|
wxStdWideString s8(s4);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s8 == "hello" );
|
2016-03-25 03:28:00 -04:00
|
|
|
|
2020-10-18 17:47:29 -04:00
|
|
|
#if wxUSE_UNICODE
|
2016-03-25 03:28:00 -04:00
|
|
|
std::string s9("\xF0\x9F\x90\xB1\0\xE7\x8C\xAB", 9); /* U+1F431 U+0000 U+732B */
|
|
|
|
wxString s10 = wxString::FromUTF8(s9);
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s10.ToStdString(wxConvUTF8) == s9 );
|
2021-03-06 09:12:07 -05:00
|
|
|
CHECK( s10.utf8_string() == s9 );
|
2020-10-18 17:47:29 -04:00
|
|
|
#endif // wxUSE_UNICODE
|
2016-03-25 03:28:00 -04:00
|
|
|
|
|
|
|
std::string s11("xyz\0\xFF", 5); /* an invalid UTF-8 sequence */
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( "" == wxString::FromUTF8(s11) );
|
2021-03-06 09:12:07 -05:00
|
|
|
|
|
|
|
CHECK( wxString("bye").utf8_string() == std::string("bye") );
|
2007-04-17 11:32:05 -04:00
|
|
|
}
|
|
|
|
#endif // wxUSE_STD_STRING
|
2016-07-14 10:36:24 -04:00
|
|
|
|
2021-03-06 09:05:23 -05:00
|
|
|
TEST_CASE("StdString::Algo", "[stdstring]")
|
2016-07-14 10:36:24 -04:00
|
|
|
{
|
|
|
|
wxString s("AB");
|
|
|
|
std::reverse(s.begin(), s.end());
|
2021-03-06 09:05:23 -05:00
|
|
|
CHECK( s == "BA" );
|
2016-07-14 10:36:24 -04:00
|
|
|
}
|