diff --git a/tests/filekind/filekind.cpp b/tests/filekind/filekind.cpp index 1e4b55455b..1898cf6ef3 100644 --- a/tests/filekind/filekind.cpp +++ b/tests/filekind/filekind.cpp @@ -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 diff --git a/tests/hashes/hashes.cpp b/tests/hashes/hashes.cpp index b4fb8fb162..5298c3c8f5 100644 --- a/tests/hashes/hashes.cpp +++ b/tests/hashes/hashes.cpp @@ -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(); } -void HashesTestCase::PtrHashMapTest() { HashMapTest(); } -void HashesTestCase::LongHashMapTest() { HashMapTest(); } -void HashesTestCase::ULongHashMapTest() { HashMapTest(); } -void HashesTestCase::UIntHashMapTest() { HashMapTest(); } -void HashesTestCase::IntHashMapTest() { HashMapTest(); } -void HashesTestCase::ShortHashMapTest() { HashMapTest(); } -void HashesTestCase::UShortHashMapTest() { HashMapTest(); } +TEST_CASE("Hashes::StringHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::PtrHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::LongHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::ULongHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::UIntHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::IntHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::ShortHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::UShortHashMap", "[hash]") { HashMapTest(); } #ifdef TEST_LONGLONG -void HashesTestCase::LLongHashMapTest() { HashMapTest(); } -void HashesTestCase::ULLongHashMapTest() { HashMapTest(); } +TEST_CASE("Hashes::LLongHashMap", "[hash]") { HashMapTest(); } +TEST_CASE("Hashes::ULLongHashMap", "[hash]") { HashMapTest(); } #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") ); } diff --git a/tests/longlong/longlongtest.cpp b/tests/longlong/longlongtest.cpp index c895d12ca3..f8b181611b 100644 --- a/tests/longlong/longlongtest.cpp +++ b/tests/longlong/longlongtest.cpp @@ -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::is_specialized ); - CPPUNIT_ASSERT( std::numeric_limits::is_specialized ); + CHECK( std::numeric_limits::is_specialized ); + CHECK( std::numeric_limits::is_specialized ); wxULongLong maxval = std::numeric_limits::max(); - CPPUNIT_ASSERT( maxval.ToDouble() > 0 ); + CHECK( maxval.ToDouble() > 0 ); } diff --git a/tests/mbconv/convautotest.cpp b/tests/mbconv/convautotest.cpp index f011ecee2a..653e494ddc 100644 --- a/tests/mbconv/convautotest.cpp +++ b/tests/mbconv/convautotest.cpp @@ -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); diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index 9fa3d21866..d1b538166c 100644 --- a/tests/mbconv/mbconvtest.cpp +++ b/tests/mbconv/mbconvtest.cpp @@ -51,174 +51,78 @@ wchar_t u10fffd[] = { 0xdbff, 0xdffd, 0 }; #endif // ---------------------------------------------------------------------------- -// test class +// test helpers // ---------------------------------------------------------------------------- -class MBConvTestCase : public CppUnit::TestCase -{ -public: - MBConvTestCase() { } +// verifies that the specified multibyte sequence decodes to the specified wchar_t sequence +static void TestDecoder( + const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t + size_t wideChars, // the number of wide characters at wideBuffer + const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" + size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + int sizeofNull // number of bytes occupied by terminating null in this encoding + ); -private: - CPPUNIT_TEST_SUITE( MBConvTestCase ); - CPPUNIT_TEST( UTF32LETests ); - CPPUNIT_TEST( UTF32BETests ); - CPPUNIT_TEST( WC2CP1250 ); - CPPUNIT_TEST( UTF7Tests ); - CPPUNIT_TEST( UTF8Tests ); - CPPUNIT_TEST( UTF16LETests ); - CPPUNIT_TEST( UTF16BETests ); - CPPUNIT_TEST( CP932Tests ); - CPPUNIT_TEST( CP1252Tests ); // depends on UTF8 Decoder functioning correctly - CPPUNIT_TEST( LibcTests ); - CPPUNIT_TEST( IconvTests ); - CPPUNIT_TEST( Latin1Tests ); - CPPUNIT_TEST( FontmapTests ); - CPPUNIT_TEST( BufSize ); - CPPUNIT_TEST( FromWCharTests ); - CPPUNIT_TEST( NonBMPCharTests ); - CPPUNIT_TEST( UTF8_41 ); - CPPUNIT_TEST( UTF8_7f ); - CPPUNIT_TEST( UTF8_80 ); - CPPUNIT_TEST( UTF8_c2_7f ); - CPPUNIT_TEST( UTF8_c2_80 ); - CPPUNIT_TEST( UTF8_ce_91 ); - CPPUNIT_TEST( UTF8_df_bf ); - CPPUNIT_TEST( UTF8_df_c0 ); - CPPUNIT_TEST( UTF8_e0_a0_7f ); - CPPUNIT_TEST( UTF8_e0_a0_80 ); - CPPUNIT_TEST( UTF8_e2_98_a0 ); - CPPUNIT_TEST( UTF8_ef_bf_bd ); - CPPUNIT_TEST( UTF8_ef_bf_c0 ); - CPPUNIT_TEST( UTF8_f0_90_80_7f ); - CPPUNIT_TEST( UTF8_f0_90_80_80 ); - CPPUNIT_TEST( UTF8_f4_8f_bf_bd ); - CPPUNIT_TEST( UTF8PUA_f4_80_82_a5 ); - CPPUNIT_TEST( UTF8Octal_backslash245 ); - CPPUNIT_TEST_SUITE_END(); - - void WC2CP1250(); - void UTF7Tests(); - void UTF8Tests(); - void UTF16LETests(); - void UTF16BETests(); - void UTF32LETests(); - void UTF32BETests(); - void CP932Tests(); - void CP1252Tests(); - void LibcTests(); - void FontmapTests(); - void BufSize(); - void FromWCharTests(); - void NonBMPCharTests(); - void IconvTests(); - void Latin1Tests(); - - // verifies that the specified multibyte sequence decodes to the specified wchar_t sequence - void TestDecoder( - const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t - size_t wideChars, // the number of wide characters at wideBuffer - const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" - size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence - int sizeofNull // number of bytes occupied by terminating null in this encoding - ); - - // verifies that the specified wchar_t sequence encodes to the specified multibyte sequence - void TestEncoder( - const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t - size_t wideChars, // the number of wide characters at wideBuffer - const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" - size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence - int sizeofNull // number of bytes occupied by terminating null in this encoding - ); +// verifies that the specified wchar_t sequence encodes to the specified multibyte sequence +static void TestEncoder( + const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t + size_t wideChars, // the number of wide characters at wideBuffer + const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" + size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + int sizeofNull // number of bytes occupied by terminating null in this encoding + ); #if wxUSE_STREAMS - // use wxTextInputStream to exercise wxMBConv interface - // (this reveals some bugs in certain wxMBConv subclasses) - void TestStreamDecoder( - const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t - size_t wideChars, // the number of wide characters at wideBuffer - const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" - size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence - ); +// use wxTextInputStream to exercise wxMBConv interface +// (this reveals some bugs in certain wxMBConv subclasses) +static void TestStreamDecoder( + const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t + size_t wideChars, // the number of wide characters at wideBuffer + const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" + size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + ); - // use wxTextOutputStream to exercise wxMBConv interface - // (this reveals some bugs in certain wxMBConv subclasses) - void TestStreamEncoder( - const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t - size_t wideChars, // the number of wide characters at wideBuffer - const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" - size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence - ); +// use wxTextOutputStream to exercise wxMBConv interface +// (this reveals some bugs in certain wxMBConv subclasses) +static void TestStreamEncoder( + const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t + size_t wideChars, // the number of wide characters at wideBuffer + const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" + size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + ); #endif - // tests the encoding and decoding capability of an wxMBConv object - // - // decodes the utf-8 bytes into wide characters - // encodes the wide characters to compare against input multiBuffer - // decodes the multiBuffer to compare against wide characters - // decodes the multiBuffer into wide characters - void TestCoder( - const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" - size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 - size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence - wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence - int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding - ); +// tests the encoding and decoding capability of an wxMBConv object +// +// decodes the utf-8 bytes into wide characters +// encodes the wide characters to compare against input multiBuffer +// decodes the multiBuffer to compare against wide characters +// decodes the multiBuffer into wide characters +static void TestCoder( + const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" + size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" + const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 + size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding + ); - // UTF-8 tests. Test the first, last and one in the middle for sequences - // of each length - void UTF8_41() { UTF8("\x41", u41); } - void UTF8_7f() { UTF8("\x7f", u7f); } - void UTF8_80() { UTF8("\x80", nullptr); } +// implementation for the utf-8 tests (see comments below) +static void UTF8(const char *charSequence, const wchar_t *wideSequence); +static void UTF8PUA(const char *charSequence, const wchar_t *wideSequence); +static void UTF8Octal(const char *charSequence, const wchar_t *wideSequence); +static void UTF8(const char *charSequence, const wchar_t *wideSequence, int option); - void UTF8_c2_7f() { UTF8("\xc2\x7f", nullptr); } - void UTF8_c2_80() { UTF8("\xc2\x80", u80); } - void UTF8_ce_91() { UTF8("\xce\x91", u391); } - void UTF8_df_bf() { UTF8("\xdf\xbf", u7ff); } - void UTF8_df_c0() { UTF8("\xdf\xc0", nullptr); } - void UTF8_e0_a0_7f() { UTF8("\xe0\xa0\x7f", nullptr); } - void UTF8_e0_a0_80() { UTF8("\xe0\xa0\x80", u800); } - void UTF8_e2_98_a0() { UTF8("\xe2\x98\xa0", u2620); } - void UTF8_ef_bf_bd() { UTF8("\xef\xbf\xbd", ufffd); } - void UTF8_ef_bf_c0() { UTF8("\xef\xbf\xc0", nullptr); } +// ---------------------------------------------------------------------------- +// tests +// ---------------------------------------------------------------------------- - void UTF8_f0_90_80_7f() { UTF8("\xf0\x90\x80\x7f", nullptr); } - void UTF8_f0_90_80_80() { UTF8("\xf0\x90\x80\x80", u10000); } - void UTF8_f4_8f_bf_bd() { UTF8("\xf4\x8f\xbf\xbd", u10fffd); } - - // test 'escaping the escape characters' for the two escaping schemes - void UTF8PUA_f4_80_82_a5() { UTF8PUA("\xf4\x80\x82\xa5", u1000a5); } - void UTF8Octal_backslash245() { UTF8Octal("\\245", L"\\245"); } - - // Test that converting string with incomplete surrogates in them fails - // (surrogates are only used in UTF-16, i.e. when wchar_t is 16 bits). -#if SIZEOF_WCHAR_T == 2 - void UTF8_fail_broken_surrogates(); -#endif // SIZEOF_WCHAR_T == 2 - - // implementation for the utf-8 tests (see comments below) - void UTF8(const char *charSequence, const wchar_t *wideSequence); - void UTF8PUA(const char *charSequence, const wchar_t *wideSequence); - void UTF8Octal(const char *charSequence, const wchar_t *wideSequence); - void UTF8(const char *charSequence, const wchar_t *wideSequence, int option); - - wxDECLARE_NO_COPY_CLASS(MBConvTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConv" ); - -void MBConvTestCase::WC2CP1250() +TEST_CASE("MBConv::WC2CP1250", "[mbconv]") { static const struct Data { @@ -236,11 +140,11 @@ void MBConvTestCase::WC2CP1250() const Data& d = data[n]; if (d.cp1250) { - CPPUNIT_ASSERT( strcmp(cs1250.cWC2MB(d.wc), d.cp1250) == 0 ); + CHECK( strcmp(cs1250.cWC2MB(d.wc), d.cp1250) == 0 ); } else { - CPPUNIT_ASSERT( (const char*)cs1250.cWC2MB(d.wc) == nullptr ); + CHECK( (const char*)cs1250.cWC2MB(d.wc) == nullptr ); } } } @@ -388,7 +292,7 @@ static const unsigned char welcome_cp932[71] = #endif #endif -void MBConvTestCase::UTF7Tests() +TEST_CASE("MBConv::UTF7Tests", "[mbconv]") { #if 0 wxCSConv convUTF7(wxFONTENCODING_UTF7); @@ -439,7 +343,7 @@ void MBConvTestCase::UTF7Tests() ); } -void MBConvTestCase::UTF8Tests() +TEST_CASE("MBConv::UTF8Tests", "[mbconv]") { TestDecoder ( @@ -463,7 +367,7 @@ void MBConvTestCase::UTF8Tests() #if SIZEOF_WCHAR_T == 2 // Can't use \ud800 as it's an invalid Unicode character. const wchar_t wc = 0xd800; - CPPUNIT_ASSERT_EQUAL(wxCONV_FAILED, wxConvUTF8.FromWChar(nullptr, 0, &wc, 1)); + CHECK(wxConvUTF8.FromWChar(nullptr, 0, &wc, 1) == wxCONV_FAILED); #endif // SIZEOF_WCHAR_T == 2 SECTION("UTF-8-FFFF") @@ -481,7 +385,7 @@ void MBConvTestCase::UTF8Tests() } } -void MBConvTestCase::UTF16LETests() +TEST_CASE("MBConv::UTF16LETests", "[mbconv]") { wxMBConvUTF16LE convUTF16LE; TestDecoder @@ -504,7 +408,7 @@ void MBConvTestCase::UTF16LETests() ); } -void MBConvTestCase::UTF16BETests() +TEST_CASE("MBConv::UTF16BETests", "[mbconv]") { wxMBConvUTF16BE convUTF16BE; TestDecoder @@ -527,7 +431,7 @@ void MBConvTestCase::UTF16BETests() ); } -void MBConvTestCase::UTF32LETests() +TEST_CASE("MBConv::UTF32LETests", "[mbconv]") { wxMBConvUTF32LE convUTF32LE; TestDecoder @@ -550,7 +454,7 @@ void MBConvTestCase::UTF32LETests() ); } -void MBConvTestCase::UTF32BETests() +TEST_CASE("MBConv::UTF32BETests", "[mbconv]") { wxMBConvUTF32BE convUTF32BE; TestDecoder @@ -573,7 +477,7 @@ void MBConvTestCase::UTF32BETests() ); } -void MBConvTestCase::CP932Tests() +TEST_CASE("MBConv::CP932Tests", "[mbconv]") { wxCSConv convCP932( wxFONTENCODING_CP932 ); TestDecoder @@ -771,7 +675,7 @@ wxWCharBuffer DecodeUTF8( // encodes the wide characters to compare against input multiBuffer // decodes the multiBuffer to compare against wide characters // decodes the multiBuffer into wide characters -void MBConvTestCase::TestCoder( +static void TestCoder( const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 @@ -811,7 +715,7 @@ void MBConvTestCase::TestCoder( WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const char* name ); -void MBConvTestCase::FontmapTests() +TEST_CASE("MBConv::FontmapTests", "[mbconv]") { #ifdef wxUSE_FONTMAP wxMBConv* converter = new_wxMBConv_wxwin("CP1252"); @@ -831,54 +735,47 @@ void MBConvTestCase::FontmapTests() #endif } -void MBConvTestCase::BufSize() +TEST_CASE("MBConv::BufSize", "[mbconv]") { wxCSConv conv1251(wxT("CP1251")); - CPPUNIT_ASSERT( conv1251.IsOk() ); + CHECK( conv1251.IsOk() ); const char *cp1251text = "\313\301\326\305\324\323\321 \325\304\301\336\316\331\315"; const size_t lenW = conv1251.MB2WC(nullptr, cp1251text, 0); - CPPUNIT_ASSERT_EQUAL( strlen(cp1251text), lenW ); + CHECK( lenW == strlen(cp1251text) ); wxWCharBuffer wbuf(lenW + 1); // allocates lenW + 2 characters wbuf.data()[lenW + 1] = L'!'; // lenW is not enough because it's the length and we need the size - CPPUNIT_ASSERT_EQUAL( - wxCONV_FAILED, conv1251.MB2WC(wbuf.data(), cp1251text, lenW) ); + CHECK(conv1251.MB2WC(wbuf.data(), cp1251text, lenW) == wxCONV_FAILED ); // lenW+1 is just fine - CPPUNIT_ASSERT( - conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 1) != wxCONV_FAILED ); + CHECK(conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 1) != wxCONV_FAILED ); // of course, greater values work too - CPPUNIT_ASSERT( - conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 2) != wxCONV_FAILED ); + CHECK(conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 2) != wxCONV_FAILED ); // but they shouldn't write more stuff to the buffer - CPPUNIT_ASSERT_EQUAL( L'!', wbuf[lenW + 1] ); + CHECK( wbuf[lenW + 1] == L'!' ); // test in the other direction too, using an encoding with multibyte NUL wxCSConv convUTF16(wxT("UTF-16LE")); - CPPUNIT_ASSERT( convUTF16.IsOk() ); + CHECK( convUTF16.IsOk() ); const wchar_t *utf16text = L"Hello"; const size_t lenMB = convUTF16.WC2MB(nullptr, utf16text, 0); - CPPUNIT_ASSERT_EQUAL( wcslen(utf16text)*2, lenMB ); + CHECK( lenMB == wcslen(utf16text)*2 ); wxCharBuffer buf(lenMB + 2); // it only adds 1 for NUL on its own, we need 2 // for NUL and an extra one for the guard byte buf.data()[lenMB + 2] = '?'; - CPPUNIT_ASSERT_EQUAL( - wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB) ); - CPPUNIT_ASSERT_EQUAL( - wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB + 1) ); - CPPUNIT_ASSERT( - convUTF16.WC2MB(buf.data(), utf16text, lenMB + 2) != wxCONV_FAILED ); - CPPUNIT_ASSERT( - convUTF16.WC2MB(buf.data(), utf16text, lenMB + 3) != wxCONV_FAILED ); - CPPUNIT_ASSERT_EQUAL( '?', buf[lenMB + 2] ); + CHECK(convUTF16.WC2MB(buf.data(), utf16text, lenMB) == wxCONV_FAILED ); + CHECK(convUTF16.WC2MB(buf.data(), utf16text, lenMB + 1) == wxCONV_FAILED ); + CHECK(convUTF16.WC2MB(buf.data(), utf16text, lenMB + 2) != wxCONV_FAILED ); + CHECK(convUTF16.WC2MB(buf.data(), utf16text, lenMB + 3) != wxCONV_FAILED ); + CHECK( buf[lenMB + 2] == '?' ); // Test cWC2MB() too. const wxCharBuffer buf2 = convUTF16.cWC2MB(utf16text); @@ -891,7 +788,7 @@ void MBConvTestCase::BufSize() CHECK( memcmp(buf, buf3, lenMB) == 0 ); } -void MBConvTestCase::FromWCharTests() +TEST_CASE("MBConv::FromWCharTests", "[mbconv]") { wxCSConv conv950("CP950"); char mbuf[10]; @@ -900,63 +797,63 @@ void MBConvTestCase::FromWCharTests() // test simple ASCII text memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 0, L"a", 1)); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[0]); + CHECK( conv950.FromWChar(mbuf, 0, L"a", 1) == wxCONV_FAILED); + CHECK( mbuf[0] == '!'); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( 1, conv950.FromWChar(mbuf, 1, L"a", 1)); - CPPUNIT_ASSERT_EQUAL( 'a', mbuf[0]); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[1]); + CHECK( conv950.FromWChar(mbuf, 1, L"a", 1) == 1); + CHECK( mbuf[0] == 'a'); + CHECK( mbuf[1] == '!'); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 1, L"a", 2)); + CHECK( conv950.FromWChar(mbuf, 1, L"a", 2) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( 2, conv950.FromWChar(mbuf, 2, L"a", 2)); - CPPUNIT_ASSERT_EQUAL( 'a', mbuf[0]); - CPPUNIT_ASSERT_EQUAL( '\0', mbuf[1]); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[2]); + CHECK( conv950.FromWChar(mbuf, 2, L"a", 2) == 2); + CHECK( mbuf[0] == 'a'); + CHECK( mbuf[1] == '\0'); + CHECK( mbuf[2] == '!'); // test non-ASCII text, 1 wchar -> 2 char memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 0, wbuf, 1)); + CHECK( conv950.FromWChar(mbuf, 0, wbuf, 1) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 1, wbuf, 1)); + CHECK( conv950.FromWChar(mbuf, 1, wbuf, 1) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( 2, conv950.FromWChar(mbuf, 2, wbuf, 1)); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[2]); + CHECK( conv950.FromWChar(mbuf, 2, wbuf, 1) == 2); + CHECK( mbuf[2] == '!'); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 2, wbuf, 2)); + CHECK( conv950.FromWChar(mbuf, 2, wbuf, 2) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( 3, conv950.FromWChar(mbuf, 3, wbuf, 2)); - CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[3]); + CHECK( conv950.FromWChar(mbuf, 3, wbuf, 2) == 3); + CHECK( mbuf[2] == '\0'); + CHECK( mbuf[3] == '!'); // test text with embedded NUL-character and srcLen specified memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 3, wbuf, 3)); + CHECK( conv950.FromWChar(mbuf, 3, wbuf, 3) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 4, wbuf, 3)); - CPPUNIT_ASSERT_EQUAL( 5, conv950.FromWChar(mbuf, 5, wbuf, 3)); - CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[5]); + CHECK( conv950.FromWChar(mbuf, 4, wbuf, 3) == wxCONV_FAILED); + CHECK( conv950.FromWChar(mbuf, 5, wbuf, 3) == 5); + CHECK( mbuf[2] == '\0'); + CHECK( mbuf[5] == '!'); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 5, wbuf, 4)); + CHECK( conv950.FromWChar(mbuf, 5, wbuf, 4) == wxCONV_FAILED); memset(mbuf, '!', sizeof(mbuf)); - CPPUNIT_ASSERT_EQUAL( 6, conv950.FromWChar(mbuf, 6, wbuf, 4)); - CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]); - CPPUNIT_ASSERT_EQUAL( '\0', mbuf[5]); - CPPUNIT_ASSERT_EQUAL( '!', mbuf[6]); + CHECK( conv950.FromWChar(mbuf, 6, wbuf, 4) == 6); + CHECK( mbuf[2] == '\0'); + CHECK( mbuf[5] == '\0'); + CHECK( mbuf[6] == '!'); } -void MBConvTestCase::NonBMPCharTests() +TEST_CASE("MBConv::NonBMPCharTests", "[mbconv]") { // U+1F363 (UTF-16: D83C DF63, UTF-8: F0 9F 8D A3) sushi (emoji) // U+732B (UTF-8: E7 8C AB) cat (kanji) @@ -1042,7 +939,7 @@ void MBConvTestCase::NonBMPCharTests() WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const char* name ); -void MBConvTestCase::IconvTests() +TEST_CASE("MBConv::IconvTests", "[mbconv]") { #ifdef HAVE_ICONV wxMBConv* converter = new_wxMBConv_iconv("CP932"); @@ -1062,7 +959,7 @@ void MBConvTestCase::IconvTests() #endif } -void MBConvTestCase::Latin1Tests() +TEST_CASE("MBConv::Latin1Tests", "[mbconv]") { TestCoder( (const char*)iso8859_1, @@ -1077,10 +974,10 @@ void MBConvTestCase::Latin1Tests() static const size_t mbLen = WXSIZEOF(nulstr) - 1; size_t wcLen; wxConvISO8859_1.cMB2WC(nulstr, mbLen, &wcLen); - CPPUNIT_ASSERT_EQUAL( mbLen, wcLen ); + CHECK( wcLen == mbLen ); } -void MBConvTestCase::CP1252Tests() +TEST_CASE("MBConv::CP1252Tests", "[mbconv]") { wxCSConv convCP1252( wxFONTENCODING_CP1252 ); TestCoder( @@ -1093,7 +990,7 @@ void MBConvTestCase::CP1252Tests() ); } -void MBConvTestCase::LibcTests() +TEST_CASE("MBConv::LibcTests", "[mbconv]") { // The locale name are OS-dependent so this test is done only under Windows // when using MSVC (surprisingly it fails with MinGW, even though it's @@ -1115,7 +1012,7 @@ void MBConvTestCase::LibcTests() } // verifies that the specified mb sequences decode to the specified wc sequence -void MBConvTestCase::TestDecoder( +static void TestDecoder( const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" @@ -1139,12 +1036,7 @@ void MBConvTestCase::TestDecoder( 0 ); // make sure the correct output length was calculated - WX_ASSERT_EQUAL_MESSAGE - ( - ("while converting \"%s\"", inputCopy), - wideChars, - outputWritten - ); + wxINFO_FMT("while converting \"%s\"", inputCopy); CHECK(outputWritten == wideChars); // convert the string size_t guardChars = 8; // to make sure we're not overrunning the output buffer @@ -1160,18 +1052,18 @@ void MBConvTestCase::TestDecoder( outputBufferChars ); // make sure the correct number of characters were outputs - CPPUNIT_ASSERT_EQUAL( wideChars, outputWritten ); + CHECK( outputWritten == wideChars ); // make sure the characters generated are correct - CPPUNIT_ASSERT( 0 == memcmp( outputBuffer, wideBuffer, wideChars*sizeof(wchar_t) ) ); + CHECK( 0 == memcmp( outputBuffer, wideBuffer, wideChars*sizeof(wchar_t) ) ); // the output buffer should be null terminated - CPPUNIT_ASSERT( outputBuffer[outputWritten] == 0 ); + CHECK( outputBuffer[outputWritten] == 0 ); // make sure the rest of the output buffer is untouched for ( size_t i = (wideChars+1)*sizeof(wchar_t); i < (outputBufferChars*sizeof(wchar_t)); i++ ) { - CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); + CHECK( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); } #if wxUSE_STREAMS @@ -1180,7 +1072,7 @@ void MBConvTestCase::TestDecoder( } // verifies that the specified wc sequences encodes to the specified mb sequence -void MBConvTestCase::TestEncoder( +static void TestEncoder( const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" @@ -1205,7 +1097,7 @@ void MBConvTestCase::TestEncoder( (const wchar_t*)inputCopy.data(), 0 ); - CPPUNIT_ASSERT( outputWritten >= multiBytes ); + CHECK( outputWritten >= multiBytes ); // convert the string size_t guardBytes = 8; // to make sure we're not overrunning the output buffer @@ -1221,23 +1113,23 @@ void MBConvTestCase::TestEncoder( ); // make sure the correct number of characters were output - CPPUNIT_ASSERT_EQUAL( multiBytes, outputWritten ); + CHECK( outputWritten == multiBytes ); // make sure the characters generated are correct - CPPUNIT_ASSERT( 0 == memcmp( outputBuffer, multiBuffer, multiBytes ) ); + CHECK( 0 == memcmp( outputBuffer, multiBuffer, multiBytes ) ); size_t i; // the output buffer should be null terminated for ( i = multiBytes; i < multiBytes + sizeofNull; i++ ) { - CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == 0 ); + CHECK( ((unsigned char*)outputBuffer.data())[i] == 0 ); } // make sure the rest of the output buffer is untouched for ( i = multiBytes + sizeofNull; i < outputBufferSize; i++ ) { - CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); + CHECK( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); } #if wxUSE_STREAMS @@ -1248,7 +1140,7 @@ void MBConvTestCase::TestEncoder( #if wxUSE_STREAMS // use wxTextInputStream to exercise wxMBConv interface // (this reveals some bugs in certain wxMBConv subclasses) -void MBConvTestCase::TestStreamDecoder( +static void TestStreamDecoder( const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" @@ -1264,21 +1156,17 @@ void MBConvTestCase::TestStreamDecoder( for ( size_t i = 0; i < wideChars; i++ ) { wxChar wc = textInputStream.GetChar(); - CPPUNIT_ASSERT_EQUAL_MESSAGE( - wxString::Format("At position %lu", (unsigned long)i).ToStdString(), - wideBuffer[i], - wc - ); + INFO(wxString::Format("At position %lu", (unsigned long)i).ToStdString()); CHECK(wc == wideBuffer[i]); } - CPPUNIT_ASSERT( 0 == textInputStream.GetChar() ); - CPPUNIT_ASSERT( memoryInputStream.Eof() ); + CHECK( 0 == textInputStream.GetChar() ); + CHECK( memoryInputStream.Eof() ); } #endif #if wxUSE_STREAMS // use wxTextInputStream to exercise wxMBConv interface // (this reveals some bugs in certain wxMBConv subclasses) -void MBConvTestCase::TestStreamEncoder( +static void TestStreamEncoder( const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" @@ -1299,10 +1187,10 @@ void MBConvTestCase::TestStreamEncoder( textOutputStream.Flush(); - CPPUNIT_ASSERT_EQUAL( multiBytes, size_t(memoryOutputStream.TellO()) ); + CHECK( size_t(memoryOutputStream.TellO()) == multiBytes ); wxCharBuffer copy( memoryOutputStream.TellO() ); memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO()); - CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy.data(), multiBuffer, multiBytes ) ); + CHECK( memcmp( copy.data(), multiBuffer, multiBytes ) == 0 ); } #endif @@ -1316,7 +1204,7 @@ void MBConvTestCase::TestStreamEncoder( // invalid sequences should roundtrip when an option is given and this is // checked. // -void MBConvTestCase::UTF8(const char *charSequence, +static void UTF8(const char *charSequence, const wchar_t *wideSequence) { UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); @@ -1327,7 +1215,7 @@ void MBConvTestCase::UTF8(const char *charSequence, // Use this alternative when 'charSequence' contains a PUA character. Such // sequences should still roundtrip ok, and this is checked. // -void MBConvTestCase::UTF8PUA(const char *charSequence, +static void UTF8PUA(const char *charSequence, const wchar_t *wideSequence) { UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); @@ -1338,7 +1226,7 @@ void MBConvTestCase::UTF8PUA(const char *charSequence, // Use this alternative when 'charSequence' contains an octal escape sequence. // Such sequences should still roundtrip ok, and this is checked. // -void MBConvTestCase::UTF8Octal(const char *charSequence, +static void UTF8Octal(const char *charSequence, const wchar_t *wideSequence) { UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); @@ -1392,11 +1280,11 @@ static size_t wx_wcslen(const wchar_t *s) // include the option in the error messages so it's possible to see which // test failed -#define UTF8ASSERT(expr) CPPUNIT_ASSERT_MESSAGE(#expr + errmsg, expr) +#define UTF8ASSERT(expr) INFO(#expr + errmsg); CHECK(expr) // The test implementation // -void MBConvTestCase::UTF8(const char *charSequence, +static void UTF8(const char *charSequence, const wchar_t *wideSequence, int option) { @@ -1464,6 +1352,31 @@ void MBConvTestCase::UTF8(const char *charSequence, UTF8ASSERT(strlen(bytesAgain) == resultAgain); } +// Test the first, last and one in the middle for sequences of each length. +TEST_CASE("MBConv::UTF8_41", "[mbconv]") { UTF8("\x41", u41); } +TEST_CASE("MBConv::UTF8_7f", "[mbconv]") { UTF8("\x7f", u7f); } +TEST_CASE("MBConv::UTF8_80", "[mbconv]") { UTF8("\x80", nullptr); } + +TEST_CASE("MBConv::UTF8_c2_7f", "[mbconv]") { UTF8("\xc2\x7f", nullptr); } +TEST_CASE("MBConv::UTF8_c2_80", "[mbconv]") { UTF8("\xc2\x80", u80); } +TEST_CASE("MBConv::UTF8_ce_91", "[mbconv]") { UTF8("\xce\x91", u391); } +TEST_CASE("MBConv::UTF8_df_bf", "[mbconv]") { UTF8("\xdf\xbf", u7ff); } +TEST_CASE("MBConv::UTF8_df_c0", "[mbconv]") { UTF8("\xdf\xc0", nullptr); } + +TEST_CASE("MBConv::UTF8_e0_a0_7f", "[mbconv]") { UTF8("\xe0\xa0\x7f", nullptr); } +TEST_CASE("MBConv::UTF8_e0_a0_80", "[mbconv]") { UTF8("\xe0\xa0\x80", u800); } +TEST_CASE("MBConv::UTF8_e2_98_a0", "[mbconv]") { UTF8("\xe2\x98\xa0", u2620); } +TEST_CASE("MBConv::UTF8_ef_bf_bd", "[mbconv]") { UTF8("\xef\xbf\xbd", ufffd); } +TEST_CASE("MBConv::UTF8_ef_bf_c0", "[mbconv]") { UTF8("\xef\xbf\xc0", nullptr); } + +TEST_CASE("MBConv::UTF8_f0_90_80_7f", "[mbconv]") { UTF8("\xf0\x90\x80\x7f", nullptr); } +TEST_CASE("MBConv::UTF8_f0_90_80_80", "[mbconv]") { UTF8("\xf0\x90\x80\x80", u10000); } +TEST_CASE("MBConv::UTF8_f4_8f_bf_bd", "[mbconv]") { UTF8("\xf4\x8f\xbf\xbd", u10fffd); } + +// Test 'escaping the escape characters' for the two escaping schemes. +TEST_CASE("MBConv::UTF8PUA_f4_80_82_a5", "[mbconv]") { UTF8PUA("\xf4\x80\x82\xa5", u1000a5); } +TEST_CASE("MBConv::UTF8Octal_backslash245", "[mbconv]") { UTF8Octal("\\245", L"\\245"); } + TEST_CASE("wxMBConv::cWC2MB", "[mbconv][wc2mb]") { wxMBConvUTF16 convUTF16; diff --git a/tests/misc/environ.cpp b/tests/misc/environ.cpp index f1204cf0b7..c789d7eae6 100644 --- a/tests/misc/environ.cpp +++ b/tests/misc/environ.cpp @@ -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()); } diff --git a/tests/misc/metatest.cpp b/tests/misc/metatest.cpp index 61091fcc6b..5d6559b137 100644 --- a/tests/misc/metatest.cpp +++ b/tests/misc/metatest.cpp @@ -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::value); - CPPUNIT_ASSERT(wxIsPod::value); - CPPUNIT_ASSERT(wxIsPod::value); - CPPUNIT_ASSERT(wxIsPod::value); - CPPUNIT_ASSERT(!wxIsPod::value); + CHECK(wxIsPod::value); + CHECK(wxIsPod::value); + CHECK(wxIsPod::value); + CHECK(wxIsPod::value); + CHECK(!wxIsPod::value); } -void MetaProgrammingTestCase::IsMovable() +TEST_CASE("MetaProgramming::IsMovable", "[meta]") { - CPPUNIT_ASSERT(wxIsMovable::value); - CPPUNIT_ASSERT(wxIsMovable::value); - CPPUNIT_ASSERT(wxIsMovable::value); - CPPUNIT_ASSERT(wxIsMovable::value); - CPPUNIT_ASSERT(!wxIsMovable::value); + CHECK(wxIsMovable::value); + CHECK(wxIsMovable::value); + CHECK(wxIsMovable::value); + CHECK(wxIsMovable::value); + CHECK(!wxIsMovable::value); } -void MetaProgrammingTestCase::ImplicitConversion() +TEST_CASE("MetaProgramming::ImplicitConversion", "[meta]") { #ifndef wxNO_RTTI - CPPUNIT_ASSERT(typeid(wxImplicitConversionType::value) == typeid(int)); - CPPUNIT_ASSERT(typeid(wxImplicitConversionType::value) == typeid(unsigned)); - CPPUNIT_ASSERT(typeid(wxImplicitConversionType::value) == typeid(float)); + CHECK(typeid(wxImplicitConversionType::value) == typeid(int)); + CHECK(typeid(wxImplicitConversionType::value) == typeid(unsigned)); + CHECK(typeid(wxImplicitConversionType::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 ); } diff --git a/tests/misc/misctests.cpp b/tests/misc/misctests.cpp index 1bfe618fb9..0c609be932 100644 --- a/tests/misc/misctests.cpp +++ b/tests/misc/misctests.cpp @@ -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 diff --git a/tests/misc/typeinfotest.cpp b/tests/misc/typeinfotest.cpp index dd6a1c2256..115ff57bd8 100644 --- a/tests/misc/typeinfotest.cpp +++ b/tests/misc/typeinfotest.cpp @@ -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; diff --git a/tests/scopeguard/scopeguardtest.cpp b/tests/scopeguard/scopeguardtest.cpp index 9db602ad15..9d19684dd2 100644 --- a/tests/scopeguard/scopeguardtest.cpp +++ b/tests/scopeguard/scopeguardtest.cpp @@ -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 ); } diff --git a/tests/strings/iostream.cpp b/tests/strings/iostream.cpp index 562441d61d..e12731e751 100644 --- a/tests/strings/iostream.cpp +++ b/tests/strings/iostream.cpp @@ -21,32 +21,14 @@ #include -#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"); diff --git a/tests/strings/tokenizer.cpp b/tests/strings/tokenizer.cpp index d552ad04e7..3ac9e56ffc 100644 --- a/tests/strings/tokenizer.cpp +++ b/tests/strings/tokenizer.cpp @@ -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() ); } } diff --git a/tests/strings/unichar.cpp b/tests/strings/unichar.cpp index fe5f9d8a2f..0431ac4844 100644 --- a/tests/strings/unichar.cpp +++ b/tests/strings/unichar.cpp @@ -21,317 +21,160 @@ #include "wx/string.h" // ---------------------------------------------------------------------------- -// test class +// tests // ---------------------------------------------------------------------------- -class UniCharTestCase : public CppUnit::TestCase -{ -public: - UniCharTestCase() {} - -private: - CPPUNIT_TEST_SUITE( UniCharTestCase ); - CPPUNIT_TEST( CharCompare ); - CPPUNIT_TEST( CharCompareIntl ); - CPPUNIT_TEST( StringCompare ); - CPPUNIT_TEST( ShortCompare ); - CPPUNIT_TEST( UnsignedShortCompare ); - CPPUNIT_TEST( IntCompare ); - CPPUNIT_TEST( UnsignedIntCompare ); - CPPUNIT_TEST( LongCompare ); - CPPUNIT_TEST( UnsignedLongCompare ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxLongLongCompare ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxULongLongCompare ); ) - CPPUNIT_TEST( WideCharCompare ); - CPPUNIT_TEST( UniCharAssignmentOperator ); - CPPUNIT_TEST( UniCharRefAssignmentOperator ); - CPPUNIT_TEST( CharAssignmentOperator ); - CPPUNIT_TEST( UnsignedCharAssignmentOperator ); - CPPUNIT_TEST( ShortAssignmentOperator ); - CPPUNIT_TEST( UnsignedShortAssignmentOperator ); - CPPUNIT_TEST( IntAssignmentOperator ); - CPPUNIT_TEST( UnsignedIntAssignmentOperator ); - CPPUNIT_TEST( LongAssignmentOperator ); - CPPUNIT_TEST( UnsignedLongAssignmentOperator ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxLongLongAssignmentOperator ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxULongLongAssignmentOperator ); ) - CPPUNIT_TEST( WideCharAssignmentOperator ); - CPPUNIT_TEST( CharParenOperator ); - CPPUNIT_TEST( UnsignedCharParenOperator ); - CPPUNIT_TEST( ShortParenOperator ); - CPPUNIT_TEST( UnsignedShortParenOperator ); - CPPUNIT_TEST( IntParenOperator ); - CPPUNIT_TEST( UnsignedIntParenOperator ); - CPPUNIT_TEST( LongParenOperator ); - CPPUNIT_TEST( UnsignedLongParenOperator ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxLongLongParenOperator ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( wxULongLongParenOperator ); ) - CPPUNIT_TEST( WideCharParenOperator ); - CPPUNIT_TEST(RefUniCharAssignmentOperator); - CPPUNIT_TEST(RefUniCharRefAssignmentOperator); - CPPUNIT_TEST(RefCharAssignmentOperator); - CPPUNIT_TEST( RefShortAssignmentOperator ); - CPPUNIT_TEST( RefUnsignedShortAssignmentOperator ); - CPPUNIT_TEST( RefIntAssignmentOperator ); - CPPUNIT_TEST( RefUnsignedIntAssignmentOperator ); - CPPUNIT_TEST( RefLongAssignmentOperator ); - CPPUNIT_TEST( RefUnsignedLongAssignmentOperator ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxLongLongAssignmentOperator ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxULongLongAssignmentOperator ); ) - CPPUNIT_TEST( RefWideCharAssignmentOperator ); - CPPUNIT_TEST(RefCharParenOperator); - CPPUNIT_TEST( RefShortParenOperator ); - CPPUNIT_TEST( RefUnsignedShortParenOperator ); - CPPUNIT_TEST( RefIntParenOperator ); - CPPUNIT_TEST( RefUnsignedIntParenOperator ); - CPPUNIT_TEST( RefLongParenOperator ); - CPPUNIT_TEST( RefUnsignedLongParenOperator ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxLongLongParenOperator ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxULongLongParenOperator ); ) - CPPUNIT_TEST( RefWideCharParenOperator ); - CPPUNIT_TEST( RefShortCompare ); - CPPUNIT_TEST( RefUnsignedShortCompare ); - CPPUNIT_TEST( RefIntCompare ); - CPPUNIT_TEST( RefUnsignedIntCompare ); - CPPUNIT_TEST( RefLongCompare ); - CPPUNIT_TEST( RefUnsignedLongCompare ); - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxLongLongCompare ); ) - wxIF_LONG_LONG_TYPE( CPPUNIT_TEST( RefwxULongLongCompare ); ) - CPPUNIT_TEST( RefWideCharCompare ); - CPPUNIT_TEST( StringCompareIntl ); - CPPUNIT_TEST_SUITE_END(); - - void CharCompare(); - void CharCompareIntl(); - void StringCompare(); - void StringCompareIntl(); - void ShortCompare(); - void UnsignedShortCompare(); - void IntCompare(); - void UnsignedIntCompare(); - void LongCompare(); - void UnsignedLongCompare(); - wxIF_LONG_LONG_TYPE( void wxLongLongCompare(); ) - wxIF_LONG_LONG_TYPE( void wxULongLongCompare(); ) - void WideCharCompare(); - void UniCharAssignmentOperator(); - void UniCharRefAssignmentOperator(); - void CharAssignmentOperator(); - void UnsignedCharAssignmentOperator(); - void ShortAssignmentOperator(); - void UnsignedShortAssignmentOperator(); - void IntAssignmentOperator(); - void UnsignedIntAssignmentOperator(); - void LongAssignmentOperator(); - void UnsignedLongAssignmentOperator(); - wxIF_LONG_LONG_TYPE( void wxLongLongAssignmentOperator(); ) - wxIF_LONG_LONG_TYPE( void wxULongLongAssignmentOperator(); ) - void WideCharAssignmentOperator(); - void CharParenOperator(); - void UnsignedCharParenOperator(); - void ShortParenOperator(); - void UnsignedShortParenOperator(); - void IntParenOperator(); - void UnsignedIntParenOperator(); - void LongParenOperator(); - void UnsignedLongParenOperator(); - wxIF_LONG_LONG_TYPE( void wxLongLongParenOperator(); ) - wxIF_LONG_LONG_TYPE( void wxULongLongParenOperator(); ) - void WideCharParenOperator(); - void RefUniCharAssignmentOperator(); - void RefUniCharRefAssignmentOperator(); - void RefCharAssignmentOperator(); - void RefUnsignedCharAssignmentOperator(); - void RefShortAssignmentOperator(); - void RefUnsignedShortAssignmentOperator(); - void RefIntAssignmentOperator(); - void RefUnsignedIntAssignmentOperator(); - void RefLongAssignmentOperator(); - void RefUnsignedLongAssignmentOperator(); - wxIF_LONG_LONG_TYPE( void RefwxLongLongAssignmentOperator(); ) - wxIF_LONG_LONG_TYPE( void RefwxULongLongAssignmentOperator(); ) - void RefWideCharAssignmentOperator(); - void RefCharParenOperator(); - void RefUnsignedCharParenOperator(); - void RefShortParenOperator(); - void RefUnsignedShortParenOperator(); - void RefIntParenOperator(); - void RefUnsignedIntParenOperator(); - void RefLongParenOperator(); - void RefUnsignedLongParenOperator(); - wxIF_LONG_LONG_TYPE( void RefwxLongLongParenOperator(); ) - wxIF_LONG_LONG_TYPE( void RefwxULongLongParenOperator(); ) - void RefWideCharParenOperator(); - void RefShortCompare(); - void RefUnsignedShortCompare(); - void RefIntCompare(); - void RefUnsignedIntCompare(); - void RefLongCompare(); - void RefUnsignedLongCompare(); - wxIF_LONG_LONG_TYPE( void RefwxLongLongCompare(); ) - wxIF_LONG_LONG_TYPE( void RefwxULongLongCompare(); ) - void RefWideCharCompare(); - - wxDECLARE_NO_COPY_CLASS(UniCharTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase, "UniCharTestCase" ); - -void UniCharTestCase::CharCompare() +TEST_CASE("UniChar::CharCompare", "[unichar]") { wxUniChar a('a'); wxUniChar b('b'); - CPPUNIT_ASSERT( a == a ); - CPPUNIT_ASSERT( a == 'a' ); - CPPUNIT_ASSERT( a == wxT('a') ); - CPPUNIT_ASSERT( a == wxUniChar('a') ); - CPPUNIT_ASSERT( a == wxUniChar(wxT('a')) ); + CHECK( a == a ); + CHECK( a == 'a' ); + CHECK( a == wxT('a') ); + CHECK( a == wxUniChar('a') ); + CHECK( a == wxUniChar(wxT('a')) ); - CPPUNIT_ASSERT( a == a ); - CPPUNIT_ASSERT( 'a' == a ); - CPPUNIT_ASSERT( wxT('a') == a ); - CPPUNIT_ASSERT( wxUniChar('a') == a ); - CPPUNIT_ASSERT( wxUniChar(wxT('a')) == a ); + CHECK( a == a ); + CHECK( 'a' == a ); + CHECK( wxT('a') == a ); + CHECK( wxUniChar('a') == a ); + CHECK( wxUniChar(wxT('a')) == a ); - CPPUNIT_ASSERT( a != b ); - CPPUNIT_ASSERT( a != 'b' ); - CPPUNIT_ASSERT( a != wxT('b') ); - CPPUNIT_ASSERT( a != wxUniChar('b') ); - CPPUNIT_ASSERT( a != wxUniChar(wxT('b')) ); + CHECK( a != b ); + CHECK( a != 'b' ); + CHECK( a != wxT('b') ); + CHECK( a != wxUniChar('b') ); + CHECK( a != wxUniChar(wxT('b')) ); - CPPUNIT_ASSERT( b != a ); - CPPUNIT_ASSERT( 'b' != a ); - CPPUNIT_ASSERT( wxT('b') != a ); - CPPUNIT_ASSERT( wxUniChar('b') != a ); - CPPUNIT_ASSERT( wxUniChar(wxT('b')) != a ); + CHECK( b != a ); + CHECK( 'b' != a ); + CHECK( wxT('b') != a ); + CHECK( wxUniChar('b') != a ); + CHECK( wxUniChar(wxT('b')) != a ); - CPPUNIT_ASSERT( a < b ); - CPPUNIT_ASSERT( a < 'b' ); - CPPUNIT_ASSERT( a < wxT('b') ); - CPPUNIT_ASSERT( a < wxUniChar('b') ); - CPPUNIT_ASSERT( a < wxUniChar(wxT('b')) ); + CHECK( a < b ); + CHECK( a < 'b' ); + CHECK( a < wxT('b') ); + CHECK( a < wxUniChar('b') ); + CHECK( a < wxUniChar(wxT('b')) ); - CPPUNIT_ASSERT( b > a ); - CPPUNIT_ASSERT( 'b' > a ); - CPPUNIT_ASSERT( wxT('b') > a ); - CPPUNIT_ASSERT( wxUniChar('b') > a ); - CPPUNIT_ASSERT( wxUniChar(wxT('b')) > a ); + CHECK( b > a ); + CHECK( 'b' > a ); + CHECK( wxT('b') > a ); + CHECK( wxUniChar('b') > a ); + CHECK( wxUniChar(wxT('b')) > a ); - CPPUNIT_ASSERT( a <= b ); - CPPUNIT_ASSERT( a <= 'b' ); - CPPUNIT_ASSERT( a <= wxT('b') ); - CPPUNIT_ASSERT( a <= wxUniChar('b') ); - CPPUNIT_ASSERT( a <= wxUniChar(wxT('b')) ); + CHECK( a <= b ); + CHECK( a <= 'b' ); + CHECK( a <= wxT('b') ); + CHECK( a <= wxUniChar('b') ); + CHECK( a <= wxUniChar(wxT('b')) ); - CPPUNIT_ASSERT( b >= a ); - CPPUNIT_ASSERT( 'b' >= a ); - CPPUNIT_ASSERT( wxT('b') >= a ); - CPPUNIT_ASSERT( wxUniChar('b') >= a ); - CPPUNIT_ASSERT( wxUniChar(wxT('b')) >= a ); + CHECK( b >= a ); + CHECK( 'b' >= a ); + CHECK( wxT('b') >= a ); + CHECK( wxUniChar('b') >= a ); + CHECK( wxUniChar(wxT('b')) >= a ); - CPPUNIT_ASSERT( a <= a ); - CPPUNIT_ASSERT( a <= 'a' ); - CPPUNIT_ASSERT( a <= wxT('a') ); - CPPUNIT_ASSERT( a <= wxUniChar('a') ); - CPPUNIT_ASSERT( a <= wxUniChar(wxT('a')) ); + CHECK( a <= a ); + CHECK( a <= 'a' ); + CHECK( a <= wxT('a') ); + CHECK( a <= wxUniChar('a') ); + CHECK( a <= wxUniChar(wxT('a')) ); - CPPUNIT_ASSERT( a >= a ); - CPPUNIT_ASSERT( 'a' >= a ); - CPPUNIT_ASSERT( wxT('a') >= a ); - CPPUNIT_ASSERT( wxUniChar('a') >= a ); - CPPUNIT_ASSERT( wxUniChar(wxT('a')) >= a ); + CHECK( a >= a ); + CHECK( 'a' >= a ); + CHECK( wxT('a') >= a ); + CHECK( wxUniChar('a') >= a ); + CHECK( wxUniChar(wxT('a')) >= a ); - CPPUNIT_ASSERT( b > a ); - CPPUNIT_ASSERT( b > 'a' ); - CPPUNIT_ASSERT( b > wxT('a') ); - CPPUNIT_ASSERT( b > wxUniChar('a') ); - CPPUNIT_ASSERT( b > wxUniChar(wxT('a')) ); + CHECK( b > a ); + CHECK( b > 'a' ); + CHECK( b > wxT('a') ); + CHECK( b > wxUniChar('a') ); + CHECK( b > wxUniChar(wxT('a')) ); - CPPUNIT_ASSERT( a < b ); - CPPUNIT_ASSERT( 'a' < b ); - CPPUNIT_ASSERT( wxT('a') < b ); - CPPUNIT_ASSERT( wxUniChar('a') < b ); - CPPUNIT_ASSERT( wxUniChar(wxT('a')) < b ); + CHECK( a < b ); + CHECK( 'a' < b ); + CHECK( wxT('a') < b ); + CHECK( wxUniChar('a') < b ); + CHECK( wxUniChar(wxT('a')) < b ); - CPPUNIT_ASSERT( b >= a ); - CPPUNIT_ASSERT( b >= 'a' ); - CPPUNIT_ASSERT( b >= wxT('a') ); - CPPUNIT_ASSERT( b >= wxUniChar('a') ); - CPPUNIT_ASSERT( b >= wxUniChar(wxT('a')) ); + CHECK( b >= a ); + CHECK( b >= 'a' ); + CHECK( b >= wxT('a') ); + CHECK( b >= wxUniChar('a') ); + CHECK( b >= wxUniChar(wxT('a')) ); - CPPUNIT_ASSERT( a <= b ); - CPPUNIT_ASSERT( 'a' <= b ); - CPPUNIT_ASSERT( wxT('a') <= b ); - CPPUNIT_ASSERT( wxUniChar('a') <= b ); - CPPUNIT_ASSERT( wxUniChar(wxT('a')) <= b ); + CHECK( a <= b ); + CHECK( 'a' <= b ); + CHECK( wxT('a') <= b ); + CHECK( wxUniChar('a') <= b ); + CHECK( wxUniChar(wxT('a')) <= b ); - CPPUNIT_ASSERT( b >= b ); - CPPUNIT_ASSERT( b >= 'b' ); - CPPUNIT_ASSERT( b >= wxT('b') ); - CPPUNIT_ASSERT( b >= wxUniChar('b') ); - CPPUNIT_ASSERT( b >= wxUniChar(wxT('b')) ); + CHECK( b >= b ); + CHECK( b >= 'b' ); + CHECK( b >= wxT('b') ); + CHECK( b >= wxUniChar('b') ); + CHECK( b >= wxUniChar(wxT('b')) ); - CPPUNIT_ASSERT( b <= b ); - CPPUNIT_ASSERT( 'b' <= b ); - CPPUNIT_ASSERT( wxT('b') <= b ); - CPPUNIT_ASSERT( wxUniChar('b') <= b ); - CPPUNIT_ASSERT( wxUniChar(wxT('b')) <= b ); + CHECK( b <= b ); + CHECK( 'b' <= b ); + CHECK( wxT('b') <= b ); + CHECK( wxUniChar('b') <= b ); + CHECK( wxUniChar(wxT('b')) <= b ); - CPPUNIT_ASSERT( b - a == 1 ); - CPPUNIT_ASSERT( a - b == -1 ); + CHECK( b - a == 1 ); + CHECK( a - b == -1 ); } #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E) #define ARABIC_LETTER_NOON ((wchar_t)0x0646) -void UniCharTestCase::CharCompareIntl() +TEST_CASE("UniChar::CharCompareIntl", "[unichar]") { wxUniChar a(CYRILLIC_SMALL_LETTER_YU); wxUniChar b(ARABIC_LETTER_NOON); - CPPUNIT_ASSERT( a == a ); - CPPUNIT_ASSERT( a == CYRILLIC_SMALL_LETTER_YU ); - CPPUNIT_ASSERT( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); + CHECK( a == a ); + CHECK( a == CYRILLIC_SMALL_LETTER_YU ); + CHECK( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); - CPPUNIT_ASSERT( a != b ); - CPPUNIT_ASSERT( a != ARABIC_LETTER_NOON ); - CPPUNIT_ASSERT( a != wxUniChar(ARABIC_LETTER_NOON) ); + CHECK( a != b ); + CHECK( a != ARABIC_LETTER_NOON ); + CHECK( a != wxUniChar(ARABIC_LETTER_NOON) ); - CPPUNIT_ASSERT( a < b ); - CPPUNIT_ASSERT( a < ARABIC_LETTER_NOON ); - CPPUNIT_ASSERT( a < wxUniChar(ARABIC_LETTER_NOON) ); + CHECK( a < b ); + CHECK( a < ARABIC_LETTER_NOON ); + CHECK( a < wxUniChar(ARABIC_LETTER_NOON) ); - CPPUNIT_ASSERT( a <= b ); - CPPUNIT_ASSERT( a <= ARABIC_LETTER_NOON ); - CPPUNIT_ASSERT( a <= wxUniChar(ARABIC_LETTER_NOON) ); + CHECK( a <= b ); + CHECK( a <= ARABIC_LETTER_NOON ); + CHECK( a <= wxUniChar(ARABIC_LETTER_NOON) ); - CPPUNIT_ASSERT( a <= a ); - CPPUNIT_ASSERT( a <= CYRILLIC_SMALL_LETTER_YU ); - CPPUNIT_ASSERT( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); + CHECK( a <= a ); + CHECK( a <= CYRILLIC_SMALL_LETTER_YU ); + CHECK( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); - CPPUNIT_ASSERT( b > a ); - CPPUNIT_ASSERT( b > CYRILLIC_SMALL_LETTER_YU ); - CPPUNIT_ASSERT( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); + CHECK( b > a ); + CHECK( b > CYRILLIC_SMALL_LETTER_YU ); + CHECK( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); - CPPUNIT_ASSERT( b >= a ); - CPPUNIT_ASSERT( b >= CYRILLIC_SMALL_LETTER_YU ); - CPPUNIT_ASSERT( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); + CHECK( b >= a ); + CHECK( b >= CYRILLIC_SMALL_LETTER_YU ); + CHECK( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); - CPPUNIT_ASSERT( b >= b ); - CPPUNIT_ASSERT( b >= ARABIC_LETTER_NOON ); - CPPUNIT_ASSERT( b >= wxUniChar(ARABIC_LETTER_NOON) ); + CHECK( b >= b ); + CHECK( b >= ARABIC_LETTER_NOON ); + CHECK( b >= wxUniChar(ARABIC_LETTER_NOON) ); - CPPUNIT_ASSERT( b - a == 504 ); - CPPUNIT_ASSERT( a - b == -504 ); + CHECK( b - a == 504 ); + CHECK( a - b == -504 ); } -void UniCharTestCase::StringCompare() +TEST_CASE("UniChar::StringCompare", "[unichar]") { // test string comparison with chars wxString sa = "a"; @@ -340,40 +183,40 @@ void UniCharTestCase::StringCompare() wchar_t c2 = wxT('a'); wxUniChar c3 = 'a'; - CPPUNIT_ASSERT( sa == 'a'); - CPPUNIT_ASSERT( 'a' == sa); - CPPUNIT_ASSERT( sb != 'a'); - CPPUNIT_ASSERT( 'a' != sb); + CHECK( sa == 'a'); + CHECK( 'a' == sa); + CHECK( sb != 'a'); + CHECK( 'a' != sb); - CPPUNIT_ASSERT( sa == c1); - CPPUNIT_ASSERT( c1 == sa); - CPPUNIT_ASSERT( sb != c1); - CPPUNIT_ASSERT( c1 != sb); + CHECK( sa == c1); + CHECK( c1 == sa); + CHECK( sb != c1); + CHECK( c1 != sb); - CPPUNIT_ASSERT( sa == c2); - CPPUNIT_ASSERT( c2 == sa); - CPPUNIT_ASSERT( sb != c2); - CPPUNIT_ASSERT( c2 != sb); + CHECK( sa == c2); + CHECK( c2 == sa); + CHECK( sb != c2); + CHECK( c2 != sb); - CPPUNIT_ASSERT( sa == c3); - CPPUNIT_ASSERT( c3 == sa); - CPPUNIT_ASSERT( sb != c3); - CPPUNIT_ASSERT( c3 != sb); + CHECK( sa == c3); + CHECK( c3 == sa); + CHECK( sb != c3); + CHECK( c3 != sb); // test wxUniCharRef: - CPPUNIT_ASSERT( sa == sa[0]); - CPPUNIT_ASSERT( sa[0] == sa); - CPPUNIT_ASSERT( sb != sa[0]); - CPPUNIT_ASSERT( sa[0] != sb); + CHECK( sa == sa[0]); + CHECK( sa[0] == sa); + CHECK( sb != sa[0]); + CHECK( sa[0] != sb); // test const version of operator[] (returns wxUniChar, not wxUniCharRef): - CPPUNIT_ASSERT( sb == sb[0]); - CPPUNIT_ASSERT( sb[0] == sb); - CPPUNIT_ASSERT( sa != sb[0]); - CPPUNIT_ASSERT( sb[0] != sa); + CHECK( sb == sb[0]); + CHECK( sb[0] == sb); + CHECK( sa != sb[0]); + CHECK( sb[0] != sa); } -void UniCharTestCase::StringCompareIntl() +TEST_CASE("UniChar::StringCompareIntl", "[unichar]") { // test string comparison with chars wxString sa = CYRILLIC_SMALL_LETTER_YU; @@ -381,45 +224,45 @@ void UniCharTestCase::StringCompareIntl() wchar_t c2 = CYRILLIC_SMALL_LETTER_YU; wxUniChar c3 = CYRILLIC_SMALL_LETTER_YU; - CPPUNIT_ASSERT( sa == CYRILLIC_SMALL_LETTER_YU); - CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU == sa); - CPPUNIT_ASSERT( sb != CYRILLIC_SMALL_LETTER_YU); - CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU != sb); + CHECK( sa == CYRILLIC_SMALL_LETTER_YU); + CHECK( CYRILLIC_SMALL_LETTER_YU == sa); + CHECK( sb != CYRILLIC_SMALL_LETTER_YU); + CHECK( CYRILLIC_SMALL_LETTER_YU != sb); - CPPUNIT_ASSERT( sa == c2); - CPPUNIT_ASSERT( c2 == sa); - CPPUNIT_ASSERT( sb != c2); - CPPUNIT_ASSERT( c2 != sb); + CHECK( sa == c2); + CHECK( c2 == sa); + CHECK( sb != c2); + CHECK( c2 != sb); - CPPUNIT_ASSERT( sa == c3); - CPPUNIT_ASSERT( c3 == sa); - CPPUNIT_ASSERT( sb != c3); - CPPUNIT_ASSERT( c3 != sb); + CHECK( sa == c3); + CHECK( c3 == sa); + CHECK( sb != c3); + CHECK( c3 != sb); // test wxUniCharRef: - CPPUNIT_ASSERT( sa == sa[0]); - CPPUNIT_ASSERT( sa[0] == sa); - CPPUNIT_ASSERT( sb != sa[0]); - CPPUNIT_ASSERT( sa[0] != sb); + CHECK( sa == sa[0]); + CHECK( sa[0] == sa); + CHECK( sb != sa[0]); + CHECK( sa[0] != sb); // test const version of operator[] (returns wxUniChar, not wxUniCharRef): - CPPUNIT_ASSERT( sb == sb[0]); - CPPUNIT_ASSERT( sb[0] == sb); - CPPUNIT_ASSERT( sa != sb[0]); - CPPUNIT_ASSERT( sb[0] != sa); + CHECK( sb == sb[0]); + CHECK( sb[0] == sb); + CHECK( sa != sb[0]); + CHECK( sb[0] != sa); } #define wxUNICHAR_TEST_INT_COMPARE \ wxUniChar a(aVal); \ - CPPUNIT_ASSERT( a == aVal ); \ - CPPUNIT_ASSERT( a != bVal ); \ - CPPUNIT_ASSERT( a < bVal ); \ - CPPUNIT_ASSERT( a <= bVal ); \ - CPPUNIT_ASSERT( a > cVal ); \ - CPPUNIT_ASSERT( a >= cVal ); + CHECK( a == aVal ); \ + CHECK( a != bVal ); \ + CHECK( a < bVal ); \ + CHECK( a <= bVal ); \ + CHECK( a > cVal ); \ + CHECK( a >= cVal ); -void UniCharTestCase::ShortCompare() +TEST_CASE("UniChar::ShortCompare", "[unichar]") { short aVal = 2; short bVal = 3; @@ -428,7 +271,7 @@ void UniCharTestCase::ShortCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::UnsignedShortCompare() +TEST_CASE("UniChar::UnsignedShortCompare", "[unichar]") { unsigned short aVal = 2; unsigned short bVal = 3; @@ -437,7 +280,7 @@ void UniCharTestCase::UnsignedShortCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::IntCompare() +TEST_CASE("UniChar::IntCompare", "[unichar]") { int aVal = 2; int bVal = 3; @@ -446,7 +289,7 @@ void UniCharTestCase::IntCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::UnsignedIntCompare() +TEST_CASE("UniChar::UnsignedIntCompare", "[unichar]") { unsigned int aVal = 2; unsigned int bVal = 3; @@ -455,7 +298,7 @@ void UniCharTestCase::UnsignedIntCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::LongCompare() +TEST_CASE("UniChar::LongCompare", "[unichar]") { long aVal = 2; long bVal = 3; @@ -464,7 +307,7 @@ void UniCharTestCase::LongCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::UnsignedLongCompare() +TEST_CASE("UniChar::UnsignedLongCompare", "[unichar]") { unsigned long aVal = 2; unsigned long bVal = 3; @@ -475,7 +318,7 @@ void UniCharTestCase::UnsignedLongCompare() #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::wxLongLongCompare() +TEST_CASE("UniChar::wxLongLongCompare", "[unichar]") { wxLongLong_t aVal = 2; wxLongLong_t bVal = 3; @@ -484,7 +327,7 @@ void UniCharTestCase::wxLongLongCompare() wxUNICHAR_TEST_INT_COMPARE } -void UniCharTestCase::wxULongLongCompare() +TEST_CASE("UniChar::wxULongLongCompare", "[unichar]") { wxULongLong_t aVal = 2; wxULongLong_t bVal = 3; @@ -495,7 +338,7 @@ void UniCharTestCase::wxULongLongCompare() #endif -void UniCharTestCase::WideCharCompare() +TEST_CASE("UniChar::WideCharCompare", "[unichar]") { wchar_t aVal = 2; wchar_t bVal = 3; @@ -510,76 +353,76 @@ void UniCharTestCase::WideCharCompare() wxUniChar a; \ wxUniChar b(bVal); \ a = b; \ - CPPUNIT_ASSERT(a == b); + CHECK(a == b); -void UniCharTestCase::UniCharAssignmentOperator() +TEST_CASE("UniChar::UniCharAssignmentOperator", "[unichar]") { wxUniChar a; wxUniChar b('b'); a = b; - CPPUNIT_ASSERT(a == b); + CHECK(a == b); } -void UniCharTestCase::UniCharRefAssignmentOperator() +TEST_CASE("UniChar::UniCharRefAssignmentOperator", "[unichar]") { wxUniChar a; wxUniChar b('b'); wxString bStr('b'); wxUniCharRef bRef = bStr[0]; a = bRef; - CPPUNIT_ASSERT(a == b); + CHECK(a == b); } -void UniCharTestCase::CharAssignmentOperator() +TEST_CASE("UniChar::CharAssignmentOperator", "[unichar]") { char bVal = 'b'; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::UnsignedCharAssignmentOperator() +TEST_CASE("UniChar::UnsignedCharAssignmentOperator", "[unichar]") { unsigned char bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::ShortAssignmentOperator() +TEST_CASE("UniChar::ShortAssignmentOperator", "[unichar]") { short bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::UnsignedShortAssignmentOperator() +TEST_CASE("UniChar::UnsignedShortAssignmentOperator", "[unichar]") { unsigned short bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::IntAssignmentOperator() +TEST_CASE("UniChar::IntAssignmentOperator", "[unichar]") { int bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::UnsignedIntAssignmentOperator() +TEST_CASE("UniChar::UnsignedIntAssignmentOperator", "[unichar]") { unsigned int bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::LongAssignmentOperator() +TEST_CASE("UniChar::LongAssignmentOperator", "[unichar]") { long bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::UnsignedLongAssignmentOperator() +TEST_CASE("UniChar::UnsignedLongAssignmentOperator", "[unichar]") { unsigned long bVal = 2; @@ -588,14 +431,14 @@ void UniCharTestCase::UnsignedLongAssignmentOperator() #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::wxLongLongAssignmentOperator() +TEST_CASE("UniChar::wxLongLongAssignmentOperator", "[unichar]") { wxLongLong_t bVal = 2; wxUNICHAR_TEST_ASSIGNMENT_OPERATOR } -void UniCharTestCase::wxULongLongAssignmentOperator() +TEST_CASE("UniChar::wxULongLongAssignmentOperator", "[unichar]") { wxULongLong_t bVal = 2; @@ -604,7 +447,7 @@ void UniCharTestCase::wxULongLongAssignmentOperator() #endif -void UniCharTestCase::WideCharAssignmentOperator() +TEST_CASE("UniChar::WideCharAssignmentOperator", "[unichar]") { wchar_t bVal = 2; @@ -613,122 +456,122 @@ void UniCharTestCase::WideCharAssignmentOperator() #undef wxUNICHAR_TEST_ASSIGNMENT_OPERATOR -void UniCharTestCase::CharParenOperator() +TEST_CASE("UniChar::CharParenOperator", "[unichar]") { char aVal; char bVal = 'b'; wxUniChar b(bVal); aVal = (char) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::UnsignedCharParenOperator() +TEST_CASE("UniChar::UnsignedCharParenOperator", "[unichar]") { unsigned char aVal; unsigned char bVal = 'b'; wxUniChar b(bVal); aVal = (unsigned char) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::ShortParenOperator() +TEST_CASE("UniChar::ShortParenOperator", "[unichar]") { short aVal; short bVal = 2; wxUniChar b(bVal); aVal = (short) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::UnsignedShortParenOperator() +TEST_CASE("UniChar::UnsignedShortParenOperator", "[unichar]") { unsigned short aVal; unsigned short bVal = 2; wxUniChar b(bVal); aVal = (unsigned short) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::IntParenOperator() +TEST_CASE("UniChar::IntParenOperator", "[unichar]") { int aVal; int bVal = 2; wxUniChar b(bVal); aVal = (int) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::UnsignedIntParenOperator() +TEST_CASE("UniChar::UnsignedIntParenOperator", "[unichar]") { unsigned int aVal; unsigned int bVal = 2; wxUniChar b(bVal); aVal = (unsigned int) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::LongParenOperator() +TEST_CASE("UniChar::LongParenOperator", "[unichar]") { long aVal; long bVal = 2; wxUniChar b(bVal); aVal = (long) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::UnsignedLongParenOperator() +TEST_CASE("UniChar::UnsignedLongParenOperator", "[unichar]") { unsigned long aVal; unsigned long bVal = 2; wxUniChar b(bVal); aVal = (unsigned long) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::wxLongLongParenOperator() +TEST_CASE("UniChar::wxLongLongParenOperator", "[unichar]") { wxLongLong_t aVal; wxLongLong_t bVal = 2; wxUniChar b(bVal); aVal = (wxLongLong_t) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::wxULongLongParenOperator() +TEST_CASE("UniChar::wxULongLongParenOperator", "[unichar]") { wxULongLong_t aVal; wxULongLong_t bVal = 2; wxUniChar b(bVal); aVal = (wxULongLong_t) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } #endif -void UniCharTestCase::WideCharParenOperator() +TEST_CASE("UniChar::WideCharParenOperator", "[unichar]") { wchar_t aVal; wchar_t bVal = 2; wxUniChar b(bVal); aVal = (wchar_t) b; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefUniCharAssignmentOperator() +TEST_CASE("UniChar::RefUniCharAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -737,10 +580,10 @@ void UniCharTestCase::RefUniCharAssignmentOperator() wxUniChar bVal(b); bRef = bVal; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefUniCharRefAssignmentOperator() +TEST_CASE("UniChar::RefUniCharRefAssignmentOperator", "[unichar]") { wxChar b = 'b'; wxString testStr(b); @@ -751,10 +594,10 @@ void UniCharTestCase::RefUniCharRefAssignmentOperator() bRef = testRef; - CPPUNIT_ASSERT(bRef == testRef); + CHECK(bRef == testRef); } -void UniCharTestCase::RefCharAssignmentOperator() +TEST_CASE("UniChar::RefCharAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -762,10 +605,10 @@ void UniCharTestCase::RefCharAssignmentOperator() char b = 'b'; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefUnsignedCharAssignmentOperator() +TEST_CASE("UniChar::RefUnsignedCharAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -773,10 +616,10 @@ void UniCharTestCase::RefUnsignedCharAssignmentOperator() unsigned char b = 'b'; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefShortAssignmentOperator() +TEST_CASE("UniChar::RefShortAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -784,10 +627,10 @@ void UniCharTestCase::RefShortAssignmentOperator() short b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefUnsignedShortAssignmentOperator() +TEST_CASE("UniChar::RefUnsignedShortAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -795,10 +638,10 @@ void UniCharTestCase::RefUnsignedShortAssignmentOperator() unsigned short b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefIntAssignmentOperator() +TEST_CASE("UniChar::RefIntAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -806,10 +649,10 @@ void UniCharTestCase::RefIntAssignmentOperator() int b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefUnsignedIntAssignmentOperator() +TEST_CASE("UniChar::RefUnsignedIntAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -817,10 +660,10 @@ void UniCharTestCase::RefUnsignedIntAssignmentOperator() unsigned int b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefLongAssignmentOperator() +TEST_CASE("UniChar::RefLongAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -828,10 +671,10 @@ void UniCharTestCase::RefLongAssignmentOperator() long b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefUnsignedLongAssignmentOperator() +TEST_CASE("UniChar::RefUnsignedLongAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -839,12 +682,12 @@ void UniCharTestCase::RefUnsignedLongAssignmentOperator() unsigned long b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::RefwxLongLongAssignmentOperator() +TEST_CASE("UniChar::RefwxLongLongAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -852,9 +695,9 @@ void UniCharTestCase::RefwxLongLongAssignmentOperator() wxLongLong_t b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefwxULongLongAssignmentOperator() +TEST_CASE("UniChar::RefwxULongLongAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -862,12 +705,12 @@ void UniCharTestCase::RefwxULongLongAssignmentOperator() unsigned long b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } #endif -void UniCharTestCase::RefWideCharAssignmentOperator() +TEST_CASE("UniChar::RefWideCharAssignmentOperator", "[unichar]") { wxString dummyStr('0'); wxUniCharRef bRef = dummyStr[0]; @@ -875,10 +718,10 @@ void UniCharTestCase::RefWideCharAssignmentOperator() wchar_t b = 2; bRef = b; - CPPUNIT_ASSERT(bRef == b); + CHECK(bRef == b); } -void UniCharTestCase::RefCharParenOperator() +TEST_CASE("UniChar::RefCharParenOperator", "[unichar]") { char aVal; char bVal = 'b'; @@ -886,21 +729,21 @@ void UniCharTestCase::RefCharParenOperator() wxUniCharRef bRef = testStr[0]; aVal = (char) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefUnsignedCharParenOperator() +TEST_CASE("UniChar::RefUnsignedCharParenOperator", "[unichar]") { unsigned char aVal; unsigned char bVal = 'b'; - wxString testStr = wxString::Format(wxT("%u"), bVal); + wxString testStr{wxUniChar(bVal)}; wxUniCharRef bRef = testStr[0]; aVal = (unsigned char) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefShortParenOperator() +TEST_CASE("UniChar::RefShortParenOperator", "[unichar]") { short aVal; short bVal = 2; @@ -911,10 +754,10 @@ void UniCharTestCase::RefShortParenOperator() bRef = b; aVal = (short) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefUnsignedShortParenOperator() +TEST_CASE("UniChar::RefUnsignedShortParenOperator", "[unichar]") { unsigned short aVal; unsigned short bVal = 2; @@ -925,10 +768,10 @@ void UniCharTestCase::RefUnsignedShortParenOperator() bRef = b; aVal = (unsigned short) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefIntParenOperator() +TEST_CASE("UniChar::RefIntParenOperator", "[unichar]") { int aVal; int bVal = 2; @@ -939,10 +782,10 @@ void UniCharTestCase::RefIntParenOperator() bRef = b; aVal = (int) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefUnsignedIntParenOperator() +TEST_CASE("UniChar::RefUnsignedIntParenOperator", "[unichar]") { unsigned int aVal; unsigned int bVal = 2; @@ -953,10 +796,10 @@ void UniCharTestCase::RefUnsignedIntParenOperator() bRef = b; aVal = (unsigned int) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefLongParenOperator() +TEST_CASE("UniChar::RefLongParenOperator", "[unichar]") { long aVal; long bVal = 2; @@ -967,10 +810,10 @@ void UniCharTestCase::RefLongParenOperator() bRef = b; aVal = (long) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefUnsignedLongParenOperator() +TEST_CASE("UniChar::RefUnsignedLongParenOperator", "[unichar]") { unsigned long aVal; unsigned long bVal = 2; @@ -981,12 +824,12 @@ void UniCharTestCase::RefUnsignedLongParenOperator() bRef = b; aVal = (unsigned long) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::RefwxLongLongParenOperator() +TEST_CASE("UniChar::RefwxLongLongParenOperator", "[unichar]") { wxLongLong_t aVal; wxLongLong_t bVal = 2; @@ -997,10 +840,10 @@ void UniCharTestCase::RefwxLongLongParenOperator() bRef = b; aVal = (wxLongLong_t) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } -void UniCharTestCase::RefwxULongLongParenOperator() +TEST_CASE("UniChar::RefwxULongLongParenOperator", "[unichar]") { wxULongLong_t aVal; wxULongLong_t bVal = 2; @@ -1011,12 +854,12 @@ void UniCharTestCase::RefwxULongLongParenOperator() bRef = b; aVal = (wxULongLong_t) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } #endif -void UniCharTestCase::RefWideCharParenOperator() +TEST_CASE("UniChar::RefWideCharParenOperator", "[unichar]") { wchar_t aVal; wchar_t bVal = 2; @@ -1027,7 +870,7 @@ void UniCharTestCase::RefWideCharParenOperator() bRef = b; aVal = (wxLongLong_t) bRef; - CPPUNIT_ASSERT(aVal == bVal); + CHECK(aVal == bVal); } #define wxUNICHARREF_TEST_INT_COMPARE \ @@ -1035,14 +878,14 @@ void UniCharTestCase::RefWideCharParenOperator() wxString dummyStr("0"); \ wxUniCharRef aRef = dummyStr[0]; \ aRef = a; \ - CPPUNIT_ASSERT( aRef == aVal ); \ - CPPUNIT_ASSERT( aRef != bVal ); \ - CPPUNIT_ASSERT( aRef < bVal ); \ - CPPUNIT_ASSERT( aRef <= bVal ); \ - CPPUNIT_ASSERT( aRef > cVal ); \ - CPPUNIT_ASSERT( aRef >= cVal ); + CHECK( aRef == aVal ); \ + CHECK( aRef != bVal ); \ + CHECK( aRef < bVal ); \ + CHECK( aRef <= bVal ); \ + CHECK( aRef > cVal ); \ + CHECK( aRef >= cVal ); -void UniCharTestCase::RefShortCompare() +TEST_CASE("UniChar::RefShortCompare", "[unichar]") { short aVal = 2; short bVal = 3; @@ -1051,7 +894,7 @@ void UniCharTestCase::RefShortCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefUnsignedShortCompare() +TEST_CASE("UniChar::RefUnsignedShortCompare", "[unichar]") { unsigned short aVal = 2; unsigned short bVal = 3; @@ -1060,7 +903,7 @@ void UniCharTestCase::RefUnsignedShortCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefIntCompare() +TEST_CASE("UniChar::RefIntCompare", "[unichar]") { int aVal = 2; int bVal = 3; @@ -1069,7 +912,7 @@ void UniCharTestCase::RefIntCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefUnsignedIntCompare() +TEST_CASE("UniChar::RefUnsignedIntCompare", "[unichar]") { unsigned int aVal = 2; unsigned int bVal = 3; @@ -1078,7 +921,7 @@ void UniCharTestCase::RefUnsignedIntCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefLongCompare() +TEST_CASE("UniChar::RefLongCompare", "[unichar]") { long aVal = 2; long bVal = 3; @@ -1087,7 +930,7 @@ void UniCharTestCase::RefLongCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefUnsignedLongCompare() +TEST_CASE("UniChar::RefUnsignedLongCompare", "[unichar]") { unsigned long aVal = 2; unsigned long bVal = 3; @@ -1098,7 +941,7 @@ void UniCharTestCase::RefUnsignedLongCompare() #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG -void UniCharTestCase::RefwxLongLongCompare() +TEST_CASE("UniChar::RefwxLongLongCompare", "[unichar]") { wxLongLong_t aVal = 2; wxLongLong_t bVal = 3; @@ -1107,7 +950,7 @@ void UniCharTestCase::RefwxLongLongCompare() wxUNICHARREF_TEST_INT_COMPARE } -void UniCharTestCase::RefwxULongLongCompare() +TEST_CASE("UniChar::RefwxULongLongCompare", "[unichar]") { wxULongLong_t aVal = 2; wxULongLong_t bVal = 3; @@ -1118,7 +961,7 @@ void UniCharTestCase::RefwxULongLongCompare() #endif -void UniCharTestCase::RefWideCharCompare() +TEST_CASE("UniChar::RefWideCharCompare", "[unichar]") { wchar_t aVal = 2; wchar_t bVal = 3; diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp index b8606ae063..f8ba41dd51 100644 --- a/tests/strings/unicode.cpp +++ b/tests/strings/unicode.cpp @@ -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++] ); } } } diff --git a/tests/textfile/textfiletest.cpp b/tests/textfile/textfiletest.cpp index d70f754456..5153a50839 100644 --- a/tests/textfile/textfiletest.cpp +++ b/tests/textfile/textfiletest.cpp @@ -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]") diff --git a/tests/weakref/evtconnection.cpp b/tests/weakref/evtconnection.cpp index 3542c881c4..89fb82c18b 100644 --- a/tests/weakref/evtconnection.cpp +++ b/tests/weakref/evtconnection.cpp @@ -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 ); } diff --git a/tests/weakref/weakref.cpp b/tests/weakref/weakref.cpp index 9f5fa14f81..0e49c4cc79 100644 --- a/tests/weakref/weakref.cpp +++ b/tests/weakref/weakref.cpp @@ -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 wro2(&eh); wxWeakRef 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 wreh(&eh); wxWeakRef 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 wro1; wxWeakRef 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 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 wro3 = pot; wxWeakRef 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 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 wro1; wxWeakRefDynamic 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 diff --git a/tests/xlocale/xlocale.cpp b/tests/xlocale/xlocale.cpp index 53a887f52c..0818f3a496 100644 --- a/tests/xlocale/xlocale.cpp +++ b/tests/xlocale/xlocale.cpp @@ -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 }