first phase of transition to unified Unicode build:

1. changed c_str() to return wxCStrData (implicitly convertible to wxChar*)
2. added template type-safe wrappers for vararg functions
3. added wxUniChar class representing single Unicode character
4. changed wxString::operator[] and wxString::iterator to return wxUniChar


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-03-17 10:26:10 +00:00
parent cd632a8617
commit c9f7896861
80 changed files with 2229 additions and 435 deletions

View File

@@ -451,19 +451,19 @@ void StdStringTestCase::StdRiter()
const wxString s(_T("fozbar"));
wxString::const_reverse_iterator ri(s.rbegin());
CPPUNIT_ASSERT_EQUAL( _T('r'), *ri );
CPPUNIT_ASSERT_EQUAL( _T('a'), *++ri );
CPPUNIT_ASSERT_EQUAL( _T('r'), *--ri );
CPPUNIT_ASSERT( _T('r') == *ri );
CPPUNIT_ASSERT( _T('a') == *++ri );
CPPUNIT_ASSERT( _T('r') == *--ri );
ri = s.rend();
ri--;
CPPUNIT_ASSERT_EQUAL( _T('f'), *ri );
CPPUNIT_ASSERT( _T('f') == *ri );
--ri;
CPPUNIT_ASSERT_EQUAL( _T('o'), *ri );
CPPUNIT_ASSERT( _T('o') == *ri );
wxString::const_iterator i = ri.base();
CPPUNIT_ASSERT_EQUAL( _T('z'), *i );
CPPUNIT_ASSERT( _T('z') == *i );
}
void StdStringTestCase::StdSubstr()

View File

@@ -630,9 +630,10 @@ void StringTestCase::WriteBuf()
wxString s;
wxStrcpy(wxStringBuffer(s, 10), _T("foo"));
CPPUNIT_ASSERT_EQUAL(_T('f'), s[0u]);
CPPUNIT_ASSERT_EQUAL(_T('o'), s[1]);
CPPUNIT_ASSERT_EQUAL(_T('o'), s[2]);
CPPUNIT_ASSERT(s[0u] == _T('f') );
CPPUNIT_ASSERT(_T('f') == s[0u]);
CPPUNIT_ASSERT(_T('o') == s[1]);
CPPUNIT_ASSERT(_T('o') == s[2]);
CPPUNIT_ASSERT_EQUAL((size_t)3, s.length());
@@ -642,10 +643,10 @@ void StringTestCase::WriteBuf()
buf.SetLength(4);
}
CPPUNIT_ASSERT_EQUAL(_T('b'), s[0u]);
CPPUNIT_ASSERT_EQUAL(_T('a'), s[1]);
CPPUNIT_ASSERT_EQUAL(_T('r'), s[2]);
CPPUNIT_ASSERT_EQUAL(_T('r'), s[3]);
CPPUNIT_ASSERT(_T('b') == s[0u]);
CPPUNIT_ASSERT(_T('a') == s[1]);
CPPUNIT_ASSERT(_T('r') == s[2]);
CPPUNIT_ASSERT(_T('r') == s[3]);
CPPUNIT_ASSERT_EQUAL((size_t)4, s.length());
CPPUNIT_ASSERT_EQUAL( 0, wxStrcmp(_T("barr"), s) );

236
tests/strings/unichar.cpp Normal file
View File

