X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9e994615409e36d441135e4fa0761cf0398a2aa..ded2661ab0b63742ea3bc612164e5a8120a649ec:/tests/regex/regextest.cpp?ds=inline diff --git a/tests/regex/regextest.cpp b/tests/regex/regextest.cpp index 261435e8ed..e5a0c89f3d 100644 --- a/tests/regex/regextest.cpp +++ b/tests/regex/regextest.cpp @@ -15,22 +15,22 @@ // // To run all the regex tests: // test regex -// +// // 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 // turn on verbose logging, e.g.: // test --verbose regex -// +// // The tests here are for the builtin library, tests for wxRegEx in general // should go in wxregex.cpp // // 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++ // include file 'regex.inc' (included below) using a script 'regex.pl'. -// +// // For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" +#include "testprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -41,18 +41,23 @@ #include "wx/wx.h" #endif -#include "wx/regex.h" -#include "wx/cppunit.h" -#include - -using namespace std; -using namespace CppUnit; // many of the tests are specific to the builtin regex lib, so only attempts // to do them when using the builtin regex lib. // #ifdef wxHAS_REGEX_ADVANCED +#include "wx/regex.h" +#include +#include + +using CppUnit::Test; +using CppUnit::TestCase; +using CppUnit::TestSuite; +using CppUnit::Exception; + +using std::string; +using std::vector; /////////////////////////////////////////////////////////////////////////////// // The test case - an instance represents a single test @@ -127,7 +132,8 @@ RegExTestCase::RegExTestCase( m_advanced(false) { bool badconv = m_pattern == convError() || m_data == convError(); - vector::const_iterator it; + //RN: Removing the std:: here will break MSVC6 compilation + std::vector::const_iterator it; for (it = expected.begin(); it != expected.end(); ++it) { m_expected.push_back(Conv(*it)); @@ -135,7 +141,7 @@ RegExTestCase::RegExTestCase( } failIf(badconv, _T("cannot convert to default character encoding")); - + // the flags need further parsing... parseFlags(m_flags); @@ -148,11 +154,11 @@ int wxWcscmp(const wchar_t* s1, const wchar_t* s2) { size_t nLen1 = wxWcslen(s1); size_t nLen2 = wxWcslen(s2); - + if (nLen1 != nLen2) return nLen1 - nLen2; - - return wxMemcmp(s1, s2, nLen1); + + return wxTmemcmp(s1, s2, nLen1); } // convert a string from UTF8 to the internal encoding @@ -221,7 +227,7 @@ void RegExTestCase::runTest() doTest(wxRE_ADVANCED); #endif } - + // Try the test for a single flavour of expression // void RegExTestCase::doTest(int flavor) @@ -250,16 +256,18 @@ void RegExTestCase::doTest(int flavor) return; // check wxRegEx has correctly counted the number of subexpressions - failIf(m_expected.size() != re.GetMatchCount(), - wxString::Format(_T("GetMatchCount() == %d, expected %d"), - re.GetMatchCount(), m_expected.size())); - - wxString result; - size_t start, len; + wxString msg; + msg << _T("GetMatchCount() == ") << re.GetMatchCount() + << _T(", expected ") << m_expected.size(); + failIf(m_expected.size() != re.GetMatchCount(), msg); for (size_t i = 0; i < m_expected.size(); i++) { - failIf(!re.GetMatch(&start, &len, i), wxString::Format( - _T("wxRegEx::GetMatch failed for match %d"), i)); + wxString result; + size_t start, len; + + msg.clear(); + msg << _T("wxRegEx::GetMatch failed for match ") << i; + failIf(!re.GetMatch(&start, &len, i), msg); // m - check the match returns the strings given if (m_mode == 'm') @@ -270,14 +278,17 @@ void RegExTestCase::doTest(int flavor) // i - check the match returns the offsets given else if (m_mode == 'i') - if (start < INT_MAX) - result = wxString::Format(_T("%d %d"), start, start + len - 1); - else + if (start > INT_MAX) result = _T("-1 -1"); + else if (start + len > 0) + result << start << _T(" ") << start + len - 1; + else + result << start << _T(" -1"); - failIf(result != m_expected[i], wxString::Format( - _T("match(%d) == %s, expected == %s"), i, - quote(result).c_str(), quote(m_expected[i]).c_str())); + msg.clear(); + msg << _T("match(") << i << _T(") == ") << quote(result) + << _T(", expected == ") << quote(m_expected[i]); + failIf(result != m_expected[i], msg); } } @@ -293,7 +304,7 @@ void RegExTestCase::fail(const wxString& msg) const for (it = m_expected.begin(); it != m_expected.end(); ++it) str << _T(" ") << quote(*it); - + if (str.length() > 77) str = str.substr(0, 74) + _T("..."); @@ -314,7 +325,7 @@ wxString RegExTestCase::quote(const wxString& arg) for (size_t i = 0; i < arg.length(); i++) { wxUChar ch = arg[i]; const wxChar *p = wxStrchr(needEscape, ch); - + if (p) str += wxString::Format(_T("\\%c"), escapes[p - needEscape]); else if (wxIscntrl(ch)) @@ -358,7 +369,7 @@ void RegExTestSuite::add( expected_results.push_back(expected); va_end(ap); - + try { addTest(new RegExTestCase( name, mode, id, flags, pattern, data, expected_results));