X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c602c59b6e623d7775c16ce6412b64b34dc5dd94..3c3ead1d1513a5eb79091a604f4e42b45d1bdf5d:/tests/log/logtest.cpp?ds=sidebyside diff --git a/tests/log/logtest.cpp b/tests/log/logtest.cpp index 0334bc6d63..8c24835b43 100644 --- a/tests/log/logtest.cpp +++ b/tests/log/logtest.cpp @@ -19,6 +19,7 @@ #ifndef WX_PRECOMP #include "wx/log.h" + #include "wx/filefn.h" #endif // WX_PRECOMP #include "wx/scopeguard.h" @@ -168,6 +169,7 @@ private: CPPUNIT_TEST( CompatLogger ); CPPUNIT_TEST( CompatLogger2 ); #endif // WXWIN_COMPATIBILITY_2_8 + CPPUNIT_TEST( SysError ); CPPUNIT_TEST_SUITE_END(); void Functions(); @@ -180,6 +182,7 @@ private: void CompatLogger(); void CompatLogger2(); #endif // WXWIN_COMPATIBILITY_2_8 + void SysError(); TestLog *m_log; wxLog *m_logOld; @@ -273,22 +276,40 @@ void LogTestCase::Component() #if wxDEBUG_LEVEL +namespace +{ + +const char *TEST_MASK = "test"; + +// this is a test vararg function (a real one, not a variadic-template-like as +// wxVLogTrace(), so care should be taken with its arguments) +void TraceTest(const char *format, ...) +{ + va_list argptr; + va_start(argptr, format); + wxVLogTrace(TEST_MASK, format, argptr); + va_end(argptr); +} + +} // anonymous namespace + void LogTestCase::Trace() { - static const char *TEST_MASK = "test"; + // we use wxLogTrace() or wxVLogTrace() from inside TraceTest() + // interchangeably here, it shouldn't make any difference wxLogTrace(TEST_MASK, "Not shown"); CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) ); wxLog::AddTraceMask(TEST_MASK); - wxLogTrace(TEST_MASK, "Shown"); + TraceTest("Shown"); CPPUNIT_ASSERT_EQUAL( wxString::Format("(%s) Shown", TEST_MASK), m_log->GetLog(wxLOG_Trace) ); wxLog::RemoveTraceMask(TEST_MASK); m_log->Clear(); - wxLogTrace(TEST_MASK, "Not shown again"); + TraceTest("Not shown again"); CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) ); } @@ -317,3 +338,21 @@ void LogTestCase::CompatLogger2() } #endif // WXWIN_COMPATIBILITY_2_8 + +void LogTestCase::SysError() +{ + wxString s; + wxLogSysError("Success"); + CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Success (", &s) ); + CPPUNIT_ASSERT( s.StartsWith("error 0") ); + + wxLogSysError(17, "Error"); + CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Error (", &s) ); + CPPUNIT_ASSERT( s.StartsWith("error 17") ); + + wxOpen("no-such-file", 0, 0); + wxLogSysError("Not found"); + CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Not found (", &s) ); + WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 2") ); +} +