diff --git a/.github/workflows/ci_msw_cross.yml b/.github/workflows/ci_msw_cross.yml index 2122000bbd..5e12ebf652 100644 --- a/.github/workflows/ci_msw_cross.yml +++ b/.github/workflows/ci_msw_cross.yml @@ -60,6 +60,11 @@ jobs: # Default to 64-bit build. HOST_TRIPLET: ${{ matrix.triplet || 'x86_64-w64-mingw32' }} + # While our tests should run in any locale natively, it seems that Wine + # requires the locale encoding to be UTF-8 for Unicode file names to work + # correctly, so set the locale explicitly for it. + LC_ALL: C.UTF-8 + # Run all commands as the normal user, created by the first step below. # # Note that the Bash options used here are the same as for the default @@ -200,11 +205,11 @@ jobs: # to exclude the tests that are not run by default, so start with this. excluded_tests=('~[.]') - # Only TestSetTimes fails, but only the full test can be excluded. - excluded_tests+=('~FileNameTestCase') + # There is 1 day difference in creation time under Wine somehow. + excluded_tests+=('~wxFileName::SetTimes') - # Only FileError fails, but the whole test has to be excluded. - excluded_tests+=('~FileFunctionsTestCase') + # Closing the file fails for unknown reason under Wine. + excluded_tests+=('~FileFunctions::Error') # Sporadic failures due to extra events. excluded_tests+=('~wxFileSystemWatcher::EventCreate') diff --git a/tests/file/filefn.cpp b/tests/file/filefn.cpp index 8962dc6bd9..cc4a896ddc 100644 --- a/tests/file/filefn.cpp +++ b/tests/file/filefn.cpp @@ -26,51 +26,11 @@ // test class // ---------------------------------------------------------------------------- -class FileFunctionsTestCase : public CppUnit::TestCase +class FileFunctionsTestCase { -public: - FileFunctionsTestCase() { } - void setUp() wxOVERRIDE; - void tearDown() wxOVERRIDE; - -private: - CPPUNIT_TEST_SUITE( FileFunctionsTestCase ); - CPPUNIT_TEST( GetTempFolder ); - CPPUNIT_TEST( CopyFile ); - CPPUNIT_TEST( CreateFile ); - CPPUNIT_TEST( FileExists ); - CPPUNIT_TEST( FindFile ); - CPPUNIT_TEST( FindFileNext ); - CPPUNIT_TEST( RemoveFile ); - CPPUNIT_TEST( RenameFile ); - CPPUNIT_TEST( ConcatenateFiles ); - CPPUNIT_TEST( GetCwd ); - CPPUNIT_TEST( FileEof ); - CPPUNIT_TEST( FileError ); - CPPUNIT_TEST( DirExists ); - CPPUNIT_TEST( IsAbsolutePath ); - CPPUNIT_TEST( PathOnly ); - CPPUNIT_TEST( Mkdir ); - CPPUNIT_TEST( Rmdir ); - CPPUNIT_TEST_SUITE_END(); - - void GetTempFolder(); - void CopyFile(); - void CreateFile(); - void FileExists(); - void FindFile(); - void FindFileNext(); - void RemoveFile(); - void RenameFile(); - void ConcatenateFiles(); - void GetCwd(); - void FileEof(); - void FileError(); - void DirExists(); - void IsAbsolutePath(); - void PathOnly(); - void Mkdir(); - void Rmdir(); +protected: + FileFunctionsTestCase(); + ~FileFunctionsTestCase(); // Helper methods void DoCreateFile(const wxString& filePath); @@ -95,17 +55,10 @@ private: }; // ---------------------------------------------------------------------------- -// CppUnit macros +// test fixture implementation // ---------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase ); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase, "FileFunctionsTestCase" ); - -// ---------------------------------------------------------------------------- -// tests implementation -// ---------------------------------------------------------------------------- - -void FileFunctionsTestCase::setUp() +FileFunctionsTestCase::FileFunctionsTestCase() { // Initialize local data @@ -123,7 +76,7 @@ void FileFunctionsTestCase::setUp() m_fileNameWork = fn3.GetFullPath(); } -void FileFunctionsTestCase::tearDown() +FileFunctionsTestCase::~FileFunctionsTestCase() { // Remove all remaining temporary files if ( wxFileExists(m_fileNameASCII) ) @@ -142,43 +95,51 @@ void FileFunctionsTestCase::tearDown() } } -void FileFunctionsTestCase::GetTempFolder() +// ---------------------------------------------------------------------------- +// tests themselves start here +// ---------------------------------------------------------------------------- + +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::GetTempFolder", + "[filefn]") { // Verify that obtained temporary folder is not empty. wxString tmpDir = wxFileName::GetTempDir(); - CPPUNIT_ASSERT( !tmpDir.IsEmpty() ); + CHECK( !tmpDir.IsEmpty() ); } -void FileFunctionsTestCase::CopyFile() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::CopyFile", + "[filefn]") { const wxString filename1(wxS("horse.xpm")); const wxString& filename2 = m_fileNameWork; - const std::string msg = - wxString::Format("File 1: %s File 2:%s", filename1, filename2) - .ToStdString(); + INFO("File 1: " << filename1 << " File 2: " << filename2); - CPPUNIT_ASSERT_MESSAGE( msg, wxCopyFile(filename1, filename2) ); + REQUIRE( wxCopyFile(filename1, filename2) ); // verify that the two files have the same contents! wxFFile f1(filename1, wxT("rb")), f2(filename2, wxT("rb")); - CPPUNIT_ASSERT_MESSAGE( msg, f1.IsOpened() ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.IsOpened() ); + REQUIRE( f1.IsOpened() ); + REQUIRE( f2.IsOpened() ); wxString s1, s2; - CPPUNIT_ASSERT_MESSAGE( msg, f1.ReadAll(&s1) ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.ReadAll(&s2) ); - CPPUNIT_ASSERT_MESSAGE( msg, s1 == s2 ); + REQUIRE( f1.ReadAll(&s1) ); + REQUIRE( f2.ReadAll(&s2) ); + CHECK( s1 == s2 ); - CPPUNIT_ASSERT_MESSAGE( msg, f1.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRemoveFile(filename2) ); + CHECK( f1.Close() ); + CHECK( f2.Close() ); + CHECK( wxRemoveFile(filename2) ); } -void FileFunctionsTestCase::CreateFile() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::CreateFile", + "[filefn]") { // Create file name containing ASCII characters only. DoCreateFile(m_fileNameASCII); @@ -190,20 +151,22 @@ void FileFunctionsTestCase::CreateFile() void FileFunctionsTestCase::DoCreateFile(const wxString& filePath) { - const std::string msg = wxString::Format("File: %s", filePath).ToStdString(); + INFO("File: " << filePath); // Create temporary file. wxTextFile file; - CPPUNIT_ASSERT_MESSAGE( msg, file.Create(filePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + REQUIRE( file.Create(filePath) ); + CHECK( file.Close() ); wxRemoveFile(filePath); } -void FileFunctionsTestCase::FileExists() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::FileExists", + "[filefn]") { - CPPUNIT_ASSERT( wxFileExists(wxT("horse.png")) ); - CPPUNIT_ASSERT( !wxFileExists(wxT("horse.___")) ); + CHECK( wxFileExists(wxT("horse.png")) ); + CHECK( !wxFileExists(wxT("horse.___")) ); // Check file name containing ASCII characters only. DoFileExists(m_fileNameASCII); @@ -215,21 +178,23 @@ void FileFunctionsTestCase::FileExists() void FileFunctionsTestCase::DoFileExists(const wxString& filePath) { - const std::string msg = wxString::Format("File: %s", filePath).ToStdString(); + INFO("File: " << filePath); // Create temporary file. wxTextFile file; - CPPUNIT_ASSERT_MESSAGE( msg, file.Create(filePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + REQUIRE( file.Create(filePath) ); + CHECK( file.Close() ); // Verify that file exists with 2 methods. - CPPUNIT_ASSERT_MESSAGE( msg, file.Exists() ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(filePath) ); + CHECK( file.Exists() ); + CHECK( wxFileExists(filePath) ); wxRemoveFile(filePath); } -void FileFunctionsTestCase::FindFile() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::FindFile", + "[filefn]") { // Find file name containing ASCII characters only. DoFindFile(m_fileNameASCII); @@ -241,28 +206,30 @@ void FileFunctionsTestCase::FindFile() void FileFunctionsTestCase::DoFindFile(const wxString& filePath) { - const std::string msg = wxString::Format("File: %s", filePath).ToStdString(); + INFO("File: " << filePath); // Create temporary file. wxTextFile file; - CPPUNIT_ASSERT_MESSAGE( msg, file.Create(filePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + REQUIRE( file.Create(filePath) ); + CHECK( file.Close() ); // Check if file can be found (method 1). wxString foundFile = wxFindFirstFile(filePath, wxFILE); - CPPUNIT_ASSERT_MESSAGE( msg, foundFile == filePath ); + CHECK( foundFile == filePath ); // Check if file can be found (method 2). wxFileSystem fs; wxString furl = fs.FindFirst(filePath, wxFILE); wxFileName fname = wxFileName::URLToFileName(furl); foundFile = fname.GetFullPath(); - CPPUNIT_ASSERT_MESSAGE( msg, foundFile == filePath ); + CHECK( foundFile == filePath ); wxRemoveFile(filePath); } -void FileFunctionsTestCase::FindFileNext() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::FindFileNext", + "[filefn]") { // Construct file name containing ASCII characters only. const wxString fileMask(wxT("horse.*")); @@ -273,9 +240,9 @@ void FileFunctionsTestCase::FindFileNext() wxFileName fn1(foundFile1); wxFileName fn2(foundFile2); // Full names must be different. - CPPUNIT_ASSERT( foundFile1 != foundFile2 ); + CHECK( foundFile1 != foundFile2 ); // Base names must be the same. - CPPUNIT_ASSERT( fn1.GetName() == fn2.GetName() ); + CHECK( fn1.GetName() == fn2.GetName() ); // Check using method 2. wxFileSystem fs; @@ -286,12 +253,14 @@ void FileFunctionsTestCase::FindFileNext() fn2 = wxFileName::URLToFileName(furl); foundFile2 = fn2.GetFullPath(); // Full names must be different. - CPPUNIT_ASSERT( fn1.GetFullPath() != fn2.GetFullPath() ); + CHECK( fn1.GetFullPath() != fn2.GetFullPath() ); // Base names must be the same. - CPPUNIT_ASSERT( fn1.GetName() == fn2.GetName() ); + CHECK( fn1.GetName() == fn2.GetName() ); } -void FileFunctionsTestCase::RemoveFile() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::RemoveFile", + "[filefn]") { // Create & remove file with name containing ASCII characters only. DoRemoveFile(m_fileNameASCII); @@ -303,19 +272,21 @@ void FileFunctionsTestCase::RemoveFile() void FileFunctionsTestCase::DoRemoveFile(const wxString& filePath) { - const std::string msg = wxString::Format("File: %s", filePath).ToStdString(); + INFO("File: " << filePath); // Create temporary file. wxTextFile file; - CPPUNIT_ASSERT_MESSAGE( msg, file.Create(filePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + REQUIRE( file.Create(filePath) ); + CHECK( file.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Exists() ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRemoveFile(filePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, !file.Exists() ); + CHECK( file.Exists() ); + CHECK( wxRemoveFile(filePath) ); + CHECK( !file.Exists() ); } -void FileFunctionsTestCase::RenameFile() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::RenameFile", + "[filefn]") { // Verify renaming file with/without overwriting // when new file already exist/don't exist. @@ -337,23 +308,21 @@ FileFunctionsTestCase::DoRenameFile(const wxString& oldFilePath, bool overwrite, bool withNew) { - const std::string msg = - wxString::Format(wxT("File 1: %s File 2:%s"), oldFilePath, newFilePath) - .ToStdString(); + INFO("File 1:" << oldFilePath << " File 2: " << newFilePath); // Create temporary source file. wxTextFile file; - CPPUNIT_ASSERT_MESSAGE( msg, file.Create(oldFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + REQUIRE( file.Create(oldFilePath) ); + CHECK( file.Close() ); if ( withNew ) { // Create destination file to test overwriting. wxTextFile file2; - CPPUNIT_ASSERT_MESSAGE( msg, file2.Create(newFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, file2.Close() ); + REQUIRE( file2.Create(newFilePath) ); + CHECK( file2.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(newFilePath) ); + CHECK( wxFileExists(newFilePath) ); } else { @@ -363,36 +332,38 @@ FileFunctionsTestCase::DoRenameFile(const wxString& oldFilePath, wxRemoveFile(newFilePath); } - CPPUNIT_ASSERT_MESSAGE( msg, !wxFileExists(newFilePath) ); + CHECK( !wxFileExists(newFilePath) ); } - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(oldFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(oldFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(oldFilePath) ); + CHECK( wxFileExists(oldFilePath) ); + CHECK( wxFileExists(oldFilePath) ); + CHECK( wxFileExists(oldFilePath) ); bool shouldFail = !overwrite && withNew; if ( shouldFail ) { - CPPUNIT_ASSERT_MESSAGE( msg, !wxRenameFile(oldFilePath, newFilePath, overwrite)); + CHECK( !wxRenameFile(oldFilePath, newFilePath, overwrite)); // Verify that file has not been renamed. - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(oldFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(newFilePath) ); + CHECK( wxFileExists(oldFilePath) ); + CHECK( wxFileExists(newFilePath) ); // Cleanup. wxRemoveFile(oldFilePath); } else { - CPPUNIT_ASSERT_MESSAGE( msg, wxRenameFile(oldFilePath, newFilePath, overwrite) ); + CHECK( wxRenameFile(oldFilePath, newFilePath, overwrite) ); // Verify that file has been renamed. - CPPUNIT_ASSERT_MESSAGE( msg, !wxFileExists(oldFilePath) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(newFilePath) ); + CHECK( !wxFileExists(oldFilePath) ); + CHECK( wxFileExists(newFilePath) ); } // Cleanup. wxRemoveFile(newFilePath); } -void FileFunctionsTestCase::ConcatenateFiles() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::ConcatenateFiles", + "[filefn]") { #if wxUSE_UNICODE DoConcatFile(m_fileNameASCII, m_fileNameNonASCII, m_fileNameWork); @@ -404,169 +375,166 @@ void FileFunctionsTestCase::DoConcatFile(const wxString& filePath1, const wxString& filePath2, const wxString& destFilePath) { - const std::string msg = - wxString::Format("File 1: %s File 2:%s File 3: %s", - filePath1, filePath2, destFilePath) - .ToStdString(); + INFO("File 1:" << filePath1 + << " File 2: " << filePath2 + << " File 3: " << destFilePath); // Prepare source data wxFFile f1(filePath1, wxT("wb")), f2(filePath2, wxT("wb")); - CPPUNIT_ASSERT_MESSAGE( msg, f1.IsOpened() ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.IsOpened() ); + REQUIRE( f1.IsOpened() ); + REQUIRE( f2.IsOpened() ); wxString s1(wxT("1234567890")); wxString s2(wxT("abcdefghij")); - CPPUNIT_ASSERT_MESSAGE( msg, f1.Write(s1) ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.Write(s2) ); + CHECK( f1.Write(s1) ); + CHECK( f2.Write(s2) ); - CPPUNIT_ASSERT_MESSAGE( msg, f1.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, f2.Close() ); + CHECK( f1.Close() ); + CHECK( f2.Close() ); // Concatenate source files - CPPUNIT_ASSERT_MESSAGE( msg, wxConcatFiles(filePath1, filePath2, destFilePath) ); + CHECK( wxConcatFiles(filePath1, filePath2, destFilePath) ); // Verify content of destination file - CPPUNIT_ASSERT_MESSAGE( msg, wxFileExists(destFilePath) ); + REQUIRE( wxFileExists(destFilePath) ); wxString sSrc = s1 + s2; wxString s3; wxFFile f3(destFilePath, wxT("rb")); - CPPUNIT_ASSERT_MESSAGE( msg, f3.ReadAll(&s3) ); - CPPUNIT_ASSERT_MESSAGE( msg, sSrc.length() == s3.length() ); - CPPUNIT_ASSERT_MESSAGE( msg, memcmp(sSrc.c_str(), s3.c_str(), sSrc.length()) == 0 ); - CPPUNIT_ASSERT_MESSAGE( msg, f3.Close() ); + CHECK( f3.ReadAll(&s3) ); + CHECK( sSrc.length() == s3.length() ); + CHECK( memcmp(sSrc.c_str(), s3.c_str(), sSrc.length()) == 0 ); + CHECK( f3.Close() ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRemoveFile(filePath1) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRemoveFile(filePath2) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRemoveFile(destFilePath) ); + CHECK( wxRemoveFile(filePath1) ); + CHECK( wxRemoveFile(filePath2) ); + CHECK( wxRemoveFile(destFilePath) ); } -void FileFunctionsTestCase::GetCwd() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::GetCwd", + "[filefn]") { // Verify that obtained working directory is not empty. wxString cwd = wxGetCwd(); - CPPUNIT_ASSERT( !cwd.IsEmpty() ); + CHECK( !cwd.IsEmpty() ); } -void FileFunctionsTestCase::FileEof() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::Eof", + "[filefn]") { const wxString filename(wxT("horse.bmp")); - const std::string msg = wxString::Format("File: %s", filename).ToStdString(); + INFO("File: " << filename); wxFFile file(filename, wxT("r")); // wxFFile::Eof must be false at start - CPPUNIT_ASSERT_MESSAGE( msg, !file.Eof() ); - CPPUNIT_ASSERT_MESSAGE( msg, file.SeekEnd() ); + CHECK( !file.Eof() ); + CHECK( file.SeekEnd() ); // wxFFile::Eof returns true only after attempt to read last byte char array[1]; - CPPUNIT_ASSERT_MESSAGE( msg, file.Read(array, 1) == 0 ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Eof() ); + CHECK( file.Read(array, 1) == 0 ); + CHECK( file.Eof() ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + CHECK( file.Close() ); // wxFFile::Eof after close should not cause crash but fail instead - bool failed = true; - try - { - file.Eof(); - failed = false; - } - catch (...) - { - } - CPPUNIT_ASSERT_MESSAGE( msg, failed ); + WX_ASSERT_FAILS_WITH_ASSERT( file.Eof() ); } -void FileFunctionsTestCase::FileError() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::Error", + "[filefn]") { const wxString filename(wxT("horse.bmp")); - const std::string msg = wxString::Format("File: %s", filename).ToStdString(); + INFO("File: " << filename); wxFFile file(filename, wxT("r")); // wxFFile::Error must be false at start assuming file "horse.bmp" exists. - CPPUNIT_ASSERT_MESSAGE( msg, !file.Error() ); + CHECK( !file.Error() ); // Attempt to write to file opened in readonly mode should cause error - CPPUNIT_ASSERT_MESSAGE( msg, !file.Write(filename) ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Error() ); + CHECK( !file.Write(filename) ); + CHECK( file.Error() ); - CPPUNIT_ASSERT_MESSAGE( msg, file.Close() ); + CHECK( file.Close() ); // wxFFile::Error after close should not cause crash but fail instead - bool failed = true; - try - { - file.Error(); - failed = false; - } - catch (...) - { - } - CPPUNIT_ASSERT_MESSAGE( msg, failed ); + WX_ASSERT_FAILS_WITH_ASSERT( file.Error() ); } - -void FileFunctionsTestCase::DirExists() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::DirExists", + "[filefn]") { wxString cwd = wxGetCwd(); - const std::string msg = wxString::Format("CWD: %s", cwd).ToStdString(); + INFO("CWD: " << cwd); // Current working directory must exist - CPPUNIT_ASSERT_MESSAGE( msg, wxDirExists(cwd)); + CHECK(wxDirExists(cwd)); } -void FileFunctionsTestCase::IsAbsolutePath() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::IsAbsolutePath", + "[filefn]") { wxString name = wxT("horse.bmp"); - const std::string msg = wxString::Format("File: %s", name).ToStdString(); + INFO("File: " << name); // File name is given as relative path - CPPUNIT_ASSERT_MESSAGE( msg, !wxIsAbsolutePath(name) ); + CHECK( !wxIsAbsolutePath(name) ); wxFileName filename(name); - CPPUNIT_ASSERT( filename.MakeAbsolute() ); + CHECK( filename.MakeAbsolute() ); // wxFileName::GetFullPath returns absolute path - CPPUNIT_ASSERT_MESSAGE( msg, wxIsAbsolutePath(filename.GetFullPath())); + CHECK( wxIsAbsolutePath(filename.GetFullPath())); #ifdef __WINDOWS__ - CPPUNIT_ASSERT( wxIsAbsolutePath("\\")); - CPPUNIT_ASSERT( wxIsAbsolutePath("c:")); - CPPUNIT_ASSERT( !wxIsAbsolutePath("c")); + CHECK( wxIsAbsolutePath("\\")); + CHECK( wxIsAbsolutePath("c:")); + CHECK( !wxIsAbsolutePath("c")); #endif } -void FileFunctionsTestCase::PathOnly() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::PathOnly", + "[filefn]") { wxString name = wxT("horse.bmp"); // Get absolute path to horse.bmp wxFileName filename(name); - CPPUNIT_ASSERT( filename.MakeAbsolute() ); + CHECK( filename.MakeAbsolute() ); wxString pathOnly = wxPathOnly(filename.GetFullPath()); if ( !wxDirExists(pathOnly) ) - CPPUNIT_ASSERT( pathOnly == wxString() ); + CHECK( pathOnly == wxString() ); } // Unit tests for Mkdir and Rmdir doesn't cover non-ASCII directory names. // Rmdir fails on them on Linux. See ticket #17644. -void FileFunctionsTestCase::Mkdir() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::Mkdir", + "[filefn]") { #if wxUSE_UNICODE wxString dirname = wxString::FromUTF8("__wxMkdir_test_dir_with_\xc3\xb6"); - const std::string msg = wxString::Format("Dir: %s", dirname).ToStdString(); - CPPUNIT_ASSERT_MESSAGE( msg, wxMkdir(dirname) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxDirExists(dirname) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRmdir(dirname) ); + INFO("Dir: " << dirname); + + CHECK( wxMkdir(dirname) ); + CHECK( wxDirExists(dirname) ); + CHECK( wxRmdir(dirname) ); #endif // wxUSE_UNICODE } -void FileFunctionsTestCase::Rmdir() +TEST_CASE_METHOD(FileFunctionsTestCase, + "FileFunctions::Rmdir", + "[filefn]") { #if wxUSE_UNICODE wxString dirname = wxString::FromUTF8("__wxRmdir_test_dir_with_\xc3\xb6"); - const std::string msg = wxString::Format("Dir: %s", dirname).ToStdString(); + INFO("Dir: " << dirname); - CPPUNIT_ASSERT_MESSAGE( msg, wxMkdir(dirname) ); - CPPUNIT_ASSERT_MESSAGE( msg, wxRmdir(dirname) ); - CPPUNIT_ASSERT_MESSAGE( msg, !wxDirExists(dirname) ); + CHECK( wxMkdir(dirname) ); + CHECK( wxRmdir(dirname) ); + CHECK( !wxDirExists(dirname) ); #endif // wxUSE_UNICODE } diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index ee381823d7..e8e4fe1145 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -114,84 +114,17 @@ static struct TestFileNameInfo }; // ---------------------------------------------------------------------------- -// test class +// tests // ---------------------------------------------------------------------------- -class FileNameTestCase : public CppUnit::TestCase -{ -public: - FileNameTestCase() { } - -private: - CPPUNIT_TEST_SUITE( FileNameTestCase ); - CPPUNIT_TEST( TestConstruction ); - CPPUNIT_TEST( TestComparison ); - CPPUNIT_TEST( TestSplit ); - CPPUNIT_TEST( TestSetPath ); - CPPUNIT_TEST( TestStrip ); - CPPUNIT_TEST( TestNormalize ); - CPPUNIT_TEST( TestRelative ); - CPPUNIT_TEST( TestReplace ); - CPPUNIT_TEST( TestGetHumanReadable ); -#ifdef __WINDOWS__ - CPPUNIT_TEST( TestShortLongPath ); -#endif // __WINDOWS__ - CPPUNIT_TEST( TestUNC ); - CPPUNIT_TEST( TestVolumeUniqueName ); - CPPUNIT_TEST( TestCreateTempFileName ); - CPPUNIT_TEST( TestGetTimes ); - CPPUNIT_TEST( TestSetTimes ); - CPPUNIT_TEST( TestExists ); - CPPUNIT_TEST( TestIsSame ); -#if defined(__UNIX__) - CPPUNIT_TEST( TestSymlinks ); -#endif // __UNIX__ -#ifdef __WINDOWS__ - CPPUNIT_TEST( TestShortcuts ); -#endif // __WINDOWS__ - CPPUNIT_TEST_SUITE_END(); - - void TestConstruction(); - void TestComparison(); - void TestSplit(); - void TestSetPath(); - void TestStrip(); - void TestRelative(); - void TestNormalize(); - void TestReplace(); - void TestGetHumanReadable(); -#ifdef __WINDOWS__ - void TestShortLongPath(); -#endif // __WINDOWS__ - void TestUNC(); - void TestVolumeUniqueName(); - void TestCreateTempFileName(); - void TestGetTimes(); - void TestSetTimes(); - void TestExists(); - void TestIsSame(); -#if defined(__UNIX__) - void TestSymlinks(); -#endif // __UNIX__ -#ifdef __WINDOWS__ - void TestShortcuts(); -#endif // __WINDOWS__ - - wxDECLARE_NO_COPY_CLASS(FileNameTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( FileNameTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileNameTestCase, "FileNameTestCase" ); - -void FileNameTestCase::TestConstruction() +TEST_CASE("wxFileName::Construction", "[filename]") { for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) { const TestFileNameInfo& fni = filenames[n]; + INFO("Test #" << n << ": \"" << fni.fullname << "\""); + wxFileName fn(fni.fullname, fni.format); // the original full name could contain consecutive [back]slashes, @@ -223,17 +156,12 @@ void FileNameTestCase::TestConstruction() fullnameOrig.Replace("//", "/"); - wxString fullname = fn.GetFullPath(fni.format); - CPPUNIT_ASSERT_EQUAL( fullnameOrig, fullname ); + CHECK( fn.GetFullPath(fni.format) == fullnameOrig ); // notice that we use a dummy working directory to ensure that paths // with "../.." in them could be normalized, otherwise this would fail // if the test is run from root directory or its direct subdirectory - CPPUNIT_ASSERT_MESSAGE - ( - (const char *)wxString::Format("Normalize(%s) failed", fni.fullname).mb_str(), - fn.Normalize(wxPATH_NORM_ALL, "/foo/bar/baz", fni.format) - ); + CHECK( fn.Normalize(wxPATH_NORM_ALL, "/foo/bar/baz", fni.format) ); if ( *fni.volume && *fni.path ) { @@ -243,10 +171,10 @@ void FileNameTestCase::TestConstruction() pathWithVolume += wxFileName::GetVolumeSeparator(fni.format); pathWithVolume += fni.path; - CPPUNIT_ASSERT_EQUAL( wxFileName(pathWithVolume, - fni.name, - fni.ext, - fni.format), fn ); + CHECK( wxFileName(pathWithVolume, + fni.name, + fni.ext, + fni.format) == fn ); } } @@ -254,31 +182,31 @@ void FileNameTestCase::TestConstruction() // empty strings fn.AssignDir(wxEmptyString); - CPPUNIT_ASSERT( !fn.IsOk() ); + CHECK( !fn.IsOk() ); fn.Assign(wxEmptyString); - CPPUNIT_ASSERT( !fn.IsOk() ); + CHECK( !fn.IsOk() ); fn.Assign(wxEmptyString, wxEmptyString); - CPPUNIT_ASSERT( !fn.IsOk() ); + CHECK( !fn.IsOk() ); fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString); - CPPUNIT_ASSERT( !fn.IsOk() ); + CHECK( !fn.IsOk() ); fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString); - CPPUNIT_ASSERT( !fn.IsOk() ); + CHECK( !fn.IsOk() ); } -void FileNameTestCase::TestComparison() +TEST_CASE("wxFileName::Comparison", "[filename]") { wxFileName fn1(wxT("/tmp/file1")); wxFileName fn2(wxT("/tmp/dir2/../file2")); fn1.Normalize(); fn2.Normalize(); - CPPUNIT_ASSERT_EQUAL(fn1.GetPath(), fn2.GetPath()); + CHECK(fn1.GetPath() == fn2.GetPath()); } -void FileNameTestCase::TestSplit() +TEST_CASE("wxFileName::Split", "[filename]") { for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) { @@ -287,29 +215,29 @@ void FileNameTestCase::TestSplit() wxFileName::SplitPath(fni.fullname, &volume, &path, &name, &ext, fni.format); - CPPUNIT_ASSERT_EQUAL( wxString(fni.volume), volume ); - CPPUNIT_ASSERT_EQUAL( wxString(fni.path), path ); - CPPUNIT_ASSERT_EQUAL( wxString(fni.name), name ); - CPPUNIT_ASSERT_EQUAL( wxString(fni.ext), ext ); + CHECK( volume == fni.volume ); + CHECK( path == fni.path ); + CHECK( name == fni.name ); + CHECK( ext == fni.ext ); } // special case of empty extension wxFileName fn("foo."); - CPPUNIT_ASSERT_EQUAL( wxString("foo."), fn.GetFullPath() ); + CHECK( fn.GetFullPath() == "foo." ); } -void FileNameTestCase::TestSetPath() +TEST_CASE("wxFileName::SetPath", "[filename]") { wxFileName fn("d:\\test\\foo.bar", wxPATH_DOS); fn.SetPath("c:\\temp", wxPATH_DOS); - CPPUNIT_ASSERT( fn.SameAs(wxFileName("c:\\temp\\foo.bar", wxPATH_DOS)) ); + CHECK( fn.SameAs(wxFileName("c:\\temp\\foo.bar", wxPATH_DOS)) ); fn = wxFileName("/usr/bin/ls", wxPATH_UNIX); fn.SetPath("/usr/local/bin", wxPATH_UNIX); - CPPUNIT_ASSERT( fn.SameAs(wxFileName("/usr/local/bin/ls", wxPATH_UNIX)) ); + CHECK( fn.SameAs(wxFileName("/usr/local/bin/ls", wxPATH_UNIX)) ); } -void FileNameTestCase::TestNormalize() +TEST_CASE("wxFileName::Normalize", "[filename]") { // prepare some data to be used later wxString sep = wxFileName::GetPathSeparator(); @@ -434,32 +362,32 @@ void FileNameTestCase::TestNormalize() !shortNamesDisabled ) { wxFileName fn("..\\MKINST~1"); - CPPUNIT_ASSERT( fn.Normalize(wxPATH_NORM_LONG, cwd) ); - CPPUNIT_ASSERT_EQUAL( "..\\mkinstalldirs", fn.GetFullPath() ); + CHECK( fn.Normalize(wxPATH_NORM_LONG, cwd) ); + CHECK( fn.GetFullPath() == "..\\mkinstalldirs" ); } //else: when in doubt, don't run the test #endif // __WINDOWS__ } -void FileNameTestCase::TestRelative() +TEST_CASE("wxFileName::Relative", "[filename]") { const wxString pathSep = wxFileName::GetPathSeparator(); wxFileName fn("a" + pathSep + "b.cpp"); fn.MakeRelativeTo("a"); - CPPUNIT_ASSERT_EQUAL( "b.cpp", fn.GetFullPath() ); + CHECK( fn.GetFullPath() == "b.cpp" ); fn.AssignDir("a" + pathSep + "b"); fn.MakeRelativeTo("a"); - CPPUNIT_ASSERT_EQUAL( "b" + pathSep, fn.GetFullPath() ); + CHECK( fn.GetFullPath() == "b" + pathSep ); fn.AssignDir("a"); fn.MakeRelativeTo("a"); - CPPUNIT_ASSERT_EQUAL( "." + pathSep, fn.GetFullPath() ); + CHECK( fn.GetFullPath() == "." + pathSep ); } -void FileNameTestCase::TestReplace() +TEST_CASE("wxFileName::Replace", "[filename]") { static const struct FileNameTest { @@ -528,11 +456,10 @@ void FileNameTestCase::TestReplace() fn.ReplaceHomeDir() ); - CPPUNIT_ASSERT_EQUAL( wxString("~/test1/test2/test3/some file"), - fn.GetFullPath(wxPATH_UNIX) ); + CHECK( fn.GetFullPath(wxPATH_UNIX) == "~/test1/test2/test3/some file" ); } -void FileNameTestCase::TestGetHumanReadable() +TEST_CASE("wxFileName::GetHumanReadable", "[filename]") { static const struct TestData { @@ -560,74 +487,69 @@ void FileNameTestCase::TestGetHumanReadable() // take care of using the decimal point for the current locale before // the actual comparison - CPPUNIT_ASSERT_EQUAL + CHECK ( - td.result, wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv) + == + td.result ); } // also test the default convention value - CPPUNIT_ASSERT_EQUAL( "1.4 MB", wxFileName::GetHumanReadableSize(1512993, "") ); + CHECK( wxFileName::GetHumanReadableSize(1512993, "") == "1.4 MB" ); } -void FileNameTestCase::TestStrip() +TEST_CASE("wxFileName::Strip", "[filename]") { - CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension("") ); - CPPUNIT_ASSERT_EQUAL( ".", wxFileName::StripExtension(".") ); - CPPUNIT_ASSERT_EQUAL( ".vimrc", wxFileName::StripExtension(".vimrc") ); - CPPUNIT_ASSERT_EQUAL( "bad", wxFileName::StripExtension("bad") ); - CPPUNIT_ASSERT_EQUAL( "good", wxFileName::StripExtension("good.wav") ); - CPPUNIT_ASSERT_EQUAL( "good.wav", wxFileName::StripExtension("good.wav.wav") ); + CHECK( wxFileName::StripExtension("") == "" ); + CHECK( wxFileName::StripExtension(".") == "." ); + CHECK( wxFileName::StripExtension(".vimrc") == ".vimrc" ); + CHECK( wxFileName::StripExtension("bad") == "bad" ); + CHECK( wxFileName::StripExtension("good.wav") == "good" ); + CHECK( wxFileName::StripExtension("good.wav.wav") == "good.wav" ); } #ifdef __WINDOWS__ -void FileNameTestCase::TestShortLongPath() +TEST_CASE("wxFileName::ShortLongPath", "[filename]") { wxFileName fn("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"); // incredibly enough, GetLongPath() used to return different results during // the first and subsequent runs, test for this - CPPUNIT_ASSERT_EQUAL( fn.GetLongPath(), fn.GetLongPath() ); - CPPUNIT_ASSERT_EQUAL( fn.GetShortPath(), fn.GetShortPath() ); + CHECK( fn.GetLongPath() == fn.GetLongPath() ); + CHECK( fn.GetShortPath() == fn.GetShortPath() ); } #endif // __WINDOWS__ -void FileNameTestCase::TestUNC() +TEST_CASE("wxFileName::UNC", "[filename]") { wxFileName fn("//share/path/name.ext", wxPATH_DOS); - CPPUNIT_ASSERT_EQUAL( "share", fn.GetVolume() ); - CPPUNIT_ASSERT_EQUAL( "\\path", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) ); + CHECK( fn.GetVolume() == "share" ); + CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path" ); fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS); - CPPUNIT_ASSERT_EQUAL( "share2", fn.GetVolume() ); - CPPUNIT_ASSERT_EQUAL( "\\path2", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) ); + CHECK( fn.GetVolume() == "share2" ); + CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path2" ); } -void FileNameTestCase::TestVolumeUniqueName() +TEST_CASE("wxFileName::VolumeUniqueName", "[filename]") { wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\", wxPATH_DOS); - CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}", - fn.GetVolume() ); - CPPUNIT_ASSERT_EQUAL( "\\", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) ); - CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\", - fn.GetFullPath(wxPATH_DOS) ); + CHECK( fn.GetVolume() == "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" ); + CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\" ); + CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" ); fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" "Program Files\\setup.exe", wxPATH_DOS); - CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}", - fn.GetVolume() ); - CPPUNIT_ASSERT_EQUAL( "\\Program Files", - fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) ); - CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" - "Program Files\\setup.exe", - fn.GetFullPath(wxPATH_DOS) ); + CHECK( fn.GetVolume() == "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" ); + CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\Program Files" ); + CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\Program Files\\setup.exe" ); } -void FileNameTestCase::TestCreateTempFileName() +TEST_CASE("wxFileName::CreateTempFileName", "[filename]") { static const struct TestData { @@ -655,106 +577,106 @@ void FileNameTestCase::TestCreateTempFileName() wxString prefix = testData[n].prefix; prefix.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir()); - std::string errDesc = wxString::Format("failed on prefix '%s'", prefix).ToStdString(); + INFO("Prefix: " << prefix); wxString path = wxFileName::CreateTempFileName(prefix); - CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, !testData[n].shouldSucceed, path.empty() ); + CHECK( path.empty() == !testData[n].shouldSucceed ); if (testData[n].shouldSucceed) { - errDesc += "; path is " + path.ToStdString(); + INFO("Path: " << path); // test the place where the temp file has been created wxString expected = testData[n].expectedFolder; expected.Replace("$SYSTEM_TEMP", wxStandardPaths::Get().GetTempDir()); expected.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir()); - CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, expected, wxFileName(path).GetPath() ); + CHECK( wxFileName(path).GetPath() == expected ); // the temporary file is created with full permissions for the current process // so we should always be able to remove it: - CPPUNIT_ASSERT_MESSAGE( errDesc, wxRemoveFile(path) ); + CHECK( wxRemoveFile(path) ); } } } -void FileNameTestCase::TestGetTimes() +TEST_CASE("wxFileName::GetTimes", "[filename]") { wxFileName fn(wxFileName::CreateTempFileName("filenametest")); - CPPUNIT_ASSERT( fn.IsOk() ); + REQUIRE( fn.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() ); wxDateTime dtAccess, dtMod, dtCreate; - CPPUNIT_ASSERT( fn.GetTimes(&dtAccess, &dtMod, &dtCreate) ); + REQUIRE( fn.GetTimes(&dtAccess, &dtMod, &dtCreate) ); // make sure all retrieved dates are equal to the current date&time // with an accuracy up to 1 minute - CPPUNIT_ASSERT(dtCreate.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); - CPPUNIT_ASSERT(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); - CPPUNIT_ASSERT(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); + CHECK(dtCreate.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); + CHECK(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); + CHECK(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1))); } -void FileNameTestCase::TestSetTimes() +TEST_CASE("wxFileName::SetTimes", "[filename]") { wxFileName fn(wxFileName::CreateTempFileName("filenametest")); - CPPUNIT_ASSERT( fn.IsOk() ); + REQUIRE( fn.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() ); const wxDateTime dtAccess(1, wxDateTime::Jan, 2013); const wxDateTime dtModify(1, wxDateTime::Feb, 2013); const wxDateTime dtCreate(1, wxDateTime::Mar, 2013); - CPPUNIT_ASSERT( fn.SetTimes(&dtAccess, &dtModify, &dtCreate) ); + REQUIRE( fn.SetTimes(&dtAccess, &dtModify, &dtCreate) ); wxDateTime dtAccess2, dtModify2, dtCreate2; - CPPUNIT_ASSERT( fn.GetTimes(&dtAccess2, &dtModify2, &dtCreate2) ); - CPPUNIT_ASSERT_EQUAL( dtAccess, dtAccess2 ); - CPPUNIT_ASSERT_EQUAL( dtModify, dtModify2 ); + REQUIRE( fn.GetTimes(&dtAccess2, &dtModify2, &dtCreate2) ); + CHECK( dtAccess2 == dtAccess ); + CHECK( dtModify2 == dtModify ); // Under Unix the creation time can't be set. #ifdef __WINDOWS__ - CPPUNIT_ASSERT_EQUAL( dtCreate, dtCreate2 ); + CHECK( dtCreate2 == dtCreate ); #endif // __WINDOWS__ } -void FileNameTestCase::TestExists() +TEST_CASE("wxFileName::Exists", "[filename]") { wxFileName fn(wxFileName::CreateTempFileName("filenametest")); - CPPUNIT_ASSERT( fn.IsOk() ); + REQUIRE( fn.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() ); - CPPUNIT_ASSERT( fn.FileExists() ); - CPPUNIT_ASSERT( !wxFileName::DirExists(fn.GetFullPath()) ); + CHECK( fn.FileExists() ); + CHECK( !wxFileName::DirExists(fn.GetFullPath()) ); - CPPUNIT_ASSERT( fn.Exists(wxFILE_EXISTS_REGULAR) ); - CPPUNIT_ASSERT( !fn.Exists(wxFILE_EXISTS_DIR) ); - CPPUNIT_ASSERT( fn.Exists() ); + CHECK( fn.Exists(wxFILE_EXISTS_REGULAR) ); + CHECK( !fn.Exists(wxFILE_EXISTS_DIR) ); + CHECK( fn.Exists() ); const wxString& tempdir = wxFileName::GetTempDir(); wxFileName fileInTempDir(tempdir, "bloordyblop"); - CPPUNIT_ASSERT( !fileInTempDir.Exists() ); - CPPUNIT_ASSERT( fileInTempDir.DirExists() ); + CHECK( !fileInTempDir.Exists() ); + CHECK( fileInTempDir.DirExists() ); wxFileName dirTemp(wxFileName::DirName(tempdir)); - CPPUNIT_ASSERT( !dirTemp.FileExists() ); - CPPUNIT_ASSERT( dirTemp.DirExists() ); + CHECK( !dirTemp.FileExists() ); + CHECK( dirTemp.DirExists() ); - CPPUNIT_ASSERT( dirTemp.Exists(wxFILE_EXISTS_DIR) ); - CPPUNIT_ASSERT( !dirTemp.Exists(wxFILE_EXISTS_REGULAR) ); - CPPUNIT_ASSERT( dirTemp.Exists() ); + CHECK( dirTemp.Exists(wxFILE_EXISTS_DIR) ); + CHECK( !dirTemp.Exists(wxFILE_EXISTS_REGULAR) ); + CHECK( dirTemp.Exists() ); #ifdef __UNIX__ - CPPUNIT_ASSERT( !wxFileName::FileExists("/dev/null") ); - CPPUNIT_ASSERT( !wxFileName::DirExists("/dev/null") ); - CPPUNIT_ASSERT( wxFileName::Exists("/dev/null") ); - CPPUNIT_ASSERT( wxFileName::Exists("/dev/null", wxFILE_EXISTS_DEVICE) ); + CHECK( !wxFileName::FileExists("/dev/null") ); + CHECK( !wxFileName::DirExists("/dev/null") ); + CHECK( wxFileName::Exists("/dev/null") ); + CHECK( wxFileName::Exists("/dev/null", wxFILE_EXISTS_DEVICE) ); #ifdef __LINUX__ // These files are only guaranteed to exist under Linux. // No need for wxFILE_EXISTS_NO_FOLLOW here; wxFILE_EXISTS_SYMLINK implies it - CPPUNIT_ASSERT( wxFileName::Exists("/proc/self", wxFILE_EXISTS_SYMLINK) ); - CPPUNIT_ASSERT( wxFileName::Exists("/dev/log", wxFILE_EXISTS_SOCKET) ); + CHECK( wxFileName::Exists("/proc/self", wxFILE_EXISTS_SYMLINK) ); + CHECK( wxFileName::Exists("/dev/log", wxFILE_EXISTS_SOCKET) ); #endif // __LINUX__ #ifndef __VMS wxString fifo = dirTemp.GetPath() + "/fifo"; @@ -762,24 +684,24 @@ void FileNameTestCase::TestExists() { wxON_BLOCK_EXIT1(wxRemoveFile, fifo); - CPPUNIT_ASSERT( wxFileName::Exists(fifo, wxFILE_EXISTS_FIFO) ); + CHECK( wxFileName::Exists(fifo, wxFILE_EXISTS_FIFO) ); } #endif #endif // __UNIX__ } -void FileNameTestCase::TestIsSame() +TEST_CASE("wxFileName::SameAs", "[filename]") { wxFileName fn1( wxFileName::CreateTempFileName( "filenametest1" ) ); - CPPUNIT_ASSERT( fn1.IsOk() ); + REQUIRE( fn1.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn1.GetFullPath() ); wxFileName fn2( wxFileName::CreateTempFileName( "filenametest2" ) ); - CPPUNIT_ASSERT( fn2.IsOk() ); + REQUIRE( fn2.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn2.GetFullPath() ); - CPPUNIT_ASSERT( fn1.SameAs( fn1 ) ); - CPPUNIT_ASSERT( !fn1.SameAs( fn2 ) ); + CHECK( fn1.SameAs( fn1 ) ); + CHECK( !fn1.SameAs( fn2 ) ); #if defined(__UNIX__) // We need to create a temporary directory and a temporary link. @@ -789,7 +711,7 @@ void FileNameTestCase::TestIsSame() const wxString tempdir1 = wxString::From8BitData(tn); free(tn); - CPPUNIT_ASSERT( wxFileName::Mkdir(tempdir1) ); + REQUIRE( wxFileName::Mkdir(tempdir1) ); // Unfortunately the casts are needed to select the overload we need here. wxON_BLOCK_EXIT2( static_cast(wxFileName::Rmdir), tempdir1, static_cast(wxPATH_RMDIR_RECURSIVE) ); @@ -797,7 +719,7 @@ void FileNameTestCase::TestIsSame() tn = tempnam(NULL, "wxfn2"); const wxString tempdir2 = wxString::From8BitData(tn); free(tn); - CPPUNIT_ASSERT_EQUAL( 0, symlink(tempdir1.c_str(), tempdir2.c_str()) ); + CHECK( symlink(tempdir1.c_str(), tempdir2.c_str()) == 0 ); wxON_BLOCK_EXIT1( wxRemoveFile, tempdir2 ); @@ -805,21 +727,21 @@ void FileNameTestCase::TestIsSame() wxFileName fn4(tempdir2, "foo"); // These files have different paths, hence are different. - CPPUNIT_ASSERT( !fn3.SameAs(fn4) ); + CHECK( !fn3.SameAs(fn4) ); // Create and close a file to trigger creating it. wxFile(fn3.GetFullPath(), wxFile::write); // Now that both files do exist we should be able to detect that they are // actually the same file. - CPPUNIT_ASSERT( fn3.SameAs(fn4) ); + CHECK( fn3.SameAs(fn4) ); #endif // __UNIX__ } #if defined(__UNIX__) // Tests for functions that are changed by ShouldFollowLink() -void FileNameTestCase::TestSymlinks() +TEST_CASE("wxFileName::Symlinks", "[filename]") { const wxString tmpdir(wxStandardPaths::Get().GetTempDir()); @@ -836,76 +758,49 @@ void FileNameTestCase::TestSymlinks() tempdir << wxFileName::GetPathSeparator(); #endif wxFileName tempdirfn(wxFileName::DirName(tempdir)); - CPPUNIT_ASSERT(tempdirfn.DirExists()); + CHECK(tempdirfn.DirExists()); // Create a regular file in that dir, to act as a symlink target wxFileName targetfn(wxFileName::CreateTempFileName(tempdir)); - CPPUNIT_ASSERT(targetfn.FileExists()); + CHECK(targetfn.FileExists()); // Resolving a non-symlink will just return the same thing - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Non-symlink didn't resolve to the same file", - targetfn, targetfn.ResolveLink() - ); + INFO("Non-symlink didn't resolve to the same file"); + CHECK( targetfn.ResolveLink() == targetfn ); // Create a symlink to that file wxFileName linktofile(tempdir, "linktofile"); - CPPUNIT_ASSERT_EQUAL(0, symlink(targetfn.GetFullPath().c_str(), - linktofile.GetFullPath().c_str())); + CHECK( symlink(targetfn.GetFullPath().c_str(), linktofile.GetFullPath().c_str()) == 0 ); // Test resolving the filename to the symlink - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Failed to resolve symlink to file", - targetfn, linktofile.ResolveLink() - ); + INFO("Failed to resolve symlink to file"); + CHECK( linktofile.ResolveLink() == targetfn ); // Create a relative symlink to that file wxFileName relativelinktofile(tempdir, "relativelinktofile"); wxString relativeFileName = "./" + targetfn.GetFullName(); - CPPUNIT_ASSERT_EQUAL(0, symlink(relativeFileName.c_str(), - relativelinktofile.GetFullPath().c_str())); - - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Failed to resolve relative symlink to absolute file path", - targetfn, relativelinktofile.ResolveLink() - ); + CHECK( symlink(relativeFileName.c_str(), relativelinktofile.GetFullPath().c_str()) == 0 ); + INFO("Failed to resolve relative symlink to absolute file path"); + CHECK( relativelinktofile.ResolveLink() == targetfn ); // ... and another to the temporary directory const wxString linktodirName(tempdir + "/linktodir"); wxFileName linktodirfn(linktodirName); wxFileName linktodir(wxFileName::DirName(linktodirName)); - CPPUNIT_ASSERT_EQUAL(0, symlink(tmpfn.GetFullPath().c_str(), - linktodirName.c_str())); - - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Failed to resolve symlink to directory", - tmpfn, linktodirfn.ResolveLink() - ); + CHECK( symlink(tmpfn.GetFullPath().c_str(), linktodirName.c_str()) == 0 ); + INFO("Failed to resolve symlink to directory"); + CHECK( linktodirfn.ResolveLink() == tmpfn ); // And symlinks to both of those symlinks wxFileName linktofilelnk(tempdir, "linktofilelnk"); - CPPUNIT_ASSERT_EQUAL(0, symlink(linktofile.GetFullPath().c_str(), - linktofilelnk.GetFullPath().c_str())); - - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Failed to resolve symlink to file symlink", - targetfn, linktofilelnk.ResolveLink() - ); + CHECK( symlink(linktofile.GetFullPath().c_str(), linktofilelnk.GetFullPath().c_str()) == 0 ); + INFO("Failed to resolve symlink to file symlink"); + CHECK( linktofilelnk.ResolveLink() == targetfn ); wxFileName linktodirlnk(tempdir, "linktodirlnk"); - CPPUNIT_ASSERT_EQUAL(0, symlink(linktodir.GetFullPath().c_str(), - linktodirlnk.GetFullPath().c_str())); - - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Failed to resolve symlink to directory symlink", - tmpfn, linktodirlnk.ResolveLink() - ); + CHECK( symlink(linktodir.GetFullPath().c_str(), linktodirlnk.GetFullPath().c_str()) == 0 ); + INFO("Failed to resolve symlink to directory symlink"); + CHECK( linktodirlnk.ResolveLink() == tmpfn ); // Run the tests twice: once in the default symlink following mode and the // second time without following symlinks. @@ -924,130 +819,77 @@ void FileNameTestCase::TestSymlinks() } // Test SameAs() - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Comparison with file" + msg, - deref, linktofile.SameAs(targetfn) - ); + INFO("Comparison with file" + msg); + CHECK( linktofile.SameAs(targetfn) == deref ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Comparison with directory" + msg, - deref, linktodir.SameAs(tmpfn) - ); + INFO("Comparison with directory" + msg); + CHECK( linktodir.SameAs(tmpfn) == deref ); // A link-to-a-link should dereference through to the final target - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Comparison with link to a file" + msg, - deref, - linktofilelnk.SameAs(targetfn) - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Comparison with link to a directory" + msg, - deref, - linktodirlnk.SameAs(tmpfn) - ); + INFO("Comparison with link to a file" + msg); + CHECK( linktofilelnk.SameAs(targetfn) == deref ); + INFO("Comparison with link to a directory" + msg); + CHECK( linktodirlnk.SameAs(tmpfn) == deref ); // Test GetTimes() + INFO("Getting times of a directory" + msg); wxDateTime dtAccess, dtMod, dtCreate; - CPPUNIT_ASSERT_MESSAGE - ( - "Getting times of a directory" + msg, - linktodir.GetTimes(&dtAccess, &dtMod, &dtCreate) - ); + CHECK( linktodir.GetTimes(&dtAccess, &dtMod, &dtCreate) ); // Test (File|Dir)Exists() - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing file existence" + msg, - deref, - linktofile.FileExists() - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing directory existence" + msg, - deref, - linktodir.DirExists() - ); + INFO("Testing file existence" + msg); + CHECK( linktofile.FileExists() == deref ); + INFO("Testing directory existence" + msg); + CHECK( linktodir.DirExists() == deref ); // Test wxFileName::Exists // The wxFILE_EXISTS_NO_FOLLOW flag should override DontFollowLink() - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing file existence" + msg, - false, - linktofile.Exists(wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing directory existence" + msg, - false, - linktodir.Exists(wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) - ); + INFO("Testing file existence" + msg); + CHECK_FALSE( linktofile.Exists(wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) ); + + INFO("Testing directory existence" + msg); + CHECK_FALSE( linktodir.Exists(wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) ); + // and the static versions - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing file existence" + msg, - false, - wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing file existence" + msg, - true, - wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR) - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing directory existence" + msg, - false, - wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) - ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Testing directory existence" + msg, - true, - wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR) - ); + INFO("Testing file existence" + msg); + CHECK_FALSE( wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) ); + CHECK( wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR) ); + + INFO("Testing directory existence" + msg); + CHECK_FALSE( wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) ); + CHECK( wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR) ); } // Finally test Exists() after removing the file. - CPPUNIT_ASSERT(wxRemoveFile(targetfn.GetFullPath())); + CHECK(wxRemoveFile(targetfn.GetFullPath())); // Resolving a file that doesn't exist returns empty - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Non-existent file didn't resolve correctly", - wxFileName(), targetfn.ResolveLink() - ); + INFO("Non-existent file didn't resolve correctly"); + CHECK( targetfn.ResolveLink() == wxFileName() ); // This should succeed, as the symlink still exists and // the default wxFILE_EXISTS_ANY implies wxFILE_EXISTS_NO_FOLLOW - CPPUNIT_ASSERT(wxFileName(tempdir, "linktofile").Exists()); + CHECK(wxFileName(tempdir, "linktofile").Exists()); // So should this one, as wxFILE_EXISTS_SYMLINK does too - CPPUNIT_ASSERT(wxFileName(tempdir, "linktofile"). - Exists(wxFILE_EXISTS_SYMLINK)); + CHECK(wxFileName(tempdir, "linktofile").Exists(wxFILE_EXISTS_SYMLINK)); // but not this one, as the now broken symlink is followed - CPPUNIT_ASSERT(!wxFileName(tempdir, "linktofile"). - Exists(wxFILE_EXISTS_REGULAR)); - CPPUNIT_ASSERT(linktofile.Exists()); + CHECK(!wxFileName(tempdir, "linktofile").Exists(wxFILE_EXISTS_REGULAR)); + CHECK(linktofile.Exists()); // This is also a convenient place to test Rmdir() as we have things to // remove. // First, check that removing a symlink to a directory fails. - CPPUNIT_ASSERT( !wxFileName::Rmdir(linktodirName) ); + CHECK( !wxFileName::Rmdir(linktodirName) ); // And recursively removing it only removes the symlink itself, not the // directory. - CPPUNIT_ASSERT( wxFileName::Rmdir(linktodirName, wxPATH_RMDIR_RECURSIVE) ); - CPPUNIT_ASSERT( tmpfn.Exists() ); + CHECK( wxFileName::Rmdir(linktodirName, wxPATH_RMDIR_RECURSIVE) ); + CHECK( tmpfn.Exists() ); // Finally removing the directory itself does remove everything. - CPPUNIT_ASSERT(tempdirfn.Rmdir(wxPATH_RMDIR_RECURSIVE)); - CPPUNIT_ASSERT( !tempdirfn.Exists() ); + CHECK(tempdirfn.Rmdir(wxPATH_RMDIR_RECURSIVE)); + CHECK( !tempdirfn.Exists() ); } #endif // __UNIX__ @@ -1066,29 +908,29 @@ void CreateShortcut(const wxString& pathFile, const wxString& pathLink) wxCOMPtr sl; hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&sl); - CPPUNIT_ASSERT( SUCCEEDED(hr) ); + REQUIRE( SUCCEEDED(hr) ); wxCOMPtr pf; hr = sl->QueryInterface(IID_IPersistFile, (void **)&pf); - CPPUNIT_ASSERT( SUCCEEDED(hr) ); + REQUIRE( SUCCEEDED(hr) ); hr = sl->SetPath(pathFile.t_str()); - CPPUNIT_ASSERT( SUCCEEDED(hr) ); + CHECK( SUCCEEDED(hr) ); hr = pf->Save(pathLink.wc_str(), TRUE); - CPPUNIT_ASSERT( SUCCEEDED(hr) ); + CHECK( SUCCEEDED(hr) ); } } // anonymous namespace -void FileNameTestCase::TestShortcuts() +TEST_CASE("wxFileName::Shortcuts", "[filename]") { wxFileName fn(wxFileName::CreateTempFileName("filenametest")); - CPPUNIT_ASSERT( fn.IsOk() ); + REQUIRE( fn.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() ); wxFileName fnLink(fn.GetPath(), "sc_" + fn.GetName(), "lnk"); - CPPUNIT_ASSERT( fnLink.IsOk() ); + REQUIRE( fnLink.IsOk() ); wxON_BLOCK_EXIT1( wxRemoveFile, fnLink.GetFullPath() ); CreateShortcut(fn.GetFullPath(), fnLink.GetFullPath()); @@ -1097,7 +939,7 @@ void FileNameTestCase::TestShortcuts() // name. wxFileName fnLinkRel(fnLink); fnLink.MakeRelativeTo("."); - CPPUNIT_ASSERT_EQUAL(fnLink.GetFullName(), fnLinkRel.GetFullName()); + CHECK( fnLinkRel.GetFullName() == fnLink.GetFullName() ); } #endif // __WINDOWS__