mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-03-23 10:18:40 +08:00
This is a combination of running clang-tidy with modernize-use-nullptr check for some ports (GTK, X11, OSX) and manual changes to the ports for which it couldn't be used easily (MSW, DFB) and also manually updating the docs. Also replace NULL with null or nullptr in the comments as this is more consistent with the use of nullptr in the code and makes it simpler to grep for the remaining occurrences of NULL itself. And also use null in the assert messages. Only a few occurrences of "NULL" are still left in non-C files, mostly corresponding to unclear comments or string output which it might not be safe to change.
86 lines
1.9 KiB
C++
86 lines
1.9 KiB
C++
///////////////////////////////////////////////////////////////////////////////
|
|
// Name: testableframe.cpp
|
|
// Purpose: An improved wxFrame for unit-testing
|
|
// Author: Steven Lamerton
|
|
// Copyright: (c) 2010 Steven Lamerton
|
|
// Licence: wxWindows licence
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
#include "testprec.h"
|
|
|
|
|
|
#include "wx/app.h"
|
|
#include "testableframe.h"
|
|
|
|
wxTestableFrame::wxTestableFrame() : wxFrame(nullptr, wxID_ANY, wxASCII_STR("Test Frame"))
|
|
{
|
|
// Use fixed position to facilitate debugging.
|
|
Move(200, 200);
|
|
|
|
Show();
|
|
}
|
|
|
|
void wxTestableFrame::OnEvent(wxEvent& evt)
|
|
{
|
|
m_count[evt.GetEventType()]++;
|
|
|
|
if(! evt.IsCommandEvent() )
|
|
evt.Skip();
|
|
}
|
|
|
|
int wxTestableFrame::GetEventCount(wxEventType type)
|
|
{
|
|
return m_count[type];
|
|
}
|
|
|
|
void wxTestableFrame::ClearEventCount(wxEventType type)
|
|
{
|
|
m_count[type] = 0;
|
|
}
|
|
|
|
EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type),
|
|
m_win(win)
|
|
|
|
{
|
|
m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame);
|
|
|
|
m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
|
nullptr, m_frame);
|
|
}
|
|
|
|
EventCounter::~EventCounter()
|
|
{
|
|
m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
|
nullptr, m_frame);
|
|
|
|
//This stops spurious counts from previous tests
|
|
Clear();
|
|
|
|
m_frame = nullptr;
|
|
m_win = nullptr;
|
|
}
|
|
|
|
bool EventCounter::WaitEvent(int timeInMs)
|
|
{
|
|
static const int SINGLE_WAIT_DURATION = 50;
|
|
|
|
for ( int i = 0; i < timeInMs / SINGLE_WAIT_DURATION; ++i )
|
|
{
|
|
wxYield();
|
|
|
|
const int count = GetCount();
|
|
if ( count )
|
|
{
|
|
CHECK( count == 1 );
|
|
|
|
Clear();
|
|
return true;
|
|
}
|
|
|
|
wxMilliSleep(SINGLE_WAIT_DURATION);
|
|
}
|
|
|
|
return false;
|
|
}
|