Merge the new GUI tests from SOC2010_GUI_TEST branch.
Add a lot of tests for many wx GUI classes. Add tests using the new wxUIActionSimulator class but disable them under OS X as too many of them currently fail there. Refactor the test suite to make organizing the existing tests and adding the new ones easier. Improve documentation using the information gathered while testing the classes. Also update the documentation of the testing system itself. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65386 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
207
tests/controls/slidertest.cpp
Normal file
207
tests/controls/slidertest.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/controls/slidertest.cpp
|
||||
// Purpose: wxSlider unit test
|
||||
// Author: Steven Lamerton
|
||||
// Created: 2010-07-20
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2010 Steven Lamerton
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#if wxUSE_SLIDER
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/slider.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/uiaction.h"
|
||||
#include "testableframe.h"
|
||||
|
||||
class SliderTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SliderTestCase() { }
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( SliderTestCase );
|
||||
WXUISIM_TEST( PageUpDown );
|
||||
WXUISIM_TEST( LineUpDown );
|
||||
WXUISIM_TEST( LinePageSize );
|
||||
CPPUNIT_TEST( Value );
|
||||
CPPUNIT_TEST( Range );
|
||||
WXUISIM_TEST( Thumb );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void PageUpDown();
|
||||
void LineUpDown();
|
||||
void LinePageSize();
|
||||
void Value();
|
||||
void Range();
|
||||
void Thumb();
|
||||
|
||||
wxSlider* m_slider;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(SliderTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
|
||||
|
||||
// also include in it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
|
||||
|
||||
void SliderTestCase::setUp()
|
||||
{
|
||||
m_slider = new wxSlider(wxTheApp->GetTopWindow(), wxID_ANY, 50, 0, 100);
|
||||
}
|
||||
|
||||
void SliderTestCase::tearDown()
|
||||
{
|
||||
wxDELETE(m_slider);
|
||||
}
|
||||
|
||||
void SliderTestCase::PageUpDown()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
||||
wxTestableFrame);
|
||||
|
||||
EventCounter count(m_slider, wxEVT_SCROLL_PAGEUP);
|
||||
EventCounter count1(m_slider, wxEVT_SCROLL_PAGEDOWN);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
m_slider->SetFocus();
|
||||
|
||||
sim.Char(WXK_PAGEUP);
|
||||
sim.Char(WXK_PAGEDOWN);
|
||||
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEUP));
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEDOWN));
|
||||
#endif
|
||||
}
|
||||
|
||||
void SliderTestCase::LineUpDown()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
||||
wxTestableFrame);
|
||||
|
||||
EventCounter count(m_slider, wxEVT_SCROLL_LINEUP);
|
||||
EventCounter count1(m_slider, wxEVT_SCROLL_LINEDOWN);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
m_slider->SetFocus();
|
||||
|
||||
sim.Char(WXK_UP);
|
||||
sim.Char(WXK_DOWN);
|
||||
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEUP));
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEDOWN));
|
||||
#endif
|
||||
}
|
||||
|
||||
void SliderTestCase::LinePageSize()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
wxUIActionSimulator sim;
|
||||
m_slider->SetFocus();
|
||||
|
||||
m_slider->SetPageSize(20);
|
||||
|
||||
sim.Char(WXK_PAGEUP);
|
||||
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(20, m_slider->GetPageSize());
|
||||
CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
|
||||
|
||||
m_slider->SetLineSize(2);
|
||||
|
||||
sim.Char(WXK_UP);
|
||||
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(2, m_slider->GetLineSize());
|
||||
CPPUNIT_ASSERT_EQUAL(28, m_slider->GetValue());
|
||||
#endif
|
||||
}
|
||||
|
||||
void SliderTestCase::Value()
|
||||
{
|
||||
m_slider->SetValue(30);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
|
||||
|
||||
//When setting a value larger that max or smaller than min
|
||||
//max and min are set
|
||||
m_slider->SetValue(-1);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, m_slider->GetValue());
|
||||
|
||||
m_slider->SetValue(110);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(100, m_slider->GetValue());
|
||||
}
|
||||
|
||||
void SliderTestCase::Range()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin());
|
||||
CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax());
|
||||
|
||||
//Test negative ranges
|
||||
m_slider->SetRange(-50, 0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(-50, m_slider->GetMin());
|
||||
CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMax());
|
||||
}
|
||||
|
||||
void SliderTestCase::Thumb()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
|
||||
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
||||
wxTestableFrame);
|
||||
|
||||
EventCounter count(m_slider, wxEVT_SCROLL_THUMBTRACK);
|
||||
EventCounter count1(m_slider, wxEVT_SCROLL_THUMBRELEASE);
|
||||
EventCounter count2(m_slider, wxEVT_SCROLL_CHANGED);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
m_slider->SetValue(0);
|
||||
|
||||
sim.MouseMove(m_slider->ClientToScreen(wxPoint(10, 10)));
|
||||
wxYield();
|
||||
|
||||
sim.MouseDown();
|
||||
wxYield();
|
||||
|
||||
sim.MouseMove(m_slider->ClientToScreen(wxPoint(50, 10)));
|
||||
wxYield();
|
||||
|
||||
sim.MouseUp();
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_SCROLL_THUMBTRACK) != 0);
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_THUMBRELEASE));
|
||||
#ifdef __WXMSW__
|
||||
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_CHANGED));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user