2010-08-22 18:16:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: testableframe.cpp
|
|
|
|
// Purpose: An improved wxFrame for unit-testing
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Copyright: (c) 2010 Steven Lamerton
|
2011-04-04 05:21:52 -04:00
|
|
|
// Licence: wxWindows licence
|
2010-08-22 18:16:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "testableframe.h"
|
|
|
|
|
|
|
|
wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame")
|
|
|
|
{
|
2014-05-27 13:27:10 -04:00
|
|
|
// Use fixed position to facilitate debugging.
|
|
|
|
Move(200, 200);
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxTestableFrame::OnEvent(wxEvent& evt)
|
|
|
|
{
|
|
|
|
m_count[evt.GetEventType()]++;
|
|
|
|
|
|
|
|
if(! evt.IsCommandEvent() )
|
|
|
|
evt.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
int wxTestableFrame::GetEventCount(wxEventType type)
|
|
|
|
{
|
2012-03-11 10:32:24 -04:00
|
|
|
return m_count[type];
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
2010-09-23 12:55:29 -04:00
|
|
|
void wxTestableFrame::ClearEventCount(wxEventType type)
|
|
|
|
{
|
|
|
|
m_count[type] = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type),
|
|
|
|
m_win(win)
|
|
|
|
|
|
|
|
{
|
2012-03-11 10:32:24 -04:00
|
|
|
m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
|
|
|
NULL, m_frame);
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EventCounter::~EventCounter()
|
|
|
|
{
|
2012-03-11 10:32:24 -04:00
|
|
|
m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
|
|
|
NULL, m_frame);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2010-09-23 12:55:29 -04:00
|
|
|
//This stops spurious counts from previous tests
|
2012-03-11 10:32:24 -04:00
|
|
|
Clear();
|
2010-09-23 12:55:29 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
m_frame = NULL;
|
|
|
|
m_win = NULL;
|
|
|
|
}
|