Convert simple non-GUI unit tests to use Catch directly

Get rid of the CppUnit-compatible macros in these tests and use Catch
TEST_CASE() and CHECK()/REQUIRE() directly instead.

No real changes, except for enabling the previously mistakenly (they
were clearly meant to be) not run RefUnsignedCharAssignmentOperator and
RefUnsignedCharParenOperator tests in unichar.cpp. Moreover, one of them
turned out to be broken and had to be fixed here as it does run now.
This commit is contained in:
Vadim Zeitlin
2026-08-24 13:38:23 +02:00
parent 1e8311d98f
commit fa6a43fc97
18 changed files with 1153 additions and 1961 deletions
+34 -66
View File
@@ -37,71 +37,44 @@
#include "testfile.h"
///////////////////////////////////////////////////////////////////////////////
// The test case
class FileKindTestCase : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(FileKindTestCase);
CPPUNIT_TEST(File);
#if defined __UNIX__ || defined _MSC_VER || defined __MINGW32__
CPPUNIT_TEST(Pipe);
#endif
#if defined __UNIX__
CPPUNIT_TEST(Socket);
#endif
CPPUNIT_TEST(Stdin);
CPPUNIT_TEST(MemoryStream);
#if wxUSE_SOCKETS
CPPUNIT_TEST(SocketStream);
#endif
CPPUNIT_TEST_SUITE_END();
void File();
void Pipe();
void Socket();
void Stdin();
void MemoryStream();
#if wxUSE_SOCKETS
void SocketStream();
#endif
void TestFILE(wxFFile& file, bool expected);
void TestFd(wxFile& file, bool expected);
};
// Helpers
// test a wxFFile and wxFFileInput/OutputStreams of a known type
//
void FileKindTestCase::TestFILE(wxFFile& file, bool expected)
static void TestFILE(wxFFile& file, bool expected)
{
CPPUNIT_ASSERT(file.IsOpened());
CPPUNIT_ASSERT((wxGetFileKind(file.fp()) == wxFILE_KIND_DISK) == expected);
CPPUNIT_ASSERT((file.GetKind() == wxFILE_KIND_DISK) == expected);
CHECK(file.IsOpened());
CHECK((wxGetFileKind(file.fp()) == wxFILE_KIND_DISK) == expected);
CHECK((file.GetKind() == wxFILE_KIND_DISK) == expected);
wxFFileInputStream inStream(file);
CPPUNIT_ASSERT(inStream.IsSeekable() == expected);
CHECK(inStream.IsSeekable() == expected);
wxFFileOutputStream outStream(file);
CPPUNIT_ASSERT(outStream.IsSeekable() == expected);
CHECK(outStream.IsSeekable() == expected);
}
// test a wxFile and wxFileInput/OutputStreams of a known type
//
void FileKindTestCase::TestFd(wxFile& file, bool expected)
static void TestFd(wxFile& file, bool expected)
{
CPPUNIT_ASSERT(file.IsOpened());
CPPUNIT_ASSERT((wxGetFileKind(file.fd()) == wxFILE_KIND_DISK) == expected);
CPPUNIT_ASSERT((file.GetKind() == wxFILE_KIND_DISK) == expected);
CHECK(file.IsOpened());
CHECK((wxGetFileKind(file.fd()) == wxFILE_KIND_DISK) == expected);
CHECK((file.GetKind() == wxFILE_KIND_DISK) == expected);
wxFileInputStream inStream(file);
CPPUNIT_ASSERT(inStream.IsSeekable() == expected);
CHECK(inStream.IsSeekable() == expected);
wxFileOutputStream outStream(file);
CPPUNIT_ASSERT(outStream.IsSeekable() == expected);
CHECK(outStream.IsSeekable() == expected);
}
///////////////////////////////////////////////////////////////////////////////
// The tests
// test with an ordinary file
//
void FileKindTestCase::File()
TEST_CASE("FileKind::File", "[filekind]")
{
TempFile tmp; // put first
wxFile file;
@@ -116,7 +89,7 @@ void FileKindTestCase::File()
// test with a pipe
//
#if defined __UNIX__ || defined _MSC_VER || defined __MINGW32__
void FileKindTestCase::Pipe()
TEST_CASE("FileKind::Pipe", "[filekind]")
{
int afd[2];
int rc;
@@ -125,7 +98,8 @@ void FileKindTestCase::Pipe()
#else
rc = _pipe(afd, 256, O_BINARY);
#endif
CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to create pipe", 0, rc);
INFO("Failed to create pipe");
REQUIRE( rc == 0 );
wxFile file0(afd[0]);
wxFile file1(afd[1]);
@@ -140,7 +114,7 @@ void FileKindTestCase::Pipe()
// test with a socket
//
#if defined __UNIX__
void FileKindTestCase::Socket()
TEST_CASE("FileKind::Socket", "[filekind]")
{
int s = socket(PF_INET, SOCK_STREAM, 0);
@@ -156,51 +130,45 @@ void FileKindTestCase::Socket()
// Socket streams should be non-seekable
//
#if wxUSE_SOCKETS
void FileKindTestCase::SocketStream()
TEST_CASE("FileKind::SocketStream", "[filekind]")
{
wxSocketClient client;
wxSocketInputStream inStream(client);
CPPUNIT_ASSERT(!inStream.IsSeekable());
CHECK(!inStream.IsSeekable());
wxSocketOutputStream outStream(client);
CPPUNIT_ASSERT(!outStream.IsSeekable());
CHECK(!outStream.IsSeekable());
wxBufferedInputStream nonSeekableBufferedInput(inStream);
CPPUNIT_ASSERT(!nonSeekableBufferedInput.IsSeekable());
CHECK(!nonSeekableBufferedInput.IsSeekable());
wxBufferedOutputStream nonSeekableBufferedOutput(outStream);
CPPUNIT_ASSERT(!nonSeekableBufferedOutput.IsSeekable());
CHECK(!nonSeekableBufferedOutput.IsSeekable());
}
#endif
// Memory streams should be seekable
//
void FileKindTestCase::MemoryStream()
TEST_CASE("FileKind::MemoryStream", "[filekind]")
{
char buf[20] = { 0 };
wxMemoryInputStream inStream(buf, sizeof(buf));
CPPUNIT_ASSERT(inStream.IsSeekable());
CHECK(inStream.IsSeekable());
wxMemoryOutputStream outStream(buf, sizeof(buf));
CPPUNIT_ASSERT(outStream.IsSeekable());
CHECK(outStream.IsSeekable());
wxBufferedInputStream seekableBufferedInput(inStream);
CPPUNIT_ASSERT(seekableBufferedInput.IsSeekable());
CHECK(seekableBufferedInput.IsSeekable());
wxBufferedOutputStream seekableBufferedOutput(outStream);
CPPUNIT_ASSERT(seekableBufferedOutput.IsSeekable());
CHECK(seekableBufferedOutput.IsSeekable());
}
// Stdin will usually be a terminal, if so then test it
//
void FileKindTestCase::Stdin()
TEST_CASE("FileKind::Stdin", "[filekind]")
{
if (isatty(0))
CPPUNIT_ASSERT(wxGetFileKind(0) == wxFILE_KIND_TERMINAL);
CHECK(wxGetFileKind(0) == wxFILE_KIND_TERMINAL);
if (isatty(fileno(stdin)))
CPPUNIT_ASSERT(wxGetFileKind(stdin) == wxFILE_KIND_TERMINAL);
CHECK(wxGetFileKind(stdin) == wxFILE_KIND_TERMINAL);
}
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION(FileKindTestCase);
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FileKindTestCase, "FileKindTestCase");
#endif // wxUSE_STREAMS
+77 -128
View File
@@ -55,61 +55,10 @@ struct FooObject : public wxObject
size_t FooObject::count = 0;
// --------------------------------------------------------------------------
// test class
// tests
// --------------------------------------------------------------------------
class HashesTestCase : public CppUnit::TestCase
{
public:
HashesTestCase() { }
private:
CPPUNIT_TEST_SUITE( HashesTestCase );
CPPUNIT_TEST( wxHashTableTest );
CPPUNIT_TEST( wxUntypedHashTableDeleteContents );
CPPUNIT_TEST( wxTypedHashTableTest );
CPPUNIT_TEST( StringHashMapTest );
CPPUNIT_TEST( PtrHashMapTest );
CPPUNIT_TEST( LongHashMapTest );
CPPUNIT_TEST( ULongHashMapTest );
CPPUNIT_TEST( UIntHashMapTest );
CPPUNIT_TEST( IntHashMapTest );
CPPUNIT_TEST( ShortHashMapTest );
CPPUNIT_TEST( UShortHashMapTest );
#ifdef TEST_LONGLONG
CPPUNIT_TEST( LLongHashMapTest );
CPPUNIT_TEST( ULLongHashMapTest );
#endif
CPPUNIT_TEST( wxHashSetTest );
CPPUNIT_TEST_SUITE_END();
void wxHashTableTest();
void wxUntypedHashTableDeleteContents();
void wxTypedHashTableTest();
void StringHashMapTest();
void PtrHashMapTest();
void LongHashMapTest();
void ULongHashMapTest();
void UIntHashMapTest();
void IntHashMapTest();
void ShortHashMapTest();
void UShortHashMapTest();
#ifdef TEST_LONGLONG
void LLongHashMapTest();
void ULLongHashMapTest();
#endif
void wxHashSetTest();
wxDECLARE_NO_COPY_CLASS(HashesTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( HashesTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HashesTestCase, "HashesTestCase" );
void HashesTestCase::wxHashTableTest()
TEST_CASE("Hashes::wxHashTable", "[hash]")
{
const int COUNT = 100;
@@ -131,42 +80,42 @@ void HashesTestCase::wxHashTableTest()
it = hash.Next();
}
CPPUNIT_ASSERT( i == COUNT );
CHECK( i == COUNT );
for ( i = 99; i >= 0; --i )
CPPUNIT_ASSERT( hash.Get(i) == o + i );
CHECK( hash.Get(i) == o + i );
for ( i = 0; i < COUNT; ++i )
hash.Put(i, o + i + 20);
for ( i = 99; i >= 0; --i )
CPPUNIT_ASSERT( hash.Get(i) == o + i);
CHECK( hash.Get(i) == o + i);
for ( i = 0; i < COUNT/2; ++i )
CPPUNIT_ASSERT( hash.Delete(i) == o + i);
CHECK( hash.Delete(i) == o + i);
for ( i = COUNT/2; i < COUNT; ++i )
CPPUNIT_ASSERT( hash.Get(i) == o + i);
CHECK( hash.Get(i) == o + i);
for ( i = 0; i < COUNT/2; ++i )
CPPUNIT_ASSERT( hash.Get(i) == o + i + 20);
CHECK( hash.Get(i) == o + i + 20);
for ( i = 0; i < COUNT/2; ++i )
CPPUNIT_ASSERT( hash.Delete(i) == o + i + 20);
CHECK( hash.Delete(i) == o + i + 20);
for ( i = 0; i < COUNT/2; ++i )
CPPUNIT_ASSERT( hash.Get(i) == nullptr);
CHECK( hash.Get(i) == nullptr);
hash2.Put(wxT("foo"), o + 1);
hash2.Put(wxT("bar"), o + 2);
hash2.Put(wxT("baz"), o + 3);
CPPUNIT_ASSERT(hash2.Get(wxT("moo")) == nullptr);
CPPUNIT_ASSERT(hash2.Get(wxT("bar")) == o + 2);
CHECK(hash2.Get(wxT("moo")) == nullptr);
CHECK(hash2.Get(wxT("bar")) == o + 2);
hash2.Put(wxT("bar"), o + 0);
CPPUNIT_ASSERT(hash2.Get(wxT("bar")) == o + 2);
CHECK(hash2.Get(wxT("bar")) == o + 2);
}
// and now some corner-case testing; 3 and 13 hash to the same bucket
@@ -177,27 +126,27 @@ void HashesTestCase::wxHashTableTest()
hash.Put(3, &dummy);
hash.Delete(3);
CPPUNIT_ASSERT(hash.Get(3) == nullptr);
CHECK(hash.Get(3) == nullptr);
hash.Put(3, &dummy);
hash.Put(13, &dummy);
hash.Delete(3);
CPPUNIT_ASSERT(hash.Get(3) == nullptr);
CHECK(hash.Get(3) == nullptr);
hash.Delete(13);
CPPUNIT_ASSERT(hash.Get(13) == nullptr);
CHECK(hash.Get(13) == nullptr);
hash.Put(3, &dummy);
hash.Put(13, &dummy);
hash.Delete(13);
CPPUNIT_ASSERT(hash.Get(13) == nullptr);
CHECK(hash.Get(13) == nullptr);
hash.Delete(3);
CPPUNIT_ASSERT(hash.Get(3) == nullptr);
CHECK(hash.Get(3) == nullptr);
}
// test for key + value access (specifically that supplying either
@@ -209,29 +158,29 @@ void HashesTestCase::wxHashTableTest()
hash.Put(3, 7, dummy + 7);
hash.Put(4, 8, dummy + 8);
CPPUNIT_ASSERT(hash.Get(7) == nullptr);
CPPUNIT_ASSERT(hash.Get(3, 7) == dummy + 7);
CPPUNIT_ASSERT(hash.Get(4) == nullptr);
CPPUNIT_ASSERT(hash.Get(3) == nullptr);
CPPUNIT_ASSERT(hash.Get(8) == nullptr);
CPPUNIT_ASSERT(hash.Get(8, 4) == nullptr);
CHECK(hash.Get(7) == nullptr);
CHECK(hash.Get(3, 7) == dummy + 7);
CHECK(hash.Get(4) == nullptr);
CHECK(hash.Get(3) == nullptr);
CHECK(hash.Get(8) == nullptr);
CHECK(hash.Get(8, 4) == nullptr);
CPPUNIT_ASSERT(hash.Delete(7) == nullptr);
CPPUNIT_ASSERT(hash.Delete(3) == nullptr);
CPPUNIT_ASSERT(hash.Delete(3, 7) == dummy + 7);
CHECK(hash.Delete(7) == nullptr);
CHECK(hash.Delete(3) == nullptr);
CHECK(hash.Delete(3, 7) == dummy + 7);
}
}
void HashesTestCase::wxUntypedHashTableDeleteContents()
TEST_CASE("Hashes::wxUntypedHashTableDeleteContents", "[hash]")
{
// need a nested scope for destruction
{
wxHashTable hash;
hash.DeleteContents(true);
CPPUNIT_ASSERT( hash.GetCount() == 0 );
CPPUNIT_ASSERT( FooObject::count == 0 );
CHECK( hash.GetCount() == 0 );
CHECK( FooObject::count == 0 );
static const int hashTestData[] =
{
@@ -244,32 +193,32 @@ void HashesTestCase::wxUntypedHashTableDeleteContents()
hash.Put(hashTestData[n], n, new FooObject(n));
}
CPPUNIT_ASSERT( hash.GetCount() == WXSIZEOF(hashTestData) );
CPPUNIT_ASSERT( FooObject::count == WXSIZEOF(hashTestData) );
CHECK( hash.GetCount() == WXSIZEOF(hashTestData) );
CHECK( FooObject::count == WXSIZEOF(hashTestData) );
// delete from hash without deleting object
FooObject* foo = (FooObject*)hash.Delete(0l);
CPPUNIT_ASSERT( FooObject::count == WXSIZEOF(hashTestData) );
CHECK( FooObject::count == WXSIZEOF(hashTestData) );
delete foo;
CPPUNIT_ASSERT( FooObject::count == WXSIZEOF(hashTestData) - 1 );
CHECK( FooObject::count == WXSIZEOF(hashTestData) - 1 );
}
// hash destroyed
CPPUNIT_ASSERT( FooObject::count == 0 );
CHECK( FooObject::count == 0 );
}
WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos);
void HashesTestCase::wxTypedHashTableTest()
TEST_CASE("Hashes::wxTypedHashTable", "[hash]")
{
// need a nested scope for destruction
{
wxHashFoos hash;
hash.DeleteContents(true);
CPPUNIT_ASSERT( hash.GetCount() == 0 );
CPPUNIT_ASSERT( Foo::count == 0 );
CHECK( hash.GetCount() == 0 );
CHECK( Foo::count == 0 );
static const int hashTestData[] =
{
@@ -282,31 +231,31 @@ void HashesTestCase::wxTypedHashTableTest()
hash.Put(hashTestData[n], n, new Foo(n));
}
CPPUNIT_ASSERT( hash.GetCount() == WXSIZEOF(hashTestData) );
CPPUNIT_ASSERT( Foo::count == WXSIZEOF(hashTestData) );
CHECK( hash.GetCount() == WXSIZEOF(hashTestData) );
CHECK( Foo::count == WXSIZEOF(hashTestData) );
for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
{
Foo *foo = hash.Get(hashTestData[n], n);
CPPUNIT_ASSERT( foo != nullptr );
CPPUNIT_ASSERT( foo->n == (int)n );
CHECK( foo != nullptr );
CHECK( foo->n == (int)n );
}
// element not in hash
CPPUNIT_ASSERT( hash.Get(1234) == nullptr );
CPPUNIT_ASSERT( hash.Get(1, 0) == nullptr );
CHECK( hash.Get(1234) == nullptr );
CHECK( hash.Get(1, 0) == nullptr );
// delete from hash without deleting object
Foo* foo = hash.Delete(0);
CPPUNIT_ASSERT( Foo::count == WXSIZEOF(hashTestData) );
CHECK( Foo::count == WXSIZEOF(hashTestData) );
delete foo;
CPPUNIT_ASSERT( Foo::count == WXSIZEOF(hashTestData) - 1 );
CHECK( Foo::count == WXSIZEOF(hashTestData) - 1 );
}
// hash destroyed
CPPUNIT_ASSERT( Foo::count == 0 );
CHECK( Foo::count == 0 );
}
// test compilation of basic map types
@@ -401,23 +350,23 @@ HashMapTest()
}
// test that insertion worked
CPPUNIT_ASSERT( sh.size() == count );
CHECK( sh.size() == count );
for( i = 0; i < count; ++i )
{
MakeKeyValuePair(i, count, buf, value);
CPPUNIT_ASSERT( sh[buf] == value );
CHECK( sh[buf] == value );
}
// check that iterators work
Itor it;
for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
{
CPPUNIT_ASSERT( i != count );
CPPUNIT_ASSERT( it->second == sh[it->first] );
CHECK( i != count );
CHECK( it->second == sh[it->first] );
}
CPPUNIT_ASSERT( sh.size() == i );
CHECK( sh.size() == i );
// test copy ctor, assignment operator
HashMapT h1( sh ), h2( 0 );
@@ -425,8 +374,8 @@ HashMapTest()
for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
{
CPPUNIT_ASSERT( h1[it->first] == it->second );
CPPUNIT_ASSERT( h2[it->first] == it->second );
CHECK( h1[it->first] == it->second );
CHECK( h2[it->first] == it->second );
}
// other tests
@@ -439,37 +388,37 @@ HashMapTest()
if( i < 100 )
{
it = sh.find( buf );
CPPUNIT_ASSERT( it != sh.end() );
CHECK( it != sh.end() );
sh.erase( it );
CPPUNIT_ASSERT( sh.find( buf ) == sh.end() );
CHECK( sh.find( buf ) == sh.end() );
}
else
// test erase(key)
{
size_t c = sh.erase( buf );
CPPUNIT_ASSERT( c == 1 );
CPPUNIT_ASSERT( sh.find( buf ) == sh.end() );
CHECK( c == 1 );
CHECK( sh.find( buf ) == sh.end() );
}
// count should decrease
CPPUNIT_ASSERT( sh.size() == sz - 1 );
CHECK( sh.size() == sz - 1 );
}
}
void HashesTestCase::StringHashMapTest() { HashMapTest<myStringHashMap>(); }
void HashesTestCase::PtrHashMapTest() { HashMapTest<myPtrHashMap>(); }
void HashesTestCase::LongHashMapTest() { HashMapTest<myLongHashMap>(); }
void HashesTestCase::ULongHashMapTest() { HashMapTest<myUnsignedHashMap>(); }
void HashesTestCase::UIntHashMapTest() { HashMapTest<myTestHashMap1>(); }
void HashesTestCase::IntHashMapTest() { HashMapTest<myTestHashMap2>(); }
void HashesTestCase::ShortHashMapTest() { HashMapTest<myTestHashMap3>(); }
void HashesTestCase::UShortHashMapTest() { HashMapTest<myTestHashMap4>(); }
TEST_CASE("Hashes::StringHashMap", "[hash]") { HashMapTest<myStringHashMap>(); }
TEST_CASE("Hashes::PtrHashMap", "[hash]") { HashMapTest<myPtrHashMap>(); }
TEST_CASE("Hashes::LongHashMap", "[hash]") { HashMapTest<myLongHashMap>(); }
TEST_CASE("Hashes::ULongHashMap", "[hash]") { HashMapTest<myUnsignedHashMap>(); }
TEST_CASE("Hashes::UIntHashMap", "[hash]") { HashMapTest<myTestHashMap1>(); }
TEST_CASE("Hashes::IntHashMap", "[hash]") { HashMapTest<myTestHashMap2>(); }
TEST_CASE("Hashes::ShortHashMap", "[hash]") { HashMapTest<myTestHashMap3>(); }
TEST_CASE("Hashes::UShortHashMap", "[hash]") { HashMapTest<myTestHashMap4>(); }
#ifdef TEST_LONGLONG
void HashesTestCase::LLongHashMapTest() { HashMapTest<myLLongHashMap>(); }
void HashesTestCase::ULLongHashMapTest() { HashMapTest<myULLongHashMap>(); }
TEST_CASE("Hashes::LLongHashMap", "[hash]") { HashMapTest<myLLongHashMap>(); }
TEST_CASE("Hashes::ULLongHashMap", "[hash]") { HashMapTest<myULLongHashMap>(); }
#endif
// test compilation of basic set types
@@ -520,22 +469,22 @@ WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet );
typedef myTestHashSet5 wxStringHashSet;
void HashesTestCase::wxHashSetTest()
TEST_CASE("Hashes::wxHashSet", "[hash]")
{
wxStringHashSet set1;
set1.insert( wxT("abc") );
CPPUNIT_ASSERT( set1.size() == 1 );
CHECK( set1.size() == 1 );
set1.insert( wxT("bbc") );
set1.insert( wxT("cbc") );
CPPUNIT_ASSERT( set1.size() == 3 );
CHECK( set1.size() == 3 );
set1.insert( wxT("abc") );
CPPUNIT_ASSERT( set1.size() == 3 );
CHECK( set1.size() == 3 );
mySet set2;
int dummy;
@@ -548,11 +497,11 @@ void HashesTestCase::wxHashSetTest()
tmp.ptr = &dummy; tmp.str = wxT("CDE");
set2.insert( tmp );
CPPUNIT_ASSERT( set2.size() == 2 );
CHECK( set2.size() == 2 );
mySet::iterator it = set2.find( tmp );
CPPUNIT_ASSERT( it != set2.end() );
CPPUNIT_ASSERT( it->ptr == &dummy );
CPPUNIT_ASSERT( it->str == wxT("ABC") );
CHECK( it != set2.end() );
CHECK( it->ptr == &dummy );
CHECK( it->str == wxT("ABC") );
}
+42 -77
View File
@@ -41,64 +41,29 @@ static const long testLongs[] =
-0x1234
};
// Seed the random number generator used by RAND_LL() to use different values
// in the different runs.
static const struct SeedRand
{
SeedRand() { srand((unsigned)time(nullptr)); }
} gs_seedRand;
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class LongLongTestCase : public CppUnit::TestCase
{
public:
LongLongTestCase();
private:
CPPUNIT_TEST_SUITE( LongLongTestCase );
CPPUNIT_TEST( Conversion );
CPPUNIT_TEST( Comparison );
CPPUNIT_TEST( Addition );
CPPUNIT_TEST( Multiplication );
CPPUNIT_TEST( Division );
CPPUNIT_TEST( BitOperations );
CPPUNIT_TEST( ToString );
CPPUNIT_TEST( LoHi );
CPPUNIT_TEST( Limits );
CPPUNIT_TEST_SUITE_END();
void Conversion();
void Comparison();
void Addition();
void Multiplication();
void Division();
void BitOperations();
void ToString();
void LoHi();
void Limits();
wxDECLARE_NO_COPY_CLASS(LongLongTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( LongLongTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LongLongTestCase, "LongLongTestCase" );
LongLongTestCase::LongLongTestCase()
{
srand((unsigned)time(nullptr));
}
void LongLongTestCase::Conversion()
TEST_CASE("LongLong::Conversion", "[longlong]")
{
for ( size_t n = 0; n < ITEMS; n++ )
{
wxLongLong a = RAND_LL();
wxLongLong b(a.GetHi(), a.GetLo());
CPPUNIT_ASSERT( a == b );
CHECK( a == b );
}
}
void LongLongTestCase::Comparison()
TEST_CASE("LongLong::Comparison", "[longlong]")
{
static const long ls[2] =
{
@@ -114,17 +79,17 @@ void LongLongTestCase::Comparison()
{
for ( size_t m = 0; m < WXSIZEOF(lls); m++ )
{
CPPUNIT_ASSERT( (lls[m] < testLongs[n]) == (ls[m] < testLongs[n]) );
CPPUNIT_ASSERT( (lls[m] > testLongs[n]) == (ls[m] > testLongs[n]) );
CPPUNIT_ASSERT( (lls[m] <= testLongs[n]) == (ls[m] <= testLongs[n]) );
CPPUNIT_ASSERT( (lls[m] >= testLongs[n]) == (ls[m] >= testLongs[n]) );
CPPUNIT_ASSERT( (lls[m] != testLongs[n]) == (ls[m] != testLongs[n]) );
CPPUNIT_ASSERT( (lls[m] == testLongs[n]) == (ls[m] == testLongs[n]) );
CHECK( (lls[m] < testLongs[n]) == (ls[m] < testLongs[n]) );
CHECK( (lls[m] > testLongs[n]) == (ls[m] > testLongs[n]) );
CHECK( (lls[m] <= testLongs[n]) == (ls[m] <= testLongs[n]) );
CHECK( (lls[m] >= testLongs[n]) == (ls[m] >= testLongs[n]) );
CHECK( (lls[m] != testLongs[n]) == (ls[m] != testLongs[n]) );
CHECK( (lls[m] == testLongs[n]) == (ls[m] == testLongs[n]) );
}
}
}
void LongLongTestCase::Addition()
TEST_CASE("LongLong::Addition", "[longlong]")
{
for ( size_t n = 0; n < ITEMS; n++ )
{
@@ -133,11 +98,11 @@ void LongLongTestCase::Addition()
wxLongLong b = RAND_LL() / 2;
wxLongLong c = a + b;
CPPUNIT_ASSERT( c.GetValue() == a.GetValue() + b.GetValue() );
CHECK( c.GetValue() == a.GetValue() + b.GetValue() );
}
}
void LongLongTestCase::Multiplication()
TEST_CASE("LongLong::Multiplication", "[longlong]")
{
for ( size_t n = 0; n < ITEMS; n++ )
{
@@ -146,16 +111,16 @@ void LongLongTestCase::Multiplication()
wxULongLong b = RAND_LL().GetValue();
wxULongLong c = a*b;
CPPUNIT_ASSERT( c.GetValue() == a.GetValue() * b.GetValue() );
CHECK( c.GetValue() == a.GetValue() * b.GetValue() );
wxULongLong a1(a.GetHi(), a.GetLo());
wxULongLong b1(b.GetHi(), b.GetLo());
wxULongLong c1 = a1*b1;
CPPUNIT_ASSERT( c1 == c );
CHECK( c1 == c );
}
}
void LongLongTestCase::Division()
TEST_CASE("LongLong::Division", "[longlong]")
{
for ( size_t n = 0; n < ITEMS; n++ )
{
@@ -172,11 +137,11 @@ void LongLongTestCase::Division()
wxLongLong q = a / l;
wxLongLong r = a % l;
CPPUNIT_ASSERT( a == ( q * l + r ) );
CHECK( a == ( q * l + r ) );
}
}
void LongLongTestCase::BitOperations()
TEST_CASE("LongLong::BitOperations", "[longlong]")
{
for ( size_t m = 0; m < ITEMS; m++ )
{
@@ -187,15 +152,15 @@ void LongLongTestCase::BitOperations()
wxLongLong b(a.GetHi(), a.GetLo()), c, d = b, e;
d >>= n;
c = b >> n;
CPPUNIT_ASSERT( c == d );
CHECK( c == d );
d <<= n;
e = c << n;
CPPUNIT_ASSERT( d == e );
CHECK( d == e );
}
}
}
void LongLongTestCase::ToString()
TEST_CASE("LongLong::ToString", "[longlong]")
{
wxString s1, s2;
@@ -204,38 +169,38 @@ void LongLongTestCase::ToString()
wxLongLong a = testLongs[n];
s1 = wxString::Format(wxT("%ld"), testLongs[n]);
s2 = a.ToString();
CPPUNIT_ASSERT( s1 == s2 );
CHECK( s1 == s2 );
s2 = wxEmptyString;
s2 << a;
CPPUNIT_ASSERT( s1 == s2 );
CHECK( s1 == s2 );
}
wxLongLong a(0x12345678, 0x87654321);
CPPUNIT_ASSERT( a.ToString() == wxT("1311768467139281697") );
CHECK( a.ToString() == wxT("1311768467139281697") );
a.Negate();
CPPUNIT_ASSERT( a.ToString() == wxT("-1311768467139281697") );
CHECK( a.ToString() == wxT("-1311768467139281697") );
wxLongLong llMin(-2147483647L - 1L, 0);
CPPUNIT_ASSERT( llMin.ToString() == wxT("-9223372036854775808") );
CHECK( llMin.ToString() == wxT("-9223372036854775808") );
}
void LongLongTestCase::LoHi()
TEST_CASE("LongLong::LoHi", "[longlong]")
{
wxLongLong ll(123, 456);
CPPUNIT_ASSERT_EQUAL( 456u, ll.GetLo() );
CPPUNIT_ASSERT_EQUAL( 123, ll.GetHi() );
CHECK( ll.GetLo() == 456u );
CHECK( ll.GetHi() == 123 );
wxULongLong ull(987, 654);
CPPUNIT_ASSERT_EQUAL( 654u, ull.GetLo() );
CPPUNIT_ASSERT_EQUAL( 987u, ull.GetHi() );
CHECK( ull.GetLo() == 654u );
CHECK( ull.GetHi() == 987u );
}
void LongLongTestCase::Limits()
TEST_CASE("LongLong::Limits", "[longlong]")
{
CPPUNIT_ASSERT( std::numeric_limits<wxLongLong>::is_specialized );
CPPUNIT_ASSERT( std::numeric_limits<wxULongLong>::is_specialized );
CHECK( std::numeric_limits<wxLongLong>::is_specialized );
CHECK( std::numeric_limits<wxULongLong>::is_specialized );
wxULongLong maxval = std::numeric_limits<wxULongLong>::max();
CPPUNIT_ASSERT( maxval.ToDouble() > 0 );
CHECK( maxval.ToDouble() > 0 );
}
+67 -133
View File
@@ -18,170 +18,103 @@
#include "wx/txtstrm.h"
// ----------------------------------------------------------------------------
// test class
// test helpers
// ----------------------------------------------------------------------------
class ConvAutoTestCase : public CppUnit::TestCase
namespace
{
public:
ConvAutoTestCase() { }
private:
CPPUNIT_TEST_SUITE( ConvAutoTestCase );
CPPUNIT_TEST( Init );
CPPUNIT_TEST( Empty );
CPPUNIT_TEST( Encode );
CPPUNIT_TEST( Short );
CPPUNIT_TEST( None );
CPPUNIT_TEST( UTF32LE );
CPPUNIT_TEST( UTF32BE );
CPPUNIT_TEST( UTF16LE );
CPPUNIT_TEST( UTF16BE );
CPPUNIT_TEST( UTF8 );
CPPUNIT_TEST( UTF8NoBom );
CPPUNIT_TEST( Fallback );
CPPUNIT_TEST( FallbackMultibyte );
CPPUNIT_TEST( FallbackShort );
CPPUNIT_TEST( StreamUTF8NoBOM );
CPPUNIT_TEST( StreamUTF8 );
CPPUNIT_TEST( StreamUTF16LE );
CPPUNIT_TEST( StreamUTF16BE );
CPPUNIT_TEST( StreamUTF32LE );
CPPUNIT_TEST( StreamUTF32BE );
CPPUNIT_TEST( StreamFallback );
CPPUNIT_TEST( StreamFallbackMultibyte );
CPPUNIT_TEST_SUITE_END();
// expected converter state, UTF-8 without BOM by default
struct ConvState
{
ConvState( wxBOM bom = wxBOM_None,
wxFontEncoding enc = wxFONTENCODING_UTF8,
bool fallback = false )
: m_bom(bom), m_enc(enc), m_fallback(fallback) {}
// expected converter state, UTF-8 without BOM by default
struct ConvState
void Check(const wxConvAuto& conv) const
{
ConvState( wxBOM bom = wxBOM_None,
wxFontEncoding enc = wxFONTENCODING_UTF8,
bool fallback = false )
: m_bom(bom), m_enc(enc), m_fallback(fallback) {}
CHECK( conv.GetBOM() == m_bom );
CHECK( conv.GetEncoding() == m_enc );
CHECK( conv.IsUsingFallbackEncoding() == m_fallback );
CHECK( conv.IsUTF8() == (m_enc == wxFONTENCODING_UTF8) );
}
void Check(const wxConvAuto& conv) const
{
CPPUNIT_ASSERT( conv.GetBOM() == m_bom );
CPPUNIT_ASSERT( conv.GetEncoding() == m_enc );
CPPUNIT_ASSERT( conv.IsUsingFallbackEncoding() == m_fallback );
CPPUNIT_ASSERT( conv.IsUTF8() == (m_enc == wxFONTENCODING_UTF8) );
}
wxBOM m_bom;
wxFontEncoding m_enc;
bool m_fallback;
};
// real test function: check that converting the src multibyte string to
// wide char using wxConvAuto yields wch as the first result
//
// the length of the string may need to be passed explicitly if it has
// embedded NULs, otherwise it's not necessary
void TestFirstChar(const char *src, wchar_t wch, size_t len = wxNO_LEN,
ConvState st = ConvState(),
wxFontEncoding fe = wxFONTENCODING_DEFAULT);
void Init();
void Empty();
void Encode();
void Short();
void None();
void UTF32LE();
void UTF32BE();
void UTF16LE();
void UTF16BE();
void UTF8();
void UTF8NoBom();
void Fallback();
void FallbackMultibyte();
void FallbackShort();
// test whether two lines of text are converted properly from a stream
void TestTextStream(const char *src,
size_t srclength,
const wxString& line1,
const wxString& line2,
wxFontEncoding fe = wxFONTENCODING_DEFAULT);
void StreamUTF8NoBOM();
void StreamUTF8();
void StreamUTF16LE();
void StreamUTF16BE();
void StreamUTF32LE();
void StreamUTF32BE();
void StreamFallback();
void StreamFallbackMultibyte();
wxBOM m_bom;
wxFontEncoding m_enc;
bool m_fallback;
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION(ConvAutoTestCase);
// real test function: check that converting the src multibyte string to
// wide char using wxConvAuto yields wch as the first result
//
// the length of the string may need to be passed explicitly if it has
// embedded NULs, otherwise it's not necessary
void TestFirstChar(const char *src, wchar_t wch, size_t len = wxNO_LEN,
ConvState st = ConvState(),
wxFontEncoding fe = wxFONTENCODING_DEFAULT)
{
wxConvAuto conv(fe);
wxWCharBuffer wbuf = conv.cMB2WC(src, len, nullptr);
REQUIRE( wbuf );
CHECK( *wbuf == wch );
st.Check(conv);
}
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConvAutoTestCase, "ConvAutoTestCase");
} // anonymous namespace
// ----------------------------------------------------------------------------
// tests
// ----------------------------------------------------------------------------
void ConvAutoTestCase::TestFirstChar(const char *src, wchar_t wch, size_t len,
ConvState st, wxFontEncoding fe)
{
wxConvAuto conv(fe);
wxWCharBuffer wbuf = conv.cMB2WC(src, len, nullptr);
CPPUNIT_ASSERT( wbuf );
CPPUNIT_ASSERT_EQUAL( wch, *wbuf );
st.Check(conv);
}
void ConvAutoTestCase::Init()
TEST_CASE("ConvAuto::Init", "[convauto]")
{
ConvState(wxBOM_Unknown, wxFONTENCODING_MAX).Check(wxConvAuto());
}
void ConvAutoTestCase::Empty()
TEST_CASE("ConvAuto::Empty", "[convauto]")
{
wxConvAuto conv;
CPPUNIT_ASSERT( !conv.cMB2WC("") );
CHECK( !conv.cMB2WC("") );
ConvState(wxBOM_Unknown, wxFONTENCODING_MAX).Check(conv);
}
void ConvAutoTestCase::Encode()
TEST_CASE("ConvAuto::Encode", "[convauto]")
{
wxConvAuto conv;
wxString str = wxString::FromUTF8("Пあ");
wxCharBuffer buf = conv.cWC2MB(str.wc_str());
CPPUNIT_ASSERT( buf );
CPPUNIT_ASSERT_EQUAL( str, wxString::FromUTF8(buf) );
CHECK( buf );
CHECK( wxString::FromUTF8(buf) == str );
ConvState(wxBOM_Unknown, wxFONTENCODING_UTF8).Check(conv);
}
void ConvAutoTestCase::Short()
TEST_CASE("ConvAuto::Short", "[convauto]")
{
TestFirstChar("1", wxT('1'));
}
void ConvAutoTestCase::None()
TEST_CASE("ConvAuto::None", "[convauto]")
{
TestFirstChar("Hello world", wxT('H'));
}
void ConvAutoTestCase::UTF32LE()
TEST_CASE("ConvAuto::UTF32LE", "[convauto]")
{
TestFirstChar("\xff\xfe\0\0A\0\0\0", wxT('A'), 8, ConvState(wxBOM_UTF32LE, wxFONTENCODING_UTF32LE));
}
void ConvAutoTestCase::UTF32BE()
TEST_CASE("ConvAuto::UTF32BE", "[convauto]")
{
TestFirstChar("\0\0\xfe\xff\0\0\0B", wxT('B'), 8, ConvState(wxBOM_UTF32BE, wxFONTENCODING_UTF32BE));
}
void ConvAutoTestCase::UTF16LE()
TEST_CASE("ConvAuto::UTF16LE", "[convauto]")
{
TestFirstChar("\xff\xfeZ\0", wxT('Z'), 4, ConvState(wxBOM_UTF16LE, wxFONTENCODING_UTF16LE));
}
void ConvAutoTestCase::UTF16BE()
TEST_CASE("ConvAuto::UTF16BE", "[convauto]")
{
TestFirstChar("\xfe\xff\0Y", wxT('Y'), 4, ConvState(wxBOM_UTF16BE, wxFONTENCODING_UTF16BE));
}
@@ -192,48 +125,49 @@ constexpr wchar_t CYRILLIC_LETTER_P = L'\u041f';
constexpr wchar_t CYRILLIC_LETTER_P = L'П';
#endif
void ConvAutoTestCase::UTF8()
TEST_CASE("ConvAuto::UTF8", "[convauto]")
{
TestFirstChar("\xef\xbb\xbfП", CYRILLIC_LETTER_P, wxNO_LEN, ConvState(wxBOM_UTF8, wxFONTENCODING_UTF8));
}
void ConvAutoTestCase::UTF8NoBom()
TEST_CASE("ConvAuto::UTF8NoBom", "[convauto]")
{
TestFirstChar("Пあ", CYRILLIC_LETTER_P, wxNO_LEN, ConvState(wxBOM_None, wxFONTENCODING_UTF8));
}
void ConvAutoTestCase::Fallback()
TEST_CASE("ConvAuto::Fallback", "[convauto]")
{
TestFirstChar("\xbf", CYRILLIC_LETTER_P, wxNO_LEN,
ConvState(wxBOM_None, wxFONTENCODING_ISO8859_5, true),
wxFONTENCODING_ISO8859_5);
}
void ConvAutoTestCase::FallbackMultibyte()
TEST_CASE("ConvAuto::FallbackMultibyte", "[convauto]")
{
TestFirstChar("\x84\x50", CYRILLIC_LETTER_P, wxNO_LEN,
ConvState(wxBOM_None, wxFONTENCODING_CP932, true),
wxFONTENCODING_CP932);
}
void ConvAutoTestCase::FallbackShort()
TEST_CASE("ConvAuto::FallbackShort", "[convauto]")
{
TestFirstChar("\x61\xc4", 'a', 2,
ConvState(wxBOM_None, wxFONTENCODING_ISO8859_5, true),
wxFONTENCODING_ISO8859_5);
}
void ConvAutoTestCase::TestTextStream(const char *src,
size_t srclength,
const wxString& line1,
const wxString& line2,
wxFontEncoding fe)
// test whether two lines of text are converted properly from a stream
static void TestTextStream(const char *src,
size_t srclength,
const wxString& line1,
const wxString& line2,
wxFontEncoding fe = wxFONTENCODING_DEFAULT)
{
wxMemoryInputStream instream(src, srclength);
wxTextInputStream text(instream, wxT(" \t"), wxConvAuto(fe));
CPPUNIT_ASSERT_EQUAL( line1, text.ReadLine() );
CPPUNIT_ASSERT_EQUAL( line2, text.ReadLine() );
CHECK( text.ReadLine() == line1 );
CHECK( text.ReadLine() == line2 );
}
// the first line of the teststring used in the following functions is an
@@ -249,52 +183,52 @@ const wxString line2 = wxString::FromUTF8("β");
} // anonymous namespace
void ConvAutoTestCase::StreamUTF8NoBOM()
TEST_CASE("ConvAuto::StreamUTF8NoBOM", "[convauto]")
{
TestTextStream("\x61\xE3\x81\x82\x0A\xCE\xB2",
7, line1, line2);
}
void ConvAutoTestCase::StreamUTF8()
TEST_CASE("ConvAuto::StreamUTF8", "[convauto]")
{
TestTextStream("\xEF\xBB\xBF\x61\xE3\x81\x82\x0A\xCE\xB2",
10, line1, line2);
}
void ConvAutoTestCase::StreamUTF16LE()
TEST_CASE("ConvAuto::StreamUTF16LE", "[convauto]")
{
TestTextStream("\xFF\xFE\x61\x00\x42\x30\x0A\x00\xB2\x03",
10, line1, line2);
}
void ConvAutoTestCase::StreamUTF16BE()
TEST_CASE("ConvAuto::StreamUTF16BE", "[convauto]")
{
TestTextStream("\xFE\xFF\x00\x61\x30\x42\x00\x0A\x03\xB2",
10, line1, line2);
}
void ConvAutoTestCase::StreamUTF32LE()
TEST_CASE("ConvAuto::StreamUTF32LE", "[convauto]")
{
TestTextStream("\xFF\xFE\0\0\x61\x00\0\0\x42\x30\0\0\x0A"
"\x00\0\0\xB2\x03\0\0",
20, line1, line2);
}
void ConvAutoTestCase::StreamUTF32BE()
TEST_CASE("ConvAuto::StreamUTF32BE", "[convauto]")
{
TestTextStream("\0\0\xFE\xFF\0\0\x00\x61\0\0\x30\x42\0\0\x00\x0A"
"\0\0\x03\xB2",
20, line1, line2);
}
void ConvAutoTestCase::StreamFallback()
TEST_CASE("ConvAuto::StreamFallback", "[convauto]")
{
TestTextStream("\x61\xbf\x0A\xe0",
4, wxString::FromUTF8("a\xd0\x9f"), wxString::FromUTF8("\xd1\x80"),
wxFONTENCODING_ISO8859_5);
}
void ConvAutoTestCase::StreamFallbackMultibyte()
TEST_CASE("ConvAuto::StreamFallbackMultibyte", "[convauto]")
{
TestTextStream("\x61\x82\xa0\x0A\x83\xc0",
6, line1, line2, wxFONTENCODING_CP932);
File diff suppressed because it is too large Load Diff
+12 -35
View File
@@ -15,56 +15,33 @@
#include "wx/utils.h"
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class EnvTestCase : public CppUnit::TestCase
{
public:
EnvTestCase() { }
private:
CPPUNIT_TEST_SUITE( EnvTestCase );
CPPUNIT_TEST( GetSet );
CPPUNIT_TEST( Path );
CPPUNIT_TEST_SUITE_END();
void GetSet();
void Path();
wxDECLARE_NO_COPY_CLASS(EnvTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( EnvTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EnvTestCase, "EnvTestCase" );
void EnvTestCase::GetSet()
TEST_CASE("Environ::GetSet", "[env]")
{
const wxChar *var = wxT("wxTestVar");
wxString contents;
CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
CPPUNIT_ASSERT(contents.empty());
CHECK(!wxGetEnv(var, &contents));
CHECK(contents.empty());
wxSetEnv(var, wxT("value for wxTestVar"));
CPPUNIT_ASSERT(wxGetEnv(var, &contents));
CPPUNIT_ASSERT(contents == wxT("value for wxTestVar"));
CHECK(wxGetEnv(var, &contents));
CHECK(contents == wxT("value for wxTestVar"));
wxSetEnv(var, wxT("another value"));
CPPUNIT_ASSERT(wxGetEnv(var, &contents));
CPPUNIT_ASSERT(contents == wxT("another value"));
CHECK(wxGetEnv(var, &contents));
CHECK(contents == wxT("another value"));
wxUnsetEnv(var);
CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
CHECK(!wxGetEnv(var, &contents));
}
void EnvTestCase::Path()
TEST_CASE("Environ::Path", "[env]")
{
wxString contents;
CPPUNIT_ASSERT(wxGetEnv(wxT("PATH"), &contents));
CPPUNIT_ASSERT(!contents.empty());
REQUIRE(wxGetEnv(wxT("PATH"), &contents));
CHECK(!contents.empty());
}
+23 -52
View File
@@ -18,77 +18,48 @@
#endif
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class MetaProgrammingTestCase : public CppUnit::TestCase
TEST_CASE("MetaProgramming::IsPod", "[meta]")
{
public:
MetaProgrammingTestCase() { }
private:
CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
CPPUNIT_TEST( IsPod );
CPPUNIT_TEST( IsMovable );
CPPUNIT_TEST( ImplicitConversion );
CPPUNIT_TEST( MinMax );
CPPUNIT_TEST_SUITE_END();
void IsPod();
void IsMovable();
void ImplicitConversion();
void MinMax();
wxDECLARE_NO_COPY_CLASS(MetaProgrammingTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
"MetaProgrammingTestCase" );
void MetaProgrammingTestCase::IsPod()
{
CPPUNIT_ASSERT(wxIsPod<bool>::value);
CPPUNIT_ASSERT(wxIsPod<signed int>::value);
CPPUNIT_ASSERT(wxIsPod<double>::value);
CPPUNIT_ASSERT(wxIsPod<wxObject*>::value);
CPPUNIT_ASSERT(!wxIsPod<wxObject>::value);
CHECK(wxIsPod<bool>::value);
CHECK(wxIsPod<signed int>::value);
CHECK(wxIsPod<double>::value);
CHECK(wxIsPod<wxObject*>::value);
CHECK(!wxIsPod<wxObject>::value);
}
void MetaProgrammingTestCase::IsMovable()
TEST_CASE("MetaProgramming::IsMovable", "[meta]")
{
CPPUNIT_ASSERT(wxIsMovable<bool>::value);
CPPUNIT_ASSERT(wxIsMovable<signed int>::value);
CPPUNIT_ASSERT(wxIsMovable<double>::value);
CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value);
CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
CHECK(wxIsMovable<bool>::value);
CHECK(wxIsMovable<signed int>::value);
CHECK(wxIsMovable<double>::value);
CHECK(wxIsMovable<wxObject*>::value);
CHECK(!wxIsMovable<wxObject>::value);
}
void MetaProgrammingTestCase::ImplicitConversion()
TEST_CASE("MetaProgramming::ImplicitConversion", "[meta]")
{
#ifndef wxNO_RTTI
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
CHECK(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
CHECK(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
CHECK(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
#endif // !wxNO_RTTI
}
void MetaProgrammingTestCase::MinMax()
TEST_CASE("MetaProgramming::MinMax", "[meta]")
{
// test that wxMax(1.1,1) returns float, not long int
float f = wxMax(1.1f, 1l);
CPPUNIT_ASSERT_EQUAL( 1.1f, f);
CHECK( f == 1.1f );
// test that comparing signed and unsigned correctly returns unsigned: this
// may seem counterintuitive in this case but this is consistent with the
// standard C conversions
CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );
CHECK( wxMin(-1, 1u) == 1 );
CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
CHECK( wxClip(-1.5, -1, 1) == -1. );
CHECK( wxClip(0, -1, 1) == 0 );
CHECK( wxClip(2l, -1, 1) == 1 );
}
+13 -40
View File
@@ -37,36 +37,9 @@
#endif
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class MiscTestCase : public CppUnit::TestCase
{
public:
MiscTestCase() { }
private:
CPPUNIT_TEST_SUITE( MiscTestCase );
CPPUNIT_TEST( Assert );
CPPUNIT_TEST( CallForEach );
CPPUNIT_TEST( Delete );
CPPUNIT_TEST( StaticCast );
CPPUNIT_TEST_SUITE_END();
void Assert();
void CallForEach();
void Delete();
void StaticCast();
wxDECLARE_NO_COPY_CLASS(MiscTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
namespace
{
@@ -79,7 +52,7 @@ bool AssertIfOdd(int n)
} // anonymous namespace
void MiscTestCase::Assert()
TEST_CASE("wxAssertHandler", "[assert]")
{
AssertIfOdd(0);
WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
@@ -90,35 +63,35 @@ void MiscTestCase::Assert()
wxSetAssertHandler(oldHandler);
}
void MiscTestCase::CallForEach()
TEST_CASE("wxCALL_FOR_EACH", "[misc]")
{
#define MY_MACRO(pos, str) s += str;
wxString s;
wxCALL_FOR_EACH(MY_MACRO, "foo", "bar", "baz");
CPPUNIT_ASSERT_EQUAL( "foobarbaz", s );
CHECK( s == "foobarbaz" );
#undef MY_MACRO
}
void MiscTestCase::Delete()
TEST_CASE("wxDELETE", "[misc]")
{
// Allocate some arbitrary memory to get a valid pointer:
long *pointer = new long;
CPPUNIT_ASSERT( pointer != nullptr );
CHECK( pointer != nullptr );
// Check that wxDELETE sets the pointer to nullptr:
wxDELETE( pointer );
CPPUNIT_ASSERT( pointer == nullptr );
CHECK( pointer == nullptr );
// Allocate some arbitrary array to get a valid pointer:
long *array = new long[ 3 ];
CPPUNIT_ASSERT( array != nullptr );
CHECK( array != nullptr );
// Check that wxDELETEA sets the pointer to nullptr:
wxDELETEA( array );
CPPUNIT_ASSERT( array == nullptr );
CHECK( array == nullptr );
// this results in compilation error, as it should
#if 0
@@ -143,19 +116,19 @@ bool IsNull(void *p)
} // anonymous namespace
void MiscTestCase::StaticCast()
TEST_CASE("wxStaticCast", "[rtti]")
{
#if wxUSE_TARSTREAM
wxTarEntry tarEntry;
CPPUNIT_ASSERT( wxStaticCast(&tarEntry, wxArchiveEntry) );
CHECK( wxStaticCast(&tarEntry, wxArchiveEntry) );
wxArchiveEntry *entry = &tarEntry;
CPPUNIT_ASSERT( wxStaticCast(entry, wxTarEntry) );
CHECK( wxStaticCast(entry, wxTarEntry) );
#if wxUSE_ZIPSTREAM
wxZipEntry zipEntry;
entry = &zipEntry;
CPPUNIT_ASSERT( wxStaticCast(entry, wxZipEntry) );
CHECK( wxStaticCast(entry, wxZipEntry) );
WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(&zipEntry, wxTarEntry)) );
#endif // wxUSE_ZIPSTREAM
+12 -30
View File
@@ -11,31 +11,9 @@
#include "wx/typeinfo.h"
// ----------------------------------------------------------------------------
// test class
// test types
// ----------------------------------------------------------------------------
class TypeInfoTestCase : public CppUnit::TestCase
{
public:
TypeInfoTestCase() { }
private:
CPPUNIT_TEST_SUITE( TypeInfoTestCase );
CPPUNIT_TEST( Test );
CPPUNIT_TEST_SUITE_END();
void Test();
wxDECLARE_NO_COPY_CLASS(TypeInfoTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( TypeInfoTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TypeInfoTestCase, "TypeInfoTestCase" );
namespace UserNameSpace {
class UserType1
{
@@ -61,7 +39,11 @@ public:
WX_DEFINE_TYPEINFO(UserType2)
void TypeInfoTestCase::Test()
// ----------------------------------------------------------------------------
// tests
// ----------------------------------------------------------------------------
TEST_CASE("TypeInfo::Compare", "[typeinfo]")
{
UserNameSpace::UserType1 uns_ut1;
UserNameSpace::UserType1* uns_ut1_p = new UserNameSpace::UserType1();
@@ -71,14 +53,14 @@ void TypeInfoTestCase::Test()
UserType2* ut2_p = new UserType2();
// These type comparison should match
CPPUNIT_ASSERT(wxTypeId(uns_ut1) == wxTypeId(*uns_ut1_p));
CPPUNIT_ASSERT(wxTypeId(ut1) == wxTypeId(*ut1_p));
CPPUNIT_ASSERT(wxTypeId(ut2) == wxTypeId(*ut2_p));
CHECK(wxTypeId(uns_ut1) == wxTypeId(*uns_ut1_p));
CHECK(wxTypeId(ut1) == wxTypeId(*ut1_p));
CHECK(wxTypeId(ut2) == wxTypeId(*ut2_p));
// These type comparison should not match
CPPUNIT_ASSERT(wxTypeId(uns_ut1) != wxTypeId(ut1));
CPPUNIT_ASSERT(wxTypeId(uns_ut1) != wxTypeId(ut2));
CPPUNIT_ASSERT(wxTypeId(ut1) != wxTypeId(ut2));
CHECK(wxTypeId(uns_ut1) != wxTypeId(ut1));
CHECK(wxTypeId(uns_ut1) != wxTypeId(ut2));
CHECK(wxTypeId(ut1) != wxTypeId(ut2));
delete uns_ut1_p;
delete ut1_p;
+52 -79
View File
@@ -45,49 +45,22 @@ private:
int m_count;
};
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class ScopeGuardTestCase : public CppUnit::TestCase
// Fixture used by the tests of the macros operating on "this" below.
class CounterFixture
{
public:
CPPUNIT_TEST_SUITE(ScopeGuardTestCase);
CPPUNIT_TEST(Normal);
CPPUNIT_TEST(Dismiss);
CPPUNIT_TEST(BlockExit);
CPPUNIT_TEST(BlockExitObj);
CPPUNIT_TEST(BlockExitThis);
CPPUNIT_TEST(BlockExitSetVar);
CPPUNIT_TEST_SUITE_END();
void Normal();
void Dismiss();
void BlockExit();
void BlockExitObj();
void BlockExitThis();
void BlockExitSetVar();
private:
void Zero() { m_count = 0; }
void Set(int n) { m_count = n; }
void Sum(int n, int m) { m_count = n + m; }
int m_count;
int m_count = 0;
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION(ScopeGuardTestCase);
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ScopeGuardTestCase,
"ScopeGuardTestCase");
// ============================================================================
// ScopeGuardTestCase implementation
// tests
// ============================================================================
void ScopeGuardTestCase::Normal()
TEST_CASE("ScopeGuard::Normal", "[scopeguard]")
{
int n = 1,
m = 2;
@@ -102,17 +75,17 @@ void ScopeGuardTestCase::Normal()
wxUnusedVar(incN);
wxUnusedVar(incMby15);
CPPUNIT_ASSERT_EQUAL( 1, gs_count );
CPPUNIT_ASSERT_EQUAL( 1, n );
CPPUNIT_ASSERT_EQUAL( 2, m );
CHECK( gs_count == 1 );
CHECK( n == 1 );
CHECK( m == 2 );
}
CPPUNIT_ASSERT_EQUAL( 2, gs_count );
CPPUNIT_ASSERT_EQUAL( 2, n );
CPPUNIT_ASSERT_EQUAL( 17, m );
CHECK( gs_count == 2 );
CHECK( n == 2 );
CHECK( m == 17 );
}
void ScopeGuardTestCase::Dismiss()
TEST_CASE("ScopeGuard::Dismiss", "[scopeguard]")
{
int n = 1,
m = 2;
@@ -127,17 +100,17 @@ void ScopeGuardTestCase::Dismiss()
incN.Dismiss();
incMby15.Dismiss();
CPPUNIT_ASSERT_EQUAL( 1, gs_count );
CPPUNIT_ASSERT_EQUAL( 1, n );
CPPUNIT_ASSERT_EQUAL( 2, m );
CHECK( gs_count == 1 );
CHECK( n == 1 );
CHECK( m == 2 );
}
CPPUNIT_ASSERT_EQUAL( 1, gs_count );
CPPUNIT_ASSERT_EQUAL( 1, n );
CPPUNIT_ASSERT_EQUAL( 2, m );
CHECK( gs_count == 1 );
CHECK( n == 1 );
CHECK( m == 2 );
}
void ScopeGuardTestCase::BlockExit()
TEST_CASE("ScopeGuard::BlockExit", "[scopeguard]")
{
int n = 1,
m = 2;
@@ -149,17 +122,17 @@ void ScopeGuardTestCase::BlockExit()
wxON_BLOCK_EXIT1(Inc, &n);
wxON_BLOCK_EXIT2(IncBy, &m, 15);
CPPUNIT_ASSERT_EQUAL( 1, gs_count );
CPPUNIT_ASSERT_EQUAL( 1, n );
CPPUNIT_ASSERT_EQUAL( 2, m );
CHECK( gs_count == 1 );
CHECK( n == 1 );
CHECK( m == 2 );
}
CPPUNIT_ASSERT_EQUAL( 2, gs_count );
CPPUNIT_ASSERT_EQUAL( 2, n );
CPPUNIT_ASSERT_EQUAL( 17, m );
CHECK( gs_count == 2 );
CHECK( n == 2 );
CHECK( m == 17 );
}
void ScopeGuardTestCase::BlockExitObj()
TEST_CASE("ScopeGuard::BlockExitObj", "[scopeguard]")
{
Counter count0(1),
count1(2),
@@ -170,74 +143,74 @@ void ScopeGuardTestCase::BlockExitObj()
wxON_BLOCK_EXIT_OBJ1(count1, Counter::Set, 17);
wxON_BLOCK_EXIT_OBJ2(count2, Counter::Sum, 2, 3);
CPPUNIT_ASSERT_EQUAL( 1, count0.GetCount() );
CPPUNIT_ASSERT_EQUAL( 2, count1.GetCount() );
CPPUNIT_ASSERT_EQUAL( 3, count2.GetCount() );
CHECK( count0.GetCount() == 1 );
CHECK( count1.GetCount() == 2 );
CHECK( count2.GetCount() == 3 );
}
CPPUNIT_ASSERT_EQUAL( 0, count0.GetCount() );
CPPUNIT_ASSERT_EQUAL( 17, count1.GetCount() );
CPPUNIT_ASSERT_EQUAL( 5, count2.GetCount() );
CHECK( count0.GetCount() == 0 );
CHECK( count1.GetCount() == 17 );
CHECK( count2.GetCount() == 5 );
}
void ScopeGuardTestCase::BlockExitThis()
TEST_CASE_METHOD(CounterFixture, "ScopeGuard::BlockExitThis", "[scopeguard]")
{
m_count = 1;
{
wxON_BLOCK_EXIT_THIS0(ScopeGuardTestCase::Zero);
wxON_BLOCK_EXIT_THIS0(CounterFixture::Zero);
CPPUNIT_ASSERT_EQUAL( 1, m_count );
CHECK( m_count == 1 );
}
CPPUNIT_ASSERT_EQUAL( 0, m_count );
CHECK( m_count == 0 );
{
wxON_BLOCK_EXIT_THIS1(ScopeGuardTestCase::Set, 17);
wxON_BLOCK_EXIT_THIS1(CounterFixture::Set, 17);
CPPUNIT_ASSERT_EQUAL( 0, m_count );
CHECK( m_count == 0 );
}
CPPUNIT_ASSERT_EQUAL( 17, m_count );
CHECK( m_count == 17 );
{
wxON_BLOCK_EXIT_THIS2(ScopeGuardTestCase::Sum, 2, 3);
CPPUNIT_ASSERT_EQUAL( 17, m_count );
wxON_BLOCK_EXIT_THIS2(CounterFixture::Sum, 2, 3);
CHECK( m_count == 17 );
}
CPPUNIT_ASSERT_EQUAL( 5, m_count );
CHECK( m_count == 5 );
}
void ScopeGuardTestCase::BlockExitSetVar()
TEST_CASE_METHOD(CounterFixture, "ScopeGuard::BlockExitSetVar", "[scopeguard]")
{
m_count = 1;
{
wxON_BLOCK_EXIT_SET(m_count, 17);
CPPUNIT_ASSERT_EQUAL( 1, m_count );
CHECK( m_count == 1 );
}
CPPUNIT_ASSERT_EQUAL( 17, m_count );
CHECK( m_count == 17 );
int count = 1;
{
wxON_BLOCK_EXIT_SET(count, 17);
CPPUNIT_ASSERT_EQUAL( 1, count );
CHECK( count == 1 );
}
CPPUNIT_ASSERT_EQUAL( 17, count );
CHECK( count == 17 );
wxString s("hi");
{
wxON_BLOCK_EXIT_SET(s, "bye");
CPPUNIT_ASSERT_EQUAL( "hi", s );
CHECK( s == "hi" );
}
CPPUNIT_ASSERT_EQUAL( "bye", s );
CHECK( s == "bye" );
ScopeGuardTestCase *p = this;
CounterFixture *p = this;
{
wxON_BLOCK_EXIT_NULL(p);
CPPUNIT_ASSERT( p );
CHECK( p );
}
CPPUNIT_ASSERT( !p );
CHECK( !p );
}
+4 -22
View File
@@ -21,32 +21,14 @@
#include <sstream>
#define ASSERT_OSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::string(p), s.str())
#define ASSERT_WOSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::wstring(p), s.str())
#define ASSERT_OSTREAM_EQUAL(p, s) CHECK(s.str() == std::string(p))
#define ASSERT_WOSTREAM_EQUAL(p, s) CHECK(s.str() == std::wstring(p))
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class StringIostreamTestCase : public CppUnit::TestCase
{
public:
StringIostreamTestCase() { }
private:
CPPUNIT_TEST_SUITE( StringIostreamTestCase );
CPPUNIT_TEST( Out );
CPPUNIT_TEST_SUITE_END();
void Out();
};
CPPUNIT_TEST_SUITE_REGISTRATION( StringIostreamTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringIostreamTestCase, "StringIostream" );
void StringIostreamTestCase::Out()
TEST_CASE("StringIostream::Out", "[wxString][iostream]")
{
std::ostringstream s;
s << wxString("hello");
+29 -73
View File
@@ -19,43 +19,6 @@
#include "wx/tokenzr.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class TokenizerTestCase : public CppUnit::TestCase
{
public:
TokenizerTestCase() { }
private:
CPPUNIT_TEST_SUITE( TokenizerTestCase );
CPPUNIT_TEST( GetCount );
CPPUNIT_TEST( GetPosition );
CPPUNIT_TEST( GetString );
CPPUNIT_TEST( LastDelimiter );
CPPUNIT_TEST( StrtokCompat );
CPPUNIT_TEST( CopyObj );
CPPUNIT_TEST( AssignObj );
CPPUNIT_TEST_SUITE_END();
void GetCount();
void GetPosition();
void GetString();
void LastDelimiter();
void StrtokCompat();
void CopyObj();
void AssignObj();
wxDECLARE_NO_COPY_CLASS(TokenizerTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( TokenizerTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TokenizerTestCase, "TokenizerTestCase" );
// ----------------------------------------------------------------------------
// test data
// ----------------------------------------------------------------------------
@@ -119,26 +82,19 @@ gs_testData[] =
{ wxT("01-02/99"), wxT("/-"), wxTOKEN_RET_DELIMS, 3 },
};
// helper function returning the string showing the index for which the test
// fails in the diagnostic message
static std::string Nth(size_t n)
{
return std::string(wxString::Format(wxT("for loop index %lu"),
(unsigned long)n).mb_str());
}
// ----------------------------------------------------------------------------
// the tests
// ----------------------------------------------------------------------------
void TokenizerTestCase::GetCount()
TEST_CASE("Tokenizer::GetCount", "[tokenizer]")
{
for ( size_t n = 0; n < WXSIZEOF(gs_testData); n++ )
{
const TokenizerTestData& ttd = gs_testData[n];
wxStringTokenizer tkz(ttd.str, ttd.delims, ttd.mode);
CPPUNIT_ASSERT_EQUAL_MESSAGE( Nth(n), ttd.count, tkz.CountTokens() );
INFO( "for loop index " << n );
CHECK( tkz.CountTokens() == ttd.count );
size_t count = 0;
while ( tkz.HasMoreTokens() )
@@ -147,7 +103,7 @@ void TokenizerTestCase::GetCount()
count++;
}
CPPUNIT_ASSERT_EQUAL_MESSAGE( Nth(n), ttd.count, count );
CHECK( count == ttd.count );
}
}
@@ -159,7 +115,7 @@ DoTestGetPosition(const wxChar *s, const wxChar *delims, int pos, ...)
{
wxStringTokenizer tkz(s, delims);
CPPUNIT_ASSERT_EQUAL( (size_t)0, tkz.GetPosition() );
CHECK( tkz.GetPosition() == (size_t)0 );
va_list ap;
va_start(ap, pos);
@@ -168,13 +124,13 @@ DoTestGetPosition(const wxChar *s, const wxChar *delims, int pos, ...)
{
if ( !pos )
{
CPPUNIT_ASSERT( !tkz.HasMoreTokens() );
CHECK( !tkz.HasMoreTokens() );
break;
}
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( (size_t)pos, tkz.GetPosition() );
CHECK( tkz.GetPosition() == (size_t)pos );
pos = va_arg(ap, int);
}
@@ -182,7 +138,7 @@ DoTestGetPosition(const wxChar *s, const wxChar *delims, int pos, ...)
va_end(ap);
}
void TokenizerTestCase::GetPosition()
TEST_CASE("Tokenizer::GetPosition", "[tokenizer]")
{
DoTestGetPosition(wxT("foo"), wxT("_"), 3, 0);
DoTestGetPosition(wxT("foo_bar"), wxT("_"), 4, 7, 0);
@@ -196,7 +152,7 @@ DoTestGetString(const wxChar *s, const wxChar *delims, int pos, ...)
{
wxStringTokenizer tkz(s, delims);
CPPUNIT_ASSERT_EQUAL( wxString(s), tkz.GetString() );
CHECK( tkz.GetString() == wxString(s) );
va_list ap;
va_start(ap, pos);
@@ -205,13 +161,13 @@ DoTestGetString(const wxChar *s, const wxChar *delims, int pos, ...)
{
if ( !pos )
{
CPPUNIT_ASSERT( tkz.GetString().empty() ) ;
CHECK( tkz.GetString().empty() ) ;
break;
}
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( wxString(s + pos), tkz.GetString() );
CHECK( tkz.GetString() == wxString(s + pos) );
pos = va_arg(ap, int);
}
@@ -219,31 +175,31 @@ DoTestGetString(const wxChar *s, const wxChar *delims, int pos, ...)
va_end(ap);
}
void TokenizerTestCase::GetString()
TEST_CASE("Tokenizer::GetString", "[tokenizer]")
{
DoTestGetString(wxT("foo"), wxT("_"), 3, 0);
DoTestGetString(wxT("foo_bar"), wxT("_"), 4, 7, 0);
DoTestGetString(wxT("foo_bar_"), wxT("_"), 4, 8, 0);
}
void TokenizerTestCase::LastDelimiter()
TEST_CASE("Tokenizer::LastDelimiter", "[tokenizer]")
{
wxStringTokenizer tkz(wxT("a+-b=c"), wxT("+-="));
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( wxT('+'), tkz.GetLastDelimiter() );
CHECK( tkz.GetLastDelimiter() == wxT('+') );
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( wxT('-'), tkz.GetLastDelimiter() );
CHECK( tkz.GetLastDelimiter() == wxT('-') );
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( wxT('='), tkz.GetLastDelimiter() );
CHECK( tkz.GetLastDelimiter() == wxT('=') );
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( wxT('\0'), tkz.GetLastDelimiter() );
CHECK( tkz.GetLastDelimiter() == wxT('\0') );
}
void TokenizerTestCase::StrtokCompat()
TEST_CASE("Tokenizer::StrtokCompat", "[tokenizer]")
{
for ( size_t n = 0; n < WXSIZEOF(gs_testData); n++ )
{
@@ -259,13 +215,13 @@ void TokenizerTestCase::StrtokCompat()
wxStringTokenizer tkz(ttd.str, ttd.delims, ttd.mode);
while ( tkz.HasMoreTokens() )
{
CPPUNIT_ASSERT_EQUAL( wxString(s), tkz.GetNextToken() );
CHECK( tkz.GetNextToken() == wxString(s) );
s = wxStrtok(nullptr, ttd.delims, &last);
}
}
}
void TokenizerTestCase::CopyObj()
TEST_CASE("Tokenizer::CopyObj", "[tokenizer]")
{
// Test copy ctor
wxStringTokenizer tkzSrc(wxT("first:second:third:fourth"), wxT(":"));
@@ -274,19 +230,19 @@ void TokenizerTestCase::CopyObj()
tkzSrc.GetNextToken();
wxStringTokenizer tkz = tkzSrc;
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
CHECK( tkz.GetPosition() == tkzSrc.GetPosition() );
CHECK( tkz.GetString() == tkzSrc.GetString() );
// Change the state of both objects and compare again...
tkzSrc.GetNextToken();
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
CHECK( tkz.GetPosition() == tkzSrc.GetPosition() );
CHECK( tkz.GetString() == tkzSrc.GetString() );
}
}
void TokenizerTestCase::AssignObj()
TEST_CASE("Tokenizer::AssignObj", "[tokenizer]")
{
// Test assignment
wxStringTokenizer tkzSrc(wxT("first:second:third:fourth"), wxT(":"));
@@ -296,14 +252,14 @@ void TokenizerTestCase::AssignObj()
tkzSrc.GetNextToken();
tkz = tkzSrc;
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
CHECK( tkz.GetPosition() == tkzSrc.GetPosition() );
CHECK( tkz.GetString() == tkzSrc.GetString() );
// Change the state of both objects and compare again...
tkzSrc.GetNextToken();
tkz.GetNextToken();
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
CHECK( tkz.GetPosition() == tkzSrc.GetPosition() );
CHECK( tkz.GetString() == tkzSrc.GetString() );
}
}
+274 -431
View File
File diff suppressed because it is too large Load Diff
+60 -127
View File
@@ -55,25 +55,13 @@ struct StringConversionData
if ( wcs )
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC failed"),
wbuf.data()
);
INFO(Message(n, "MB2WC failed")); CHECK(wbuf.data());
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC", wbuf, wcs),
wxStrcmp(wbuf, wcs) == 0
);
INFO(Message(n, "MB2WC", wbuf, wcs)); CHECK(wxStrcmp(wbuf, wcs) == 0);
}
else // conversion is supposed to fail
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC succeeded"),
!wbuf.data()
);
INFO(Message(n, "MB2WC succeeded")); CHECK(!wbuf.data());
}
}
@@ -83,25 +71,13 @@ struct StringConversionData
if ( str )
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB failed"),
buf.data()
);
INFO(Message(n, "WC2MB failed")); CHECK(buf.data());
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB", buf, str),
strcmp(buf, str) == 0
);
INFO(Message(n, "WC2MB", buf, str)); CHECK(strcmp(buf, str) == 0);
}
else
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB succeeded"),
!buf.data()
);
INFO(Message(n, "WC2MB succeeded")); CHECK(!buf.data());
}
}
}
@@ -127,67 +103,24 @@ private:
};
// ----------------------------------------------------------------------------
// test class
// tests
// ----------------------------------------------------------------------------
class UnicodeTestCase : public CppUnit::TestCase
{
public:
UnicodeTestCase();
private:
CPPUNIT_TEST_SUITE( UnicodeTestCase );
CPPUNIT_TEST( ToFromAscii );
CPPUNIT_TEST( ConstructorsWithConversion );
CPPUNIT_TEST( ConversionFixed );
CPPUNIT_TEST( ConversionWithNULs );
CPPUNIT_TEST( ConversionUTF7 );
CPPUNIT_TEST( ConversionUTF8 );
CPPUNIT_TEST( ConversionUTF16 );
CPPUNIT_TEST( ConversionUTF32 );
CPPUNIT_TEST( IsConvOk );
CPPUNIT_TEST( Iteration );
CPPUNIT_TEST_SUITE_END();
void ToFromAscii();
void ConstructorsWithConversion();
void ConversionFixed();
void ConversionWithNULs();
void ConversionUTF7();
void ConversionUTF8();
void ConversionUTF16();
void ConversionUTF32();
void IsConvOk();
void Iteration();
wxDECLARE_NO_COPY_CLASS(UnicodeTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "UnicodeTestCase" );
UnicodeTestCase::UnicodeTestCase()
{
}
void UnicodeTestCase::ToFromAscii()
TEST_CASE("Unicode::ToFromAscii", "[unicode]")
{
#define TEST_TO_FROM_ASCII(txt) \
{ \
static const char *msg = txt; \
wxString s = wxString::FromAscii(msg); \
CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \
CHECK( strcmp( s.ToAscii() , msg ) == 0 ); \
}
TEST_TO_FROM_ASCII( "Hello, world!" );
TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
}
void UnicodeTestCase::ConstructorsWithConversion()
TEST_CASE("Unicode::ConstructorsWithConversion", "[unicode]")
{
const unsigned char utf8Buf[] = "Déjà";
const unsigned char utf8subBuf[] = "Déj";
@@ -197,73 +130,73 @@ void UnicodeTestCase::ConstructorsWithConversion()
wxString s1(utf8, wxConvUTF8);
const wchar_t wchar[] = {0x44,0xE9,0x6A,0xE0,0};
CPPUNIT_ASSERT_EQUAL( wchar, s1 );
CHECK( s1 == wchar );
wxString s2(wchar);
CPPUNIT_ASSERT_EQUAL( wchar, s2 );
CPPUNIT_ASSERT_EQUAL( wxString::FromUTF8(utf8), s2 );
CHECK( s2 == wchar );
CHECK( s2 == wxString::FromUTF8(utf8) );
wxString sub(utf8sub, wxConvUTF8); // "Dej" substring
wxString s3(utf8, wxConvUTF8, 4);
CPPUNIT_ASSERT_EQUAL( sub, s3 );
CHECK( s3 == sub );
wxString s4(wchar, 3);
CPPUNIT_ASSERT_EQUAL( sub, s4 );
CHECK( s4 == sub );
// conversion should stop with failure at pos 35
wxString s("\t[pl]open.format.Sformatuj dyskietk\xea=gfloppy %f", wxConvUTF8);
CPPUNIT_ASSERT( s.empty() );
CHECK( s.empty() );
// test using Unicode strings together with char* strings (this must work
// in ANSI mode as well, of course):
wxString s5("ascii");
CPPUNIT_ASSERT_EQUAL( "ascii", s5 );
CHECK( s5 == "ascii" );
s5 += " value";
CPPUNIT_ASSERT( strcmp(s5.mb_str(), "ascii value") == 0 );
CPPUNIT_ASSERT_EQUAL( "ascii value", s5 );
CPPUNIT_ASSERT( s5 != "SomethingElse" );
CHECK( strcmp(s5.mb_str(), "ascii value") == 0 );
CHECK( s5 == "ascii value" );
CHECK( s5 != "SomethingElse" );
}
void UnicodeTestCase::ConversionFixed()
TEST_CASE("Unicode::ConversionFixed", "[unicode]")
{
size_t len;
wxConvLibc.cWC2MB(L"", 0, &len);
CPPUNIT_ASSERT_EQUAL( 0, len );
CHECK( len == 0 );
// check that when we convert a fixed number of characters we obtain the
// expected return value
CPPUNIT_ASSERT_EQUAL( 0, wxConvLibc.ToWChar(nullptr, 0, "", 0) );
CPPUNIT_ASSERT_EQUAL( 1, wxConvLibc.ToWChar(nullptr, 0, "x", 1) );
CPPUNIT_ASSERT_EQUAL( 2, wxConvLibc.ToWChar(nullptr, 0, "x", 2) );
CPPUNIT_ASSERT_EQUAL( 2, wxConvLibc.ToWChar(nullptr, 0, "xy", 2) );
CHECK( wxConvLibc.ToWChar(nullptr, 0, "", 0) == 0 );
CHECK( wxConvLibc.ToWChar(nullptr, 0, "x", 1) == 1 );
CHECK( wxConvLibc.ToWChar(nullptr, 0, "x", 2) == 2 );
CHECK( wxConvLibc.ToWChar(nullptr, 0, "xy", 2) == 2 );
}
void UnicodeTestCase::ConversionWithNULs()
TEST_CASE("Unicode::ConversionWithNULs", "[unicode]")
{
static const size_t lenNulString = 10;
wxString szTheString(L"The\0String", lenNulString);
wxCharBuffer theBuffer = szTheString.mb_str(wxConvLibc);
CPPUNIT_ASSERT( memcmp(theBuffer.data(), "The\0String",
CHECK( memcmp(theBuffer.data(), "The\0String",
lenNulString + 1) == 0 );
wxString szTheString2("The\0String", wxConvLocal, lenNulString);
CPPUNIT_ASSERT_EQUAL( lenNulString, szTheString2.length() );
CPPUNIT_ASSERT( wxTmemcmp(szTheString2.c_str(), L"The\0String",
CHECK( szTheString2.length() == lenNulString );
CHECK( wxTmemcmp(szTheString2.c_str(), L"The\0String",
lenNulString) == 0 );
const char *null4buff = "\0\0\0\0";
wxString null4str(null4buff, 4);
CPPUNIT_ASSERT_EQUAL( 4, null4str.length() );
CHECK( null4str.length() == 4 );
}
void UnicodeTestCase::ConversionUTF7()
TEST_CASE("Unicode::ConversionUTF7", "[unicode]")
{
static const StringConversionData utf7data[] =
{
@@ -306,7 +239,7 @@ void UnicodeTestCase::ConversionUTF7()
}
}
void UnicodeTestCase::ConversionUTF8()
TEST_CASE("Unicode::ConversionUTF8", "[unicode]")
{
static const StringConversionData utf8data[] =
{
@@ -327,21 +260,21 @@ void UnicodeTestCase::ConversionUTF8()
static const char* const u25a6 = "\xe2\x96\xa6";
wxMBConvUTF8 c(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL);
CPPUNIT_ASSERT_EQUAL( 2, c.ToWChar(nullptr, 0, u25a6, wxNO_LEN) );
CPPUNIT_ASSERT_EQUAL( 0, c.ToWChar(nullptr, 0, u25a6, 0) );
CPPUNIT_ASSERT_EQUAL( 1, c.ToWChar(nullptr, 0, u25a6, 3) );
CPPUNIT_ASSERT_EQUAL( 2, c.ToWChar(nullptr, 0, u25a6, 4) );
CHECK( c.ToWChar(nullptr, 0, u25a6, wxNO_LEN) == 2 );
CHECK( c.ToWChar(nullptr, 0, u25a6, 0) == 0 );
CHECK( c.ToWChar(nullptr, 0, u25a6, 3) == 1 );
CHECK( c.ToWChar(nullptr, 0, u25a6, 4) == 2 );
// Verify that converting a string with embedded NULs works.
CPPUNIT_ASSERT_EQUAL( 5, wxString::FromUTF8("abc\0\x32", 5).length() );
CHECK( wxString::FromUTF8("abc\0\x32", 5).length() == 5 );
// Verify that converting a string containing invalid UTF-8 does not work,
// even if it happens after an embedded NUL.
CPPUNIT_ASSERT( wxString::FromUTF8("abc\xff").empty() );
CPPUNIT_ASSERT( wxString::FromUTF8("abc\0\xff", 5).empty() );
CHECK( wxString::FromUTF8("abc\xff").empty() );
CHECK( wxString::FromUTF8("abc\0\xff", 5).empty() );
}
void UnicodeTestCase::ConversionUTF16()
TEST_CASE("Unicode::ConversionUTF16", "[unicode]")
{
static const StringConversionData utf16data[] =
{
@@ -368,7 +301,7 @@ void UnicodeTestCase::ConversionUTF16()
// got confused in this case
size_t len;
conv.cMB2WC("\x01\0\0B\0C" /* A macron BC */, 6, &len);
CPPUNIT_ASSERT_EQUAL( 3, len );
CHECK( len == 3 );
// When using UTF-16 internally (i.e. MSW), we don't have any surrogate
// support, so the length of the string below is 2, not 1.
@@ -376,7 +309,7 @@ void UnicodeTestCase::ConversionUTF16()
// Another one: verify that the length of the resulting string is computed
// correctly when there is a surrogate in the input.
wxMBConvUTF16BE().cMB2WC("\xd8\x03\xdc\x01\0" /* OLD TURKIC LETTER YENISEI A */, wxNO_LEN, &len);
CPPUNIT_ASSERT_EQUAL( 1, len );
CHECK( len == 1 );
#endif // UTF-32 internal representation
#if SIZEOF_WCHAR_T == 2
@@ -389,11 +322,11 @@ void UnicodeTestCase::ConversionUTF16()
wchar_t ws[2];
ws[0] = 0xd83d;
ws[1] = 0xdc31;
CPPUNIT_ASSERT_EQUAL( 4, wxMBConvUTF32BE().FromWChar(nullptr, 0, ws, 2) );
CHECK( wxMBConvUTF32BE().FromWChar(nullptr, 0, ws, 2) == 4 );
#endif // UTF-16 internal representation
}
void UnicodeTestCase::ConversionUTF32()
TEST_CASE("Unicode::ConversionUTF32", "[unicode]")
{
static const StringConversionData utf32data[] =
{
@@ -417,35 +350,35 @@ void UnicodeTestCase::ConversionUTF32()
size_t len;
conv.cMB2WC("\0\0\x01\0\0\0\0B\0\0\0C" /* A macron BC */, 12, &len);
CPPUNIT_ASSERT_EQUAL( 3, len );
CHECK( len == 3 );
}
void UnicodeTestCase::IsConvOk()
TEST_CASE("Unicode::IsConvOk", "[unicode]")
{
CPPUNIT_ASSERT( wxCSConv(wxFONTENCODING_SYSTEM).IsOk() );
CPPUNIT_ASSERT( wxCSConv("US-ASCII").IsOk() );
CPPUNIT_ASSERT( wxCSConv("UTF-8").IsOk() );
CPPUNIT_ASSERT( !wxCSConv("NoSuchConversion").IsOk() );
CHECK( wxCSConv(wxFONTENCODING_SYSTEM).IsOk() );
CHECK( wxCSConv("US-ASCII").IsOk() );
CHECK( wxCSConv("UTF-8").IsOk() );
CHECK( !wxCSConv("NoSuchConversion").IsOk() );
#ifdef __WINDOWS__
CPPUNIT_ASSERT( wxCSConv("WINDOWS-437").IsOk() );
CHECK( wxCSConv("WINDOWS-437").IsOk() );
#endif
}
void UnicodeTestCase::Iteration()
TEST_CASE("Unicode::Iteration", "[unicode]")
{
static const char *textUTF8 = "čeština";// "czech" in Czech
static const wchar_t textUTF16[] = {0x10D, 0x65, 0x161, 0x74, 0x69, 0x6E, 0x61, 0};
wxString text(wxString::FromUTF8(textUTF8));
CPPUNIT_ASSERT( wxStrcmp(text.wc_str(), textUTF16) == 0 );
CHECK( wxStrcmp(text.wc_str(), textUTF16) == 0 );
// verify the string was decoded correctly:
{
size_t idx = 0;
for ( auto c : text )
{
CPPUNIT_ASSERT( c == textUTF16[idx++] );
CHECK( c == textUTF16[idx++] );
}
}
@@ -465,12 +398,12 @@ void UnicodeTestCase::Iteration()
{
c = textUTF16[idx++];
CPPUNIT_ASSERT( end1 == text.end() );
CPPUNIT_ASSERT( end2 == text.end() );
CHECK( end1 == text.end() );
CHECK( end2 == text.end() );
}
CPPUNIT_ASSERT( end1 == text.end() );
CPPUNIT_ASSERT( end2 == text.end() );
CHECK( end1 == text.end() );
CHECK( end2 == text.end() );
}
// and verify it again:
@@ -478,7 +411,7 @@ void UnicodeTestCase::Iteration()
size_t idx = 0;
for ( auto c : text )
{
CPPUNIT_ASSERT( c == textUTF16[idx++] );
CHECK( c == textUTF16[idx++] );
}
}
}
+104 -137
View File
@@ -26,10 +26,13 @@
#endif
// ----------------------------------------------------------------------------
// test class
// test fixture
// ----------------------------------------------------------------------------
class TextFileTestCase : public CppUnit::TestCase
namespace
{
class TextFileTestCase
{
public:
TextFileTestCase()
@@ -37,39 +40,9 @@ public:
srand((unsigned)time(nullptr));
}
virtual void tearDown() override { unlink(GetTestFileName()); }
private:
CPPUNIT_TEST_SUITE( TextFileTestCase );
CPPUNIT_TEST( ReadEmpty );
CPPUNIT_TEST( ReadDOS );
CPPUNIT_TEST( ReadDOSLast );
CPPUNIT_TEST( ReadUnix );
CPPUNIT_TEST( ReadUnixLast );
CPPUNIT_TEST( ReadMac );
CPPUNIT_TEST( ReadMacLast );
CPPUNIT_TEST( ReadMixed );
CPPUNIT_TEST( ReadMixedWithFuzzing );
CPPUNIT_TEST( ReadCRCRLF );
CPPUNIT_TEST( ReadUTF8 );
CPPUNIT_TEST( ReadUTF16 );
CPPUNIT_TEST( ReadBig );
CPPUNIT_TEST_SUITE_END();
void ReadEmpty();
void ReadDOS();
void ReadDOSLast();
void ReadUnix();
void ReadUnixLast();
void ReadMac();
void ReadMacLast();
void ReadMixed();
void ReadMixedWithFuzzing();
void ReadCRCRLF();
void ReadUTF8();
void ReadUTF16();
void ReadBig();
~TextFileTestCase() { unlink(GetTestFileName()); }
protected:
// return the name of the test file we use
static const char *GetTestFileName() { return "textfiletest.txt"; }
@@ -81,139 +54,136 @@ private:
// create the test file with the given contents (version must be used if
// contents contains NULs)
static void CreateTestFile(size_t len, const char *contents);
static void CreateTestFile(size_t len, const char *contents)
{
FILE *f = fopen(GetTestFileName(), "wb");
REQUIRE( f );
CHECK( fwrite(contents, 1, len, f) == len );
CHECK( fclose(f) == 0 );
}
wxDECLARE_NO_COPY_CLASS(TextFileTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( TextFileTestCase );
} // anonymous namespace
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TextFileTestCase, "TextFileTestCase" );
// ----------------------------------------------------------------------------
// tests
// ----------------------------------------------------------------------------
void TextFileTestCase::CreateTestFile(size_t len, const char *contents)
{
FILE *f = fopen(GetTestFileName(), "wb");
CPPUNIT_ASSERT( f );
CPPUNIT_ASSERT_EQUAL( len, fwrite(contents, 1, len, f) );
CPPUNIT_ASSERT_EQUAL( 0, fclose(f) );
}
void TextFileTestCase::ReadEmpty()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadEmpty", "[textfile]")
{
CreateTestFile("");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)0, f.GetLineCount() );
CPPUNIT_ASSERT( f.Eof() );
CPPUNIT_ASSERT_EQUAL( "", f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( "", f.GetLastLine() );
CHECK( f.GetLineCount() == (size_t)0 );
CHECK( f.Eof() );
CHECK( f.GetFirstLine() == "" );
CHECK( f.GetLastLine() == "" );
}
void TextFileTestCase::ReadDOS()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadDOS", "[textfile]")
{
CreateTestFile("foo\r\nbar\r\nbaz");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)3, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(2) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("bar")), f.GetLine(1) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
CHECK( f.GetLineCount() == (size_t)3 );
CHECK( f.GetLineType(0) == wxTextFileType_Dos );
CHECK( f.GetLineType(2) == wxTextFileType_None );
CHECK( f.GetLine(1) == wxString(wxT("bar")) );
CHECK( f.GetLastLine() == wxString(wxT("baz")) );
}
void TextFileTestCase::ReadDOSLast()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadDOSLast", "[textfile]")
{
CreateTestFile("foo\r\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CHECK( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
CHECK( f.GetLineCount() == 1 );
CHECK( f.GetLineType(0) == wxTextFileType_Dos );
CHECK( f.GetFirstLine() == "foo" );
}
void TextFileTestCase::ReadUnix()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadUnix", "[textfile]")
{
CreateTestFile("foo\nbar\nbaz");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)3, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(2) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("bar")), f.GetLine(1) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
CHECK( f.GetLineCount() == (size_t)3 );
CHECK( f.GetLineType(0) == wxTextFileType_Unix );
CHECK( f.GetLineType(2) == wxTextFileType_None );
CHECK( f.GetLine(1) == wxString(wxT("bar")) );
CHECK( f.GetLastLine() == wxString(wxT("baz")) );
}
void TextFileTestCase::ReadUnixLast()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadUnixLast", "[textfile]")
{
CreateTestFile("foo\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CHECK( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
CHECK( f.GetLineCount() == 1 );
CHECK( f.GetLineType(0) == wxTextFileType_Unix );
CHECK( f.GetFirstLine() == "foo" );
}
void TextFileTestCase::ReadMac()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadMac", "[textfile]")
{
CreateTestFile("foo\rbar\r\rbaz");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)4, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(1) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(2) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(3) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("foo")), f.GetLine(0) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("bar")), f.GetLine(1) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("")), f.GetLine(2) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
CHECK( f.GetLineCount() == (size_t)4 );
CHECK( f.GetLineType(0) == wxTextFileType_Mac );
CHECK( f.GetLineType(1) == wxTextFileType_Mac );
CHECK( f.GetLineType(2) == wxTextFileType_Mac );
CHECK( f.GetLineType(3) == wxTextFileType_None );
CHECK( f.GetLine(0) == wxString(wxT("foo")) );
CHECK( f.GetLine(1) == wxString(wxT("bar")) );
CHECK( f.GetLine(2) == wxString(wxT("")) );
CHECK( f.GetLastLine() == wxString(wxT("baz")) );
}
void TextFileTestCase::ReadMacLast()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadMacLast", "[textfile]")
{
CreateTestFile("foo\r");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CHECK( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
CHECK( f.GetLineCount() == 1 );
CHECK( f.GetLineType(0) == wxTextFileType_Mac );
CHECK( f.GetFirstLine() == "foo" );
}
void TextFileTestCase::ReadMixed()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadMixed", "[textfile]")
{
CreateTestFile("foo\rbar\r\nbaz\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)3, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(1) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(2) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("foo")), f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("bar")), f.GetLine(1) );
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
CHECK( f.GetLineCount() == (size_t)3 );
CHECK( f.GetLineType(0) == wxTextFileType_Mac );
CHECK( f.GetLineType(1) == wxTextFileType_Dos );
CHECK( f.GetLineType(2) == wxTextFileType_Unix );
CHECK( f.GetFirstLine() == wxString(wxT("foo")) );
CHECK( f.GetLine(1) == wxString(wxT("bar")) );
CHECK( f.GetLastLine() == wxString(wxT("baz")) );
}
void TextFileTestCase::ReadMixedWithFuzzing()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadMixedWithFuzzing", "[textfile]")
{
for ( int iteration = 0; iteration < 100; iteration++)
{
@@ -240,12 +210,12 @@ void TextFileTestCase::ReadMixedWithFuzzing()
CreateTestFile(data);
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CPPUNIT_ASSERT_EQUAL( (size_t)linesCnt, f.GetLineCount() );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.GetLineCount() == (size_t)linesCnt );
}
}
void TextFileTestCase::ReadCRCRLF()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadCRCRLF", "[textfile]")
{
// Notepad may create files with CRCRLF line endings (see
// https://stackoverflow.com/questions/6998506/text-file-with-0d-0d-0a-line-breaks).
@@ -256,36 +226,35 @@ void TextFileTestCase::ReadCRCRLF()
CreateTestFile("foo\r\r\nbar\r\r\r\nbaz\r\r\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName())) );
wxString all;
for ( wxString str = f.GetFirstLine(); !f.Eof(); str = f.GetNextLine() )
all += str;
CPPUNIT_ASSERT_EQUAL( "foobarbaz", all );
CHECK( all == "foobarbaz" );
}
void TextFileTestCase::ReadUTF8()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadUTF8", "[textfile]")
{
CreateTestFile("П\nривет");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName()), wxConvUTF8) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName()), wxConvUTF8) );
CPPUNIT_ASSERT_EQUAL( (size_t)2, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(1) );
CHECK( f.GetLineCount() == (size_t)2 );
CHECK( f.GetLineType(0) == wxTextFileType_Unix );
CHECK( f.GetLineType(1) == wxTextFileType_None );
#ifdef wxMUST_USE_U_ESCAPE
CPPUNIT_ASSERT_EQUAL( wxString(L"\u041f"), f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( wxString(L"\u0440\u0438\u0432\u0435\u0442"),
f.GetLastLine() );
CHECK( f.GetFirstLine() == wxString(L"\u041f") );
CHECK( f.GetLastLine() == wxString(L"\u0440\u0438\u0432\u0435\u0442") );
#else
CPPUNIT_ASSERT_EQUAL( wxString(L"П"), f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( wxString(L"ривет"), f.GetLastLine() );
CHECK( f.GetFirstLine() == wxString(L"П") );
CHECK( f.GetLastLine() == wxString(L"ривет") );
#endif
}
void TextFileTestCase::ReadUTF16()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadUTF16", "[textfile]")
{
CreateTestFile(16,
"\x1f\x04\x0d\x00\x0a\x00"
@@ -293,23 +262,22 @@ void TextFileTestCase::ReadUTF16()
wxTextFile f;
wxMBConvUTF16LE conv;
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName()), conv) );
CHECK( f.Open(wxString::FromAscii(GetTestFileName()), conv) );
CPPUNIT_ASSERT_EQUAL( (size_t)2, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(1) );
CHECK( f.GetLineCount() == (size_t)2 );
CHECK( f.GetLineType(0) == wxTextFileType_Dos );
CHECK( f.GetLineType(1) == wxTextFileType_None );
#ifdef wxMUST_USE_U_ESCAPE
CPPUNIT_ASSERT_EQUAL( wxString(L"\u041f"), f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( wxString(L"\u0440\u0438\u0432\u0435\u0442"),
f.GetLastLine() );
CHECK( f.GetFirstLine() == wxString(L"\u041f") );
CHECK( f.GetLastLine() == wxString(L"\u0440\u0438\u0432\u0435\u0442") );
#else
CPPUNIT_ASSERT_EQUAL( wxString(L"П"), f.GetFirstLine() );
CPPUNIT_ASSERT_EQUAL( wxString(L"ривет"), f.GetLastLine() );
CHECK( f.GetFirstLine() == wxString(L"П") );
CHECK( f.GetLastLine() == wxString(L"ривет") );
#endif
}
void TextFileTestCase::ReadBig()
TEST_CASE_METHOD(TextFileTestCase, "TextFile::ReadBig", "[textfile]")
{
static const size_t NUM_LINES = 10000;
@@ -322,14 +290,13 @@ void TextFileTestCase::ReadBig()
}
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CHECK( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( NUM_LINES, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxString("Line 1"), f[0] );
CPPUNIT_ASSERT_EQUAL( wxString("Line 999"), f[998] );
CPPUNIT_ASSERT_EQUAL( wxString("Line 1000"), f[999] );
CPPUNIT_ASSERT_EQUAL( wxString::Format("Line %lu", (unsigned long)NUM_LINES),
f[NUM_LINES - 1] );
CHECK( f.GetLineCount() == NUM_LINES );
CHECK( f[0] == wxString("Line 1") );
CHECK( f[998] == wxString("Line 999") );
CHECK( f[999] == wxString("Line 1000") );
CHECK( f[NUM_LINES - 1] == wxString::Format("Line %lu", (unsigned long)NUM_LINES) );
}
TEST_CASE("wxTextBuffer::Translate", "[textbuffer]")
+17 -44
View File
@@ -12,7 +12,6 @@
#include "testprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif // WX_PRECOMP
@@ -59,39 +58,10 @@ public:
}
};
// --------------------------------------------------------------------------
// test class
// helpers
// --------------------------------------------------------------------------
class EvtConnectionTestCase : public CppUnit::TestCase
{
public:
EvtConnectionTestCase() {}
private:
CPPUNIT_TEST_SUITE( EvtConnectionTestCase );
CPPUNIT_TEST( SinkTest );
CPPUNIT_TEST( SourceDestroyTest );
CPPUNIT_TEST( MultiConnectionTest );
CPPUNIT_TEST_SUITE_END();
void SinkTest();
void SourceDestroyTest();
void MultiConnectionTest();
wxDECLARE_NO_COPY_CLASS(EvtConnectionTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( EvtConnectionTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EvtConnectionTestCase, "EvtConnectionTestCase" );
// Helpers
void DoConnect( wxEvtHandler& eh1, wxEvtHandler& eh2, wxTestSink& ts ){
eh1.Connect(wxEVT_TEST, (wxObjectEventFunction)&wxTestSink::OnTestEvent,
nullptr, &ts);
@@ -106,8 +76,11 @@ void DoDisconnect( wxEvtHandler& eh1, wxEvtHandler& eh2, wxTestSink& ts ){
nullptr, &ts);
}
// --------------------------------------------------------------------------
// tests
// --------------------------------------------------------------------------
void EvtConnectionTestCase::SinkTest()
TEST_CASE("EvtConnection::Sink", "[weakref][evtconnection]")
{
// Let the sink be destroyed before the sources
@@ -121,7 +94,7 @@ void EvtConnectionTestCase::SinkTest()
{
wxTestSink ts;
CPPUNIT_ASSERT( !ts.GetFirst() );
CHECK( !ts.GetFirst() );
DoConnect(eh1, eh2, ts);
DoDisconnect(eh1, eh2, ts);
@@ -135,7 +108,7 @@ void EvtConnectionTestCase::SinkTest()
eh2.ProcessEvent(evt);
// Make sure they were processed correctly
CPPUNIT_ASSERT_EQUAL( 0x00010001, gs_value );
CHECK( gs_value == 0x00010001 );
}
// Fire events again, should be no sink connected now
@@ -146,10 +119,10 @@ void EvtConnectionTestCase::SinkTest()
eh2.ProcessEvent( evt );
// Make sure no processing happened
CPPUNIT_ASSERT_EQUAL( 0, gs_value );
CHECK( gs_value == 0 );
}
void EvtConnectionTestCase::SourceDestroyTest()
TEST_CASE("EvtConnection::SourceDestroy", "[weakref][evtconnection]")
{
// Let the sources be destroyed before the sink
wxTestSink ts;
@@ -157,7 +130,7 @@ void EvtConnectionTestCase::SourceDestroyTest()
{
wxEvtHandler eh1;
{
CPPUNIT_ASSERT( !ts.GetFirst() );
CHECK( !ts.GetFirst() );
// Connect two event handlers to one sink
wxEvtHandler eh2;
@@ -173,7 +146,7 @@ void EvtConnectionTestCase::SourceDestroyTest()
eh2.ProcessEvent( evt );
// Make sure they were processed correctly
CPPUNIT_ASSERT_EQUAL( 0x00010001, gs_value );
CHECK( gs_value == 0x00010001 );
}
gs_value = 0;
@@ -181,12 +154,12 @@ void EvtConnectionTestCase::SourceDestroyTest()
eh1.ProcessEvent( evt );
// Make sure still connected
CPPUNIT_ASSERT_EQUAL( 0x00000001, gs_value );
CHECK( gs_value == 0x00000001 );
}
CPPUNIT_ASSERT( !ts.GetFirst() );
CHECK( !ts.GetFirst() );
}
void EvtConnectionTestCase::MultiConnectionTest()
TEST_CASE("EvtConnection::MultiConnection", "[weakref][evtconnection]")
{
// events used below
wxTestEvent evt;
@@ -215,7 +188,7 @@ void EvtConnectionTestCase::MultiConnectionTest()
eh1.ProcessEvent(evt);
eh1.ProcessEvent(evt1);
eh1.ProcessEvent(evt2);
CPPUNIT_ASSERT( gs_value==0x01010100 );
CHECK( gs_value==0x01010100 );
{
// Declare weak references to the objects (using same list)
@@ -228,7 +201,7 @@ void EvtConnectionTestCase::MultiConnectionTest()
eh1.ProcessEvent(evt);
eh1.ProcessEvent(evt1);
eh1.ProcessEvent(evt2);
CPPUNIT_ASSERT_EQUAL( 0x02010200, gs_value );
CHECK( gs_value == 0x02010200 );
}
// No connection should be left now
@@ -238,6 +211,6 @@ void EvtConnectionTestCase::MultiConnectionTest()
eh1.ProcessEvent(evt2);
// Nothing should have been done
CPPUNIT_ASSERT_EQUAL( 0, gs_value );
CHECK( gs_value == 0 );
}
+58 -94
View File
@@ -12,7 +12,6 @@
#include "testprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif // WX_PRECOMP
@@ -32,47 +31,9 @@ public:
};
// --------------------------------------------------------------------------
// test class
// helpers
// --------------------------------------------------------------------------
class WeakRefTestCase : public CppUnit::TestCase
{
public:
WeakRefTestCase() {}
private:
CPPUNIT_TEST_SUITE( WeakRefTestCase );
CPPUNIT_TEST( DeclareTest );
CPPUNIT_TEST( AssignTest );
CPPUNIT_TEST( AssignWeakRefTest );
CPPUNIT_TEST( MultiAssignTest );
CPPUNIT_TEST( CleanupTest );
CPPUNIT_TEST( DeleteTest );
#ifdef HAVE_DYNAMIC_CAST
CPPUNIT_TEST( DynamicRefTest );
#endif
CPPUNIT_TEST_SUITE_END();
void DeclareTest();
void AssignTest();
void AssignWeakRefTest();
void MultiAssignTest();
void CleanupTest();
void DeleteTest();
#ifdef HAVE_DYNAMIC_CAST
void DynamicRefTest();
#endif
wxDECLARE_NO_COPY_CLASS(WeakRefTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( WeakRefTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WeakRefTestCase, "WeakRefTestCase" );
// Test weak reference to an incomplete type, this should work if the type is
// fully defined before it is used (but currently doesn't, see #11916)
struct ForwardDeclaredClass;
@@ -83,7 +44,11 @@ struct ForwardDeclaredClass : wxEvtHandler { };
// A incomplete class that would be defined in other compilation units
struct IncompleteClass;
void WeakRefTestCase::DeclareTest()
// --------------------------------------------------------------------------
// tests
// --------------------------------------------------------------------------
TEST_CASE("WeakRef::Declare", "[weakref]")
{
{
// Not initializing or initializing with nullptr should work too
@@ -99,19 +64,18 @@ void WeakRefTestCase::DeclareTest()
wxWeakRef<wxEvtHandler> wro2(&eh);
wxWeakRef<wxObjectTrackable> wro3(&ot);
CPPUNIT_ASSERT( wro2.get() == &eh );
CPPUNIT_ASSERT( wro3.get() == &ot );
CHECK( wro2.get() == &eh );
CHECK( wro3.get() == &ot );
// Test accessing wxObject members
CPPUNIT_ASSERT( !wro2->GetRefData() );
CPPUNIT_ASSERT( !wro3->GetRefData() );
CHECK( !wro2->GetRefData() );
CHECK( !wro3->GetRefData() );
wxWeakRef<wxEvtHandler> wreh(&eh);
wxWeakRef<wxObjectTrackable> wrot(&ot);
CPPUNIT_ASSERT( wreh.get() == &eh );
CPPUNIT_ASSERT( wrot.get() == &ot );
CHECK( wreh.get() == &eh );
CHECK( wrot.get() == &ot );
}
// This test requires a working dynamic_cast<>
@@ -119,10 +83,10 @@ void WeakRefTestCase::DeclareTest()
{
ForwardDeclaredClass fdc;
g_incompleteWeakRef = &fdc;
CPPUNIT_ASSERT( g_incompleteWeakRef );
CHECK( g_incompleteWeakRef );
}
CPPUNIT_ASSERT( !g_incompleteWeakRef );
CHECK( !g_incompleteWeakRef );
#endif // RTTI enabled
{
@@ -143,7 +107,7 @@ void WeakRefTestCase::DeclareTest()
}
}
void WeakRefTestCase::AssignTest()
TEST_CASE("WeakRef::Assign", "[weakref]")
{
wxWeakRef<wxEvtHandler> wro1;
wxWeakRef<wxObjectTrackable> wro2;
@@ -155,13 +119,13 @@ void WeakRefTestCase::AssignTest()
wro1 = &eh;
wro2 = &ot;
CPPUNIT_ASSERT( wro1.get() == &eh );
CPPUNIT_ASSERT( wro2.get() == &ot );
CHECK( wro1.get() == &eh );
CHECK( wro2.get() == &ot );
}
// Should be reset now
CPPUNIT_ASSERT( !wro1 );
CPPUNIT_ASSERT( !wro2 );
CHECK( !wro1 );
CHECK( !wro2 );
// Explicitly resetting should work too
wxEvtHandler eh;
@@ -173,11 +137,11 @@ void WeakRefTestCase::AssignTest()
wro1 = nullptr;
wro2 = nullptr;
CPPUNIT_ASSERT( !wro1 );
CPPUNIT_ASSERT( !wro2 );
CHECK( !wro1 );
CHECK( !wro2 );
}
void WeakRefTestCase::AssignWeakRefTest()
TEST_CASE("WeakRef::AssignWeakRef", "[weakref]")
{
// Test declare when T is wxObject
wxWeakRef<wxEvtHandler> wro1;
@@ -194,21 +158,21 @@ void WeakRefTestCase::AssignWeakRefTest()
wro3 = wro1;
wro4 = wro2;
CPPUNIT_ASSERT( wro1.get() == &eh );
CPPUNIT_ASSERT( wro2.get() == &ot );
CPPUNIT_ASSERT( wro3.get() == &eh );
CPPUNIT_ASSERT( wro4.get() == &ot );
CHECK( wro1.get() == &eh );
CHECK( wro2.get() == &ot );
CHECK( wro3.get() == &eh );
CHECK( wro4.get() == &ot );
wro4.Release();
CPPUNIT_ASSERT( !wro4.get() );
CHECK( !wro4.get() );
}
// Should be reset now
CPPUNIT_ASSERT( !wro1 );
CPPUNIT_ASSERT( !wro2 );
CHECK( !wro1 );
CHECK( !wro2 );
}
void WeakRefTestCase::MultiAssignTest()
TEST_CASE("WeakRef::MultiAssign", "[weakref]")
{
// Object is tracked by several refs
wxEvtHandler *peh = new wxEvtHandler;
@@ -221,22 +185,22 @@ void WeakRefTestCase::MultiAssignTest()
wxWeakRef<wxObjectTrackable> wro3 = pot;
wxWeakRef<wxObjectTrackable> wro4 = pot;
CPPUNIT_ASSERT( wro1.get() == peh );
CPPUNIT_ASSERT( wro2.get() == peh );
CPPUNIT_ASSERT( wro3.get() == pot );
CPPUNIT_ASSERT( wro4.get() == pot );
CHECK( wro1.get() == peh );
CHECK( wro2.get() == peh );
CHECK( wro3.get() == pot );
CHECK( wro4.get() == pot );
delete peh;
delete pot;
// Should be reset now
CPPUNIT_ASSERT( !wro1 );
CPPUNIT_ASSERT( !wro2 );
CPPUNIT_ASSERT( !wro3 );
CPPUNIT_ASSERT( !wro4 );
CHECK( !wro1 );
CHECK( !wro2 );
CHECK( !wro3 );
CHECK( !wro4 );
}
void WeakRefTestCase::CleanupTest()
TEST_CASE("WeakRef::Cleanup", "[weakref]")
{
// Make sure that trackable objects have no left over tracker nodes after use.
// This time the references goes out of scope before the objects.
@@ -258,18 +222,18 @@ void WeakRefTestCase::CleanupTest()
// Access members of reffed object
wro3->TestFunc();
CPPUNIT_ASSERT( eh.GetFirst()==&wro2 );
CPPUNIT_ASSERT( ots.wxTrackable::GetFirst()==&wro3 );
CPPUNIT_ASSERT( otd.wxTrackable::GetFirst()==&wro4 );
CHECK( eh.GetFirst()==&wro2 );
CHECK( ots.wxTrackable::GetFirst()==&wro3 );
CHECK( otd.wxTrackable::GetFirst()==&wro4 );
}
// Should be reset now
CPPUNIT_ASSERT( !eh.GetFirst() );
CPPUNIT_ASSERT( !ots.wxTrackable::GetFirst() );
CPPUNIT_ASSERT( !otd.wxTrackable::GetFirst() );
CHECK( !eh.GetFirst() );
CHECK( !ots.wxTrackable::GetFirst() );
CHECK( !otd.wxTrackable::GetFirst() );
}
void WeakRefTestCase::DeleteTest()
TEST_CASE("WeakRef::Delete", "[weakref]")
{
// Object is tracked by several refs
wxEvtHandler *peh = new wxEvtHandler;
@@ -278,18 +242,18 @@ void WeakRefTestCase::DeleteTest()
wxEvtHandlerRef wre(peh);
wxWeakRef<wxEvtHandler> wro(peh);
CPPUNIT_ASSERT( wre.get() == peh );
CPPUNIT_ASSERT( wro.get() == peh );
CHECK( wre.get() == peh );
CHECK( wro.get() == peh );
delete wre.get();
CPPUNIT_ASSERT( !wre );
CPPUNIT_ASSERT( !wro );
CHECK( !wre );
CHECK( !wro );
}
#ifdef HAVE_DYNAMIC_CAST
void WeakRefTestCase::DynamicRefTest()
TEST_CASE("WeakRef::DynamicRef", "[weakref]")
{
wxWeakRefDynamic<wxEvtHandler> wro1;
wxWeakRefDynamic<wxObjectTrackable> wro2;
@@ -301,24 +265,24 @@ void WeakRefTestCase::DynamicRefTest()
wro1 = &eh;
}
CPPUNIT_ASSERT( !wro1 );
CHECK( !wro1 );
wxObjectTrackable otd1;
wxObjectTrackable otd2;
wro2 = &otd1;
wro3 = &otd2;
CPPUNIT_ASSERT( wro2.get() == &otd1 );
CPPUNIT_ASSERT( wro3.get() == &otd2 );
CHECK( wro2.get() == &otd1 );
CHECK( wro3.get() == &otd2 );
wro3 = wro2;
CPPUNIT_ASSERT( wro2.get() == &otd1 );
CPPUNIT_ASSERT( wro3.get() == &otd1 );
CHECK( wro2.get() == &otd1 );
CHECK( wro3.get() == &otd1 );
}
// Should be reset now
CPPUNIT_ASSERT( !wro2 );
CPPUNIT_ASSERT( !wro3 );
CHECK( !wro2 );
CHECK( !wro3 );
}
#endif // HAVE_DYNAMIC_CAST
+105 -136
View File
@@ -24,169 +24,138 @@
#include "wx/xlocale.h"
// --------------------------------------------------------------------------
// test class
// tests
// --------------------------------------------------------------------------
class XLocaleTestCase : public CppUnit::TestCase
{
public:
XLocaleTestCase() { }
private:
CPPUNIT_TEST_SUITE( XLocaleTestCase );
CPPUNIT_TEST( TestCtor );
CPPUNIT_TEST( PreserveLocale );
CPPUNIT_TEST( TestCtypeFunctions );
CPPUNIT_TEST( TestStdlibFunctions );
CPPUNIT_TEST_SUITE_END();
void TestCtor();
void PreserveLocale();
void TestCtypeFunctions();
void TestStdlibFunctions();
void TestCtypeFunctionsWith(const wxXLocale& loc);
void TestStdlibFunctionsWith(const wxXLocale& loc);
wxDECLARE_NO_COPY_CLASS(XLocaleTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( XLocaleTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XLocaleTestCase, "XLocaleTestCase" );
// test the different wxXLocale ctors
void XLocaleTestCase::TestCtor()
TEST_CASE("XLocale::Ctor", "[xlocale]")
{
CPPUNIT_ASSERT( !wxXLocale().IsOk() );
CPPUNIT_ASSERT( wxCLocale.IsOk() );
CPPUNIT_ASSERT( wxXLocale("C").IsOk() );
CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() );
CHECK( !wxXLocale().IsOk() );
CHECK( wxCLocale.IsOk() );
CHECK( wxXLocale("C").IsOk() );
CHECK( !wxXLocale("bloordyblop").IsOk() );
#ifdef wxHAS_XLOCALE_SUPPORT
if ( wxXLocale(wxLANGUAGE_FRENCH).IsOk() )
{
#ifdef __WINDOWS__
CPPUNIT_ASSERT( wxXLocale("french").IsOk() );
CHECK( wxXLocale("french").IsOk() );
#else
CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() );
CHECK( wxXLocale("fr_FR").IsOk() );
#endif
}
#endif // wxHAS_XLOCALE_SUPPORT
}
void XLocaleTestCase::PreserveLocale()
TEST_CASE("XLocale::PreserveLocale", "[xlocale]")
{
// Test that using locale functions doesn't change the global C locale.
const wxString origLocale(setlocale(LC_ALL, nullptr));
wxStrtod_l(wxT("1.234"), nullptr, wxCLocale);
CPPUNIT_ASSERT_EQUAL( origLocale, setlocale(LC_ALL, nullptr) );
CHECK( setlocale(LC_ALL, nullptr) == origLocale );
}
// test the ctype functions with the given locale
void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc)
static void TestCtypeFunctionsWith(const wxXLocale& loc)
{
// NOTE: here go the checks which must pass under _any_ locale "loc";
// checks for specific locales are in TestCtypeFunctions()
// isalnum
CPPUNIT_ASSERT( wxIsalnum_l('0', loc) );
CPPUNIT_ASSERT( wxIsalnum_l('9', loc) );
CPPUNIT_ASSERT( wxIsalnum_l('A', loc) );
CPPUNIT_ASSERT( wxIsalnum_l('Z', loc) );
CPPUNIT_ASSERT( wxIsalnum_l('a', loc) );
CPPUNIT_ASSERT( wxIsalnum_l('z', loc) );
CPPUNIT_ASSERT( !wxIsalnum_l('*', loc) );
CPPUNIT_ASSERT( !wxIsalnum_l('@', loc) );
CPPUNIT_ASSERT( !wxIsalnum_l('+', loc) );
CHECK( wxIsalnum_l('0', loc) );
CHECK( wxIsalnum_l('9', loc) );
CHECK( wxIsalnum_l('A', loc) );
CHECK( wxIsalnum_l('Z', loc) );
CHECK( wxIsalnum_l('a', loc) );
CHECK( wxIsalnum_l('z', loc) );
CHECK( !wxIsalnum_l('*', loc) );
CHECK( !wxIsalnum_l('@', loc) );
CHECK( !wxIsalnum_l('+', loc) );
// isalpha
CPPUNIT_ASSERT( !wxIsalpha_l('0', loc) );
CPPUNIT_ASSERT( !wxIsalpha_l('9', loc) );
CPPUNIT_ASSERT( wxIsalpha_l('A', loc) );
CPPUNIT_ASSERT( wxIsalpha_l('Z', loc) );
CPPUNIT_ASSERT( wxIsalpha_l('a', loc) );
CPPUNIT_ASSERT( wxIsalpha_l('z', loc) );
CPPUNIT_ASSERT( !wxIsalpha_l('*', loc) );
CPPUNIT_ASSERT( !wxIsalpha_l('@', loc) );
CPPUNIT_ASSERT( !wxIsalpha_l('+', loc) );
CHECK( !wxIsalpha_l('0', loc) );
CHECK( !wxIsalpha_l('9', loc) );
CHECK( wxIsalpha_l('A', loc) );
CHECK( wxIsalpha_l('Z', loc) );
CHECK( wxIsalpha_l('a', loc) );
CHECK( wxIsalpha_l('z', loc) );
CHECK( !wxIsalpha_l('*', loc) );
CHECK( !wxIsalpha_l('@', loc) );
CHECK( !wxIsalpha_l('+', loc) );
// TODO: iscntrl
// isdigit
CPPUNIT_ASSERT( wxIsdigit_l('0', loc) );
CPPUNIT_ASSERT( wxIsdigit_l('9', loc) );
CPPUNIT_ASSERT( !wxIsdigit_l('A', loc) );
CPPUNIT_ASSERT( !wxIsdigit_l('Z', loc) );
CPPUNIT_ASSERT( !wxIsdigit_l('a', loc) );
CPPUNIT_ASSERT( !wxIsdigit_l('z', loc) );
CHECK( wxIsdigit_l('0', loc) );
CHECK( wxIsdigit_l('9', loc) );
CHECK( !wxIsdigit_l('A', loc) );
CHECK( !wxIsdigit_l('Z', loc) );
CHECK( !wxIsdigit_l('a', loc) );
CHECK( !wxIsdigit_l('z', loc) );
// TODO: isgraph
// islower
CPPUNIT_ASSERT( !wxIslower_l('A', loc) );
CPPUNIT_ASSERT( !wxIslower_l('Z', loc) );
CPPUNIT_ASSERT( wxIslower_l('a', loc) );
CPPUNIT_ASSERT( wxIslower_l('z', loc) );
CPPUNIT_ASSERT( !wxIslower_l('0', loc) );
CPPUNIT_ASSERT( !wxIslower_l('9', loc) );
CHECK( !wxIslower_l('A', loc) );
CHECK( !wxIslower_l('Z', loc) );
CHECK( wxIslower_l('a', loc) );
CHECK( wxIslower_l('z', loc) );
CHECK( !wxIslower_l('0', loc) );
CHECK( !wxIslower_l('9', loc) );
// TODO: isprint
// TODO: ispunct
// isspace
CPPUNIT_ASSERT( wxIsspace_l(' ', loc) );
CPPUNIT_ASSERT( wxIsspace_l('\t', loc) );
CPPUNIT_ASSERT( wxIsspace_l('\r', loc) );
CPPUNIT_ASSERT( wxIsspace_l('\n', loc) );
CPPUNIT_ASSERT( !wxIsspace_l('0', loc) );
CPPUNIT_ASSERT( !wxIsspace_l('a', loc) );
CPPUNIT_ASSERT( !wxIsspace_l('A', loc) );
CHECK( wxIsspace_l(' ', loc) );
CHECK( wxIsspace_l('\t', loc) );
CHECK( wxIsspace_l('\r', loc) );
CHECK( wxIsspace_l('\n', loc) );
CHECK( !wxIsspace_l('0', loc) );
CHECK( !wxIsspace_l('a', loc) );
CHECK( !wxIsspace_l('A', loc) );
// isupper
CPPUNIT_ASSERT( !wxIsupper_l('0', loc) );
CPPUNIT_ASSERT( !wxIsupper_l('9', loc) );
CPPUNIT_ASSERT( wxIsupper_l('A', loc) );
CPPUNIT_ASSERT( wxIsupper_l('Z', loc) );
CPPUNIT_ASSERT( !wxIsupper_l('a', loc) );
CPPUNIT_ASSERT( !wxIsupper_l('z', loc) );
CHECK( !wxIsupper_l('0', loc) );
CHECK( !wxIsupper_l('9', loc) );
CHECK( wxIsupper_l('A', loc) );
CHECK( wxIsupper_l('Z', loc) );
CHECK( !wxIsupper_l('a', loc) );
CHECK( !wxIsupper_l('z', loc) );
// isxdigit
CPPUNIT_ASSERT( wxIsxdigit_l('0', loc) );
CPPUNIT_ASSERT( wxIsxdigit_l('9', loc) );
CPPUNIT_ASSERT( wxIsxdigit_l('A', loc) );
CPPUNIT_ASSERT( wxIsxdigit_l('F', loc) );
CPPUNIT_ASSERT( !wxIsxdigit_l('Z', loc) );
CPPUNIT_ASSERT( wxIsxdigit_l('a', loc) );
CPPUNIT_ASSERT( wxIsxdigit_l('f', loc) );
CPPUNIT_ASSERT( !wxIsxdigit_l('z', loc) );
CHECK( wxIsxdigit_l('0', loc) );
CHECK( wxIsxdigit_l('9', loc) );
CHECK( wxIsxdigit_l('A', loc) );
CHECK( wxIsxdigit_l('F', loc) );
CHECK( !wxIsxdigit_l('Z', loc) );
CHECK( wxIsxdigit_l('a', loc) );
CHECK( wxIsxdigit_l('f', loc) );
CHECK( !wxIsxdigit_l('z', loc) );
// tolower
CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('A', loc) );
CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('a', loc) );
CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('Z', loc) );
CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('z', loc) );
CPPUNIT_ASSERT_EQUAL( '0', (char)wxTolower_l('0', loc) );
CPPUNIT_ASSERT_EQUAL( '9', (char)wxTolower_l('9', loc) );
CHECK( (char)wxTolower_l('A', loc) == 'a' );
CHECK( (char)wxTolower_l('a', loc) == 'a' );
CHECK( (char)wxTolower_l('Z', loc) == 'z' );
CHECK( (char)wxTolower_l('z', loc) == 'z' );
CHECK( (char)wxTolower_l('0', loc) == '0' );
CHECK( (char)wxTolower_l('9', loc) == '9' );
// toupper
CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('A', loc) );
CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('a', loc) );
CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('Z', loc) );
CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('z', loc) );
CPPUNIT_ASSERT_EQUAL( '0', (char)wxToupper_l('0', loc) );
CPPUNIT_ASSERT_EQUAL( '9', (char)wxToupper_l('9', loc) );
CHECK( (char)wxToupper_l('A', loc) == 'A' );
CHECK( (char)wxToupper_l('a', loc) == 'A' );
CHECK( (char)wxToupper_l('Z', loc) == 'Z' );
CHECK( (char)wxToupper_l('z', loc) == 'Z' );
CHECK( (char)wxToupper_l('0', loc) == '0' );
CHECK( (char)wxToupper_l('9', loc) == '9' );
}
// test the stdlib functions with the given locale
void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& loc)
static void TestStdlibFunctionsWith(const wxXLocale& loc)
{
// NOTE: here go the checks which must pass under _any_ locale "loc";
// checks for specific locales are in TestStdlibFunctions()
@@ -194,28 +163,28 @@ void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& loc)
wchar_t* endptr;
// strtod (don't use decimal separator as it's locale-specific)
CPPUNIT_ASSERT_EQUAL( 0.0, wxStrtod_l(wxT("0"), nullptr, loc) );
CPPUNIT_ASSERT_EQUAL( 1234.0, wxStrtod_l(wxT("1234"), nullptr, loc) );
CHECK( wxStrtod_l(wxT("0"), nullptr, loc) == 0.0 );
CHECK( wxStrtod_l(wxT("1234"), nullptr, loc) == 1234.0 );
// strtol
endptr = nullptr;
CPPUNIT_ASSERT_EQUAL( 100, wxStrtol_l(wxT("100"), nullptr, 0, loc) );
CPPUNIT_ASSERT_EQUAL( 0xFF, wxStrtol_l(wxT("0xFF"), nullptr, 0, loc) );
CPPUNIT_ASSERT_EQUAL( 2001, wxStrtol_l(wxT("2001 60c0c0 -1101110100110100100000 0x6fffff"), &endptr, 10, loc) );
CPPUNIT_ASSERT_EQUAL( 0x60c0c0, wxStrtol_l(endptr, &endptr, 16, loc) );
CPPUNIT_ASSERT_EQUAL( -0x374D20, wxStrtol_l(endptr, &endptr, 2, loc) );
CPPUNIT_ASSERT_EQUAL( 0x6fffff, wxStrtol_l(endptr, nullptr, 0, loc) );
CHECK( wxStrtol_l(wxT("100"), nullptr, 0, loc) == 100 );
CHECK( wxStrtol_l(wxT("0xFF"), nullptr, 0, loc) == 0xFF );
CHECK( wxStrtol_l(wxT("2001 60c0c0 -1101110100110100100000 0x6fffff"), &endptr, 10, loc) == 2001 );
CHECK( wxStrtol_l(endptr, &endptr, 16, loc) == 0x60c0c0 );
CHECK( wxStrtol_l(endptr, &endptr, 2, loc) == -0x374D20 );
CHECK( wxStrtol_l(endptr, nullptr, 0, loc) == 0x6fffff );
// strtoul
// NOTE: 3147483647 and 0xEE6B2800 are greater than LONG_MAX (on 32bit machines) but
// smaller than ULONG_MAX
CPPUNIT_ASSERT_EQUAL( 3147483647ul, wxStrtoul_l(wxT("3147483647"), nullptr, 0, loc) );
CPPUNIT_ASSERT_EQUAL( 0xEE6B2800ul, wxStrtoul_l(wxT("0xEE6B2800"), nullptr, 0, loc) );
CHECK( wxStrtoul_l(wxT("3147483647"), nullptr, 0, loc) == 3147483647ul );
CHECK( wxStrtoul_l(wxT("0xEE6B2800"), nullptr, 0, loc) == 0xEE6B2800ul );
// TODO: test for "failure" behaviour of the functions above
}
void XLocaleTestCase::TestCtypeFunctions()
TEST_CASE("XLocale::CtypeFunctions", "[xlocale]")
{
SECTION("C")
{
@@ -234,13 +203,13 @@ void XLocaleTestCase::TestCtypeFunctions()
TestCtypeFunctionsWith(locFR);
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe9'), locFR) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe9'), locFR) );
CPPUNIT_ASSERT( !wxIslower_l(wxT('\xc9'), locFR) );
CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc9'), locFR) );
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe7'), locFR) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe7'), locFR) );
CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc7'), locFR) );
CHECK( wxIsalpha_l(wxT('\xe9'), locFR) );
CHECK( wxIslower_l(wxT('\xe9'), locFR) );
CHECK( !wxIslower_l(wxT('\xc9'), locFR) );
CHECK( wxIsupper_l(wxT('\xc9'), locFR) );
CHECK( wxIsalpha_l(wxT('\xe7'), locFR) );
CHECK( wxIslower_l(wxT('\xe7'), locFR) );
CHECK( wxIsupper_l(wxT('\xc7'), locFR) );
}
SECTION("Italian")
@@ -251,13 +220,13 @@ void XLocaleTestCase::TestCtypeFunctions()
TestCtypeFunctionsWith(locIT);
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe1'), locIT) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe1'), locIT) );
CHECK( wxIsalpha_l(wxT('\xe1'), locIT) );
CHECK( wxIslower_l(wxT('\xe1'), locIT) );
}
#endif // wxHAS_XLOCALE_SUPPORT
}
void XLocaleTestCase::TestStdlibFunctions()
TEST_CASE("XLocale::StdlibFunctions", "[xlocale]")
{
SECTION("C")
{
@@ -267,11 +236,11 @@ void XLocaleTestCase::TestStdlibFunctions()
// strtod checks specific for C locale
endptr = nullptr;
CPPUNIT_ASSERT_EQUAL( 0.0, wxStrtod_l(wxT("0.000"), nullptr, wxCLocale) );
CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1.234"), nullptr, wxCLocale) );
CPPUNIT_ASSERT_EQUAL( -1.234E-5, wxStrtod_l(wxT("-1.234E-5"), nullptr, wxCLocale) );
CPPUNIT_ASSERT_EQUAL( 365.24, wxStrtod_l(wxT("365.24 29.53"), &endptr, wxCLocale) );
CPPUNIT_ASSERT_EQUAL( 29.53, wxStrtod_l(endptr, nullptr, wxCLocale) );
CHECK( wxStrtod_l(wxT("0.000"), nullptr, wxCLocale) == 0.0 );
CHECK( wxStrtod_l(wxT("1.234"), nullptr, wxCLocale) == 1.234 );
CHECK( wxStrtod_l(wxT("-1.234E-5"), nullptr, wxCLocale) == -1.234E-5 );
CHECK( wxStrtod_l(wxT("365.24 29.53"), &endptr, wxCLocale) == 365.24 );
CHECK( wxStrtod_l(endptr, nullptr, wxCLocale) == 29.53 );
}
#ifdef wxHAS_XLOCALE_SUPPORT
@@ -284,10 +253,10 @@ void XLocaleTestCase::TestStdlibFunctions()
TestCtypeFunctionsWith(locFR);
// comma as decimal point:
CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), nullptr, locFR) );
CHECK( wxStrtod_l(wxT("1,234"), nullptr, locFR) == 1.234 );
// space as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1 234,5"), nullptr, locFR) );
CHECK( 1234.5 != wxStrtod_l(wxT("1 234,5"), nullptr, locFR) );
}
@@ -300,10 +269,10 @@ void XLocaleTestCase::TestStdlibFunctions()
TestStdlibFunctionsWith(locIT);
// comma as decimal point:
CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), nullptr, locIT) );
CHECK( wxStrtod_l(wxT("1,234"), nullptr, locIT) == 1.234 );
// dot as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), nullptr, locIT) );
CHECK( 1234.5 != wxStrtod_l(wxT("1.234,5"), nullptr, locIT) );
}
#endif // wxHAS_XLOCALE_SUPPORT
}