Make it simpler to write useful tests comparing windows

Allow creating wxWindowPtr from wxScopedPtr<> too, to avoid having to
use .get() in the test code, and add CHECK_SAME_WINDOW() macro which
gives more useful information about the windows in case of failure.
This commit is contained in:
Vadim Zeitlin 2020-09-21 15:52:40 +02:00
parent 1a4f628e40
commit ee55427c28

View File

@ -9,6 +9,7 @@
#ifndef _WX_TESTS_TESTWINDOW_H_
#define _WX_TESTS_TESTWINDOW_H_
#include "wx/scopedptr.h"
#include "wx/window.h"
// We need to wrap wxWindow* in a class as specializing StringMaker for
@ -17,6 +18,8 @@ class wxWindowPtr
{
public:
explicit wxWindowPtr(wxWindow* win) : m_win(win) {}
template <typename W>
explicit wxWindowPtr(const wxScopedPtr<W>& win) : m_win(win.get()) {}
wxString Dump() const
{
@ -44,7 +47,9 @@ private:
// Macro providing more information about the current focus if comparison
// fails.
#define CHECK_FOCUS_IS(w) CHECK(wxWindowPtr(wxWindow::FindFocus()) == wxWindowPtr(w))
#define CHECK_SAME_WINDOW(w1, w2) CHECK(wxWindowPtr(w1) == wxWindowPtr(w2))
#define CHECK_FOCUS_IS(w) CHECK_SAME_WINDOW(wxWindow::FindFocus(), w)
namespace Catch
{