]>
Commit | Line | Data |
---|---|---|
232fdc63 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: testableframe.cpp | |
3 | // Purpose: An improved wxFrame for unit-testing | |
4 | // Author: Steven Lamerton | |
232fdc63 | 5 | // Copyright: (c) 2010 Steven Lamerton |
3fdcd5d5 | 6 | // Licence: wxWindows licence |
232fdc63 VZ |
7 | /////////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | // For compilers that support precompilation, includes "wx/wx.h". | |
10 | #include "testprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
13 | #pragma hdrstop | |
14 | #endif | |
15 | ||
16 | #include "wx/app.h" | |
17 | #include "testableframe.h" | |
18 | ||
19 | wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame") | |
20 | { | |
21 | } | |
22 | ||
23 | void wxTestableFrame::OnEvent(wxEvent& evt) | |
24 | { | |
25 | m_count[evt.GetEventType()]++; | |
26 | ||
27 | if(! evt.IsCommandEvent() ) | |
28 | evt.Skip(); | |
29 | } | |
30 | ||
31 | int wxTestableFrame::GetEventCount(wxEventType type) | |
32 | { | |
744d91d4 | 33 | return m_count[type]; |
232fdc63 VZ |
34 | } |
35 | ||
4ceca854 SL |
36 | void wxTestableFrame::ClearEventCount(wxEventType type) |
37 | { | |
38 | m_count[type] = 0; | |
39 | } | |
40 | ||
232fdc63 VZ |
41 | EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type), |
42 | m_win(win) | |
43 | ||
44 | { | |
744d91d4 | 45 | m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame); |
232fdc63 | 46 | |
744d91d4 SL |
47 | m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent), |
48 | NULL, m_frame); | |
232fdc63 VZ |
49 | } |
50 | ||
51 | EventCounter::~EventCounter() | |
52 | { | |
744d91d4 SL |
53 | m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent), |
54 | NULL, m_frame); | |
232fdc63 | 55 | |
4ceca854 | 56 | //This stops spurious counts from previous tests |
744d91d4 | 57 | Clear(); |
4ceca854 | 58 | |
232fdc63 VZ |
59 | m_frame = NULL; |
60 | m_win = NULL; | |
61 | } |