From dc7f9c9cee113d6359ce2b280e69ccde1d616bd6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 19 Sep 2008 10:18:30 +0000 Subject: [PATCH] add unit test for wxTextEntry methods of wxComboBox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55733 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/Makefile.in | 4 ++ tests/controls/comboboxtest.cpp | 83 ++++++++++++++++++++++++++++++++ tests/controls/textentrytest.cpp | 8 ++- tests/controls/textentrytest.h | 9 ++++ tests/makefile.bcc | 4 ++ tests/makefile.gcc | 4 ++ tests/makefile.vc | 4 ++ tests/makefile.wat | 4 ++ tests/test.bkl | 1 + tests/test_test_gui.dsp | 4 ++ tests/test_vc7_test_gui.vcproj | 2 + tests/test_vc8_test_gui.vcproj | 3 ++ 12 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 tests/controls/comboboxtest.cpp diff --git a/tests/Makefile.in b/tests/Makefile.in index b19b5a6d4d..bbff08c43a 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -120,6 +120,7 @@ TEST_GUI_OBJECTS = \ test_gui_size.o \ test_gui_point.o \ test_gui_config.o \ + test_gui_comboboxtest.o \ test_gui_textctrltest.o \ test_gui_textentrytest.o \ test_gui_rawbmp.o \ @@ -518,6 +519,9 @@ test_gui_point.o: $(srcdir)/geometry/point.cpp $(TEST_GUI_ODEP) test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/config/config.cpp +test_gui_comboboxtest.o: $(srcdir)/controls/comboboxtest.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/comboboxtest.cpp + test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textctrltest.cpp diff --git a/tests/controls/comboboxtest.cpp b/tests/controls/comboboxtest.cpp new file mode 100644 index 0000000000..82678cc1e4 --- /dev/null +++ b/tests/controls/comboboxtest.cpp @@ -0,0 +1,83 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/controls/comboboxtest.cpp +// Purpose: wxComboBox unit test +// Author: Vadim Zeitlin +// Created: 2007-09-25 +// RCS-ID: $Id$ +// Copyright: (c) 2007 Vadim Zeitlin +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/combobox.h" +#endif // WX_PRECOMP + +#include "textentrytest.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class ComboBoxTestCase : public TextEntryTestCase +{ +public: + ComboBoxTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + virtual wxTextEntry *GetTestEntry() const { return m_combo; } + virtual wxWindow *GetTestWindow() const { return m_combo; } + + virtual void CheckStringSelection(const char * WXUNUSED(sel)) + { + // do nothing here, as explained in TextEntryTestCase comment, our + // GetStringSelection() is the wxChoice, not wxTextEntry, one and there + // is no way to return the selection contents directly + } + + CPPUNIT_TEST_SUITE( ComboBoxTestCase ); + wxTEXT_ENTRY_TESTS(); + CPPUNIT_TEST_SUITE_END(); + + wxComboBox *m_combo; + + DECLARE_NO_COPY_CLASS(ComboBoxTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase, "ComboBoxTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +void ComboBoxTestCase::setUp() +{ + m_combo = new wxComboBox(wxTheApp->GetTopWindow(), wxID_ANY); +} + +void ComboBoxTestCase::tearDown() +{ + delete m_combo; + m_combo = NULL; +} + +// ---------------------------------------------------------------------------- +// tests themselves +// ---------------------------------------------------------------------------- + diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index 80e6482fa9..03adf47680 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -96,6 +96,11 @@ void TextEntryTestCase::TextChangeEvents() CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); } +void TextEntryTestCase::CheckStringSelection(const char *sel) +{ + CPPUNIT_ASSERT_EQUAL( sel, GetTestEntry()->GetStringSelection() ); +} + void TextEntryTestCase::AssertSelection(int from, int to, const char *sel) { wxTextEntry * const entry = GetTestEntry(); @@ -107,9 +112,10 @@ void TextEntryTestCase::AssertSelection(int from, int to, const char *sel) entry->GetSelection(&fromReal, &toReal); CPPUNIT_ASSERT_EQUAL( from, fromReal ); CPPUNIT_ASSERT_EQUAL( to, toReal ); - CPPUNIT_ASSERT_EQUAL( sel, entry->GetStringSelection() ); CPPUNIT_ASSERT_EQUAL( from, entry->GetInsertionPoint() ); + + CheckStringSelection(sel); } void TextEntryTestCase::Selection() diff --git a/tests/controls/textentrytest.h b/tests/controls/textentrytest.h index db4058c2cb..b8376ddde0 100644 --- a/tests/controls/textentrytest.h +++ b/tests/controls/textentrytest.h @@ -49,6 +49,15 @@ private: // function parameters void AssertSelection(int from, int to, const char *sel); + // helper of AssertSelection(): check that the text selected in the control + // is the given one + // + // this is necessary to disable testing this in wxComboBox test as it + // doesn't provide any way to access the string selection directly, its + // GetStringSelection() method returns the currently selected string in the + // wxChoice part of the control, not the selected text + virtual void CheckStringSelection(const char *sel); + DECLARE_NO_COPY_CLASS(TextEntryTestCase) }; diff --git a/tests/makefile.bcc b/tests/makefile.bcc index e49acfeb04..28fac03543 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -108,6 +108,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_size.obj \ $(OBJS)\test_gui_point.obj \ $(OBJS)\test_gui_config.obj \ + $(OBJS)\test_gui_comboboxtest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ $(OBJS)\test_gui_rawbmp.obj \ @@ -559,6 +560,9 @@ $(OBJS)\test_gui_point.obj: .\geometry\point.cpp $(OBJS)\test_gui_config.obj: .\config\config.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp +$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp + $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index f26f896dc9..b5c426383d 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -101,6 +101,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_size.o \ $(OBJS)\test_gui_point.o \ $(OBJS)\test_gui_config.o \ + $(OBJS)\test_gui_comboboxtest.o \ $(OBJS)\test_gui_textctrltest.o \ $(OBJS)\test_gui_textentrytest.o \ $(OBJS)\test_gui_rawbmp.o \ @@ -537,6 +538,9 @@ $(OBJS)\test_gui_point.o: ./geometry/point.cpp $(OBJS)\test_gui_config.o: ./config/config.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_comboboxtest.o: ./controls/comboboxtest.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index ba13c39562..e3fea7ba25 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -104,6 +104,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_size.obj \ $(OBJS)\test_gui_point.obj \ $(OBJS)\test_gui_config.obj \ + $(OBJS)\test_gui_comboboxtest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ $(OBJS)\test_gui_rawbmp.obj \ @@ -644,6 +645,9 @@ $(OBJS)\test_gui_point.obj: .\geometry\point.cpp $(OBJS)\test_gui_config.obj: .\config\config.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp +$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp + $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 0289c7618e..497e62e0bf 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -313,6 +313,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_size.obj & $(OBJS)\test_gui_point.obj & $(OBJS)\test_gui_config.obj & + $(OBJS)\test_gui_comboboxtest.obj & $(OBJS)\test_gui_textctrltest.obj & $(OBJS)\test_gui_textentrytest.obj & $(OBJS)\test_gui_rawbmp.obj & @@ -590,6 +591,9 @@ $(OBJS)\test_gui_point.obj : .AUTODEPEND .\geometry\point.cpp $(OBJS)\test_gui_config.obj : .AUTODEPEND .\config\config.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_comboboxtest.obj : .AUTODEPEND .\controls\comboboxtest.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) $< diff --git a/tests/test.bkl b/tests/test.bkl index de3a9f76e3..80ec00b75f 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -105,6 +105,7 @@ geometry/size.cpp geometry/point.cpp config/config.cpp + controls/comboboxtest.cpp controls/textctrltest.cpp controls/textentrytest.cpp image/rawbmp.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index 03cc75b4ce..231f673414 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -239,6 +239,10 @@ SOURCE=.\window\clientsize.cpp # End Source File # Begin Source File +SOURCE=.\controls\comboboxtest.cpp +# End Source File +# Begin Source File + SOURCE=.\config\config.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index cd9e2a00b7..aa09fa5139 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -651,6 +651,8 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"> + + -- 2.47.2