@@ -0,0 +1,236 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/strings/unichar.cpp
// Purpose: Test for wxUniChar class
// Author: Vaclav Slavik
// Created: 2007-03-11
// RCS-ID: $Id$
// Copyright: (c) 2007 REA Elektronik GmbH
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif // WX_PRECOMP
#include "wx/string.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class UniCharTestCase : public CppUnit::TestCase
{
public:
UniCharTestCase() {}
private:
CPPUNIT_TEST_SUITE( UniCharTestCase );
CPPUNIT_TEST( CharCompare );
CPPUNIT_TEST( CharCompareIntl );
CPPUNIT_TEST( StringCompare );
CPPUNIT_TEST( StringCompareIntl );
CPPUNIT_TEST_SUITE_END();
void CharCompare();
void CharCompareIntl();
void StringCompare();
void StringCompareIntl();
DECLARE_NO_COPY_CLASS(UniCharTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase );
// also include in it's own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase, "UniCharTestCase" );
void UniCharTestCase::CharCompare()
{
wxUniChar a('a');
wxUniChar b('b');
CPPUNIT_ASSERT( a == a );
CPPUNIT_ASSERT( a == 'a' );
CPPUNIT_ASSERT( a == _T('a') );
CPPUNIT_ASSERT( a == wxUniChar('a') );
CPPUNIT_ASSERT( a == wxUniChar(_T('a')) );
CPPUNIT_ASSERT( a != b );
CPPUNIT_ASSERT( a != 'b' );
CPPUNIT_ASSERT( a != _T('b') );
CPPUNIT_ASSERT( a != wxUniChar('b') );
CPPUNIT_ASSERT( a != wxUniChar(_T('b')) );
CPPUNIT_ASSERT( a < b );
CPPUNIT_ASSERT( a < 'b' );
CPPUNIT_ASSERT( a < _T('b') );
CPPUNIT_ASSERT( a < wxUniChar('b') );
CPPUNIT_ASSERT( a < wxUniChar(_T('b')) );
CPPUNIT_ASSERT( a <= b );
CPPUNIT_ASSERT( a <= 'b' );
CPPUNIT_ASSERT( a <= _T('b') );
CPPUNIT_ASSERT( a <= wxUniChar('b') );
CPPUNIT_ASSERT( a <= wxUniChar(_T('b')) );
CPPUNIT_ASSERT( a <= a );
CPPUNIT_ASSERT( a <= 'a' );
CPPUNIT_ASSERT( a <= _T('a') );
CPPUNIT_ASSERT( a <= wxUniChar('a') );
CPPUNIT_ASSERT( a <= wxUniChar(_T('a')) );
CPPUNIT_ASSERT( b > a );
CPPUNIT_ASSERT( b > 'a' );
CPPUNIT_ASSERT( b > _T('a') );
CPPUNIT_ASSERT( b > wxUniChar('a') );
CPPUNIT_ASSERT( b > wxUniChar(_T('a')) );
CPPUNIT_ASSERT( b >= a );
CPPUNIT_ASSERT( b >= 'a' );
CPPUNIT_ASSERT( b >= _T('a') );
CPPUNIT_ASSERT( b >= wxUniChar('a') );
CPPUNIT_ASSERT( b >= wxUniChar(_T('a')) );
CPPUNIT_ASSERT( b >= b );
CPPUNIT_ASSERT( b >= 'b' );
CPPUNIT_ASSERT( b >= _T('b') );
CPPUNIT_ASSERT( b >= wxUniChar('b') );
CPPUNIT_ASSERT( b >= wxUniChar(_T('b')) );
CPPUNIT_ASSERT( b - a == 1 );
CPPUNIT_ASSERT( a - b == -1 );
}
#define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
#define ARABIC_LETTER_NOON ((wchar_t)0x0646)
void UniCharTestCase::CharCompareIntl()
{
wxUniChar a(CYRILLIC_SMALL_LETTER_YU);
wxUniChar b(ARABIC_LETTER_NOON);
CPPUNIT_ASSERT( a == a );
CPPUNIT_ASSERT( a == CYRILLIC_SMALL_LETTER_YU );
CPPUNIT_ASSERT( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
CPPUNIT_ASSERT( a != b );
CPPUNIT_ASSERT( a != ARABIC_LETTER_NOON );
CPPUNIT_ASSERT( a != wxUniChar(ARABIC_LETTER_NOON) );
CPPUNIT_ASSERT( a < b );
CPPUNIT_ASSERT( a < ARABIC_LETTER_NOON );
CPPUNIT_ASSERT( a < wxUniChar(ARABIC_LETTER_NOON) );
CPPUNIT_ASSERT( a <= b );
CPPUNIT_ASSERT( a <= ARABIC_LETTER_NOON );
CPPUNIT_ASSERT( a <= wxUniChar(ARABIC_LETTER_NOON) );
CPPUNIT_ASSERT( a <= a );
CPPUNIT_ASSERT( a <= CYRILLIC_SMALL_LETTER_YU );
CPPUNIT_ASSERT( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
CPPUNIT_ASSERT( b > a );
CPPUNIT_ASSERT( b > CYRILLIC_SMALL_LETTER_YU );
CPPUNIT_ASSERT( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
CPPUNIT_ASSERT( b >= a );
CPPUNIT_ASSERT( b >= CYRILLIC_SMALL_LETTER_YU );
CPPUNIT_ASSERT( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
CPPUNIT_ASSERT( b >= b );
CPPUNIT_ASSERT( b >= ARABIC_LETTER_NOON );
CPPUNIT_ASSERT( b >= wxUniChar(ARABIC_LETTER_NOON) );
CPPUNIT_ASSERT( b - a == 504 );
CPPUNIT_ASSERT( a - b == -504 );
}
void UniCharTestCase::StringCompare()
{
// test string comparison with chars
wxString sa = "a";
const wxString sb = "b";
char c1 = 'a';
wchar_t c2 = _T('a');
wxUniChar c3 = 'a';
CPPUNIT_ASSERT( sa == 'a');
CPPUNIT_ASSERT( 'a' == sa);
CPPUNIT_ASSERT( sb != 'a');
CPPUNIT_ASSERT( 'a' != sb);
CPPUNIT_ASSERT( sa == c1);
CPPUNIT_ASSERT( c1 == sa);
CPPUNIT_ASSERT( sb != c1);
CPPUNIT_ASSERT( c1 != sb);
CPPUNIT_ASSERT( sa == c2);
CPPUNIT_ASSERT( c2 == sa);
CPPUNIT_ASSERT( sb != c2);
CPPUNIT_ASSERT( c2 != sb);
CPPUNIT_ASSERT( sa == c3);
CPPUNIT_ASSERT( c3 == sa);
CPPUNIT_ASSERT( sb != c3);
CPPUNIT_ASSERT( c3 != sb);
// test wxUniCharRef:
CPPUNIT_ASSERT( sa == sa[0]);
CPPUNIT_ASSERT( sa[0] == sa);
CPPUNIT_ASSERT( sb != sa[0]);
CPPUNIT_ASSERT( sa[0] != sb);
// test const version of operator[] (returns wxUniChar, not wxUniCharRef):
CPPUNIT_ASSERT( sb == sb[0]);
CPPUNIT_ASSERT( sb[0] == sb);
CPPUNIT_ASSERT( sa != sb[0]);
CPPUNIT_ASSERT( sb[0] != sa);
}
void UniCharTestCase::StringCompareIntl()
{
// test string comparison with chars
wxString sa = CYRILLIC_SMALL_LETTER_YU;
const wxString sb = ARABIC_LETTER_NOON;
wchar_t c2 = CYRILLIC_SMALL_LETTER_YU;
wxUniChar c3 = CYRILLIC_SMALL_LETTER_YU;
CPPUNIT_ASSERT( sa == CYRILLIC_SMALL_LETTER_YU);
CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU == sa);
CPPUNIT_ASSERT( sb != CYRILLIC_SMALL_LETTER_YU);
CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU != sb);
CPPUNIT_ASSERT( sa == c2);
CPPUNIT_ASSERT( c2 == sa);
CPPUNIT_ASSERT( sb != c2);
CPPUNIT_ASSERT( c2 != sb);
CPPUNIT_ASSERT( sa == c3);
CPPUNIT_ASSERT( c3 == sa);
CPPUNIT_ASSERT( sb != c3);
CPPUNIT_ASSERT( c3 != sb);
// test wxUniCharRef:
CPPUNIT_ASSERT( sa == sa[0]);
CPPUNIT_ASSERT( sa[0] == sa);
CPPUNIT_ASSERT( sb != sa[0]);
CPPUNIT_ASSERT( sa[0] != sb);
// test const version of operator[] (returns wxUniChar, not wxUniCharRef):
CPPUNIT_ASSERT( sb == sb[0]);
CPPUNIT_ASSERT( sb[0] == sb);
CPPUNIT_ASSERT( sa != sb[0]);
CPPUNIT_ASSERT( sb[0] != sa);
}

67
tests/strings/vararg.cpp Normal file
View File

@@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/strings/vararg.cpp
// Purpose: Test for wx vararg look-alike macros
// Author: Vaclav Slavik
// Created: 2007-02-20
// RCS-ID: $Id$
// Copyright: (c) 2007 REA Elektronik GmbH
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif // WX_PRECOMP
#include "wx/string.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class VarArgTestCase : public CppUnit::TestCase
{
public:
VarArgTestCase() {}
private:
CPPUNIT_TEST_SUITE( VarArgTestCase );
CPPUNIT_TEST( StringPrintf );
CPPUNIT_TEST_SUITE_END();
void StringPrintf();
DECLARE_NO_COPY_CLASS(VarArgTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( VarArgTestCase );
// also include in it's own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VarArgTestCase, "VarArgTestCase" );
void VarArgTestCase::StringPrintf()
{
wxString s, s2;
s.Printf("%s %i", "foo", 42);
CPPUNIT_ASSERT( s == "foo 42" );
s.Printf("%s %s %i", _T("bar"), "=", 11);
CPPUNIT_ASSERT( s == "bar = 11" );
s2.Printf("(%s)", s.c_str());
CPPUNIT_ASSERT( s2 == "(bar = 11)" );
s2.Printf(_T("[%s](%s)"), s.c_str(), "str");
CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
s2.Printf(_T("[%s](%s)"), s, "str");
CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
}