From e3f579ae9dc5e2cb734b31c294a2276ad76ad6a4 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Sun, 27 Feb 2011 17:38:44 +0000 Subject: [PATCH] Format-safe printing in the unittests There was no real need for a printf-like function. Worse, if the string to be printed contained unexpected format specifiers, the result was undefined. --- .svn-revision | 2 +- unittests/muleunit/test.cpp | 2 +- unittests/muleunit/test.h | 11 +++-------- unittests/muleunit/testcase.cpp | 11 +++++------ 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.svn-revision b/.svn-revision index e73dda0f..71538ce2 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10456 +10458 diff --git a/unittests/muleunit/test.cpp b/unittests/muleunit/test.cpp index 222f421b..3779f8c0 100644 --- a/unittests/muleunit/test.cpp +++ b/unittests/muleunit/test.cpp @@ -77,7 +77,7 @@ void CTestFailureException::PrintBT() const for (; it != m_bt->snapshot.end(); ++it) { indent += ' '; - Printf(indent + it->file + wxT(":%i -- ") + it->msg, it->line); + Print(indent + it->file + wxString::Format(wxT(":%i -- "), it->line) + it->msg); } } diff --git a/unittests/muleunit/test.h b/unittests/muleunit/test.h index 2429a402..79bd2457 100644 --- a/unittests/muleunit/test.h +++ b/unittests/muleunit/test.h @@ -48,15 +48,10 @@ inline size_t ArraySize(T(&)[N]) } -/** Printf for wide-char strings. */ -inline void Printf(const wxChar *pszFormat, ...) +/** Print wide-char strings. */ +inline void Print(const wxString& str) { - va_list argptr; - va_start(argptr, pszFormat); - - wxPuts(wxString::FormatV(pszFormat, argptr).c_str()); - - va_end(argptr); + wxPuts(str.c_str()); } diff --git a/unittests/muleunit/testcase.cpp b/unittests/muleunit/testcase.cpp index 96bd76b3..4acf48c9 100644 --- a/unittests/muleunit/testcase.cpp +++ b/unittests/muleunit/testcase.cpp @@ -60,8 +60,7 @@ const wxString& TestCase::getName() const bool TestCase::run() { - Printf(wxT("\nRunning test-collection \"") + m_name + wxT("\" with %u test-cases:"), - m_tests.size()); + Print(wxT("\nRunning test-collection \"") + m_name + wxString::Format(wxT("\" with %u test-cases:"), m_tests.size())); bool failures = false; @@ -69,7 +68,7 @@ bool TestCase::run() for (; it != m_tests.end(); ++it) { Test* test = *it; - Printf(wxT("\tTest \"") + test->getTestName() + wxT("\" ")); + Print(wxT("\tTest \"") + test->getTestName() + wxT("\" ")); bool wasSetup = false; try { @@ -77,7 +76,7 @@ bool TestCase::run() wasSetup = true; } catch (const CTestFailureException& e) { failures = true; - Printf(wxT("\t\tFailure in setUp:\n")); + Print(wxT("\t\tFailure in setUp:\n")); e.PrintBT(); } @@ -88,7 +87,7 @@ bool TestCase::run() test->run(); } catch (const CTestFailureException& e) { failures = true; - Printf(wxT("\t\tFailure running:")); + Print(wxT("\t\tFailure running:")); e.PrintBT(); } } @@ -97,7 +96,7 @@ bool TestCase::run() test->tearDown(); } catch (const CTestFailureException& e) { failures = true; - Printf(wxT("\t\tFailure in tearDown:")); + Print(wxT("\t\tFailure in tearDown:")); e.PrintBT(); } } -- 2.11.4.GIT