Merge branch 'test-fixes'

Miscellaneous test fixes and disable the UI tests by default under
non-MSW platforms.
This commit is contained in:
Vadim Zeitlin
2017-11-05 23:44:01 +01:00
8 changed files with 109 additions and 34 deletions

View File

@@ -171,6 +171,11 @@ void ExecTestCase::TestShell()
void ExecTestCase::TestExecute() void ExecTestCase::TestExecute()
{ {
// Launching interactive programs doesn't work without an interactive
// session.
if ( IsAutomaticTest() )
return;
AsyncInEventLoop asyncInEventLoop; AsyncInEventLoop asyncInEventLoop;
// test asynch exec // test asynch exec
@@ -238,6 +243,9 @@ void ExecTestCase::TestExecute()
void ExecTestCase::TestProcess() void ExecTestCase::TestProcess()
{ {
if ( IsAutomaticTest() )
return;
AsyncInEventLoop asyncInEventLoop; AsyncInEventLoop asyncInEventLoop;
// test wxExecute with wxProcess // test wxExecute with wxProcess

View File

@@ -37,6 +37,8 @@
#define fileno _fileno #define fileno _fileno
#endif #endif
#include "testfile.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// The test case // The test case
@@ -100,23 +102,17 @@ void FileKindTestCase::TestFd(wxFile& file, bool expected)
CPPUNIT_ASSERT(outStream.IsSeekable() == expected); CPPUNIT_ASSERT(outStream.IsSeekable() == expected);
} }
struct TempFile
{
~TempFile() { if (!m_name.IsEmpty()) wxRemoveFile(m_name); }
wxString m_name;
};
// test with an ordinary file // test with an ordinary file
// //
void FileKindTestCase::File() void FileKindTestCase::File()
{ {
TempFile tmp; // put first TempFile tmp; // put first
wxFile file; wxFile file;
tmp.m_name = wxFileName::CreateTempFileName(wxT("wxft"), &file); tmp.Assign(wxFileName::CreateTempFileName(wxT("wxft"), &file));
TestFd(file, true); TestFd(file, true);
file.Close(); file.Close();
wxFFile ffile(tmp.m_name); wxFFile ffile(tmp.GetName());
TestFILE(ffile, true); TestFILE(ffile, true);
} }

View File

@@ -1484,8 +1484,8 @@ TEST_CASE("wxMBConv::cMB2WC", "[mbconv][mb2wc]")
CHECK( convUTF16.cMB2WC("\0").length() == 0 ); CHECK( convUTF16.cMB2WC("\0").length() == 0 );
CHECK( convUTF16.cMB2WC(wxCharBuffer()).length() == 0 ); CHECK( convUTF16.cMB2WC(wxCharBuffer()).length() == 0 );
CHECK( convUTF16.cMB2WC("H\0i\0").length() == 2 ); CHECK( convUTF16.cMB2WC("H\0i\0\0").length() == 2 );
CHECK( convUTF16.cMB2WC(wxCharBuffer::CreateNonOwned("H\0i\0", 4)).length() == 2 ); CHECK( convUTF16.cMB2WC(wxCharBuffer::CreateNonOwned("H\0i\0\0", 4)).length() == 2 );
CHECK( wxConvUTF7.cMB2WC("").length() == 0 ); CHECK( wxConvUTF7.cMB2WC("").length() == 0 );
CHECK( wxConvUTF7.cMB2WC(wxCharBuffer()).length() == 0 ); CHECK( wxConvUTF7.cMB2WC(wxCharBuffer()).length() == 0 );

View File

@@ -26,6 +26,8 @@
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/math.h" #include "wx/math.h"
#include "testfile.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -107,8 +109,10 @@ DataStreamTestCase::DataStreamTestCase()
wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue) wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
{ {
TempFile f("mytext.dat");
{ {
wxFileOutputStream pFileOutput( wxT("mytext.dat") ); wxFileOutputStream pFileOutput( f.GetName() );
wxDataOutputStream pDataOutput( pFileOutput ); wxDataOutputStream pDataOutput( pFileOutput );
if ( ms_useBigEndianFormat ) if ( ms_useBigEndianFormat )
pDataOutput.BigEndianOrdered(true); pDataOutput.BigEndianOrdered(true);
@@ -121,7 +125,7 @@ wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
pDataOutput << fValue; pDataOutput << fValue;
} }
wxFileInputStream pFileInput( wxT("mytext.dat") ); wxFileInputStream pFileInput( f.GetName() );
wxDataInputStream pDataInput( pFileInput ); wxDataInputStream pDataInput( pFileInput );
if ( ms_useBigEndianFormat ) if ( ms_useBigEndianFormat )
pDataInput.BigEndianOrdered(true); pDataInput.BigEndianOrdered(true);
@@ -156,15 +160,17 @@ private:
{ {
ValueArray InValues(Size); ValueArray InValues(Size);
TempFile f("mytext.dat");
{ {
wxFileOutputStream FileOutput( wxT("mytext.dat") ); wxFileOutputStream FileOutput( f.GetName() );
wxDataOutputStream DataOutput( FileOutput ); wxDataOutputStream DataOutput( FileOutput );
(DataOutput.*pfnWriter)(Values, Size); (DataOutput.*pfnWriter)(Values, Size);
} }
{ {
wxFileInputStream FileInput( wxT("mytext.dat") ); wxFileInputStream FileInput( f.GetName() );
wxDataInputStream DataInput( FileInput ); wxDataInputStream DataInput( FileInput );
(DataInput.*pfnReader)(&*InValues.begin(), InValues.size()); (DataInput.*pfnReader)(&*InValues.begin(), InValues.size());
@@ -207,15 +213,17 @@ T TestRW(const T &Value)
{ {
T InValue; T InValue;
TempFile f("mytext.dat");
{ {
wxFileOutputStream FileOutput( wxT("mytext.dat") ); wxFileOutputStream FileOutput( f.GetName() );
wxDataOutputStream DataOutput( FileOutput ); wxDataOutputStream DataOutput( FileOutput );
DataOutput << Value; DataOutput << Value;
} }
{ {
wxFileInputStream FileInput( wxT("mytext.dat") ); wxFileInputStream FileInput( f.GetName() );
wxDataInputStream DataInput( FileInput ); wxDataInputStream DataInput( FileInput );
DataInput >> InValue; DataInput >> InValue;

View File

@@ -31,6 +31,8 @@
#include "wx/mstream.h" #include "wx/mstream.h"
#endif // wxUSE_UNICODE #endif // wxUSE_UNICODE
#include "testfile.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -105,23 +107,22 @@ TextStreamTestCase::TextStreamTestCase()
void TextStreamTestCase::Endline() void TextStreamTestCase::Endline()
{ {
wxFileOutputStream* pOutFile = new wxFileOutputStream(wxT("test.txt")); TempFile f("test.txt");
wxTextOutputStream* pOutText = new wxTextOutputStream(*pOutFile);
*pOutText << wxT("Test text") << endl
<< wxT("More Testing Text (There should be newline before this)");
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]; char szIn[9 + NEWLINELEN];
pInFile->Read(szIn, 9 + NEWLINELEN); pInFile.Read(szIn, 9 + NEWLINELEN);
CPPUNIT_ASSERT( memcmp(&szIn[9], NEWLINE, NEWLINELEN) == 0 ); CPPUNIT_ASSERT( memcmp(&szIn[9], NEWLINE, NEWLINELEN) == 0 );
delete pInFile;
} }
void TextStreamTestCase::MiscTests() void TextStreamTestCase::MiscTests()
@@ -147,8 +148,10 @@ void TextStreamTestCase::MiscTests()
template <typename T> template <typename T>
static void DoTestRoundTrip(const T *values, size_t numValues) 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); wxTextOutputStream textOut(fileOut);
for ( size_t n = 0; n < numValues; n++ ) 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); wxTextInputStream textIn(fileIn);
T value; T value;

View File

@@ -360,6 +360,37 @@ extern bool IsAutomaticTest()
#if wxUSE_GUI #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) void DeleteTestWindow(wxWindow* win)
{ {
if ( !win ) if ( !win )

View File

@@ -41,5 +41,30 @@ private:
wxString m_name; 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_ #endif // _WX_TESTS_TEMPFILE_H_

View File

@@ -10,13 +10,14 @@
// this allows the tests that do not rely on it to run on platforms that don't // this allows the tests that do not rely on it to run on platforms that don't
// support it. // support it.
// //
// FIXME: And while OS X does support it, more or less, too many tests // Unfortunately, currently too many of the UI tests fail on non-MSW platforms,
// currently fail under it so disable all interactive tests there. They // so they're disabled there by default. This really, really needs to be fixed,
// should, of course, be reenabled a.s.a.p. // but for now having the UI tests always failing is not helpful as it prevents
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) // other test failures from being noticed, so disable them there.
#define WXUISIM_TEST(test) CPPUNIT_TEST(test) #if wxUSE_UIACTIONSIMULATOR
#define WXUISIM_TEST(test) if ( EnableUITests() ) { CPPUNIT_TEST(test) }
#else #else
#define WXUISIM_TEST(test) (void)0 #define WXUISIM_TEST(test)
#endif #endif
// define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants // define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants
@@ -169,6 +170,9 @@ private:
#if wxUSE_GUI #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 // Helper function deleting the window without asserts (and hence exceptions
// thrown from its dtor!) even if it has mouse capture. // thrown from its dtor!) even if it has mouse capture.
void DeleteTestWindow(wxWindow* win); void DeleteTestWindow(wxWindow* win);