Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets
Commits:
c8d018dd by Blake-Madden at 2025-09-02T19:24:40-04:00
Upgrade tests to Catch2
- - - - -
2bc4bcb3 by Blake-Madden at 2025-09-07T18:38:37-04:00
Migrate fuzzer unit test to Catch2
- - - - -
35a838a6 by Blake-Madden at 2025-09-08T06:32:35-04:00
Upgrade fontmapper unit tests to Catch2
- - - - -
559ce0ae by Blake-Madden at 2025-09-08T06:37:15-04:00
Upgrade thread unit tests to Catch2
- - - - -
8a02590d by Blake-Madden at 2025-09-08T07:45:06-04:00
Upgrade wxRegion unit tests to Catch2
- - - - -
1780193e by Blake-Madden at 2025-09-08T09:57:50-04:00
Upgrade format unit tests to Catch2
- - - - -
8b56a66a by Blake-Madden at 2025-09-08T10:20:54-04:00
Suppress -Wunused-but-set-variable warning with clang
- - - - -
e8049375 by Blake-Madden at 2025-09-08T10:21:57-04:00
Improve test case name
- - - - -
aef78cba by Blake-Madden at 2025-09-08T10:55:54-04:00
Migrate some affine matrix tests to Catch2
- - - - -
ab0891db by Vadim Zeitlin at 2025-09-09T00:09:05+02:00
Use operator<<() inside Catch INFO() for consistency
No real changes, just prefer using streaming operator to string
concatenation.
- - - - -
4132f2bc by Vadim Zeitlin at 2025-09-09T00:09:55+02:00
Put braces around non-trivial compound statement bodies in test
No real changes, just make the code a bit more readable.
- - - - -
f680059b by Vadim Zeitlin at 2025-09-09T00:12:02+02:00
Use std::vector instead of manual memory management in a test
Make the test code a bit safer.
- - - - -
6f4586aa by Vadim Zeitlin at 2025-09-09T00:12:32+02:00
Merge branch 'rm-cppunit'
Upgrade more tests to use Catch2 directly instead of via legacy
CppUnit-compatible macros.
See #25760.
- - - - -
7 changed files:
- tests/fontmap/fontmaptest.cpp
- tests/formatconverter/formatconvertertest.cpp
- tests/geometry/region.cpp
- tests/graphics/affinematrix.cpp
- tests/log/logtest.cpp
- tests/misc/garbage.cpp
- tests/thread/tls.cpp
Changes:
=====================================
tests/fontmap/fontmaptest.cpp
=====================================
@@ -26,29 +26,7 @@
// test class
// ----------------------------------------------------------------------------
-class FontMapperTestCase : public CppUnit::TestCase
-{
-public:
- FontMapperTestCase() { }
-
-private:
- CPPUNIT_TEST_SUITE( FontMapperTestCase );
- CPPUNIT_TEST( NamesAndDesc );
- CPPUNIT_TEST_SUITE_END();
-
- void NamesAndDesc();
-
- wxDECLARE_NO_COPY_CLASS(FontMapperTestCase);
-};
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION( FontMapperTestCase );
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FontMapperTestCase, "FontMapperTestCase" );
-
-
-void FontMapperTestCase::NamesAndDesc()
+TEST_CASE("wxFontMapper::NamesAndDesc", "[fontmapper]")
{
static const wxChar *charsets[] =
{
@@ -108,8 +86,8 @@ void FontMapperTestCase::NamesAndDesc()
for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
{
wxFontEncoding enc = fmap.CharsetToEncoding(charsets[n]);
- CPPUNIT_ASSERT_EQUAL( names[n], fmap.GetEncodingName(enc).Lower() );
- CPPUNIT_ASSERT_EQUAL( descriptions[n], fmap.GetEncodingDescription(enc) );
+ CHECK( fmap.GetEncodingName(enc).Lower() == names[n] );
+ CHECK( fmap.GetEncodingDescription(enc) == descriptions[n] );
}
}
=====================================
tests/formatconverter/formatconvertertest.cpp
=====================================
@@ -31,7 +31,7 @@
// I've put in some checks, such as this which will flag up any platforms
// where this is not the case:
//
-// CPPUNIT_ASSERT(wxString::Format(wxT("%hs"), "test") == wxT("test"));
+// CHECK(wxString::Format(wxT("%hs"), "test") == wxT("test"));
//
// For compilers that support precompilation, includes "wx/wx.h".
@@ -44,7 +44,6 @@
#endif
-using CppUnit::TestCase;
using std::string;
///////////////////////////////////////////////////////////////////////////////
@@ -54,155 +53,190 @@ using std::string;
// equally, therefore it is enough to choose just one other for testing, %d
// will do.
-class FormatConverterTestCase : public TestCase
+void check(const wxString& input, const wxString& expectedScanf,
+ const wxString& expectedUtf8,
+ const wxString& expectedWcharUnix,
+ const wxString& expectedWcharWindows)
{
- CPPUNIT_TEST_SUITE(FormatConverterTestCase);
- CPPUNIT_TEST(format_d);
- CPPUNIT_TEST(format_hd);
- CPPUNIT_TEST(format_ld);
- CPPUNIT_TEST(format_s);
- CPPUNIT_TEST(format_hs);
- CPPUNIT_TEST(format_ls);
- CPPUNIT_TEST(format_c);
- CPPUNIT_TEST(format_hc);
- CPPUNIT_TEST(format_lc);
- CPPUNIT_TEST(format_S);
- CPPUNIT_TEST(format_hS);
- CPPUNIT_TEST(format_lS);
- CPPUNIT_TEST(format_C);
- CPPUNIT_TEST(format_hC);
- CPPUNIT_TEST(format_lC);
- CPPUNIT_TEST(testLonger);
- CPPUNIT_TEST_SUITE_END();
-
- void format_d();
- void format_hd();
- void format_ld();
- void format_s();
- void format_hs();
- void format_ls();
- void format_c();
- void format_hc();
- void format_lc();
-
- void format_S();
- void format_hS();
- void format_lS();
- void format_C();
- void format_hC();
- void format_lC();
- void testLonger();
-
- void doTest(const char *input, const char *expectedScanf,
- const char *expectedUtf8,
- const char *expectedWcharUnix,
- const char *expectedWcharWindows);
- void check(const wxString& input, const wxString& expectedScanf,
- const wxString& expectedUtf8,
- const wxString& expectedWcharUnix,
- const wxString& expectedWcharWindows);
-};
-
-void FormatConverterTestCase::format_d()
+ INFO("expectedScanf: " << expectedScanf);
+ INFO("expectedUtf8: " << expectedUtf8);
+ INFO("expectedWcharUnix: " << expectedWcharUnix);
+ INFO("expectedWcharWindows: " << expectedWcharWindows);
+
+ wxString result, msg;
+ wxUnusedVar(result);
+ wxUnusedVar(msg);
+
+#ifndef __WINDOWS__
+ // on windows, wxScanf() string needs no modifications
+ result = wxScanfConvertFormatW(input.wc_str());
+
+ msg = wxT("input: '") + input +
+ wxT("', result (scanf): '") + result +
+ wxT("', expected: '") + expectedScanf + wxT("'");
+ CHECK(result == expectedScanf);
+#endif // !__WINDOWS__
+
+#if wxUSE_UNICODE_UTF8
+ result = (const char*)wxFormatString(input);
+
+ msg = wxT("input: '") + input +
+ wxT("', result (UTF-8): '") + result +
+ wxT("', expected: '") + expectedUtf8 + wxT("'");
+ CHECK(result == expectedUtf8);
+#endif // wxUSE_UNICODE_UTF8
+
+#if !wxUSE_UTF8_LOCALE_ONLY
+ result = (const wchar_t*)wxFormatString(input);
+
+#if defined(__WINDOWS__) && \
+ !defined(__CYGWIN__) && \
+ !defined(__MINGW32__)
+ wxString expectedWchar(expectedWcharWindows);
+#else
+ wxString expectedWchar(expectedWcharUnix);
+#endif
+
+ msg = wxT("input: '") + input +
+ wxT("', result (wchar_t): '") + result +
+ wxT("', expected: '") + expectedWchar + wxT("'");
+ CHECK(result == expectedWchar);
+#endif // !wxUSE_UTF8_LOCALE_ONLY
+}
+
+void doTest(const char* input, const char* expectedScanf,
+ const char* expectedUtf8,
+ const char* expectedWcharUnix,
+ const char* expectedWcharWindows)
+{
+ static const wxChar* flag_width[] =
+ { wxT(""), wxT("*"), wxT("10"), wxT("-*"), wxT("-10"), nullptr };
+ static const wxChar* precision[] =
+ { wxT(""), wxT(".*"), wxT(".10"), nullptr };
+ static const wxChar* empty[] =
+ { wxT(""), nullptr };
+
+ // no precision for %c or %C
+ const wxChar** precs = wxTolower(input[wxStrlen(input) - 1]) == wxT('c') ?
+ empty : precision;
+
+ wxString fmt(wxT("%"));
+
+ // try the test for a variety of combinations of flag, width and precision
+ for (const wxChar** prec = precs; *prec; prec++)
+ {
+ for (const wxChar** width = flag_width; *width; width++)
+ {
+ check(fmt + *width + *prec + input,
+ fmt + *width + *prec + expectedScanf,
+ fmt + *width + *prec + expectedUtf8,
+ fmt + *width + *prec + expectedWcharUnix,
+ fmt + *width + *prec + expectedWcharWindows);
+ }
+ }
+}
+
+
+TEST_CASE("Format::d", "[formatconverter]")
{
doTest("d", "d", "d", "d", "d");
- CPPUNIT_ASSERT(wxString::Format(wxT("%d"), 255) == wxT("255"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%05d"), 255) == wxT("00255"));
- CPPUNIT_ASSERT(wxString::Format(wxT("% 5d"), 255) == wxT(" 255"));
- CPPUNIT_ASSERT(wxString::Format(wxT("% 5d"), -255) == wxT(" -255"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%-5d"), -255) == wxT("-255 "));
- CPPUNIT_ASSERT(wxString::Format(wxT("%+5d"), 255) == wxT(" +255"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%*d"), 5, 255) == wxT(" 255"));
+ CHECK(wxString::Format(wxT("%d"), 255) == wxT("255"));
+ CHECK(wxString::Format(wxT("%05d"), 255) == wxT("00255"));
+ CHECK(wxString::Format(wxT("% 5d"), 255) == wxT(" 255"));
+ CHECK(wxString::Format(wxT("% 5d"), -255) == wxT(" -255"));
+ CHECK(wxString::Format(wxT("%-5d"), -255) == wxT("-255 "));
+ CHECK(wxString::Format(wxT("%+5d"), 255) == wxT(" +255"));
+ CHECK(wxString::Format(wxT("%*d"), 5, 255) == wxT(" 255"));
}
-void FormatConverterTestCase::format_hd()
+TEST_CASE("Format::hd", "[formatconverter]")
{
doTest("hd", "hd", "hd", "hd", "hd");
short s = 32767;
- CPPUNIT_ASSERT(wxString::Format(wxT("%hd"), s) == wxT("32767"));
+ CHECK(wxString::Format(wxT("%hd"), s) == wxT("32767"));
}
-void FormatConverterTestCase::format_ld()
+TEST_CASE("Format::ld", "[formatconverter]")
{
doTest("ld", "ld", "ld", "ld", "ld");
long l = 2147483647L;
- CPPUNIT_ASSERT(wxString::Format(wxT("%ld"), l) == wxT("
2147483647"));
+ CHECK(wxString::Format(wxT("%ld"), l) == wxT("
2147483647"));
}
-void FormatConverterTestCase::format_s()
+TEST_CASE("Format::s", "[formatconverter]")
{
doTest("s", "ls", "s", "ls", "s");
- CPPUNIT_ASSERT(wxString::Format(wxT("%s!"), wxT("test")) == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%6s!"), wxT("test")) == wxT(" test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%-6s!"), wxT("test")) == wxT("test !"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%.6s!"), wxT("test")) == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%6.4s!"), wxT("testing")) == wxT(" test!"));
+ CHECK(wxString::Format(wxT("%s!"), wxT("test")) == wxT("test!"));
+ CHECK(wxString::Format(wxT("%6s!"), wxT("test")) == wxT(" test!"));
+ CHECK(wxString::Format(wxT("%-6s!"), wxT("test")) == wxT("test !"));
+ CHECK(wxString::Format(wxT("%.6s!"), wxT("test")) == wxT("test!"));
+ CHECK(wxString::Format(wxT("%6.4s!"), wxT("testing")) == wxT(" test!"));
}
-void FormatConverterTestCase::format_hs()
+TEST_CASE("Format::hs", "[formatconverter]")
{
doTest("hs", "hs", "s", "ls", "s");
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%hs!")), "test") == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%6hs!")), "test") == wxT(" test!"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%-6hs!")), "test") == wxT("test !"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%.6hs!")), "test") == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%6.4hs!")), "testing") == wxT(" test!"));
+ CHECK(wxString::Format(wxString(wxT("%hs!")), "test") == wxT("test!"));
+ CHECK(wxString::Format(wxString(wxT("%6hs!")), "test") == wxT(" test!"));
+ CHECK(wxString::Format(wxString(wxT("%-6hs!")), "test") == wxT("test !"));
+ CHECK(wxString::Format(wxString(wxT("%.6hs!")), "test") == wxT("test!"));
+ CHECK(wxString::Format(wxString(wxT("%6.4hs!")), "testing") == wxT(" test!"));
}
-void FormatConverterTestCase::format_ls()
+TEST_CASE("Format::ls", "[formatconverter]")
{
doTest("ls", "ls", "s", "ls", "s");
- CPPUNIT_ASSERT(wxString::Format(wxT("%ls!"), L"test") == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%6ls!"), L"test") == wxT(" test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%-6ls!"), L"test") == wxT("test !"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%.6ls!"), L"test") == wxT("test!"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%6.4ls!"), L"testing") == wxT(" test!"));
+ CHECK(wxString::Format(wxT("%ls!"), L"test") == wxT("test!"));
+ CHECK(wxString::Format(wxT("%6ls!"), L"test") == wxT(" test!"));
+ CHECK(wxString::Format(wxT("%-6ls!"), L"test") == wxT("test !"));
+ CHECK(wxString::Format(wxT("%.6ls!"), L"test") == wxT("test!"));
+ CHECK(wxString::Format(wxT("%6.4ls!"), L"testing") == wxT(" test!"));
}
-void FormatConverterTestCase::format_c()
+TEST_CASE("Format::c", "[formatconverter]")
{
doTest("c", "lc", "lc", "lc", "c");
- CPPUNIT_ASSERT(wxString::Format(wxT("%c"), wxT('x')) == wxT("x"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%2c"), wxT('x')) == wxT(" x"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%-2c"), wxT('x')) == wxT("x "));
+ CHECK(wxString::Format(wxT("%c"), wxT('x')) == wxT("x"));
+ CHECK(wxString::Format(wxT("%2c"), wxT('x')) == wxT(" x"));
+ CHECK(wxString::Format(wxT("%-2c"), wxT('x')) == wxT("x "));
}
-void FormatConverterTestCase::format_hc()
+TEST_CASE("Format::hc", "[formatconverter]")
{
doTest("hc", "hc", "lc", "lc", "c");
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%hc")), 'x') == wxT("x"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%2hc")), 'x') == wxT(" x"));
- CPPUNIT_ASSERT(wxString::Format(wxString(wxT("%-2hc")), 'x') == wxT("x "));
+ CHECK(wxString::Format(wxString(wxT("%hc")), 'x') == wxT("x"));
+ CHECK(wxString::Format(wxString(wxT("%2hc")), 'x') == wxT(" x"));
+ CHECK(wxString::Format(wxString(wxT("%-2hc")), 'x') == wxT("x "));
}
-void FormatConverterTestCase::format_lc()
+TEST_CASE("Format::lc", "[formatconverter]")
{
doTest("lc", "lc", "lc", "lc", "c");
- CPPUNIT_ASSERT(wxString::Format(wxT("%lc"), L'x') == wxT("x"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%2lc"), L'x') == wxT(" x"));
- CPPUNIT_ASSERT(wxString::Format(wxT("%-2lc"), L'x') == wxT("x "));
+ CHECK(wxString::Format(wxT("%lc"), L'x') == wxT("x"));
+ CHECK(wxString::Format(wxT("%2lc"), L'x') == wxT(" x"));
+ CHECK(wxString::Format(wxT("%-2lc"), L'x') == wxT("x "));
}
-void FormatConverterTestCase::format_S()
+TEST_CASE("Format::S", "[formatconverter]")
{ doTest("S", "s", "s", "ls", "s"); }
-void FormatConverterTestCase::format_hS()
+TEST_CASE("Format::hS", "[formatconverter]")
{ doTest("hS", "s", "s", "ls", "s"); }
-void FormatConverterTestCase::format_lS()
+TEST_CASE("Format::lS", "[formatconverter]")
{ doTest("lS", "ls", "s", "ls", "s"); }
-void FormatConverterTestCase::format_C()
+TEST_CASE("Format::C", "[formatconverter]")
{ doTest("C", "c", "lc", "lc", "c"); }
-void FormatConverterTestCase::format_hC()
+TEST_CASE("Format::hC", "[formatconverter]")
{ doTest("hC", "c", "lc", "lc", "c"); }
-void FormatConverterTestCase::format_lC()
+TEST_CASE("Format::lC", "[formatconverter]")
{ doTest("lC", "lc", "lc", "lc", "c"); }
// It's possible that although a format converts correctly alone, it leaves
// the converter in a bad state that will affect subsequent formats, so
// check with a selection of longer patterns.
//
-void FormatConverterTestCase::testLonger()
+TEST_CASE("Format::Longer", "[formatconverter]")
{
struct {
const char *input;
@@ -242,92 +276,3 @@ void FormatConverterTestCase::testLonger()
}
}
}
-
-void FormatConverterTestCase::doTest(const char *input,
- const char *expectedScanf,
- const char *expectedUtf8,
- const char *expectedWcharUnix,
- const char *expectedWcharWindows)
-{
- static const wxChar *flag_width[] =
- { wxT(""), wxT("*"), wxT("10"), wxT("-*"), wxT("-10"), nullptr };
- static const wxChar *precision[] =
- { wxT(""), wxT(".*"), wxT(".10"), nullptr };
- static const wxChar *empty[] =
- { wxT(""), nullptr };
-
- // no precision for %c or %C
- const wxChar **precs = wxTolower(input[wxStrlen(input)-1]) == wxT('c') ?
- empty : precision;
-
- wxString fmt(wxT("%"));
-
- // try the test for a variety of combinations of flag, width and precision
- for (const wxChar **prec = precs; *prec; prec++)
- for (const wxChar **width = flag_width; *width; width++)
- check(fmt + *width + *prec + input,
- fmt + *width + *prec + expectedScanf,
- fmt + *width + *prec + expectedUtf8,
- fmt + *width + *prec + expectedWcharUnix,
- fmt + *width + *prec + expectedWcharWindows);
-}
-
-void FormatConverterTestCase::check(const wxString& input,
- const wxString& expectedScanf,
- const wxString& expectedUtf8,
- const wxString& expectedWcharUnix,
- const wxString& expectedWcharWindows)
-{
- // all of them are unused in some build configurations
- wxUnusedVar(expectedScanf);
- wxUnusedVar(expectedUtf8);
- wxUnusedVar(expectedWcharUnix);
- wxUnusedVar(expectedWcharWindows);
-
- wxString result, msg;
-
-#ifndef __WINDOWS__
- // on windows, wxScanf() string needs no modifications
- result = wxScanfConvertFormatW(input.wc_str());
-
- msg = wxT("input: '") + input +
- wxT("', result (scanf): '") + result +
- wxT("', expected: '") + expectedScanf + wxT("'");
- CPPUNIT_ASSERT_MESSAGE(string(msg.mb_str()), result == expectedScanf);
-#endif // !__WINDOWS__
-
-#if wxUSE_UNICODE_UTF8
- result = (const char*)wxFormatString(input);
-
- msg = wxT("input: '") + input +
- wxT("', result (UTF-8): '") + result +
- wxT("', expected: '") + expectedUtf8 + wxT("'");
- CPPUNIT_ASSERT_MESSAGE(string(msg.mb_str()), result == expectedUtf8);
-#endif // wxUSE_UNICODE_UTF8
-
-#if !wxUSE_UTF8_LOCALE_ONLY
- result = (const wchar_t*)wxFormatString(input);
-
-#if defined(__WINDOWS__) && \
- !defined(__CYGWIN__) && \
- !defined(__MINGW32__)
- wxString expectedWchar(expectedWcharWindows);
-#else
- wxString expectedWchar(expectedWcharUnix);
-#endif
-
- msg = wxT("input: '") + input +
- wxT("', result (wchar_t): '") + result +
- wxT("', expected: '") + expectedWchar + wxT("'");
- CPPUNIT_ASSERT_MESSAGE(string(msg.mb_str()), result == expectedWchar);
-#endif // !wxUSE_UTF8_LOCALE_ONLY
-}
-
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION(FormatConverterTestCase);
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FormatConverterTestCase,
- "FormatConverterTestCase");
-
=====================================
tests/geometry/region.cpp
=====================================
@@ -40,7 +40,7 @@ unsigned GetRectsCount(const wxRegion& rgn)
} // anonymous namespace
-// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxRegions
+// this operator is needed to use CHECK with wxRegions
std::ostream& operator<<(std::ostream& os, const wxRegion& rgn)
{
wxRect r = rgn.GetBox();
@@ -55,63 +55,39 @@ std::ostream& operator<<(std::ostream& os, const wxRegion& rgn)
// test class
// ----------------------------------------------------------------------------
-class RegionTestCase : public CppUnit::TestCase
-{
-public:
- RegionTestCase() { }
-
-private:
- CPPUNIT_TEST_SUITE( RegionTestCase );
- CPPUNIT_TEST( Validity );
- CPPUNIT_TEST( Intersect );
- CPPUNIT_TEST_SUITE_END();
-
- void Validity();
- void Intersect();
-
- wxDECLARE_NO_COPY_CLASS(RegionTestCase);
-};
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION( RegionTestCase );
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegionTestCase, "RegionTestCase" );
-
-void RegionTestCase::Validity()
+TEST_CASE("wxRegion::Validity", "[region]")
{
wxRegion r;
- CPPUNIT_ASSERT_MESSAGE
+ // Default constructed region must be invalid
+ CHECK_FALSE
(
- "Default constructed region must be invalid",
- !r.IsOk()
+ r.IsOk()
);
- CPPUNIT_ASSERT_MESSAGE
+ // Invalid region should be empty
+ CHECK
(
- "Invalid region should be empty",
r.IsEmpty()
);
// Offsetting an invalid region doesn't make sense.
WX_ASSERT_FAILS_WITH_ASSERT( r.Offset(1, 1) );
- CPPUNIT_ASSERT_MESSAGE
+ // Combining with a valid region should create a valid region
+ CHECK
(
- "Combining with a valid region should create a valid region",
r.Union(0, 0, 10, 10)
);
- CPPUNIT_ASSERT_EQUAL_MESSAGE
+ // Union() with invalid region should give the same region
+ CHECK
(
- "Union() with invalid region should give the same region",
- wxRegion(0, 0, 10, 10),
- r
+ wxRegion(0, 0, 10, 10) == r
);
}
-void RegionTestCase::Intersect()
+TEST_CASE("wxRegion::Intersect", "[region]")
{
const wxPoint points1[] = {
wxPoint(310, 392),
@@ -131,6 +107,6 @@ void RegionTestCase::Intersect()
wxRegion region2(4,points2);
- CPPUNIT_ASSERT( region1.Intersect(region2) );
- CPPUNIT_ASSERT( region1.IsEmpty() );
+ CHECK( region1.Intersect(region2) );
+ CHECK( region1.IsEmpty() );
}
=====================================
tests/graphics/affinematrix.cpp
=====================================
@@ -27,30 +27,7 @@
// Affine transform test class
// ----------------------------------------------------------------------------
-class AffineTransformTestCase : public CppUnit::TestCase
-{
-public:
- AffineTransformTestCase() {}
-
-private:
- CPPUNIT_TEST_SUITE( AffineTransformTestCase );
- CPPUNIT_TEST( InvertMatrix );
- CPPUNIT_TEST( Concat );
- CPPUNIT_TEST_SUITE_END();
-
- void InvertMatrix();
- void Concat();
-
- wxDECLARE_NO_COPY_CLASS(AffineTransformTestCase);
-};
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION( AffineTransformTestCase );
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AffineTransformTestCase, "AffineTransformTestCase" );
-
-void AffineTransformTestCase::InvertMatrix()
+TEST_CASE("AffineTransform::InvertMatrix", "[affine-transform]")
{
wxAffineMatrix2D matrix1;
matrix1.Set(wxMatrix2D(2, 1, 1, 1), wxPoint2DDouble(1, 1));
@@ -62,18 +39,18 @@ void AffineTransformTestCase::InvertMatrix()
wxMatrix2D m;
wxPoint2DDouble p;
matrix2.Get(&m, &p);
- CPPUNIT_ASSERT_EQUAL( 1, (int)m.m_11 );
- CPPUNIT_ASSERT_EQUAL( -1, (int)m.m_12 );
- CPPUNIT_ASSERT_EQUAL( -1, (int)m.m_21 );
- CPPUNIT_ASSERT_EQUAL( 2, (int)m.m_22 );
- CPPUNIT_ASSERT_EQUAL( 0, (int)p.m_x );
- CPPUNIT_ASSERT_EQUAL( -1, (int)p.m_y );
+ CHECK( (int)m.m_11 == 1 );
+ CHECK( (int)m.m_12 == -1 );
+ CHECK( (int)m.m_21 == -1 );
+ CHECK( (int)m.m_22 == 2 );
+ CHECK( (int)p.m_x == 0 );
+ CHECK( (int)p.m_y == -1 );
matrix2.Concat(matrix1);
- CPPUNIT_ASSERT( matrix2.IsIdentity() );
+ CHECK( matrix2.IsIdentity() );
}
-void AffineTransformTestCase::Concat()
+TEST_CASE("AffineTransform::Concat", "[affine-transform]")
{
wxAffineMatrix2D m1;
m1.Set(wxMatrix2D(0.9, 0.4, -0.4, 0.9), wxPoint2DDouble(0.0, 0.0));
@@ -86,12 +63,12 @@ void AffineTransformTestCase::Concat()
m1.Get(&m, &p);
const double delta = 0.01;
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9, m.m_11, delta );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.4, m.m_12, delta );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.4, m.m_21, delta );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9, m.m_22, delta );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.7, p.m_x, delta );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.7, p.m_y, delta );
+ CHECK_THAT( m.m_11 , Catch::Matchers::WithinAbs(0.9, delta) );
+ CHECK_THAT( m.m_12, Catch::Matchers::WithinAbs(0.4, delta) );
+ CHECK_THAT( m.m_21, Catch::Matchers::WithinAbs(-0.4, delta) );
+ CHECK_THAT( m.m_22, Catch::Matchers::WithinAbs(0.9, delta) );
+ CHECK_THAT( p.m_x, Catch::Matchers::WithinAbs(0.7, delta) );
+ CHECK_THAT( p.m_y, Catch::Matchers::WithinAbs(5.7,delta) );
}
#if wxUSE_DC_TRANSFORM_MATRIX
=====================================
tests/log/logtest.cpp
=====================================
@@ -69,8 +69,7 @@ TEST_CASE_METHOD(LogTestCase, "wxLogNull()", "[log]")
TEST_CASE_METHOD(LogTestCase, "wxLog::Component", "[log]")
{
wxLogMessage("Message");
- CPPUNIT_ASSERT_EQUAL( std::string(wxLOG_COMPONENT),
- m_log->GetInfo(wxLOG_Message).component );
+ CHECK( m_log->GetInfo(wxLOG_Message).component == std::string(wxLOG_COMPONENT) );
// completely disable logging for this component
wxLog::SetComponentLevel("test/ignore", wxLOG_FatalError);
=====================================
tests/misc/garbage.cpp
=====================================
@@ -29,64 +29,6 @@
// test class
// ----------------------------------------------------------------------------
-class GarbageTestCase : public CppUnit::TestCase
-{
-public:
- GarbageTestCase() { }
-
-private:
- CPPUNIT_TEST_SUITE( GarbageTestCase );
- CPPUNIT_TEST( LoadGarbage );
- CPPUNIT_TEST_SUITE_END();
-
- void LoadGarbage();
- void DoLoadFile(const wxString& fullname);
- void DoLoadStream(wxInputStream& stream);
-
- wxDECLARE_NO_COPY_CLASS(GarbageTestCase);
-};
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION( GarbageTestCase );
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GarbageTestCase, "GarbageTestCase" );
-
-
-void GarbageTestCase::LoadGarbage()
-{
- srand(1234);
-
- wxInitAllImageHandlers();
-
- for (size_t size = 1; size < GARBAGE_DATA_SIZE; size *= size+1)
- {
- // first, generate some garbage data
- unsigned char *data = new unsigned char[size];
- for (size_t i = 0; i < size; i++)
- data[i] = rand();
-
- // write it to a file
- wxString garbagename = wxFileName::CreateTempFileName("garbage");
- CPPUNIT_ASSERT( !garbagename.empty() );
-
- wxFile garbage(garbagename, wxFile::write);
- CPPUNIT_ASSERT( garbage.IsOpened() );
-
- CPPUNIT_ASSERT( garbage.Write(data, size) == size );
- garbage.Close();
-
- // try to load it by name
- DoLoadFile(garbagename);
-
- // try to load it from a wxInputStream
- wxMemoryInputStream stream(data, size);
- DoLoadStream(stream);
-
- wxDELETEA(data);
- }
-}
-
// Execute the given macro with the given first and second parameters and
// bitmap type as its third parameter for all bitmap types.
#define wxFOR_ALL_VALID_BITMAP_TYPES(m, p1, p2) \
@@ -119,7 +61,7 @@ void GarbageTestCase::LoadGarbage()
!func(arg) \
)
-void GarbageTestCase::DoLoadFile(const wxString& fullname)
+void DoLoadGarbageFile(const wxString& fullname)
{
// test wxImage
wxImage img;
@@ -145,27 +87,27 @@ void GarbageTestCase::DoLoadFile(const wxString& fullname)
// test wxDynamicLibrary
wxDynamicLibrary lib;
- CPPUNIT_ASSERT( lib.Load(fullname) == false );
+ CHECK_FALSE( lib.Load(fullname) );
/*
#if wxUSE_MEDIACTRL
// test wxMediaCtrl
wxMediaCtrl *media = new wxMediaCtrl(wxTheApp->GetTopWindow());
- CPPUNIT_ASSERT( media->Load(fullname) == false );
+ CHECK_FALSE( media->Load(fullname) );
#endif
// test wxHtmlWindow
wxHtmlWindow *htmlwin = new wxHtmlWindow(wxTheApp->GetTopWindow());
- CPPUNIT_ASSERT( htmlwin->LoadFile(fullname) == false );
+ CHECK_FALSE( htmlwin->LoadFile(fullname) );
delete htmlwin;
*/
// test wxXmlResource
#if wxUSE_XRC
- CPPUNIT_ASSERT( wxXmlResource::Get()->Load(fullname) == false );
+ CHECK_FALSE( wxXmlResource::Get()->Load(fullname) );
#endif
}
-void GarbageTestCase::DoLoadStream(wxInputStream& stream)
+void DoLoadGarbageStream(wxInputStream& stream)
{
// NOTE: not all classes tested by DoLoadFile() supports loading
// from an input stream!
@@ -184,11 +126,44 @@ void GarbageTestCase::DoLoadStream(wxInputStream& stream)
/*
// test wxHtmlWindow
wxHtmlWindow *htmlwin = new wxHtmlWindow(wxTheApp->GetTopWindow());
- CPPUNIT_ASSERT( htmlwin->LoadFile(fullname) == false );
+ CHECK_FALSE( htmlwin->LoadFile(fullname) );
delete htmlwin;
*/
}
+TEST_CASE("Load", "[garbage]")
+{
+ srand(1234);
+
+ wxInitAllImageHandlers();
+
+ for (size_t size = 1; size < GARBAGE_DATA_SIZE; size *= size + 1)
+ {
+ // first, generate some garbage data
+ std::vector<unsigned char> buffer(size);
+ unsigned char* data = &buffer[0];
+ for (size_t i = 0; i < size; i++)
+ data[i] = rand();
+
+ // write it to a file
+ wxString garbagename = wxFileName::CreateTempFileName("garbage");
+ CHECK(!garbagename.empty());
+
+ wxFile garbage(garbagename, wxFile::write);
+ CHECK(garbage.IsOpened());
+
+ CHECK(garbage.Write(data, size) == size);
+ garbage.Close();
+
+ // try to load it by name
+ DoLoadGarbageFile(garbagename);
+
+ // try to load it from a wxInputStream
+ wxMemoryInputStream stream(data, size);
+ DoLoadGarbageStream(stream);
+ }
+}
+
#undef ASSERT_FUNC_FAILS
#undef ASSERT_FUNC_FAILS_FOR_TYPE
#undef wxFOR_ALL_VALID_ANIMATION_TYPES
=====================================
tests/thread/tls.cpp
=====================================
@@ -72,54 +72,30 @@ public:
// test class
// ----------------------------------------------------------------------------
-class TLSTestCase : public CppUnit::TestCase
+TEST_CASE("TLS::Int", "[tls]")
{
-public:
- TLSTestCase() { }
-
-private:
- CPPUNIT_TEST_SUITE( TLSTestCase );
- CPPUNIT_TEST( TestInt );
- CPPUNIT_TEST( TestStruct );
- CPPUNIT_TEST_SUITE_END();
-
- void TestInt();
- void TestStruct();
-
- wxDECLARE_NO_COPY_CLASS(TLSTestCase);
-};
-
-// register in the unnamed registry so that these tests are run by default
-CPPUNIT_TEST_SUITE_REGISTRATION( TLSTestCase );
-
-// also include in its own registry so that these tests can be run alone
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TLSTestCase, "TLSTestCase" );
-
-void TLSTestCase::TestInt()
-{
- CPPUNIT_ASSERT_EQUAL( 0, gs_threadInt );
+ CHECK( gs_threadInt == 0 );
gs_threadInt++;
- CPPUNIT_ASSERT_EQUAL( 1, gs_threadInt );
+ CHECK( gs_threadInt == 1 );
TLSTestThread().Wait();
- CPPUNIT_ASSERT_EQUAL( 1, gs_threadInt );
+ CHECK( gs_threadInt == 1 );
}
-void TLSTestCase::TestStruct()
+TEST_CASE("TLS::Struct", "[tls]")
{
- CPPUNIT_ASSERT_EQUAL( nullptr, gs_threadData.name );
- CPPUNIT_ASSERT_EQUAL( 0, gs_threadData.number );
+ CHECK( gs_threadData.name == nullptr);
+ CHECK( gs_threadData.number == 0 );
gs_threadData.name = "main";
gs_threadData.number = 1;
- CPPUNIT_ASSERT_EQUAL( 1, gs_threadData.number );
+ CHECK( gs_threadData.number == 1 );
TLSTestThread().Wait();
- CPPUNIT_ASSERT_EQUAL( std::string("main"), gs_threadData.name );
- CPPUNIT_ASSERT_EQUAL( 1, gs_threadData.number );
+ CHECK( gs_threadData.name == std::string("main") );
+ CHECK( gs_threadData.number == 1 );
}
-
View it on GitLab:
https://gitlab.com/wxwidgets/wxwidgets/-/compare/212bfaf97731543e0bd16cbd598bd9fee8ca133e...6f4586aa125e7e65cb9194b6dffd01415f193627
--
View it on GitLab:
https://gitlab.com/wxwidgets/wxwidgets/-/compare/212bfaf97731543e0bd16cbd598bd9fee8ca133e...6f4586aa125e7e65cb9194b6dffd01415f193627
You're receiving this email because of your account on
gitlab.com.