2007-09-25 20:28:31 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2008-09-19 04:55:25 -04:00
|
|
|
// Name: tests/controls/textctrltest.cpp
|
2007-09-25 20:28:31 -04:00
|
|
|
// Purpose: wxTextCtrl unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2007-09-25
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2008-09-19 04:55:25 -04:00
|
|
|
#include "textentrytest.h"
|
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-09-19 04:55:25 -04:00
|
|
|
class TextCtrlTestCase : public TextEntryTestCase
|
2007-09-25 20:28:31 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextCtrlTestCase() { }
|
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
|
|
|
private:
|
2008-09-19 04:55:25 -04:00
|
|
|
virtual wxTextEntry *GetTestEntry() const { return m_text; }
|
|
|
|
virtual wxWindow *GetTestWindow() const { return m_text; }
|
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
CPPUNIT_TEST_SUITE( TextCtrlTestCase );
|
2008-09-19 04:55:25 -04:00
|
|
|
wxTEXT_ENTRY_TESTS();
|
2009-04-14 09:22:09 -04:00
|
|
|
CPPUNIT_TEST( MultiLineReplace );
|
2007-09-25 20:28:31 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2009-04-14 09:22:09 -04:00
|
|
|
void MultiLineReplace();
|
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
wxTextCtrl *m_text;
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(TextCtrlTestCase)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( TextCtrlTestCase );
|
|
|
|
|
|
|
|
// also include in it's own registry so that these tests can be run alone
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TextCtrlTestCase, "TextCtrlTestCase" );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test initialization
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void TextCtrlTestCase::setUp()
|
|
|
|
{
|
|
|
|
m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextCtrlTestCase::tearDown()
|
|
|
|
{
|
|
|
|
delete m_text;
|
|
|
|
m_text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// tests themselves
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-04-14 09:22:09 -04:00
|
|
|
void TextCtrlTestCase::MultiLineReplace()
|
|
|
|
{
|
|
|
|
// we need a multiline control for this test so recreate it
|
|
|
|
delete m_text;
|
|
|
|
m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
|
|
|
|
m_text->SetValue("Hello replace\n"
|
|
|
|
"0123456789012");
|
|
|
|
m_text->SetInsertionPoint(0);
|
|
|
|
|
|
|
|
m_text->Replace(6, 13, "changed");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Hello changed\n"
|
|
|
|
"0123456789012",
|
|
|
|
m_text->GetValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
|
|
|
|
|
|
|
|
m_text->Replace(13, -1, "");
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Hello changed", m_text->GetValue());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
|
|
|
|
}
|
|
|
|
|