File: testableframe.h

package info (click to toggle)
wxwidgets3.2 3.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 179,460 kB
  • sloc: cpp: 992,335; ansic: 102,143; makefile: 51,623; sh: 11,572; python: 5,590; perl: 1,563; php: 326; xml: 200; javascript: 181
file content (49 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download
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
///////////////////////////////////////////////////////////////////////////////
// Name:        testableframe.h
// Purpose:     An improved wxFrame for unit-testing
// Author:      Steven Lamerton
// Copyright:   (c) 2010 Steven Lamerton
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#include "wx/frame.h"
#include "wx/hashmap.h"
#include "wx/event.h"

class wxTestableFrame : public wxFrame
{
public:
    wxTestableFrame();

    void OnEvent(wxEvent& evt);

private:
    friend class EventCounter;

    int GetEventCount(wxEventType type);
    void ClearEventCount(wxEventType type);

    wxLongToLongHashMap m_count;
};

class EventCounter
{
public:
    EventCounter(wxWindow* win, wxEventType type);
    ~EventCounter();

    int GetCount() { return m_frame->GetEventCount(m_type); }
    void Clear() { m_frame->ClearEventCount(m_type); }

    // Sometimes we need to yield a few times before getting the event we
    // expect, so provide a function waiting for the expected event for up to
    // the given number of milliseconds (supposed to be divisible by 50).
    //
    // Return true if we did receive the event or false otherwise.
    bool WaitEvent(int timeInMs = 10000);

private:
    wxEventType m_type;
    wxTestableFrame* m_frame;
    wxWindow* m_win;
};