From 683dfcdfae33c04317f10717d8b133027a7c4f1d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:35:14 +0200 Subject: [PATCH] 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 }