initial commit
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
435
libs/wxWidgets-3.3.1/tests/validators/valnum.cpp
Normal file
435
libs/wxWidgets-3.3.1/tests/validators/valnum.cpp
Normal file
@@ -0,0 +1,435 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/validators/valnum.cpp
|
||||
// Purpose: Unit tests for numeric validators.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-01-18
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/textctrl.h"
|
||||
#include "wx/validate.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/valnum.h"
|
||||
|
||||
#include "asserthelper.h"
|
||||
#include "testableframe.h"
|
||||
|
||||
#include "wx/scopeguard.h"
|
||||
#include "wx/uiaction.h"
|
||||
|
||||
#include "waitfor.h"
|
||||
|
||||
class NumValidatorTestCase
|
||||
{
|
||||
public:
|
||||
NumValidatorTestCase();
|
||||
~NumValidatorTestCase();
|
||||
|
||||
protected:
|
||||
wxTextCtrl* const m_text;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(NumValidatorTestCase);
|
||||
};
|
||||
|
||||
NumValidatorTestCase::NumValidatorTestCase()
|
||||
: m_text(new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY))
|
||||
{
|
||||
}
|
||||
|
||||
NumValidatorTestCase::~NumValidatorTestCase()
|
||||
{
|
||||
delete m_text;
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::TransferInt", "[valnum]")
|
||||
{
|
||||
int value = 0;
|
||||
wxIntegerValidator<int> valInt(&value);
|
||||
valInt.SetWindow(m_text);
|
||||
|
||||
CHECK( valInt.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "0" );
|
||||
|
||||
value = 17;
|
||||
CHECK( valInt.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "17" );
|
||||
|
||||
|
||||
m_text->ChangeValue("foobar");
|
||||
CHECK( !valInt.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("-234");
|
||||
CHECK( valInt.TransferFromWindow() );
|
||||
CHECK( value == -234 );
|
||||
|
||||
m_text->ChangeValue("9223372036854775808"); // == LLONG_MAX + 1
|
||||
CHECK( !valInt.TransferFromWindow() );
|
||||
|
||||
m_text->Clear();
|
||||
CHECK( !valInt.TransferFromWindow() );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::TransferUnsigned", "[valnum]")
|
||||
{
|
||||
unsigned value = 0;
|
||||
wxIntegerValidator<unsigned> valUnsigned(&value);
|
||||
valUnsigned.SetWindow(m_text);
|
||||
|
||||
CHECK( valUnsigned.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "0" );
|
||||
|
||||
value = 17;
|
||||
CHECK( valUnsigned.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "17" );
|
||||
|
||||
|
||||
m_text->ChangeValue("foobar");
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("-234");
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("234");
|
||||
CHECK( valUnsigned.TransferFromWindow() );
|
||||
CHECK( value == 234 );
|
||||
|
||||
m_text->ChangeValue("4294967295"); // == ULONG_MAX in 32 bits
|
||||
CHECK( valUnsigned.TransferFromWindow() );
|
||||
CHECK( value == wxUINT32_MAX );
|
||||
CHECK( valUnsigned.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "4294967295" );
|
||||
|
||||
m_text->ChangeValue("4294967296"); // == ULONG_MAX + 1
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("18446744073709551616"); // == ULLONG_MAX + 1
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->Clear();
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::TransferUnsignedRange", "[valnum]")
|
||||
{
|
||||
unsigned value = 1;
|
||||
wxIntegerValidator<unsigned> valUnsigned(&value, 1, 20);
|
||||
valUnsigned.SetWindow(m_text);
|
||||
|
||||
CHECK( valUnsigned.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "1" );
|
||||
|
||||
value = 17;
|
||||
CHECK( valUnsigned.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "17" );
|
||||
|
||||
m_text->ChangeValue("foobar");
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("0");
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("1");
|
||||
CHECK( valUnsigned.TransferFromWindow() );
|
||||
CHECK( value == 1);
|
||||
|
||||
m_text->ChangeValue("20");
|
||||
CHECK( valUnsigned.TransferFromWindow() );
|
||||
CHECK( value == 20);
|
||||
|
||||
m_text->ChangeValue("21");
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
|
||||
m_text->Clear();
|
||||
CHECK( !valUnsigned.TransferFromWindow() );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::TransferULL", "[valnum]")
|
||||
{
|
||||
unsigned long long value = 0;
|
||||
wxIntegerValidator<unsigned long long> valULL(&value);
|
||||
valULL.SetWindow(m_text);
|
||||
|
||||
SECTION("LLONG_MAX")
|
||||
{
|
||||
m_text->ChangeValue("9223372036854775807"); // == LLONG_MAX
|
||||
REQUIRE( valULL.TransferFromWindow() );
|
||||
CHECK( value == static_cast<wxULongLong_t>(wxINT64_MAX) );
|
||||
|
||||
REQUIRE( valULL.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "9223372036854775807" );
|
||||
}
|
||||
|
||||
SECTION("LLONG_MAX+1")
|
||||
{
|
||||
m_text->ChangeValue("9223372036854775808"); // == LLONG_MAX + 1
|
||||
REQUIRE( valULL.TransferFromWindow() );
|
||||
CHECK( value == static_cast<wxULongLong_t>(wxINT64_MAX) + 1 );
|
||||
|
||||
REQUIRE( valULL.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "9223372036854775808" );
|
||||
}
|
||||
|
||||
SECTION("ULLONG_MAX")
|
||||
{
|
||||
m_text->ChangeValue("18446744073709551615"); // == ULLONG_MAX
|
||||
REQUIRE( valULL.TransferFromWindow() );
|
||||
CHECK( value == wxUINT64_MAX );
|
||||
|
||||
REQUIRE( valULL.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "18446744073709551615" );
|
||||
}
|
||||
|
||||
SECTION("ULLONG_MAX+1")
|
||||
{
|
||||
m_text->ChangeValue("18446744073709551616"); // == ULLONG_MAX + 1
|
||||
CHECK( !valULL.TransferFromWindow() );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::TransferFloat", "[valnum]")
|
||||
{
|
||||
// We need a locale with point as decimal separator.
|
||||
wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);
|
||||
|
||||
float value = 0;
|
||||
wxFloatingPointValidator<float> valFloat(3, &value);
|
||||
valFloat.SetWindow(m_text);
|
||||
|
||||
CHECK( valFloat.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "0.000" );
|
||||
|
||||
value = 1.234f;
|
||||
CHECK( valFloat.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "1.234" );
|
||||
|
||||
value = 1.2345678f;
|
||||
CHECK( valFloat.TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "1.235" );
|
||||
|
||||
|
||||
m_text->ChangeValue("foobar");
|
||||
CHECK( !valFloat.TransferFromWindow() );
|
||||
|
||||
m_text->ChangeValue("-234.567");
|
||||
CHECK( valFloat.TransferFromWindow() );
|
||||
CHECK( value == -234.567f );
|
||||
|
||||
m_text->Clear();
|
||||
CHECK( !valFloat.TransferFromWindow() );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::ZeroAsBlank", "[valnum]")
|
||||
{
|
||||
long value = 0;
|
||||
m_text->SetValidator(
|
||||
wxMakeIntegerValidator(&value, wxNUM_VAL_ZERO_AS_BLANK));
|
||||
|
||||
wxValidator * const val = m_text->GetValidator();
|
||||
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "" );
|
||||
|
||||
value++;
|
||||
CHECK( val->TransferFromWindow() );
|
||||
CHECK( value == 0 );
|
||||
|
||||
// Check that switching focus to another control doesn't change the value:
|
||||
// we need to trigger the "kill focus" event for m_text, so create another
|
||||
// control which can be focused and give it the focus and also mark this
|
||||
// control as "modified" because we we avoid changing its contents if it
|
||||
// has never been modified at all.
|
||||
m_text->SetSize(100, 50);
|
||||
m_text->MarkDirty();
|
||||
m_text->SetFocus();
|
||||
std::unique_ptr<wxTextCtrl>
|
||||
text2(new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "Test",
|
||||
wxPoint(0, 100), wxSize(100, 50)));
|
||||
text2->SetFocus();
|
||||
WaitFor("the other control to become focused", [&text2]() {
|
||||
return text2->HasFocus();
|
||||
});
|
||||
CHECK( m_text->GetValue() == "" );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::NoTrailingZeroes", "[valnum]")
|
||||
{
|
||||
// We need a locale with point as decimal separator.
|
||||
wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);
|
||||
|
||||
double value = 1.2;
|
||||
m_text->SetValidator(
|
||||
wxMakeFloatingPointValidator(3, &value, wxNUM_VAL_NO_TRAILING_ZEROES));
|
||||
|
||||
wxValidator * const val = m_text->GetValidator();
|
||||
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "1.2" );
|
||||
|
||||
value = 1.234;
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "1.234" );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::SignPlus", "[valnum]")
|
||||
{
|
||||
double value = 1.2;
|
||||
m_text->SetValidator(
|
||||
wxMakeFloatingPointValidator(3, &value, wxNUM_VAL_NO_TRAILING_ZEROES |
|
||||
wxNUM_VAL_SIGN_PLUS));
|
||||
|
||||
wxValidator * const val = m_text->GetValidator();
|
||||
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "+1.2" );
|
||||
|
||||
value = 1.234;
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == "+1.234" );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::SignSpace", "[valnum]")
|
||||
{
|
||||
double value = 1.2;
|
||||
m_text->SetValidator(
|
||||
wxMakeFloatingPointValidator(3, &value, wxNUM_VAL_NO_TRAILING_ZEROES |
|
||||
wxNUM_VAL_SIGN_SPACE));
|
||||
|
||||
wxValidator * const val = m_text->GetValidator();
|
||||
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == " 1.2" );
|
||||
|
||||
value = 1.234;
|
||||
CHECK( val->TransferToWindow() );
|
||||
CHECK( m_text->GetValue() == " 1.234" );
|
||||
}
|
||||
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::Interactive", "[valnum]")
|
||||
{
|
||||
// Set a locale using comma as thousands separator character.
|
||||
wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);
|
||||
|
||||
m_text->SetValidator(
|
||||
wxIntegerValidator<unsigned>(nullptr, wxNUM_VAL_THOUSANDS_SEPARATOR));
|
||||
|
||||
// Create a sibling text control to be able to switch focus and thus
|
||||
// trigger the control validation/normalization.
|
||||
wxTextCtrl * const text2 = new wxTextCtrl(m_text->GetParent(), wxID_ANY);
|
||||
wxON_BLOCK_EXIT_OBJ0( *text2, wxWindow::Destroy );
|
||||
text2->Move(10, 80); // Just to see it better while debugging...
|
||||
wxFloatingPointValidator<float> valFloat(3);
|
||||
valFloat.SetRange(-10., 10.);
|
||||
text2->SetValidator(valFloat);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
// Entering '-' in a control with positive range is not allowed.
|
||||
m_text->SetFocus();
|
||||
wxYield();
|
||||
sim.Char('-');
|
||||
wxYield();
|
||||
CHECK( m_text->GetValue() == "" );
|
||||
|
||||
// Neither is entering '.' or any non-digit character.
|
||||
sim.Text(".a+/");
|
||||
wxYield();
|
||||
CHECK( m_text->GetValue() == "" );
|
||||
|
||||
// Entering digits should work though and after leaving the control the
|
||||
// contents should be normalized.
|
||||
sim.Text("1234567");
|
||||
wxYield();
|
||||
text2->SetFocus();
|
||||
wxYield();
|
||||
if ( loc.IsOk() )
|
||||
CHECK( m_text->GetValue() == "1,234,567" );
|
||||
else
|
||||
CHECK( m_text->GetValue() == "1234567" );
|
||||
|
||||
|
||||
// Entering both '-' and '.' in this control should work but only in the
|
||||
// correct order.
|
||||
sim.Char('-');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-" );
|
||||
|
||||
text2->SetInsertionPoint(0);
|
||||
sim.Char('.');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-" );
|
||||
|
||||
text2->SetInsertionPointEnd();
|
||||
sim.Char('.');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-." );
|
||||
|
||||
// Adding up to three digits after the point should work.
|
||||
sim.Text("987");
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-.987" );
|
||||
|
||||
// But no more.
|
||||
sim.Text("654");
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-.987" );
|
||||
|
||||
// We can remove one digit and another one though.
|
||||
sim.Char(WXK_BACK);
|
||||
sim.Char(WXK_BACK);
|
||||
sim.Char('6');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-.96" );
|
||||
|
||||
|
||||
// Also test the range constraint.
|
||||
valFloat.SetRange(10., 20.);
|
||||
text2->SetValidator(valFloat);
|
||||
text2->Clear();
|
||||
|
||||
// Entering a value which is out of range but within
|
||||
// the extended input range is allowed.
|
||||
sim.Char('9');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "9" );
|
||||
|
||||
// Entering a value greater than the positive range maximum
|
||||
// is not allowed.
|
||||
sim.Char('9');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "9" );
|
||||
|
||||
// A value that is out of range but within the extended input
|
||||
// range must be clamped to the valid range on focus loss.
|
||||
m_text->SetFocus();
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "10.000" );
|
||||
|
||||
// Repeat the test with a negative invalid value.
|
||||
valFloat.SetRange(-20., -10.);
|
||||
text2->SetValidator(valFloat);
|
||||
text2->Clear();
|
||||
text2->SetFocus();
|
||||
|
||||
sim.Text("-2");
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-2" );
|
||||
|
||||
sim.Char('2');
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-2" );
|
||||
|
||||
m_text->SetFocus();
|
||||
wxYield();
|
||||
CHECK( text2->GetValue() == "-10.000" );
|
||||
}
|
||||
|
||||
#endif // wxUSE_UIACTIONSIMULATOR
|
||||
212
libs/wxWidgets-3.3.1/tests/validators/valtext.cpp
Normal file
212
libs/wxWidgets-3.3.1/tests/validators/valtext.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/validators/valtext.cpp
|
||||
// Purpose: wxTextValidator unit test
|
||||
// Author: Ali Kettab
|
||||
// Created: 2019-01-01
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#if wxUSE_VALIDATORS && wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/textctrl.h"
|
||||
#include "wx/valtext.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/uiaction.h"
|
||||
|
||||
class TextValidatorTestCase
|
||||
{
|
||||
public:
|
||||
TextValidatorTestCase()
|
||||
: m_text(new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY))
|
||||
{
|
||||
}
|
||||
|
||||
~TextValidatorTestCase()
|
||||
{
|
||||
delete m_text;
|
||||
}
|
||||
|
||||
protected:
|
||||
wxTextCtrl* const m_text;
|
||||
};
|
||||
|
||||
#define TEXT_VALIDATOR_TEST_CASE(name, tags) \
|
||||
TEST_CASE_METHOD(TextValidatorTestCase, name, tags)
|
||||
|
||||
TEXT_VALIDATOR_TEST_CASE("wxTextValidator::IsValid", "[wxTextValidator][filters]")
|
||||
{
|
||||
wxString value = "";
|
||||
wxTextValidator val(wxFILTER_NONE, &value);
|
||||
|
||||
SECTION("wxFILTER_NONE - no filtering should take place")
|
||||
{
|
||||
CHECK( val.IsValid("wx-90.?! @_~E+{").empty() );
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_EMPTY - empty strings are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_EMPTY);
|
||||
|
||||
CHECK( !val.IsValid("").empty() );
|
||||
CHECK( val.IsValid(" ").empty() ); // space is valid
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_ASCII - non-ASCII characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_ASCII);
|
||||
|
||||
CHECK( val.IsValid("wx-90.?! @_~E+{").empty() );
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_ALPHA - non-alpha characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_ALPHA);
|
||||
|
||||
CHECK( val.IsValid("wx").empty() );
|
||||
CHECK( !val.IsValid("wx_").empty() ); // _ is not alpha
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_ALPHANUMERIC - non-alphanumeric characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_ALPHANUMERIC);
|
||||
|
||||
CHECK( val.IsValid("wx01").empty() );
|
||||
CHECK( !val.IsValid("wx 01").empty() ); // 'space' is not alphanumeric
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_DIGITS - non-digit characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_DIGITS);
|
||||
|
||||
CHECK( val.IsValid("97").empty() );
|
||||
CHECK( !val.IsValid("9.7").empty() ); // . is not digit
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_XDIGITS - non-xdigit characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_XDIGITS);
|
||||
|
||||
CHECK( val.IsValid("90AEF").empty() );
|
||||
CHECK( !val.IsValid("90GEF").empty() ); // G is not xdigit
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_NUMERIC - non-numeric characters are filtered out")
|
||||
{
|
||||
val.SetStyle(wxFILTER_NUMERIC);
|
||||
|
||||
CHECK( val.IsValid("+90.e-2").empty() );
|
||||
CHECK( !val.IsValid("-8.5#0").empty() ); // # is not numeric
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_INCLUDE_LIST - use include list")
|
||||
{
|
||||
val.SetStyle(wxFILTER_INCLUDE_LIST);
|
||||
|
||||
wxArrayString includes;
|
||||
includes.push_back("wxMSW");
|
||||
includes.push_back("wxGTK");
|
||||
includes.push_back("wxOSX");
|
||||
val.SetIncludes(includes);
|
||||
|
||||
CHECK( val.IsValid("wxGTK").empty() );
|
||||
CHECK( !val.IsValid("wxQT").empty() ); // wxQT is not included
|
||||
|
||||
SECTION("wxFILTER_EXCLUDE_LIST - use exclude with include list")
|
||||
{
|
||||
wxArrayString excludes;
|
||||
excludes.push_back("wxGTK");
|
||||
val.SetExcludes(excludes);
|
||||
|
||||
CHECK( val.IsValid("wxOSX").empty() );
|
||||
CHECK( !val.IsValid("wxGTK").empty() ); // wxGTK now excluded
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_EXCLUDE_LIST - use exclude list")
|
||||
{
|
||||
val.SetStyle(wxFILTER_EXCLUDE_LIST);
|
||||
|
||||
wxArrayString excludes;
|
||||
excludes.push_back("wxMSW");
|
||||
excludes.push_back("wxGTK");
|
||||
excludes.push_back("wxOSX");
|
||||
val.SetExcludes(excludes);
|
||||
|
||||
CHECK( val.IsValid("wxQT & wxUNIV").empty() );
|
||||
CHECK( !val.IsValid("wxMSW").empty() ); // wxMSW is excluded
|
||||
|
||||
SECTION("wxFILTER_INCLUDE_LIST - use include with exclude list")
|
||||
{
|
||||
wxArrayString includes;
|
||||
includes.push_back("wxGTK");
|
||||
val.SetIncludes(includes); // exclusion takes priority over inclusion.
|
||||
|
||||
CHECK( val.IsValid("wxUNIV").empty() );
|
||||
CHECK( !val.IsValid("wxMSW").empty() ); // wxMSW still excluded
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_INCLUDE_CHAR_LIST - use include char list")
|
||||
{
|
||||
val.SetStyle(wxFILTER_INCLUDE_CHAR_LIST);
|
||||
val.SetCharIncludes("tuvwxyz.012+-");
|
||||
|
||||
CHECK( val.IsValid("0.2t+z-1").empty() );
|
||||
CHECK( !val.IsValid("x*y").empty() ); // * is not included
|
||||
|
||||
val.AddCharIncludes("*");
|
||||
|
||||
CHECK( val.IsValid("x*y").empty() ); // * now included
|
||||
CHECK( !val.IsValid("x%y").empty() ); // % is not included
|
||||
|
||||
val.AddCharExcludes("*"); // exclusion takes priority over inclusion.
|
||||
|
||||
CHECK( !val.IsValid("x*y").empty() ); // * now excluded
|
||||
}
|
||||
|
||||
SECTION("wxFILTER_EXCLUDE_CHAR_LIST - use exclude char list")
|
||||
{
|
||||
val.SetStyle(wxFILTER_EXCLUDE_CHAR_LIST);
|
||||
val.SetCharExcludes("tuvwxyz.012+-");
|
||||
|
||||
CHECK( val.IsValid("A*B=?").empty() );
|
||||
CHECK( !val.IsValid("0.6/t").empty() ); // t is excluded
|
||||
|
||||
val.AddCharIncludes("t"); // exclusion takes priority over inclusion.
|
||||
|
||||
CHECK( !val.IsValid("0.6/t").empty() ); // t still excluded
|
||||
}
|
||||
}
|
||||
|
||||
TEXT_VALIDATOR_TEST_CASE("wxTextValidator::TransferToWindow", "[wxTextValidator][transferdata]")
|
||||
{
|
||||
wxString value = "wxwidgets";
|
||||
wxTextValidator val(wxFILTER_ALPHA, &value);
|
||||
m_text->SetValidator(val);
|
||||
|
||||
CHECK( m_text->IsEmpty() );
|
||||
|
||||
REQUIRE( m_text->TransferDataToWindow() );
|
||||
|
||||
CHECK( m_text->GetValue() == "wxwidgets" );
|
||||
}
|
||||
|
||||
TEXT_VALIDATOR_TEST_CASE("wxTextValidator::TransferFromWindow", "[wxTextValidator][transferdata]")
|
||||
{
|
||||
wxString value;
|
||||
wxTextValidator val(wxFILTER_ALPHA, &value);
|
||||
m_text->SetValidator(val);
|
||||
|
||||
m_text->ChangeValue("wxwidgets");
|
||||
|
||||
REQUIRE( m_text->TransferDataFromWindow() );
|
||||
|
||||
CHECK( value == "wxwidgets" );
|
||||
}
|
||||
|
||||
#endif // wxUSE_VALIDATORS && wxUSE_UIACTIONSIMULATOR
|
||||
Reference in New Issue
Block a user