From 9ae625518db2961df172e34d111d87b8a3531742 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Jan 2015 22:09:00 +0000 Subject: [PATCH] Use C++ RTTI in dialog testing code if wxRTTI is not available. This allows to get the best possible description of the dialog: if its class uses wxRTTI macros, its user-readable name will be used, but otherwise we now fall back on possibly unreadable but still informative mangled C++ class name rather than showing just "wxDialog" which is not useful at all. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78415 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/testing.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/include/wx/testing.h b/include/wx/testing.h index 751a223ff5..891ec0fc40 100644 --- a/include/wx/testing.h +++ b/include/wx/testing.h @@ -34,8 +34,31 @@ class WXDLLIMPEXP_FWD_CORE wxFileDialogBase; #include "wx/msgdlg.h" #include "wx/filedlg.h" +#include + class wxTestingModalHook; +// This helper is used to construct the best possible name for the dialog of +// the given type using wxRTTI for this type, if any, and the C++ RTTI for +// either the type T statically or the dynamic type of "dlg" if it's non-null. +template +wxString wxGetDialogClassDescription(const wxClassInfo *ci, T* dlg = NULL) +{ + // We prefer to use the name from wxRTTI as it's guaranteed to be readable, + // unlike the name returned by type_info::name() which may need to be + // demangled, but if wxRTTI macros were not used for this object, it's + // better to return a not-very-readable-but-informative mangled name rather + // than a readable but useless "wxDialog". + if ( ci == wxCLASSINFO(wxDialog) ) + { + return wxString::Format("dialog of type \"%s\"", + (dlg ? typeid(*dlg) : typeid(T)).name()); + } + + // We consider that an unmangled name is clear enough to be used on its own. + return ci->GetClassName(); +} + // Non-template base class for wxExpectModal (via wxExpectModalBase). // Only used internally. class wxModalExpectation @@ -127,7 +150,7 @@ protected: /// Returns description of the expected dialog (by default, its class). virtual wxString GetDefaultDescription() const { - return wxCLASSINFO(T)->GetClassName(); + return wxGetDialogClassDescription(wxCLASSINFO(T)); } /** @@ -363,7 +386,7 @@ protected: return wxString::Format ( "A %s with title \"%s\"", - dlg->GetClassInfo()->GetClassName(), + wxGetDialogClassDescription(dlg->GetClassInfo(), dlg), dlg->GetTitle() ); }