2010-08-22 22:16:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/slidertest.cpp
|
|
|
|
// Purpose: wxSlider unit test
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Created: 2010-07-20
|
|
|
|
// 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 );
|
2013-06-11 22:33:00 +00:00
|
|
|
#ifndef __WXOSX__
|
2010-08-22 22:16:05 +00:00
|
|
|
WXUISIM_TEST( PageUpDown );
|
|
|
|
WXUISIM_TEST( LineUpDown );
|
|
|
|
WXUISIM_TEST( LinePageSize );
|
2013-06-11 22:33:00 +00:00
|
|
|
#endif
|
2010-08-22 22:16:05 +00:00
|
|
|
CPPUNIT_TEST( Value );
|
|
|
|
CPPUNIT_TEST( Range );
|
|
|
|
WXUISIM_TEST( Thumb );
|
2010-12-13 18:10:02 +00:00
|
|
|
CPPUNIT_TEST( PseudoTest_Inversed );
|
|
|
|
CPPUNIT_TEST( Value );
|
|
|
|
CPPUNIT_TEST( Range );
|
2010-08-22 22:16:05 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void PageUpDown();
|
|
|
|
void LineUpDown();
|
|
|
|
void LinePageSize();
|
|
|
|
void Value();
|
|
|
|
void Range();
|
|
|
|
void Thumb();
|
2010-12-13 18:10:02 +00:00
|
|
|
void PseudoTest_Inversed() { ms_inversed = true; }
|
|
|
|
|
|
|
|
static bool ms_inversed;
|
2010-08-22 22:16:05 +00:00
|
|
|
|
|
|
|
wxSlider* m_slider;
|
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(SliderTestCase);
|
2010-08-22 22:16:05 +00:00
|
|
|
};
|
|
|
|
|
2010-12-13 18:10:02 +00:00
|
|
|
bool SliderTestCase::ms_inversed = false;
|
|
|
|
|
2010-08-22 22:16:05 +00:00
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
|
|
|
|
|
2011-04-30 10:57:04 +00:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2010-08-22 22:16:05 +00:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
|
|
|
|
|
|
|
|
void SliderTestCase::setUp()
|
|
|
|
{
|
2010-12-13 18:10:02 +00:00
|
|
|
long style = wxSL_HORIZONTAL;
|
|
|
|
|
|
|
|
if ( ms_inversed )
|
|
|
|
style |= wxSL_INVERSE;
|
|
|
|
|
|
|
|
m_slider = new wxSlider(wxTheApp->GetTopWindow(), wxID_ANY, 50, 0, 100,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
style);
|
2010-08-22 22:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SliderTestCase::tearDown()
|
|
|
|
{
|
|
|
|
wxDELETE(m_slider);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderTestCase::PageUpDown()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 14:32:24 +00:00
|
|
|
EventCounter pageup(m_slider, wxEVT_SCROLL_PAGEUP);
|
|
|
|
EventCounter pagedown(m_slider, wxEVT_SCROLL_PAGEDOWN);
|
2010-08-22 22:16:05 +00:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_slider->SetFocus();
|
|
|
|
|
|
|
|
sim.Char(WXK_PAGEUP);
|
|
|
|
sim.Char(WXK_PAGEDOWN);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 14:32:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, pageup.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, pagedown.GetCount());
|
2010-08-22 22:16:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderTestCase::LineUpDown()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 14:32:24 +00:00
|
|
|
EventCounter lineup(m_slider, wxEVT_SCROLL_LINEUP);
|
|
|
|
EventCounter linedown(m_slider, wxEVT_SCROLL_LINEDOWN);
|
2010-08-22 22:16:05 +00:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
2014-09-23 17:43:06 +00:00
|
|
|
wxYield();
|
2010-08-22 22:16:05 +00:00
|
|
|
m_slider->SetFocus();
|
|
|
|
|
|
|
|
sim.Char(WXK_UP);
|
|
|
|
sim.Char(WXK_DOWN);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 14:32:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, lineup.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, linedown.GetCount());
|
2010-08-22 22:16:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderTestCase::LinePageSize()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
wxUIActionSimulator sim;
|
2014-09-23 17:43:06 +00:00
|
|
|
wxYield();
|
2010-08-22 22:16:05 +00:00
|
|
|
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());
|
|
|
|
|
2010-12-13 18:10:02 +00:00
|
|
|
// Changing range shouldn't change the value.
|
|
|
|
m_slider->SetValue(17);
|
|
|
|
m_slider->SetRange(0, 200);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(17, m_slider->GetValue());
|
|
|
|
|
2010-08-22 22:16:05 +00:00
|
|
|
//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__)
|
2012-03-11 14:32:24 +00:00
|
|
|
EventCounter track(m_slider, wxEVT_SCROLL_THUMBTRACK);
|
|
|
|
EventCounter release(m_slider, wxEVT_SCROLL_THUMBRELEASE);
|
|
|
|
EventCounter changed(m_slider, wxEVT_SCROLL_CHANGED);
|
2010-08-22 22:16:05 +00:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_slider->SetValue(0);
|
|
|
|
|
2013-06-13 14:06:02 +00:00
|
|
|
sim.MouseDragDrop(m_slider->ClientToScreen(wxPoint(10, 10)),m_slider->ClientToScreen(wxPoint(50, 10)));
|
2010-08-22 22:16:05 +00:00
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 14:32:24 +00:00
|
|
|
CPPUNIT_ASSERT(track.GetCount() != 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, release.GetCount());
|
2010-08-22 22:16:05 +00:00
|
|
|
#ifdef __WXMSW__
|
2012-03-11 14:32:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
|
2010-08-22 22:16:05 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|