File: testwindow.h

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (66 lines) | stat: -rw-r--r-- 1,765 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/testwindow.h
// Purpose:     Unit test helper for comparing wxWindow pointers.
// Author:      Vadim Zeitlin
// Copyright:   (c) 2019 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#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
// wxWindow* doesn't seem to work.
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
    {
        if ( !m_win )
            return "(no window)";

        wxString s = m_win->GetClassInfo()->GetClassName();
        const wxString& label = m_win->GetLabel();
        if ( !label.empty() )
        {
            s += wxString::Format(" (label=\"%s\")", label);
        }

        return s;
    }

private:
    friend bool operator==(wxWindowPtr wp1, wxWindowPtr wp2)
    {
        return wp1.m_win == wp2.m_win;
    }

    wxWindow* const m_win;
};

// Macro providing more information about the current focus if comparison
// fails.
#define CHECK_SAME_WINDOW(w1, w2) CHECK(wxWindowPtr(w1) == wxWindowPtr(w2))

#define CHECK_FOCUS_IS(w) CHECK_SAME_WINDOW(wxWindow::FindFocus(), w)

namespace Catch
{
    template <>
    struct StringMaker<wxWindowPtr>
    {
        static std::string convert(const wxWindowPtr window)
        {
            return window.Dump().ToStdString();
        }
    };
}

#endif // _WX_TESTS_TESTWINDOW_H_