2010-08-22 18:16:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/spinctrldbltest.cpp
|
|
|
|
// Purpose: wxSpinCtrlDouble unit test
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Created: 2010-07-22
|
|
|
|
// Copyright: (c) 2010 Steven Lamerton
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
2020-05-08 02:01:56 -04:00
|
|
|
#if wxUSE_SPINCTRL
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "testableframe.h"
|
|
|
|
#include "wx/uiaction.h"
|
|
|
|
#include "wx/spinctrl.h"
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
class SpinCtrlDoubleTestCase
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
|
|
|
public:
|
2021-04-19 15:57:17 -04:00
|
|
|
SpinCtrlDoubleTestCase(int style = wxSP_ARROW_KEYS)
|
|
|
|
: m_spin(new wxSpinCtrlDouble(wxTheApp->GetTopWindow(), wxID_ANY, "",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
style))
|
|
|
|
{
|
|
|
|
}
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
~SpinCtrlDoubleTestCase()
|
|
|
|
{
|
|
|
|
delete m_spin;
|
|
|
|
}
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
protected:
|
|
|
|
wxSpinCtrlDouble* const m_spin;
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase);
|
|
|
|
};
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
class SpinCtrlDoubleTestCaseWrap : public SpinCtrlDoubleTestCase
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
2021-04-19 15:57:17 -04:00
|
|
|
public:
|
|
|
|
SpinCtrlDoubleTestCaseWrap()
|
|
|
|
: SpinCtrlDoubleTestCase(wxSP_ARROW_KEYS | wxSP_WRAP)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
TEST_CASE("SpinCtrlDouble::NoEventsInCtor", "[spinctrl][spinctrldouble]")
|
2013-08-06 12:59:54 -04:00
|
|
|
{
|
|
|
|
// Verify that creating the control does not generate any events. This is
|
|
|
|
// unexpected and shouldn't happen.
|
2021-04-19 15:57:17 -04:00
|
|
|
wxSpinCtrlDouble *m_spin = new wxSpinCtrlDouble;
|
2013-08-06 12:59:54 -04:00
|
|
|
|
2013-08-06 13:00:00 -04:00
|
|
|
EventCounter updatedSpin(m_spin, wxEVT_SPINCTRLDOUBLE);
|
|
|
|
EventCounter updatedText(m_spin, wxEVT_TEXT);
|
2013-08-06 12:59:54 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
m_spin->Create(wxTheApp->GetTopWindow(), wxID_ANY, "",
|
2013-08-06 12:59:54 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize, 0,
|
|
|
|
0., 100., 17.);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( updatedSpin.GetCount() == 0 );
|
|
|
|
CHECK( updatedText.GetCount() == 0 );
|
2013-08-06 12:59:54 -04:00
|
|
|
}
|
|
|
|
|
2020-05-06 21:45:17 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2021-04-19 15:57:17 -04:00
|
|
|
|
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
|
|
|
"SpinCtrlDouble::Arrows", "[spinctrl][spinctrldouble]")
|
|
|
|
{
|
2013-04-25 06:11:03 -04:00
|
|
|
EventCounter updated(m_spin, wxEVT_SPINCTRLDOUBLE);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_spin->SetFocus();
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.Char(WXK_UP);
|
|
|
|
wxYield();
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( updated.GetCount() == 1 );
|
|
|
|
CHECK( m_spin->GetValue() == 1.0 );
|
2012-03-11 10:32:24 -04:00
|
|
|
updated.Clear();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.Char(WXK_DOWN);
|
|
|
|
wxYield();
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( updated.GetCount() == 1 );
|
|
|
|
CHECK( m_spin->GetValue() == 0.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCaseWrap,
|
|
|
|
"SpinCtrlDouble::Wrap", "[spinctrl][spinctrldouble]")
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_spin->SetFocus();
|
2014-09-23 13:41:06 -04:00
|
|
|
wxYield();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.Char(WXK_DOWN);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 100.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.Char(WXK_UP);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 0.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
2021-04-19 15:57:17 -04:00
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
|
|
|
"SpinCtrlDouble::Range", "[spinctrl][spinctrldouble]")
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetMin() == 0.0 );
|
|
|
|
CHECK( m_spin->GetMax() == 100.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2013-08-06 13:00:00 -04:00
|
|
|
// Test that the value is adjusted to be inside the new valid range but
|
|
|
|
// that this doesn't result in any events (as this is not something done by
|
|
|
|
// the user).
|
|
|
|
{
|
|
|
|
EventCounter updatedSpin(m_spin, wxEVT_SPINCTRLDOUBLE);
|
|
|
|
EventCounter updatedText(m_spin, wxEVT_TEXT);
|
|
|
|
|
|
|
|
m_spin->SetRange(1., 10.);
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 1. );
|
2013-08-06 13:00:00 -04:00
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( updatedSpin.GetCount() == 0 );
|
|
|
|
CHECK( updatedText.GetCount() == 0 );
|
2013-08-06 13:00:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//Test negative ranges
|
2010-08-22 18:16:05 -04:00
|
|
|
m_spin->SetRange(-10.0, 10.0);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetMin() == -10.0 );
|
|
|
|
CHECK( m_spin->GetMax() == 10.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
//Test backwards ranges
|
|
|
|
m_spin->SetRange(75.0, 50.0);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetMin() == 75.0 );
|
|
|
|
CHECK( m_spin->GetMax() == 50.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
|
|
|
"SpinCtrlDouble::Value", "[spinctrl][spinctrldouble]")
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
2013-08-06 13:00:00 -04:00
|
|
|
EventCounter updatedSpin(m_spin, wxEVT_SPINCTRLDOUBLE);
|
|
|
|
EventCounter updatedText(m_spin, wxEVT_TEXT);
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
m_spin->SetDigits(2);
|
|
|
|
m_spin->SetIncrement(0.1);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 0.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_spin->SetValue(50.0);
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 50.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_spin->SetValue(49.1);
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 49.1 );
|
2013-08-06 13:00:00 -04:00
|
|
|
|
|
|
|
// Calling SetValue() shouldn't have generated any events.
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( updatedSpin.GetCount() == 0 );
|
|
|
|
CHECK( updatedText.GetCount() == 0 );
|
2021-04-19 18:55:02 -04:00
|
|
|
|
|
|
|
// Also test that setting the text value works.
|
|
|
|
CHECK( m_spin->GetTextValue() == "49.10" );
|
|
|
|
|
|
|
|
m_spin->SetValue("57.30");
|
|
|
|
CHECK( m_spin->GetTextValue() == "57.30" );
|
|
|
|
CHECK( m_spin->GetValue() == 57.3 );
|
|
|
|
|
|
|
|
m_spin->SetValue("");
|
|
|
|
CHECK( m_spin->GetTextValue() == "" );
|
|
|
|
CHECK( m_spin->GetValue() == 57.3 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
2020-05-06 21:45:17 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2021-04-19 15:57:17 -04:00
|
|
|
|
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
|
|
|
"SpinCtrlDouble::Increment", "[spinctrl][spinctrldouble]")
|
|
|
|
{
|
|
|
|
CHECK( m_spin->GetIncrement() == 1.0 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2020-05-18 14:23:41 -04:00
|
|
|
m_spin->SetDigits(1);
|
2010-08-22 18:16:05 -04:00
|
|
|
m_spin->SetIncrement(0.1);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetIncrement() == 0.1 );
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_spin->SetFocus();
|
2014-09-23 13:41:06 -04:00
|
|
|
wxYield();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.Char(WXK_UP);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetValue() == 0.1 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
|
|
|
"SpinCtrlDouble::Digits", "[spinctrl][spinctrldouble]")
|
2010-08-22 18:16:05 -04:00
|
|
|
{
|
|
|
|
m_spin->SetDigits(5);
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
CHECK( m_spin->GetDigits() == 5 );
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
2020-05-08 02:01:56 -04:00
|
|
|
|
2020-05-18 12:55:22 -04:00
|
|
|
static inline unsigned int GetInitialDigits(double inc)
|
|
|
|
{
|
|
|
|
wxSpinCtrlDouble* sc = new wxSpinCtrlDouble(wxTheApp->GetTopWindow(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS,
|
|
|
|
0, 50, 0, inc);
|
|
|
|
unsigned int digits = sc->GetDigits();
|
|
|
|
delete sc;
|
|
|
|
return digits;
|
|
|
|
}
|
|
|
|
|
2021-04-19 15:57:17 -04:00
|
|
|
TEST_CASE("SpinCtrlDouble::InitialDigits", "[spinctrldouble][initialdigits]")
|
2020-05-18 12:55:22 -04:00
|
|
|
{
|
|
|
|
REQUIRE(GetInitialDigits(15) == 0);
|
|
|
|
REQUIRE(GetInitialDigits(10) == 0);
|
|
|
|
REQUIRE(GetInitialDigits(1) == 0);
|
|
|
|
REQUIRE(GetInitialDigits(0.999) == 1);
|
|
|
|
REQUIRE(GetInitialDigits(0.15) == 1);
|
|
|
|
REQUIRE(GetInitialDigits(0.11) == 1);
|
|
|
|
REQUIRE(GetInitialDigits(0.1) == 1);
|
|
|
|
REQUIRE(GetInitialDigits(0.0999) == 2);
|
|
|
|
REQUIRE(GetInitialDigits(0.015) == 2);
|
|
|
|
REQUIRE(GetInitialDigits(0.011) == 2);
|
|
|
|
REQUIRE(GetInitialDigits(0.01) == 2);
|
|
|
|
REQUIRE(GetInitialDigits(9.99e-5) == 5);
|
|
|
|
REQUIRE(GetInitialDigits(1e-5) == 5);
|
|
|
|
REQUIRE(GetInitialDigits(9.9999e-10) == 10);
|
|
|
|
REQUIRE(GetInitialDigits(1e-10) == 10);
|
|
|
|
REQUIRE(GetInitialDigits(9.9999e-20) == 20);
|
|
|
|
REQUIRE(GetInitialDigits(1e-20) == 20);
|
|
|
|
REQUIRE(GetInitialDigits(9.9999e-21) == 20);
|
|
|
|
REQUIRE(GetInitialDigits(1e-21) == 20);
|
|
|
|
REQUIRE(GetInitialDigits(9.9999e-22) == 20);
|
|
|
|
REQUIRE(GetInitialDigits(1e-22) == 20);
|
|
|
|
}
|
|
|
|
|
2020-05-08 02:01:56 -04:00
|
|
|
#endif
|