From 035b8ad99fb736de53bbe43b5ffbd6be7b14efa6 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 24 Jul 2026 06:37:37 -0600 Subject: [PATCH] tests: Add TempDir::IsOk() Add a small helper for checking whether TempDir was created successfully and use it instead of checking the temporary directory name directly. --- tests/archive/archivetest.cpp | 2 +- tests/filename/filenametest.cpp | 6 +++--- tests/fswatcher/fswatchertest.cpp | 2 +- tests/intl/intltest.cpp | 2 +- tests/testfile.h | 5 +++++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/archive/archivetest.cpp b/tests/archive/archivetest.cpp index e51310d849..ca46b8832c 100644 --- a/tests/archive/archivetest.cpp +++ b/tests/archive/archivetest.cpp @@ -302,7 +302,7 @@ private: ArchiveTempDir::ArchiveTempDir() : m_tmp(wxT("arctest-")) { - CPPUNIT_ASSERT(!m_tmp.GetName().empty()); + CPPUNIT_ASSERT(m_tmp.IsOk()); m_original = wxGetCwd(); CPPUNIT_ASSERT(wxSetWorkingDirectory(m_tmp.GetName())); } diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index c79a933d93..547bf5add5 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -747,7 +747,7 @@ TEST_CASE("wxFileName::Exists", "[filename]") #endif // __LINUX__ #ifndef __VMS TempDir socktempdir("socktmpdir"); - REQUIRE(!socktempdir.GetName().empty()); + REQUIRE(socktempdir.IsOk()); wxFileName sockfilename(socktempdir.GetName(), "socket"); wxString sockfile = sockfilename.GetFullPath(); wxTCPServer server; @@ -791,7 +791,7 @@ TEST_CASE("wxFileName::SameAs", "[filename]") #if defined(__UNIX__) TempDir tempdir("wxfn"); - REQUIRE(!tempdir.GetName().empty()); + REQUIRE(tempdir.IsOk()); wxFileName tempdir1fn; tempdir1fn.AssignDir(tempdir.GetName()); @@ -826,7 +826,7 @@ TEST_CASE("wxFileName::SameAs", "[filename]") TEST_CASE("wxFileName::Symlinks", "[filename]") { TempDir tempdirRoot("filenametest"); - REQUIRE(!tempdirRoot.GetName().empty()); + REQUIRE(tempdirRoot.IsOk()); const wxString tmpdir(wxFileName::GetTempDir()); wxFileName tmpfn(wxFileName::DirName(tmpdir)); diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 9a5438b328..66ea98452b 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -133,7 +133,7 @@ public: return ms_watchDir; ms_watchDirData.reset(new TempDir("fswatcher_test")); - REQUIRE(!ms_watchDirData->GetName().empty()); + REQUIRE(ms_watchDirData->IsOk()); TestLogEnabler enableLogs; ms_watchDir.AssignDir(ms_watchDirData->GetName()); diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 7f52ff5d02..9231d152f8 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -262,7 +262,7 @@ public: TranslationsTestCatalogs() : m_prefix("wxintltest-") { - REQUIRE(!m_prefix.GetName().empty()); + REQUIRE(m_prefix.IsOk()); CopyCatalog("en_GB"); CopyCatalog("fr"); diff --git a/tests/testfile.h b/tests/testfile.h index 3fe6ad512d..992988c76c 100644 --- a/tests/testfile.h +++ b/tests/testfile.h @@ -90,6 +90,11 @@ public: ~TempDir() { Remove(); } + bool IsOk() const + { + return !m_name.empty(); + } + const wxString& GetName() const { return m_name; } bool Remove()