From 7231f2fdf511e3d82bf339bd9357b3f8dd839005 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Jan 2015 22:08:44 +0000 Subject: [PATCH] Improve error reporting from wxTEST_DIALOG() macro. Give the location (i.e. file name, line number and the name of the function) at which this macro itself appears instead of the location of ReportFailure() method inside wxTestingModalHook which was quite useless as it was the same for all the tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/testing.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/include/wx/testing.h b/include/wx/testing.h index 9139e6febd..6a635579fb 100644 --- a/include/wx/testing.h +++ b/include/wx/testing.h @@ -205,7 +205,14 @@ protected: class wxTestingModalHook : public wxModalDialogHook { public: - wxTestingModalHook() + // This object is created with the location of the macro containing it by + // wxTEST_DIALOG macro, otherwise it falls back to the location of this + // line itself, which is not very useful, so normally you should provide + // your own values. + wxTestingModalHook(const char* file = NULL, + int line = 0, + const char* func = NULL) + : m_file(file), m_line(line), m_func(func) { Register(); } @@ -312,10 +319,17 @@ protected: // course, can itself be customized. virtual void ReportFailure(const wxString& msg) { - wxFAIL_MSG( msg ); + wxFAIL_MSG_AT( msg, + m_file ? m_file : __FILE__, + m_line ? m_line : __LINE__, + m_func ? m_func : __WXFUNCTION__ ); } private: + const char* const m_file; + const int m_line; + const char* const m_func; + std::queue m_expectations; wxDECLARE_NO_COPY_CLASS(wxTestingModalHook); @@ -392,7 +406,7 @@ private: #define wxTEST_DIALOG(codeToRun, ...) \ { \ - wxTEST_DIALOG_HOOK_CLASS wx_hook; \ + wxTEST_DIALOG_HOOK_CLASS wx_hook(__FILE__, __LINE__, __WXFUNCTION__); \ wxCALL_FOR_EACH(WX_TEST_IMPL_ADD_EXPECTATION, __VA_ARGS__) \ codeToRun; \ wx_hook.CheckUnmetExpectations(); \