// Update the text value to correspond to the current time. By default also // generate an event but this can be avoided by calling the "WithoutEvent" // variant. void UpdateText() { UpdateTextWithoutEvent(); wxWindow* const ctrl = m_text->GetParent(); wxDateEvent event(ctrl, m_time, wxEVT_TIME_CHANGED); ctrl->HandleWindowEvent(event); }
void NumValidatorTestCase::Interactive() { // FIXME: This test fails on MSW buildbot slaves although works fine on // development machine, no idea why. It seems to be a problem with // wxUIActionSimulator rather the wxListCtrl control itself however. if ( wxGetUserId().Lower().Matches("buildslave*") ) return; // Set a locale using comma as thousands separator character. wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT); m_text->SetValidator( wxIntegerValidator<unsigned>(NULL, 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); 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(); sim.Char('-'); wxYield(); CPPUNIT_ASSERT_EQUAL( "", m_text->GetValue() ); // Neither is entering '.' or any non-digit character. sim.Text(".a+/"); wxYield(); CPPUNIT_ASSERT_EQUAL( "", 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() ) CPPUNIT_ASSERT_EQUAL( "1,234,567", m_text->GetValue() ); else CPPUNIT_ASSERT_EQUAL( "1234567", m_text->GetValue() ); // Entering both '-' and '.' in this control should work but only in the // correct order. sim.Char('-'); wxYield(); CPPUNIT_ASSERT_EQUAL( "-", text2->GetValue() ); text2->SetInsertionPoint(0); sim.Char('.'); wxYield(); CPPUNIT_ASSERT_EQUAL( "-", text2->GetValue() ); text2->SetInsertionPointEnd(); sim.Char('.'); wxYield(); CPPUNIT_ASSERT_EQUAL( "-.", text2->GetValue() ); // Adding up to three digits after the point should work. sim.Text("987"); wxYield(); CPPUNIT_ASSERT_EQUAL( "-.987", text2->GetValue() ); // But no more. sim.Text("654"); wxYield(); CPPUNIT_ASSERT_EQUAL( "-.987", text2->GetValue() ); // We can remove one digit and another one though. sim.Char(WXK_BACK); sim.Char(WXK_BACK); sim.Char('6'); wxYield(); CPPUNIT_ASSERT_EQUAL( "-.96", text2->GetValue() ); // Also test the range constraint. text2->Clear(); sim.Char('9'); wxYield(); CPPUNIT_ASSERT_EQUAL( "9", text2->GetValue() ); sim.Char('9'); wxYield(); CPPUNIT_ASSERT_EQUAL( "9", text2->GetValue() ); }