Patch 1053127 - Test fixes.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30431 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -56,9 +56,8 @@
|
|||||||
extern wxString wxConvertFormat(const wxChar *format);
|
extern wxString wxConvertFormat(const wxChar *format);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using CppUnit::TestCase;
|
||||||
using namespace CppUnit;
|
using std::string;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// The test case
|
// The test case
|
||||||
|
@@ -15,19 +15,19 @@
|
|||||||
//
|
//
|
||||||
// To run all the regex tests:
|
// To run all the regex tests:
|
||||||
// test regex
|
// test regex
|
||||||
//
|
//
|
||||||
// Some tests must be skipped since they use features which we do not make
|
// Some tests must be skipped since they use features which we do not make
|
||||||
// available through wxRegEx. To see the list of tests that have been skipped
|
// available through wxRegEx. To see the list of tests that have been skipped
|
||||||
// turn on verbose logging, e.g.:
|
// turn on verbose logging, e.g.:
|
||||||
// test --verbose regex
|
// test --verbose regex
|
||||||
//
|
//
|
||||||
// The tests here are for the builtin library, tests for wxRegEx in general
|
// The tests here are for the builtin library, tests for wxRegEx in general
|
||||||
// should go in wxregex.cpp
|
// should go in wxregex.cpp
|
||||||
//
|
//
|
||||||
// The tests are generated from Henry Spencer's reg.test, additional test
|
// The tests are generated from Henry Spencer's reg.test, additional test
|
||||||
// can be added in wxreg.test. These test files are then turned into a C++
|
// can be added in wxreg.test. These test files are then turned into a C++
|
||||||
// include file 'regex.inc' (included below) using a script 'regex.pl'.
|
// include file 'regex.inc' (included below) using a script 'regex.pl'.
|
||||||
//
|
//
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx/wx.h".
|
// For compilers that support precompilation, includes "wx/wx.h".
|
||||||
#include "wx/wxprec.h"
|
#include "wx/wxprec.h"
|
||||||
@@ -43,10 +43,16 @@
|
|||||||
|
|
||||||
#include "wx/regex.h"
|
#include "wx/regex.h"
|
||||||
#include "wx/cppunit.h"
|
#include "wx/cppunit.h"
|
||||||
#include <stdexcept>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using CppUnit::Test;
|
||||||
using namespace CppUnit;
|
using CppUnit::TestCase;
|
||||||
|
using CppUnit::TestSuite;
|
||||||
|
using CppUnit::Exception;
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
// many of the tests are specific to the builtin regex lib, so only attempts
|
// many of the tests are specific to the builtin regex lib, so only attempts
|
||||||
// to do them when using the builtin regex lib.
|
// to do them when using the builtin regex lib.
|
||||||
@@ -135,7 +141,7 @@ RegExTestCase::RegExTestCase(
|
|||||||
}
|
}
|
||||||
|
|
||||||
failIf(badconv, _T("cannot convert to default character encoding"));
|
failIf(badconv, _T("cannot convert to default character encoding"));
|
||||||
|
|
||||||
// the flags need further parsing...
|
// the flags need further parsing...
|
||||||
parseFlags(m_flags);
|
parseFlags(m_flags);
|
||||||
|
|
||||||
@@ -148,10 +154,10 @@ int wxWcscmp(const wchar_t* s1, const wchar_t* s2)
|
|||||||
{
|
{
|
||||||
size_t nLen1 = wxWcslen(s1);
|
size_t nLen1 = wxWcslen(s1);
|
||||||
size_t nLen2 = wxWcslen(s2);
|
size_t nLen2 = wxWcslen(s2);
|
||||||
|
|
||||||
if (nLen1 != nLen2)
|
if (nLen1 != nLen2)
|
||||||
return nLen1 - nLen2;
|
return nLen1 - nLen2;
|
||||||
|
|
||||||
return wxMemcmp(s1, s2, nLen1);
|
return wxMemcmp(s1, s2, nLen1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +227,7 @@ void RegExTestCase::runTest()
|
|||||||
doTest(wxRE_ADVANCED);
|
doTest(wxRE_ADVANCED);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try the test for a single flavour of expression
|
// Try the test for a single flavour of expression
|
||||||
//
|
//
|
||||||
void RegExTestCase::doTest(int flavor)
|
void RegExTestCase::doTest(int flavor)
|
||||||
@@ -293,7 +299,7 @@ void RegExTestCase::fail(const wxString& msg) const
|
|||||||
|
|
||||||
for (it = m_expected.begin(); it != m_expected.end(); ++it)
|
for (it = m_expected.begin(); it != m_expected.end(); ++it)
|
||||||
str << _T(" ") << quote(*it);
|
str << _T(" ") << quote(*it);
|
||||||
|
|
||||||
if (str.length() > 77)
|
if (str.length() > 77)
|
||||||
str = str.substr(0, 74) + _T("...");
|
str = str.substr(0, 74) + _T("...");
|
||||||
|
|
||||||
@@ -314,7 +320,7 @@ wxString RegExTestCase::quote(const wxString& arg)
|
|||||||
for (size_t i = 0; i < arg.length(); i++) {
|
for (size_t i = 0; i < arg.length(); i++) {
|
||||||
wxUChar ch = arg[i];
|
wxUChar ch = arg[i];
|
||||||
const wxChar *p = wxStrchr(needEscape, ch);
|
const wxChar *p = wxStrchr(needEscape, ch);
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
str += wxString::Format(_T("\\%c"), escapes[p - needEscape]);
|
str += wxString::Format(_T("\\%c"), escapes[p - needEscape]);
|
||||||
else if (wxIscntrl(ch))
|
else if (wxIscntrl(ch))
|
||||||
@@ -358,7 +364,7 @@ void RegExTestSuite::add(
|
|||||||
expected_results.push_back(expected);
|
expected_results.push_back(expected);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addTest(new RegExTestCase(
|
addTest(new RegExTestCase(
|
||||||
name, mode, id, flags, pattern, data, expected_results));
|
name, mode, id, flags, pattern, data, expected_results));
|
||||||
|
@@ -24,8 +24,10 @@
|
|||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using CppUnit::Test;
|
||||||
using namespace CppUnit;
|
using CppUnit::TestCase;
|
||||||
|
using CppUnit::TestSuite;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -143,7 +145,7 @@ public:
|
|||||||
m_expected(expected),
|
m_expected(expected),
|
||||||
m_count(count),
|
m_count(count),
|
||||||
m_flags(flags)
|
m_flags(flags)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void runTest();
|
void runTest();
|
||||||
|
@@ -27,7 +27,8 @@
|
|||||||
#include "wx/cppunit.h"
|
#include "wx/cppunit.h"
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace CppUnit;
|
using CppUnit::TestSuite;
|
||||||
|
using CppUnit::Test;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Streams main test suite, it houses all stream test suites.
|
// Streams main test suite, it houses all stream test suites.
|
||||||
@@ -36,8 +37,8 @@ using namespace CppUnit;
|
|||||||
class StreamCase : public TestSuite
|
class StreamCase : public TestSuite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StreamCase()
|
StreamCase()
|
||||||
:TestSuite(STREAM_TEST_NAME)
|
:TestSuite(STREAM_TEST_NAME)
|
||||||
{ /* Nothing extra */ }
|
{ /* Nothing extra */ }
|
||||||
static Test *suite();
|
static Test *suite();
|
||||||
};
|
};
|
||||||
@@ -49,14 +50,14 @@ Test *StreamCase::suite()
|
|||||||
/*
|
/*
|
||||||
* Register all sub stream test suites.
|
* Register all sub stream test suites.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
STREAM_REGISTER_SUB_SUITE(memStream);
|
STREAM_REGISTER_SUB_SUITE(memStream);
|
||||||
STREAM_REGISTER_SUB_SUITE(strStream);
|
STREAM_REGISTER_SUB_SUITE(strStream);
|
||||||
STREAM_REGISTER_SUB_SUITE(fileStream);
|
STREAM_REGISTER_SUB_SUITE(fileStream);
|
||||||
STREAM_REGISTER_SUB_SUITE(ffileStream);
|
STREAM_REGISTER_SUB_SUITE(ffileStream);
|
||||||
STREAM_REGISTER_SUB_SUITE(zlibStream);
|
STREAM_REGISTER_SUB_SUITE(zlibStream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Add more stream subtests here
|
** Add more stream subtests here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
#define _WX_TESTBSTREAM_H__
|
#define _WX_TESTBSTREAM_H__
|
||||||
|
|
||||||
#include "wx/cppunit.h"
|
#include "wx/cppunit.h"
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Some macros preventing us from typing too much ;-)
|
// Some macros preventing us from typing too much ;-)
|
||||||
@@ -21,10 +20,10 @@ using namespace CppUnit;
|
|||||||
#define COMPOSE_TEST_NAME(Name) \
|
#define COMPOSE_TEST_NAME(Name) \
|
||||||
STREAM_TEST_NAME "." #Name
|
STREAM_TEST_NAME "." #Name
|
||||||
#define STREAM_REGISTER_SUB_SUITE(Name) \
|
#define STREAM_REGISTER_SUB_SUITE(Name) \
|
||||||
extern Test* Get##Name##Suite(); \
|
extern CppUnit::Test* Get##Name##Suite(); \
|
||||||
suite->addTest(Get##Name##Suite())
|
suite->addTest(Get##Name##Suite())
|
||||||
#define STREAM_IMPLEMENT_SUB_REGISTRATION_ROUTINE(Name) \
|
#define STREAM_IMPLEMENT_SUB_REGISTRATION_ROUTINE(Name) \
|
||||||
Test* Get##Name##Suite() { return Name::suite(); }
|
CppUnit::Test* Get##Name##Suite() { return Name::suite(); }
|
||||||
#define STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(Name) \
|
#define STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(Name) \
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( Name, COMPOSE_TEST_NAME(Name) ); \
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( Name, COMPOSE_TEST_NAME(Name) ); \
|
||||||
STREAM_IMPLEMENT_SUB_REGISTRATION_ROUTINE( Name )
|
STREAM_IMPLEMENT_SUB_REGISTRATION_ROUTINE( Name )
|
||||||
@@ -34,7 +33,7 @@ using namespace CppUnit;
|
|||||||
// Template class that implements a test for all base stream functions.
|
// Template class that implements a test for all base stream functions.
|
||||||
//
|
//
|
||||||
|
|
||||||
template <class TStreamIn, class TStreamOut> class BaseStreamTestCase : public TestCase
|
template <class TStreamIn, class TStreamOut> class BaseStreamTestCase : public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
typedef BaseStreamTestCase<TStreamIn, TStreamOut> StreamTestCase;
|
typedef BaseStreamTestCase<TStreamIn, TStreamOut> StreamTestCase;
|
||||||
|
@@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
#define DATABUFFER_SIZE 1024
|
#define DATABUFFER_SIZE 1024
|
||||||
|
|
||||||
static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test");
|
static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test");
|
||||||
@@ -74,7 +71,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Implement base class functions.
|
// Implement base class functions.
|
||||||
virtual wxFFileInputStream *DoCreateInStream();
|
virtual wxFFileInputStream *DoCreateInStream();
|
||||||
virtual wxFFileOutputStream *DoCreateOutStream();
|
virtual wxFFileOutputStream *DoCreateOutStream();
|
||||||
virtual void DoDeleteOutStream();
|
virtual void DoDeleteOutStream();
|
||||||
|
|
||||||
@@ -95,14 +92,14 @@ ffileStream::~ffileStream()
|
|||||||
::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
|
::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileInputStream *ffileStream::DoCreateInStream()
|
wxFFileInputStream *ffileStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
|
wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
|
||||||
CPPUNIT_ASSERT(pFileInStream->IsOk());
|
CPPUNIT_ASSERT(pFileInStream->IsOk());
|
||||||
return pFileInStream;
|
return pFileInStream;
|
||||||
}
|
}
|
||||||
wxFFileOutputStream *ffileStream::DoCreateOutStream()
|
wxFFileOutputStream *ffileStream::DoCreateOutStream()
|
||||||
{
|
{
|
||||||
wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM);
|
wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM);
|
||||||
CPPUNIT_ASSERT(pFileOutStream->IsOk());
|
CPPUNIT_ASSERT(pFileOutStream->IsOk());
|
||||||
return pFileOutStream;
|
return pFileOutStream;
|
||||||
@@ -124,7 +121,7 @@ wxString ffileStream::GetInFileName() const
|
|||||||
// Make sure we have a input file...
|
// Make sure we have a input file...
|
||||||
char buf[DATABUFFER_SIZE];
|
char buf[DATABUFFER_SIZE];
|
||||||
wxFFileOutputStream out(FILENAME_FFILEINSTREAM);
|
wxFFileOutputStream out(FILENAME_FFILEINSTREAM);
|
||||||
|
|
||||||
// Init the data buffer.
|
// Init the data buffer.
|
||||||
for (size_t i = 0; i < DATABUFFER_SIZE; i++)
|
for (size_t i = 0; i < DATABUFFER_SIZE; i++)
|
||||||
buf[i] = (i % 0xFF);
|
buf[i] = (i % 0xFF);
|
||||||
|
@@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
#define DATABUFFER_SIZE 1024
|
#define DATABUFFER_SIZE 1024
|
||||||
|
|
||||||
static const wxString FILENAME_FILEINSTREAM = _T("fileinstream.test");
|
static const wxString FILENAME_FILEINSTREAM = _T("fileinstream.test");
|
||||||
@@ -74,7 +71,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Implement base class functions.
|
// Implement base class functions.
|
||||||
virtual wxFileInputStream *DoCreateInStream();
|
virtual wxFileInputStream *DoCreateInStream();
|
||||||
virtual wxFileOutputStream *DoCreateOutStream();
|
virtual wxFileOutputStream *DoCreateOutStream();
|
||||||
virtual void DoDeleteOutStream();
|
virtual void DoDeleteOutStream();
|
||||||
|
|
||||||
@@ -94,14 +91,14 @@ fileStream::~fileStream()
|
|||||||
::wxRemoveFile(FILENAME_FILEOUTSTREAM);
|
::wxRemoveFile(FILENAME_FILEOUTSTREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileInputStream *fileStream::DoCreateInStream()
|
wxFileInputStream *fileStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
|
wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
|
||||||
CPPUNIT_ASSERT(pFileInStream->IsOk());
|
CPPUNIT_ASSERT(pFileInStream->IsOk());
|
||||||
return pFileInStream;
|
return pFileInStream;
|
||||||
}
|
}
|
||||||
wxFileOutputStream *fileStream::DoCreateOutStream()
|
wxFileOutputStream *fileStream::DoCreateOutStream()
|
||||||
{
|
{
|
||||||
wxFileOutputStream *pFileOutStream = new wxFileOutputStream(FILENAME_FILEOUTSTREAM);
|
wxFileOutputStream *pFileOutStream = new wxFileOutputStream(FILENAME_FILEOUTSTREAM);
|
||||||
CPPUNIT_ASSERT(pFileOutStream->IsOk());
|
CPPUNIT_ASSERT(pFileOutStream->IsOk());
|
||||||
return pFileOutStream;
|
return pFileOutStream;
|
||||||
@@ -123,7 +120,7 @@ wxString fileStream::GetInFileName() const
|
|||||||
// Make sure we have a input file...
|
// Make sure we have a input file...
|
||||||
char buf[DATABUFFER_SIZE];
|
char buf[DATABUFFER_SIZE];
|
||||||
wxFileOutputStream out(FILENAME_FILEINSTREAM);
|
wxFileOutputStream out(FILENAME_FILEINSTREAM);
|
||||||
|
|
||||||
// Init the data buffer.
|
// Init the data buffer.
|
||||||
for (size_t i = 0; i < DATABUFFER_SIZE; i++)
|
for (size_t i = 0; i < DATABUFFER_SIZE; i++)
|
||||||
buf[i] = (i % 0xFF);
|
buf[i] = (i % 0xFF);
|
||||||
|
@@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
#define DATABUFFER_SIZE 256
|
#define DATABUFFER_SIZE 256
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -74,7 +71,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Implement base class functions.
|
// Implement base class functions.
|
||||||
virtual wxMemoryInputStream *DoCreateInStream();
|
virtual wxMemoryInputStream *DoCreateInStream();
|
||||||
virtual wxMemoryOutputStream *DoCreateOutStream();
|
virtual wxMemoryOutputStream *DoCreateOutStream();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -98,14 +95,14 @@ const char *memStream::GetDataBuffer()
|
|||||||
return m_DataBuffer;
|
return m_DataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMemoryInputStream *memStream::DoCreateInStream()
|
wxMemoryInputStream *memStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE);
|
wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE);
|
||||||
CPPUNIT_ASSERT(pMemInStream->IsOk());
|
CPPUNIT_ASSERT(pMemInStream->IsOk());
|
||||||
return pMemInStream;
|
return pMemInStream;
|
||||||
}
|
}
|
||||||
wxMemoryOutputStream *memStream::DoCreateOutStream()
|
wxMemoryOutputStream *memStream::DoCreateOutStream()
|
||||||
{
|
{
|
||||||
wxMemoryOutputStream *pMemOutStream = new wxMemoryOutputStream();
|
wxMemoryOutputStream *pMemOutStream = new wxMemoryOutputStream();
|
||||||
CPPUNIT_ASSERT(pMemOutStream->IsOk());
|
CPPUNIT_ASSERT(pMemOutStream->IsOk());
|
||||||
return pMemOutStream;
|
return pMemOutStream;
|
||||||
|
@@ -23,9 +23,6 @@
|
|||||||
|
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// The test case
|
// The test case
|
||||||
//
|
//
|
||||||
@@ -65,7 +62,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Implement base class functions.
|
// Implement base class functions.
|
||||||
virtual wxStringInputStream *DoCreateInStream();
|
virtual wxStringInputStream *DoCreateInStream();
|
||||||
virtual wxStringOutputStream *DoCreateOutStream();
|
virtual wxStringOutputStream *DoCreateOutStream();
|
||||||
|
|
||||||
wxString m_str;
|
wxString m_str;
|
||||||
@@ -85,15 +82,15 @@ strStream::~strStream()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxStringInputStream *strStream::DoCreateInStream()
|
wxStringInputStream *strStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxStringInputStream *pStrInStream = new wxStringInputStream(m_str);
|
wxStringInputStream *pStrInStream = new wxStringInputStream(m_str);
|
||||||
CPPUNIT_ASSERT(pStrInStream->IsOk());
|
CPPUNIT_ASSERT(pStrInStream->IsOk());
|
||||||
return pStrInStream;
|
return pStrInStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxStringOutputStream *strStream::DoCreateOutStream()
|
wxStringOutputStream *strStream::DoCreateOutStream()
|
||||||
{
|
{
|
||||||
wxStringOutputStream *pStrOutStream = new wxStringOutputStream();
|
wxStringOutputStream *pStrOutStream = new wxStringOutputStream();
|
||||||
CPPUNIT_ASSERT(pStrOutStream->IsOk());
|
CPPUNIT_ASSERT(pStrOutStream->IsOk());
|
||||||
return pStrOutStream;
|
return pStrOutStream;
|
||||||
|
@@ -33,8 +33,7 @@
|
|||||||
|
|
||||||
#include "bstream.h"
|
#include "bstream.h"
|
||||||
|
|
||||||
using namespace std;
|
using std::string;
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
#define WXTEST_WITH_GZIP_CONDITION(testMethod) \
|
#define WXTEST_WITH_GZIP_CONDITION(testMethod) \
|
||||||
WXTEST_WITH_CONDITION( COMPOSE_TEST_NAME(zlibStream), wxZlibInputStream::CanHandleGZip() && wxZlibOutputStream::CanHandleGZip(), testMethod )
|
WXTEST_WITH_CONDITION( COMPOSE_TEST_NAME(zlibStream), wxZlibInputStream::CanHandleGZip() && wxZlibOutputStream::CanHandleGZip(), testMethod )
|
||||||
@@ -112,7 +111,7 @@ protected:
|
|||||||
void TestStream_ZLibGZip();
|
void TestStream_ZLibGZip();
|
||||||
// Try to decompress bad data.
|
// Try to decompress bad data.
|
||||||
void Decompress_BadData();
|
void Decompress_BadData();
|
||||||
// Decompress data that was compress by an external app.
|
// Decompress data that was compress by an external app.
|
||||||
// (like test wx 2.4.2, 2.5.1 and gzip data)
|
// (like test wx 2.4.2, 2.5.1 and gzip data)
|
||||||
// Note: This test is limited in testing range!
|
// Note: This test is limited in testing range!
|
||||||
#if WXWIN_COMPATIBILITY_2_4
|
#if WXWIN_COMPATIBILITY_2_4
|
||||||
@@ -120,9 +119,9 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
void Decompress_wx251_zlib114_Data_NoHeader();
|
void Decompress_wx251_zlib114_Data_NoHeader();
|
||||||
void Decompress_wx251_zlib114_Data_ZLib();
|
void Decompress_wx251_zlib114_Data_ZLib();
|
||||||
void Decompress_gzip135Data();
|
void Decompress_gzip135Data();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *GetDataBuffer();
|
const char *GetDataBuffer();
|
||||||
const unsigned char *GetCompressedData();
|
const unsigned char *GetCompressedData();
|
||||||
void doTestStreamData(int input_flag, int output_flag, int compress_level);
|
void doTestStreamData(int input_flag, int output_flag, int compress_level);
|
||||||
@@ -130,12 +129,12 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Implement base class functions.
|
// Implement base class functions.
|
||||||
virtual wxZlibInputStream *DoCreateInStream();
|
virtual wxZlibInputStream *DoCreateInStream();
|
||||||
virtual wxZlibOutputStream *DoCreateOutStream();
|
virtual wxZlibOutputStream *DoCreateOutStream();
|
||||||
virtual void DoDeleteInStream();
|
virtual void DoDeleteInStream();
|
||||||
virtual void DoDeleteOutStream();
|
virtual void DoDeleteOutStream();
|
||||||
|
|
||||||
// Helper that can be used to create new wx compatibility tests...
|
// Helper that can be used to create new wx compatibility tests...
|
||||||
// Otherwise not used by the tests.
|
// Otherwise not used by the tests.
|
||||||
void genExtTestData(wxTextOutputStream &out, const char *buf, int flag);
|
void genExtTestData(wxTextOutputStream &out, const char *buf, int flag);
|
||||||
|
|
||||||
@@ -235,7 +234,7 @@ void zlibStream::TestStream_GZip_BestComp()
|
|||||||
|
|
||||||
void zlibStream::TestStream_ZLibGZip()
|
void zlibStream::TestStream_ZLibGZip()
|
||||||
{
|
{
|
||||||
// Only use default compression level, as this test is
|
// Only use default compression level, as this test is
|
||||||
// for testing if the streams can determine the stream type info them self...
|
// for testing if the streams can determine the stream type info them self...
|
||||||
doTestStreamData(wxZLIB_AUTO, wxZLIB_ZLIB, wxZ_DEFAULT_COMPRESSION);
|
doTestStreamData(wxZLIB_AUTO, wxZLIB_ZLIB, wxZ_DEFAULT_COMPRESSION);
|
||||||
doTestStreamData(wxZLIB_AUTO, wxZLIB_GZIP, wxZ_DEFAULT_COMPRESSION);
|
doTestStreamData(wxZLIB_AUTO, wxZLIB_GZIP, wxZ_DEFAULT_COMPRESSION);
|
||||||
@@ -247,7 +246,7 @@ void zlibStream::Decompress_BadData()
|
|||||||
wxMemoryInputStream memstream_in(GetDataBuffer(), DATABUFFER_SIZE);
|
wxMemoryInputStream memstream_in(GetDataBuffer(), DATABUFFER_SIZE);
|
||||||
CPPUNIT_ASSERT(memstream_in.IsOk());
|
CPPUNIT_ASSERT(memstream_in.IsOk());
|
||||||
wxZlibInputStream zstream_in(memstream_in);
|
wxZlibInputStream zstream_in(memstream_in);
|
||||||
CPPUNIT_ASSERT(zstream_in.IsOk()); // We did not yet read from the stream
|
CPPUNIT_ASSERT(zstream_in.IsOk()); // We did not yet read from the stream
|
||||||
// so it should still be OK.
|
// so it should still be OK.
|
||||||
// Try to force the stream to go to bad status.
|
// Try to force the stream to go to bad status.
|
||||||
CPPUNIT_ASSERT(!zstream_in.Eof());
|
CPPUNIT_ASSERT(!zstream_in.Eof());
|
||||||
@@ -262,7 +261,7 @@ void zlibStream::Decompress_BadData()
|
|||||||
#if WXWIN_COMPATIBILITY_2_4
|
#if WXWIN_COMPATIBILITY_2_4
|
||||||
void zlibStream::Decompress_wx24Data()
|
void zlibStream::Decompress_wx24Data()
|
||||||
{
|
{
|
||||||
// The wx24_value was used in a wxWidgets 2.4(.2)
|
// The wx24_value was used in a wxWidgets 2.4(.2)
|
||||||
// application to produce wx24_data, using wxZlibOutputStream.
|
// application to produce wx24_data, using wxZlibOutputStream.
|
||||||
const unsigned char wx24_data[] = {120,156,242,72,205,201,201,87,40,207,47,202,73,97,0,0,0,0,255,255,0};
|
const unsigned char wx24_data[] = {120,156,242,72,205,201,201,87,40,207,47,202,73,97,0,0,0,0,255,255,0};
|
||||||
const char *wx24_value = "Hello world";
|
const char *wx24_value = "Hello world";
|
||||||
@@ -324,13 +323,13 @@ const unsigned char *zlibStream::GetCompressedData()
|
|||||||
zstream_out.Write(buf, strlen(buf));
|
zstream_out.Write(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the to the
|
// Copy the to the
|
||||||
m_SizeCompressedData = memstream_out.GetSize();
|
m_SizeCompressedData = memstream_out.GetSize();
|
||||||
m_pCompressedData = new unsigned char[m_SizeCompressedData];
|
m_pCompressedData = new unsigned char[m_SizeCompressedData];
|
||||||
memstream_out.CopyTo(m_pCompressedData, m_SizeCompressedData);
|
memstream_out.CopyTo(m_pCompressedData, m_SizeCompressedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT(m_pCompressedData != NULL);
|
CPPUNIT_ASSERT(m_pCompressedData != NULL);
|
||||||
return m_pCompressedData;
|
return m_pCompressedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +355,7 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
|
|||||||
fstream_out.PutC(' ');
|
fstream_out.PutC(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Part two: Verify that the compressed data when uncompressed
|
{ // Part two: Verify that the compressed data when uncompressed
|
||||||
// matches the original data.
|
// matches the original data.
|
||||||
wxFileInputStream fstream_in(FILENAME_GZ);
|
wxFileInputStream fstream_in(FILENAME_GZ);
|
||||||
CPPUNIT_ASSERT(fstream_in.IsOk());
|
CPPUNIT_ASSERT(fstream_in.IsOk());
|
||||||
@@ -368,7 +367,7 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
|
|||||||
for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
|
for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
|
||||||
{
|
{
|
||||||
last_value = zstream_in.GetC();
|
last_value = zstream_in.GetC();
|
||||||
if (zstream_in.LastRead() != 1 ||
|
if (zstream_in.LastRead() != 1 ||
|
||||||
last_value != pbuf[fail_pos])
|
last_value != pbuf[fail_pos])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -382,7 +381,7 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
|
|||||||
// Check state of the verify action.
|
// Check state of the verify action.
|
||||||
if (fail_pos != DATABUFFER_SIZE || !bWasEOF)
|
if (fail_pos != DATABUFFER_SIZE || !bWasEOF)
|
||||||
{
|
{
|
||||||
wxString msg(wxString::Format(_T("Wrong data item at pos %d (Org_val %d != Zlib_val %d), with compression level %d"),
|
wxString msg(wxString::Format(_T("Wrong data item at pos %d (Org_val %d != Zlib_val %d), with compression level %d"),
|
||||||
fail_pos, GetDataBuffer()[fail_pos], last_value, compress_level));
|
fail_pos, GetDataBuffer()[fail_pos], last_value, compress_level));
|
||||||
CPPUNIT_FAIL(string(msg.mb_str()));
|
CPPUNIT_FAIL(string(msg.mb_str()));
|
||||||
}
|
}
|
||||||
@@ -413,7 +412,7 @@ void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char
|
|||||||
wxLogError(_T("gzip data seems to not be gzip data!"));
|
wxLogError(_T("gzip data seems to not be gzip data!"));
|
||||||
break;
|
break;
|
||||||
case wxZLIB_AUTO:
|
case wxZLIB_AUTO:
|
||||||
if (!(data_size >= 1 && data[0] == 0x78) ||
|
if (!(data_size >= 1 && data[0] == 0x78) ||
|
||||||
!(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
|
!(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
|
||||||
wxLogError(_T("Data seems to not be zlib or gzip data!"));
|
wxLogError(_T("Data seems to not be zlib or gzip data!"));
|
||||||
default:
|
default:
|
||||||
@@ -460,13 +459,13 @@ void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char
|
|||||||
// Move one item along in the stream.
|
// Move one item along in the stream.
|
||||||
(void)zstream_in.GetC();
|
(void)zstream_in.GetC();
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
// Check if we are in an infinite loop by multiplying value_size
|
// Check if we are in an infinite loop by multiplying value_size
|
||||||
// by 5 to have a *much* bigger range then the real range.
|
// by 5 to have a *much* bigger range then the real range.
|
||||||
// Note: Incase you ask your self, why 5, the answer is no reason...
|
// Note: Incase you ask your self, why 5, the answer is no reason...
|
||||||
// it is not to big and not to small a size, nothing more
|
// it is not to big and not to small a size, nothing more
|
||||||
// nothing less to it.
|
// nothing less to it.
|
||||||
if (i > (value_size*5))
|
if (i > (value_size*5))
|
||||||
{
|
{
|
||||||
// Note: Please make sure Input_Eof test passed.
|
// Note: Please make sure Input_Eof test passed.
|
||||||
CPPUNIT_FAIL("Infinite stream detected, breaking the infinite loop");
|
CPPUNIT_FAIL("Infinite stream detected, breaking the infinite loop");
|
||||||
@@ -476,12 +475,12 @@ void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT_MESSAGE("Could not decompress the compressed data, original and restored value did not match.",
|
CPPUNIT_ASSERT_MESSAGE("Could not decompress the compressed data, original and restored value did not match.",
|
||||||
i == value_size && bValueEq);
|
i == value_size && bValueEq);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxZlibInputStream *zlibStream::DoCreateInStream()
|
wxZlibInputStream *zlibStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
const unsigned char *buf = GetCompressedData();
|
const unsigned char *buf = GetCompressedData();
|
||||||
m_pTmpMemInStream = new wxMemoryInputStream(buf, m_SizeCompressedData);
|
m_pTmpMemInStream = new wxMemoryInputStream(buf, m_SizeCompressedData);
|
||||||
CPPUNIT_ASSERT(m_pTmpMemInStream->IsOk());
|
CPPUNIT_ASSERT(m_pTmpMemInStream->IsOk());
|
||||||
@@ -490,20 +489,20 @@ wxZlibInputStream *zlibStream::DoCreateInStream()
|
|||||||
return pzstream_in;
|
return pzstream_in;
|
||||||
}
|
}
|
||||||
wxZlibOutputStream *zlibStream::DoCreateOutStream()
|
wxZlibOutputStream *zlibStream::DoCreateOutStream()
|
||||||
{
|
{
|
||||||
m_pTmpMemOutStream = new wxMemoryOutputStream();
|
m_pTmpMemOutStream = new wxMemoryOutputStream();
|
||||||
CPPUNIT_ASSERT(m_pTmpMemOutStream->IsOk());
|
CPPUNIT_ASSERT(m_pTmpMemOutStream->IsOk());
|
||||||
wxZlibOutputStream *pzstream_out = new wxZlibOutputStream(*m_pTmpMemOutStream);
|
wxZlibOutputStream *pzstream_out = new wxZlibOutputStream(*m_pTmpMemOutStream);
|
||||||
CPPUNIT_ASSERT(pzstream_out->IsOk());
|
CPPUNIT_ASSERT(pzstream_out->IsOk());
|
||||||
return pzstream_out;
|
return pzstream_out;
|
||||||
}
|
}
|
||||||
void zlibStream::DoDeleteInStream()
|
void zlibStream::DoDeleteInStream()
|
||||||
{
|
{
|
||||||
delete m_pTmpMemInStream;
|
delete m_pTmpMemInStream;
|
||||||
m_pTmpMemInStream = NULL;
|
m_pTmpMemInStream = NULL;
|
||||||
}
|
}
|
||||||
void zlibStream::DoDeleteOutStream()
|
void zlibStream::DoDeleteOutStream()
|
||||||
{
|
{
|
||||||
delete m_pTmpMemOutStream;
|
delete m_pTmpMemOutStream;
|
||||||
m_pTmpMemOutStream = NULL;
|
m_pTmpMemOutStream = NULL;
|
||||||
}
|
}
|
||||||
@@ -513,7 +512,7 @@ void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int fl
|
|||||||
{
|
{
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
{ // Gen data
|
{ // Gen data
|
||||||
wxMemoryOutputStream memstream_out;
|
wxMemoryOutputStream memstream_out;
|
||||||
{
|
{
|
||||||
@@ -522,7 +521,7 @@ void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int fl
|
|||||||
}
|
}
|
||||||
if (flag == wxZLIB_NO_HEADER)
|
if (flag == wxZLIB_NO_HEADER)
|
||||||
memstream_out.PutC(' ');
|
memstream_out.PutC(' ');
|
||||||
|
|
||||||
size = memstream_out.GetSize();
|
size = memstream_out.GetSize();
|
||||||
data = new unsigned char[size];
|
data = new unsigned char[size];
|
||||||
memstream_out.CopyTo(data, size);
|
memstream_out.CopyTo(data, size);
|
||||||
@@ -530,7 +529,7 @@ void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int fl
|
|||||||
|
|
||||||
out << _T("void zlibStream::Decompress_wxXXXData()") << _T("\n");
|
out << _T("void zlibStream::Decompress_wxXXXData()") << _T("\n");
|
||||||
out << _T("{") << _T("\n") << _T(" const unsigned char data[] = {");
|
out << _T("{") << _T("\n") << _T(" const unsigned char data[] = {");
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
@@ -538,7 +537,7 @@ void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int fl
|
|||||||
out << wxString::Format(_T("%d,"), data[i]);
|
out << wxString::Format(_T("%d,"), data[i]);
|
||||||
else
|
else
|
||||||
out << wxString::Format(_T("%d"), data[i]);
|
out << wxString::Format(_T("%d"), data[i]);
|
||||||
}
|
}
|
||||||
delete [] data;
|
delete [] data;
|
||||||
|
|
||||||
out << _T("};") << _T("\n");
|
out << _T("};") << _T("\n");
|
||||||
|
@@ -28,8 +28,15 @@
|
|||||||
#include "wx/cppunit.h"
|
#include "wx/cppunit.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using CppUnit::Test;
|
||||||
using namespace CppUnit;
|
using CppUnit::TestSuite;
|
||||||
|
using CppUnit::TestFactoryRegistry;
|
||||||
|
using CppUnit::TextUi::TestRunner;
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::auto_ptr;
|
||||||
|
using std::cout;
|
||||||
|
|
||||||
// The application class
|
// The application class
|
||||||
//
|
//
|
||||||
@@ -66,7 +73,7 @@ TestApp::TestApp()
|
|||||||
bool TestApp::OnInit()
|
bool TestApp::OnInit()
|
||||||
{
|
{
|
||||||
cout << "Test program for wxWidgets\n"
|
cout << "Test program for wxWidgets\n"
|
||||||
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << endl;
|
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << std::endl;
|
||||||
return wxAppConsole::OnInit();
|
return wxAppConsole::OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,7 +107,7 @@ bool TestApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
|||||||
m_registries.push_back(string(parser.GetParam(i).mb_str()));
|
m_registries.push_back(string(parser.GetParam(i).mb_str()));
|
||||||
else
|
else
|
||||||
m_registries.push_back("");
|
m_registries.push_back("");
|
||||||
|
|
||||||
m_longlist = parser.Found(_T("longlist"));
|
m_longlist = parser.Found(_T("longlist"));
|
||||||
m_list = m_longlist || parser.Found(_T("list"));
|
m_list = m_longlist || parser.Found(_T("list"));
|
||||||
|
|
||||||
@@ -112,7 +119,7 @@ bool TestApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
|||||||
//
|
//
|
||||||
int TestApp::OnRun()
|
int TestApp::OnRun()
|
||||||
{
|
{
|
||||||
TextUi::TestRunner runner;
|
TestRunner runner;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_registries.size(); i++) {
|
for (size_t i = 0; i < m_registries.size(); i++) {
|
||||||
auto_ptr<Test> test(m_registries[i].empty() ?
|
auto_ptr<Test> test(m_registries[i].empty() ?
|
||||||
@@ -132,16 +139,15 @@ int TestApp::OnRun()
|
|||||||
|
|
||||||
#if wxUSE_LOG
|
#if wxUSE_LOG
|
||||||
// Switch off logging unless --verbose
|
// Switch off logging unless --verbose
|
||||||
wxLog::EnableLogging(wxLog::GetVerbose());
|
bool verbose = wxLog::GetVerbose();
|
||||||
#endif // wxUSE_LOG
|
wxLog::EnableLogging(verbose);
|
||||||
|
|
||||||
return m_list || runner.run("", false, true,
|
|
||||||
#if wxUSE_LOG
|
|
||||||
!wxLog::GetVerbose()
|
|
||||||
#else
|
#else
|
||||||
true
|
bool verbose = false;
|
||||||
#endif // wxUSE_LOG
|
#endif
|
||||||
) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
|
return ( m_list || runner.run("", false, true, !verbose) )
|
||||||
|
? EXIT_SUCCESS
|
||||||
|
: EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List the tests
|
// List the tests
|
||||||
|
Reference in New Issue
Block a user