From 3e9d66f9253d8ba38cbf78b6d27e7020db1e272a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:27:20 +0200 Subject: [PATCH 1/2] Remove CppUnit test case class from wxDir unit tests No real changes, just simplify the code by getting rid of unnecessary CppUnit boilerplate. --- tests/file/dir.cpp | 49 +++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/tests/file/dir.cpp b/tests/file/dir.cpp index 84a41a6709..25a35b75ab 100644 --- a/tests/file/dir.cpp +++ b/tests/file/dir.cpp @@ -21,30 +21,16 @@ #define SEP wxFileName::GetPathSeparator() // ---------------------------------------------------------------------------- -// test class +// test fixture // ---------------------------------------------------------------------------- -class DirTestCase : public CppUnit::TestCase +class DirTestCase { public: - DirTestCase() { } - - virtual void setUp() wxOVERRIDE; - virtual void tearDown() wxOVERRIDE; - -private: - CPPUNIT_TEST_SUITE( DirTestCase ); - CPPUNIT_TEST( DirExists ); - CPPUNIT_TEST( Traverse ); - CPPUNIT_TEST( Enum ); - CPPUNIT_TEST( GetName ); - CPPUNIT_TEST_SUITE_END(); - - void DirExists(); - void Traverse(); - void Enum(); - void GetName(); + DirTestCase(); + ~DirTestCase(); +protected: void CreateTempFile(const wxString& path); wxArrayString DirEnumHelper(wxDir& dir, int flags = wxDIR_DEFAULT, @@ -54,14 +40,7 @@ private: }; // ---------------------------------------------------------------------------- -// CppUnit macros -// ---------------------------------------------------------------------------- - -CPPUNIT_TEST_SUITE_REGISTRATION( DirTestCase ); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DirTestCase, "DirTestCase" ); - -// ---------------------------------------------------------------------------- -// tests implementation +// test fixture implementation // ---------------------------------------------------------------------------- void DirTestCase::CreateTempFile(const wxString& path) @@ -71,7 +50,7 @@ void DirTestCase::CreateTempFile(const wxString& path) f.Close(); } -void DirTestCase::setUp() +DirTestCase::DirTestCase() { // create a test directory hierarchy wxDir::Make(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder1", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); @@ -85,7 +64,7 @@ void DirTestCase::setUp() CreateTempFile(DIRTEST_FOLDER + SEP + "folder3" + SEP + "subfolder1" + SEP + "dummy.foo.bar"); } -void DirTestCase::tearDown() +DirTestCase::~DirTestCase() { wxRemove(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder2" + SEP + "dummy"); wxRemove(DIRTEST_FOLDER + SEP + "dummy"); @@ -112,7 +91,11 @@ wxArrayString DirTestCase::DirEnumHelper(wxDir& dir, return ret; } -void DirTestCase::Enum() +// ---------------------------------------------------------------------------- +// tests themselves start here +// ---------------------------------------------------------------------------- + +TEST_CASE_METHOD(DirTestCase, "Dir::Enum", "[dir]") { wxDir dir(DIRTEST_FOLDER); CPPUNIT_ASSERT( dir.IsOpened() ); @@ -156,7 +139,7 @@ public: } }; -void DirTestCase::Traverse() +TEST_CASE_METHOD(DirTestCase, "Dir::Traverse", "[dir]") { // enum all files wxArrayString files; @@ -172,7 +155,7 @@ void DirTestCase::Traverse() CPPUNIT_ASSERT_EQUAL(6, traverser.dirs.size()); } -void DirTestCase::DirExists() +TEST_CASE_METHOD(DirTestCase, "Dir::Exists", "[dir]") { struct { @@ -232,7 +215,7 @@ void DirTestCase::DirExists() CPPUNIT_ASSERT( wxDir::Exists(wxGetCwd()) ); } -void DirTestCase::GetName() +TEST_CASE_METHOD(DirTestCase, "Dir::GetName", "[dir]") { wxDir d; From 683dfcdfae33c04317f10717d8b133027a7c4f1d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:35:14 +0200 Subject: [PATCH 2/2] Use native CATCH macros in wxDir unit test They provide more information than CppUnit-compatibility ones. --- tests/file/dir.cpp | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/file/dir.cpp b/tests/file/dir.cpp index 25a35b75ab..d72984d7ec 100644 --- a/tests/file/dir.cpp +++ b/tests/file/dir.cpp @@ -78,7 +78,7 @@ wxArrayString DirTestCase::DirEnumHelper(wxDir& dir, const wxString& filespec) { wxArrayString ret; - CPPUNIT_ASSERT( dir.IsOpened() ); + CHECK( dir.IsOpened() ); wxString filename; bool cont = dir.GetFirst(&filename, filespec, flags); @@ -98,28 +98,28 @@ wxArrayString DirTestCase::DirEnumHelper(wxDir& dir, TEST_CASE_METHOD(DirTestCase, "Dir::Enum", "[dir]") { wxDir dir(DIRTEST_FOLDER); - CPPUNIT_ASSERT( dir.IsOpened() ); + CHECK( dir.IsOpened() ); // enumerating everything in test directory - CPPUNIT_ASSERT_EQUAL(4, DirEnumHelper(dir).size()); + CHECK( DirEnumHelper(dir).size() == 4 ); // enumerating really everything in test directory recursively - CPPUNIT_ASSERT_EQUAL(6, DirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT).size()); + CHECK( DirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT).size() == 6 ); // enumerating object files in test directory - CPPUNIT_ASSERT_EQUAL(0, DirEnumHelper(dir, wxDIR_DEFAULT, "*.o*").size()); + CHECK( DirEnumHelper(dir, wxDIR_DEFAULT, "*.o*").size() == 0 ); // enumerating directories in test directory - CPPUNIT_ASSERT_EQUAL(3, DirEnumHelper(dir, wxDIR_DIRS).size()); + CHECK( DirEnumHelper(dir, wxDIR_DIRS).size() == 3 ); // enumerating files in test directory - CPPUNIT_ASSERT_EQUAL(1, DirEnumHelper(dir, wxDIR_FILES).size()); + CHECK( DirEnumHelper(dir, wxDIR_FILES).size() == 1 ); // enumerating files including hidden in test directory - CPPUNIT_ASSERT_EQUAL(1, DirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN).size()); + CHECK( DirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN).size() == 1 ); // enumerating files and folders in test directory - CPPUNIT_ASSERT_EQUAL(4, DirEnumHelper(dir, wxDIR_FILES | wxDIR_DIRS).size()); + CHECK( DirEnumHelper(dir, wxDIR_FILES | wxDIR_DIRS).size() == 4 ); } class TestDirTraverser : public wxDirTraverser @@ -143,16 +143,16 @@ TEST_CASE_METHOD(DirTestCase, "Dir::Traverse", "[dir]") { // enum all files wxArrayString files; - CPPUNIT_ASSERT_EQUAL(4, wxDir::GetAllFiles(DIRTEST_FOLDER, &files)); + CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files) == 4 ); // enum all files according to the filter - CPPUNIT_ASSERT_EQUAL(1, wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "*.foo")); + CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "*.foo") == 1 ); // enum again with custom traverser wxDir dir(DIRTEST_FOLDER); TestDirTraverser traverser; dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN); - CPPUNIT_ASSERT_EQUAL(6, traverser.dirs.size()); + CHECK( traverser.dirs.size() == 6 ); } TEST_CASE_METHOD(DirTestCase, "Dir::Exists", "[dir]") @@ -205,29 +205,30 @@ TEST_CASE_METHOD(DirTestCase, "Dir::Exists", "[dir]") dirname.Replace("$MSW_DRIVE", homedrive); #endif // __WINDOWS__ - std::string errDesc = wxString::Format("failed on directory '%s'", dirname).ToStdString(); - CPPUNIT_ASSERT_EQUAL_MESSAGE(errDesc, testData[n].shouldExist, wxDir::Exists(dirname)); + const bool shouldExist = testData[n].shouldExist; + + INFO("Directory " << dirname << ", should exist: " << shouldExist); + CHECK( wxDir::Exists(dirname) == shouldExist ); wxDir d(dirname); - CPPUNIT_ASSERT_EQUAL(testData[n].shouldExist, d.IsOpened()); + CHECK( d.IsOpened() == shouldExist ); } - CPPUNIT_ASSERT( wxDir::Exists(wxGetCwd()) ); + CHECK( wxDir::Exists(wxGetCwd()) ); } TEST_CASE_METHOD(DirTestCase, "Dir::GetName", "[dir]") { wxDir d; - CPPUNIT_ASSERT( d.Open(".") ); - CPPUNIT_ASSERT( d.GetName().Last() != wxFILE_SEP_PATH ); - CPPUNIT_ASSERT( d.GetNameWithSep().Last() == wxFILE_SEP_PATH ); - CPPUNIT_ASSERT_EQUAL( d.GetName() + wxFILE_SEP_PATH, - d.GetNameWithSep() ); + CHECK( d.Open(".") ); + CHECK( d.GetName().Last() != wxFILE_SEP_PATH ); + CHECK( d.GetNameWithSep().Last() == wxFILE_SEP_PATH ); + CHECK( d.GetNameWithSep() == d.GetName() + wxFILE_SEP_PATH ); #ifdef __UNIX__ - CPPUNIT_ASSERT( d.Open("/") ); - CPPUNIT_ASSERT_EQUAL( "/", d.GetName() ); - CPPUNIT_ASSERT_EQUAL( "/", d.GetNameWithSep() ); + CHECK( d.Open("/") ); + CHECK( d.GetName() == "/" ); + CHECK( d.GetNameWithSep() == "/" ); #endif }