test_gui_rect.o \
test_gui_size.o \
test_gui_point.o \
- test_gui_config.o
+ test_gui_config.o \
+ test_gui_textctrltest.o
TEST_GUI_ODEP = $(___pch_testprec_test_gui_testprec_h_gch___depname)
PRINTFBENCH_CXXFLAGS = $(__printfbench_PCH_INC) -D__WX$(TOOLKIT)__ \
$(__WXUNIV_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/config/config.cpp
+test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP)
+ $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textctrltest.cpp
+
printfbench_printfbench.o: $(srcdir)/benchmarks/printfbench.cpp $(PRINTFBENCH_ODEP)
$(CXXC) -c -o $@ $(PRINTFBENCH_CXXFLAGS) $(srcdir)/benchmarks/printfbench.cpp
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/textctrl/textctrltest.cpp
+// 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
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class TextCtrlTestCase : public CppUnit::TestCase
+{
+public:
+ TextCtrlTestCase() { }
+
+ virtual void setUp();
+ virtual void tearDown();
+
+private:
+ CPPUNIT_TEST_SUITE( TextCtrlTestCase );
+ CPPUNIT_TEST( SetValue );
+ CPPUNIT_TEST( TextChangeEvents );
+ CPPUNIT_TEST_SUITE_END();
+
+ void SetValue();
+ void TextChangeEvents();
+
+ wxTextCtrl *m_text;
+ wxFrame *m_frame;
+
+ 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
+// ----------------------------------------------------------------------------
+
+void TextCtrlTestCase::SetValue()
+{
+ CPPUNIT_ASSERT( m_text->IsEmpty() );
+
+ m_text->SetValue("foo");
+ WX_ASSERT_STR_EQUAL( "foo", m_text->GetValue() );
+
+ m_text->SetValue("");
+ CPPUNIT_ASSERT( m_text->IsEmpty() );
+
+ m_text->SetValue("hi");
+ WX_ASSERT_STR_EQUAL( "hi", m_text->GetValue() );
+
+ m_text->SetValue("bye");
+ WX_ASSERT_STR_EQUAL( "bye", m_text->GetValue() );
+}
+
+void TextCtrlTestCase::TextChangeEvents()
+{
+ class TextTestEventHandler : public wxEvtHandler
+ {
+ public:
+ TextTestEventHandler() { m_events = 0; }
+
+ // calling this automatically resets the events counter
+ int GetEvents()
+ {
+ const int events = m_events;
+ m_events = 0;
+ return events;
+ }
+
+ void OnText(wxCommandEvent& WXUNUSED(event)) { m_events++; }
+
+ private:
+ int m_events;
+ } handler;
+
+ m_text->Connect(wxEVT_COMMAND_TEXT_UPDATED,
+ wxCommandEventHandler(TextTestEventHandler::OnText),
+ NULL,
+ &handler);
+
+ // notice that SetValue() generates an event even if the text didn't change
+ m_text->SetValue("");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->SetValue("foo");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->SetValue("foo");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->ChangeValue("bar");
+ CPPUNIT_ASSERT_EQUAL( 0, handler.GetEvents() );
+
+ m_text->AppendText("bar");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->Replace(3, 6, "baz");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->Remove(0, 3);
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->WriteText("foo");
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+
+ m_text->Clear();
+ CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+}
+
$(OBJS)\test_gui_rect.obj \
$(OBJS)\test_gui_size.obj \
$(OBJS)\test_gui_point.obj \
- $(OBJS)\test_gui_config.obj
+ $(OBJS)\test_gui_config.obj \
+ $(OBJS)\test_gui_textctrltest.obj
PRINTFBENCH_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
$(__OPTIMIZEFLAG) $(__THREADSFLAG_1) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
$(OBJS)\test_gui_config.obj: .\config\config.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) $**
+$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) $**
+
$(OBJS)\printfbench_dummy.obj: .\dummy.cpp
$(CXX) -q -c -P -o$@ $(PRINTFBENCH_CXXFLAGS) -H $**
$(OBJS)\test_gui_rect.o \
$(OBJS)\test_gui_size.o \
$(OBJS)\test_gui_point.o \
- $(OBJS)\test_gui_config.o
+ $(OBJS)\test_gui_config.o \
+ $(OBJS)\test_gui_textctrltest.o
PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) \
$(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
$(OBJS)\test_gui_config.o: ./config/config.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp
+ $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\printfbench_dummy.o: ./dummy.cpp
$(CXX) -c -o $@ $(PRINTFBENCH_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_gui_rect.obj \
$(OBJS)\test_gui_size.obj \
$(OBJS)\test_gui_point.obj \
- $(OBJS)\test_gui_config.obj
+ $(OBJS)\test_gui_config.obj \
+ $(OBJS)\test_gui_textctrltest.obj
PRINTFBENCH_CXXFLAGS = /M$(__RUNTIME_LIBS_38)$(__DEBUGRUNTIME) /DWIN32 \
$(__DEBUGINFO) /Fd$(OBJS)\printfbench.pdb $(____DEBUGRUNTIME) \
$(__OPTIMIZEFLAG) $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(OBJS)\test_gui_config.obj: .\config\config.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) $**
+$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) $**
+
$(OBJS)\printfbench_dummy.obj: .\dummy.cpp
$(CXX) /c /nologo /TP /Fo$@ $(PRINTFBENCH_CXXFLAGS) /Yctestprec.h $**
$(OBJS)\test_gui_rect.obj &
$(OBJS)\test_gui_size.obj &
$(OBJS)\test_gui_point.obj &
- $(OBJS)\test_gui_config.obj
+ $(OBJS)\test_gui_config.obj &
+ $(OBJS)\test_gui_textctrltest.obj
PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
$(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
$(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) &
$(OBJS)\test_gui_config.obj : .AUTODEPEND .\config\config.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+$(OBJS)\test_gui_textctrltest.obj : .AUTODEPEND .\controls\textctrltest.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
$(OBJS)\printfbench_dummy.obj : .AUTODEPEND .\dummy.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(PRINTFBENCH_CXXFLAGS) $<
geometry/size.cpp
geometry/point.cpp
config/config.cpp
+ controls/textctrltest.cpp
</sources>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>
using std::auto_ptr;
using std::cout;
+#if wxUSE_GUI
+ typedef wxApp TestAppBase;
+#else
+ typedef wxAppConsole TestAppBase;
+#endif
+
// The application class
//
-class TestApp : public wxAppConsole
+class TestApp : public TestAppBase
{
public:
TestApp();
// standard overrides
- void OnInitCmdLine(wxCmdLineParser& parser);
- bool OnCmdLineParsed(wxCmdLineParser& parser);
- bool OnInit();
- int OnRun();
+ virtual void OnInitCmdLine(wxCmdLineParser& parser);
+ virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
+ virtual bool OnInit();
+ virtual int OnRun();
+ virtual int OnExit();
private:
void List(Test *test, const string& parent = "") const;
//
bool TestApp::OnInit()
{
+ if ( !TestAppBase::OnInit() )
+ return false;
+
cout << "Test program for wxWidgets\n"
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << std::endl;
cout << "\n";
#endif
- return wxAppConsole::OnInit();
+#if wxUSE_GUI
+ // create a hidden parent window to be used as parent for the GUI controls
+ new wxFrame(NULL, wxID_ANY, "Hidden wx test frame");
+#endif // wxUSE_GUI
+
+ return true;
};
// The table of command line options
//
void TestApp::OnInitCmdLine(wxCmdLineParser& parser)
{
- wxAppConsole::OnInitCmdLine(parser);
+ TestAppBase::OnInitCmdLine(parser);
static const wxCmdLineEntryDesc cmdLineDesc[] = {
{ wxCMD_LINE_SWITCH, "l", "list",
m_longlist = parser.Found(_T("longlist"));
m_list = m_longlist || parser.Found(_T("list"));
- return wxAppConsole::OnCmdLineParsed(parser);
+ return TestAppBase::OnCmdLineParsed(parser);
}
// Run
: EXIT_FAILURE;
}
+int TestApp::OnExit()
+{
+#if wxUSE_GUI
+ delete GetTopWindow();
+#endif // wxUSE_GUI
+
+ return 0;
+}
+
// List the tests
//
void TestApp::List(Test *test, const string& parent /*=""*/) const
\r
SOURCE=.\test.cpp\r
# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\controls\textctrltest.cpp\r
+# End Source File\r
# End Group\r
# End Target\r
# End Project\r