]>
git.saurik.com Git - wxWidgets.git/blob - tests/testableframe.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: testableframe.cpp
3 // Purpose: An improved wxFrame for unit-testing
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "testableframe.h"
20 wxTestableFrame::wxTestableFrame() : wxFrame(NULL
, wxID_ANY
, "Test Frame")
24 void wxTestableFrame::OnEvent(wxEvent
& evt
)
26 m_count
[evt
.GetEventType()]++;
28 if(! evt
.IsCommandEvent() )
32 int wxTestableFrame::GetEventCount(wxEventType type
)
34 if (type
== wxEVT_ANY
)
36 //Get the total event count
39 for(wxLongToLongHashMap::iterator iter
= m_count
.begin();
40 iter
!= m_count
.end();
43 total
+= iter
->second
;
51 long count
= m_count
[type
];
57 void wxTestableFrame::ClearEventCount(wxEventType type
)
62 EventCounter::EventCounter(wxWindow
* win
, wxEventType type
) : m_type(type
),
66 m_frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
69 m_win
->Connect(m_type
,
70 wxEventHandler(wxTestableFrame::OnEvent
),
75 EventCounter::~EventCounter()
77 m_win
->Disconnect(m_type
,
78 wxEventHandler(wxTestableFrame::OnEvent
),
82 //This stops spurious counts from previous tests
83 m_frame
->ClearEventCount(m_type
);