]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/textctrltest.cpp
Added typeinfo.h which implements wxTypeId, using C++ RTTI if available. wxAny and...
[wxWidgets.git] / tests / controls / textctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/textctrltest.cpp
3 // Purpose: wxTextCtrl unit test
4 // Author: Vadim Zeitlin
5 // Created: 2007-09-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/textctrl.h"
23 #endif // WX_PRECOMP
24
25 #include "textentrytest.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class TextCtrlTestCase : public TextEntryTestCase
32 {
33 public:
34 TextCtrlTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 virtual wxTextEntry *GetTestEntry() const { return m_text; }
41 virtual wxWindow *GetTestWindow() const { return m_text; }
42
43 CPPUNIT_TEST_SUITE( TextCtrlTestCase );
44 wxTEXT_ENTRY_TESTS();
45 CPPUNIT_TEST( MultiLineReplace );
46 CPPUNIT_TEST_SUITE_END();
47
48 void MultiLineReplace();
49
50 wxTextCtrl *m_text;
51
52 DECLARE_NO_COPY_CLASS(TextCtrlTestCase)
53 };
54
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( TextCtrlTestCase );
57
58 // also include in it's own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TextCtrlTestCase, "TextCtrlTestCase" );
60
61 // ----------------------------------------------------------------------------
62 // test initialization
63 // ----------------------------------------------------------------------------
64
65 void TextCtrlTestCase::setUp()
66 {
67 m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY);
68 }
69
70 void TextCtrlTestCase::tearDown()
71 {
72 delete m_text;
73 m_text = NULL;
74 }
75
76 // ----------------------------------------------------------------------------
77 // tests themselves
78 // ----------------------------------------------------------------------------
79
80 void TextCtrlTestCase::MultiLineReplace()
81 {
82 // we need a multiline control for this test so recreate it
83 delete m_text;
84 m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
85 wxDefaultPosition, wxDefaultSize,
86 wxTE_MULTILINE);
87
88 m_text->SetValue("Hello replace\n"
89 "0123456789012");
90 m_text->SetInsertionPoint(0);
91
92 m_text->Replace(6, 13, "changed");
93
94 CPPUNIT_ASSERT_EQUAL("Hello changed\n"
95 "0123456789012",
96 m_text->GetValue());
97 CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
98
99 m_text->Replace(13, -1, "");
100 CPPUNIT_ASSERT_EQUAL("Hello changed", m_text->GetValue());
101 CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
102 }
103