diff --git a/tests/exec/exec.cpp b/tests/exec/exec.cpp index e3be763544..bc2cdfe052 100644 --- a/tests/exec/exec.cpp +++ b/tests/exec/exec.cpp @@ -171,6 +171,11 @@ void ExecTestCase::TestShell() void ExecTestCase::TestExecute() { + // Launching interactive programs doesn't work without an interactive + // session. + if ( IsAutomaticTest() ) + return; + AsyncInEventLoop asyncInEventLoop; // test asynch exec @@ -238,6 +243,9 @@ void ExecTestCase::TestExecute() void ExecTestCase::TestProcess() { + if ( IsAutomaticTest() ) + return; + AsyncInEventLoop asyncInEventLoop; // test wxExecute with wxProcess diff --git a/tests/filekind/filekind.cpp b/tests/filekind/filekind.cpp index aa812b0884..fa270897b4 100644 --- a/tests/filekind/filekind.cpp +++ b/tests/filekind/filekind.cpp @@ -37,6 +37,8 @@ #define fileno _fileno #endif +#include "testfile.h" + /////////////////////////////////////////////////////////////////////////////// // The test case @@ -100,23 +102,17 @@ void FileKindTestCase::TestFd(wxFile& file, bool expected) CPPUNIT_ASSERT(outStream.IsSeekable() == expected); } -struct TempFile -{ - ~TempFile() { if (!m_name.IsEmpty()) wxRemoveFile(m_name); } - wxString m_name; -}; - // test with an ordinary file // void FileKindTestCase::File() { TempFile tmp; // put first wxFile file; - tmp.m_name = wxFileName::CreateTempFileName(wxT("wxft"), &file); + tmp.Assign(wxFileName::CreateTempFileName(wxT("wxft"), &file)); TestFd(file, true); file.Close(); - wxFFile ffile(tmp.m_name); + wxFFile ffile(tmp.GetName()); TestFILE(ffile, true); } diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index 0b2b1507c6..5a0afa4e5b 100644 --- a/tests/mbconv/mbconvtest.cpp +++ b/tests/mbconv/mbconvtest.cpp @@ -1484,8 +1484,8 @@ TEST_CASE("wxMBConv::cMB2WC", "[mbconv][mb2wc]") CHECK( convUTF16.cMB2WC("\0").length() == 0 ); CHECK( convUTF16.cMB2WC(wxCharBuffer()).length() == 0 ); - CHECK( convUTF16.cMB2WC("H\0i\0").length() == 2 ); - CHECK( convUTF16.cMB2WC(wxCharBuffer::CreateNonOwned("H\0i\0", 4)).length() == 2 ); + CHECK( convUTF16.cMB2WC("H\0i\0\0").length() == 2 ); + CHECK( convUTF16.cMB2WC(wxCharBuffer::CreateNonOwned("H\0i\0\0", 4)).length() == 2 ); CHECK( wxConvUTF7.cMB2WC("").length() == 0 ); CHECK( wxConvUTF7.cMB2WC(wxCharBuffer()).length() == 0 ); diff --git a/tests/streams/datastreamtest.cpp b/tests/streams/datastreamtest.cpp index ae6c1564ad..ca2456a6c5 100644 --- a/tests/streams/datastreamtest.cpp +++ b/tests/streams/datastreamtest.cpp @@ -26,6 +26,8 @@ #include "wx/wfstream.h" #include "wx/math.h" +#include "testfile.h" + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -107,8 +109,10 @@ DataStreamTestCase::DataStreamTestCase() wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue) { + TempFile f("mytext.dat"); + { - wxFileOutputStream pFileOutput( wxT("mytext.dat") ); + wxFileOutputStream pFileOutput( f.GetName() ); wxDataOutputStream pDataOutput( pFileOutput ); if ( ms_useBigEndianFormat ) pDataOutput.BigEndianOrdered(true); @@ -121,7 +125,7 @@ wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue) pDataOutput << fValue; } - wxFileInputStream pFileInput( wxT("mytext.dat") ); + wxFileInputStream pFileInput( f.GetName() ); wxDataInputStream pDataInput( pFileInput ); if ( ms_useBigEndianFormat ) pDataInput.BigEndianOrdered(true); @@ -156,15 +160,17 @@ private: { ValueArray InValues(Size); + TempFile f("mytext.dat"); + { - wxFileOutputStream FileOutput( wxT("mytext.dat") ); + wxFileOutputStream FileOutput( f.GetName() ); wxDataOutputStream DataOutput( FileOutput ); (DataOutput.*pfnWriter)(Values, Size); } { - wxFileInputStream FileInput( wxT("mytext.dat") ); + wxFileInputStream FileInput( f.GetName() ); wxDataInputStream DataInput( FileInput ); (DataInput.*pfnReader)(&*InValues.begin(), InValues.size()); @@ -207,15 +213,17 @@ T TestRW(const T &Value) { T InValue; + TempFile f("mytext.dat"); + { - wxFileOutputStream FileOutput( wxT("mytext.dat") ); + wxFileOutputStream FileOutput( f.GetName() ); wxDataOutputStream DataOutput( FileOutput ); DataOutput << Value; } { - wxFileInputStream FileInput( wxT("mytext.dat") ); + wxFileInputStream FileInput( f.GetName() ); wxDataInputStream DataInput( FileInput ); DataInput >> InValue; diff --git a/tests/streams/textstreamtest.cpp b/tests/streams/textstreamtest.cpp index ec88c01ec8..0975e7526e 100644 --- a/tests/streams/textstreamtest.cpp +++ b/tests/streams/textstreamtest.cpp @@ -31,6 +31,8 @@ #include "wx/mstream.h" #endif // wxUSE_UNICODE +#include "testfile.h" + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -105,23 +107,22 @@ TextStreamTestCase::TextStreamTestCase() void TextStreamTestCase::Endline() { - wxFileOutputStream* pOutFile = new wxFileOutputStream(wxT("test.txt")); - wxTextOutputStream* pOutText = new wxTextOutputStream(*pOutFile); - *pOutText << wxT("Test text") << endl - << wxT("More Testing Text (There should be newline before this)"); + TempFile f("test.txt"); - delete pOutText; - delete pOutFile; + { + wxFileOutputStream pOutFile(f.GetName()); + wxTextOutputStream pOutText(pOutFile); + pOutText << wxT("Test text") << endl + << wxT("More Testing Text (There should be newline before this)"); + } - wxFileInputStream* pInFile = new wxFileInputStream(wxT("test.txt")); + wxFileInputStream pInFile(f.GetName()); char szIn[9 + NEWLINELEN]; - pInFile->Read(szIn, 9 + NEWLINELEN); + pInFile.Read(szIn, 9 + NEWLINELEN); CPPUNIT_ASSERT( memcmp(&szIn[9], NEWLINE, NEWLINELEN) == 0 ); - - delete pInFile; } void TextStreamTestCase::MiscTests() @@ -147,8 +148,10 @@ void TextStreamTestCase::MiscTests() template static void DoTestRoundTrip(const T *values, size_t numValues) { + TempFile f("test.txt"); + { - wxFileOutputStream fileOut(wxT("test.txt")); + wxFileOutputStream fileOut(f.GetName()); wxTextOutputStream textOut(fileOut); for ( size_t n = 0; n < numValues; n++ ) @@ -158,7 +161,7 @@ static void DoTestRoundTrip(const T *values, size_t numValues) } { - wxFileInputStream fileIn(wxT("test.txt")); + wxFileInputStream fileIn(f.GetName()); wxTextInputStream textIn(fileIn); T value; diff --git a/tests/test.cpp b/tests/test.cpp index 5e2f6c5c7d..ba853d53ea 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -360,6 +360,37 @@ extern bool IsAutomaticTest() #if wxUSE_GUI +bool EnableUITests() +{ + static int s_enabled = -1; + if ( s_enabled == -1 ) + { + // Allow explicitly configuring this via an environment variable under + // all platforms. + wxString enabled; + if ( wxGetEnv("WX_UI_TESTS", &enabled) ) + { + if ( enabled == "1" ) + s_enabled = 1; + else if ( enabled == "0" ) + s_enabled = 0; + else + wxFprintf(stderr, "Unknown \"WX_UI_TESTS\" value \"%s\" ignored.\n", enabled); + } + + if ( s_enabled == -1 ) + { +#ifdef __WXMSW__ + s_enabled = 1; +#else // !__WXMSW__ + s_enabled = 0; +#endif // __WXMSW__/!__WXMSW__ + } + } + + return s_enabled == 1; +} + void DeleteTestWindow(wxWindow* win) { if ( !win ) diff --git a/tests/testfile.h b/tests/testfile.h index 519acbe8b2..9c1f5afa3d 100644 --- a/tests/testfile.h +++ b/tests/testfile.h @@ -41,5 +41,30 @@ private: wxString m_name; }; +// ---------------------------------------------------------------------------- +// TempFile: just a self deleting file +// ---------------------------------------------------------------------------- + +class TempFile +{ +public: + explicit TempFile(const wxString& name = wxString()) : m_name(name) { } + + void Assign(const wxString& name) { m_name = name; } + + const wxString& GetName() const { return m_name; } + + ~TempFile() + { + if ( !m_name.empty() ) + wxRemoveFile(m_name); + } + +private: + wxString m_name; + + wxDECLARE_NO_COPY_CLASS(TempFile); +}; + #endif // _WX_TESTS_TEMPFILE_H_ diff --git a/tests/testprec.h b/tests/testprec.h index 8bbaf4be70..f5661446ed 100644 --- a/tests/testprec.h +++ b/tests/testprec.h @@ -10,13 +10,14 @@ // this allows the tests that do not rely on it to run on platforms that don't // support it. // -// FIXME: And while OS X does support it, more or less, too many tests -// currently fail under it so disable all interactive tests there. They -// should, of course, be reenabled a.s.a.p. -#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) - #define WXUISIM_TEST(test) CPPUNIT_TEST(test) +// Unfortunately, currently too many of the UI tests fail on non-MSW platforms, +// so they're disabled there by default. This really, really needs to be fixed, +// but for now having the UI tests always failing is not helpful as it prevents +// other test failures from being noticed, so disable them there. +#if wxUSE_UIACTIONSIMULATOR + #define WXUISIM_TEST(test) if ( EnableUITests() ) { CPPUNIT_TEST(test) } #else - #define WXUISIM_TEST(test) (void)0 + #define WXUISIM_TEST(test) #endif // define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants @@ -169,6 +170,9 @@ private: #if wxUSE_GUI +// Return true if the UI tests are enabled, used by WXUISIM_TEST(). +extern bool EnableUITests(); + // Helper function deleting the window without asserts (and hence exceptions // thrown from its dtor!) even if it has mouse capture. void DeleteTestWindow(wxWindow* win);