From 3feea201da74fc4357ebbe65358625f13f9e83d2 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 12 Jul 2020 15:55:35 +0200 Subject: [PATCH] Add tests of setting wxSpinCtrl base and range --- tests/controls/spinctrltest.cpp | 67 ++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/controls/spinctrltest.cpp b/tests/controls/spinctrltest.cpp index 19d95c99fe..e4c94e313e 100644 --- a/tests/controls/spinctrltest.cpp +++ b/tests/controls/spinctrltest.cpp @@ -199,6 +199,7 @@ TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Range", "[spinctrl]") { CHECK(m_spin->GetMin() == 0); CHECK(m_spin->GetMax() == 100); + CHECK(m_spin->GetBase() == 10); // 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 @@ -214,12 +215,36 @@ TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Range", "[spinctrl]") CHECK(updatedText.GetCount() == 0); } - //Test negative ranges + // Test negative ranges m_spin->SetRange(-10, 10); CHECK(m_spin->GetMin() == -10); CHECK(m_spin->GetMax() == 10); + // With base 16 only ranges including values >= 0 are allowed + m_spin->SetRange(0, 10); + int oldMinVal = m_spin->GetMin(); + int oldMaxVal = m_spin->GetMax(); + CHECK(oldMinVal == 0); + CHECK(oldMaxVal == 10); + + CHECK(m_spin->SetBase(16) == true); + CHECK(m_spin->GetBase() == 16); + + // New range should be silently ignored + m_spin->SetRange(-20, 20); + CHECK(m_spin->GetMin() == oldMinVal); + CHECK(m_spin->GetMax() == oldMaxVal); + + // This range should be accepted + m_spin->SetRange(2, 8); + CHECK(m_spin->GetMin() == 2); + CHECK(m_spin->GetMax() == 8); + + CHECK(m_spin->SetBase(10) == true); + + CHECK(m_spin->GetBase() == 10); + //Test backwards ranges m_spin->SetRange(75, 50); @@ -248,6 +273,46 @@ TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Value", "[spinctrl]") CHECK(updatedText.GetCount() == 0); } +TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Base`", "[spinctrl]") +{ + CHECK(m_spin->GetMin() == 0); + CHECK(m_spin->GetMax() == 100); + CHECK(m_spin->GetBase() == 10); + + // Only 10 and 16 bases are allowed + CHECK(m_spin->SetBase(10) == true); + CHECK(m_spin->GetBase() == 10); + + CHECK_FALSE(m_spin->SetBase(8)); + CHECK(m_spin->GetBase() == 10); + + CHECK_FALSE(m_spin->SetBase(2)); + CHECK(m_spin->GetBase() == 10); + + CHECK(m_spin->SetBase(16) == true); + CHECK(m_spin->GetBase() == 16); + + CHECK(m_spin->SetBase(10) == true); + CHECK(m_spin->GetBase() == 10); + + // When range contains negative values only base 10 is allowed + m_spin->SetRange(-10, 10); + CHECK(m_spin->GetMin() == -10); + CHECK(m_spin->GetMax() == 10); + + CHECK_FALSE(m_spin->SetBase(8)); + CHECK(m_spin->GetBase() == 10); + + CHECK_FALSE(m_spin->SetBase(2)); + CHECK(m_spin->GetBase() == 10); + + CHECK_FALSE(m_spin->SetBase(16)); + CHECK(m_spin->GetBase() == 10); + + CHECK(m_spin->SetBase(10) == true); + CHECK(m_spin->GetBase() == 10); +} + TEST_CASE_METHOD(SpinCtrlTestCase3, "SpinCtrl::SetValueInsideEventHandler", "[spinctrl]") { #if wxUSE_UIACTIONSIMULATOR