]> git.saurik.com Git - wxWidgets.git/commitdiff
Added OwnerDrawnComboBoxTestCase (currently only has copies of wxComboBox tests)
authorJaakko Salli <jaakko.salli@dnainternet.net>
Mon, 20 Dec 2010 13:55:40 +0000 (13:55 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Mon, 20 Dec 2010 13:55:40 +0000 (13:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/controls/ownerdrawncomboboxtest.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj
tests/test_vc9_test_gui.vcproj

index 7c2829446b3c073454764a11807205b4f9adb876..02f665d2f1e8e226f67c6780d5a0c833ca402f19 100644 (file)
@@ -178,6 +178,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_listctrltest.o \
        test_gui_listviewtest.o \
        test_gui_notebooktest.o \
+       test_gui_ownerdrawncomboboxtest.o \
        test_gui_pickerbasetest.o \
        test_gui_pickertest.o \
        test_gui_radioboxtest.o \
@@ -758,6 +759,9 @@ test_gui_listviewtest.o: $(srcdir)/controls/listviewtest.cpp $(TEST_GUI_ODEP)
 test_gui_notebooktest.o: $(srcdir)/controls/notebooktest.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/notebooktest.cpp
 
+test_gui_ownerdrawncomboboxtest.o: $(srcdir)/controls/ownerdrawncomboboxtest.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/ownerdrawncomboboxtest.cpp
+
 test_gui_pickerbasetest.o: $(srcdir)/controls/pickerbasetest.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/pickerbasetest.cpp
 
diff --git a/tests/controls/ownerdrawncomboboxtest.cpp b/tests/controls/ownerdrawncomboboxtest.cpp
new file mode 100644 (file)
index 0000000..54c2286
--- /dev/null
@@ -0,0 +1,197 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/controls/ownerdrawncomboboxtest.cpp
+// Purpose:     OwnerDrawnComboBox unit test
+// Author:      Jaakko Salli
+// Created:     2010-12-17
+// RCS-ID:      $Id$
+// Copyright:   (c) 2010 Jaakko Salli
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#if wxUSE_ODCOMBOBOX
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+#endif // WX_PRECOMP
+
+#include "wx/odcombo.h"
+
+#include "textentrytest.h"
+#include "itemcontainertest.h"
+#include "testableframe.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class OwnerDrawnComboBoxTestCase : public TextEntryTestCase,
+                                   public ItemContainerTestCase,
+                                   public CppUnit::TestCase
+{
+public:
+    OwnerDrawnComboBoxTestCase() { }
+
+    virtual void setUp();
+    virtual void tearDown();
+
+private:
+    virtual wxTextEntry *GetTestEntry() const { return m_combo; }
+    virtual wxWindow *GetTestWindow() const { return m_combo; }
+
+    virtual wxItemContainer *GetContainer() const { return m_combo; }
+    virtual wxWindow *GetContainerWindow() 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( OwnerDrawnComboBoxTestCase );
+        wxTEXT_ENTRY_TESTS();
+        wxITEM_CONTAINER_TESTS();
+        CPPUNIT_TEST( Size );
+        CPPUNIT_TEST( PopDismiss );
+        CPPUNIT_TEST( Sort );
+        CPPUNIT_TEST( ReadOnly );
+    CPPUNIT_TEST_SUITE_END();
+
+    void Size();
+    void PopDismiss();
+    void Sort();
+    void ReadOnly();
+
+    wxOwnerDrawnComboBox *m_combo;
+
+    DECLARE_NO_COPY_CLASS(OwnerDrawnComboBoxTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( OwnerDrawnComboBoxTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OwnerDrawnComboBoxTestCase,
+                                       "OwnerDrawnComboBoxTestCase" );
+
+// ----------------------------------------------------------------------------
+// test initialization
+// ----------------------------------------------------------------------------
+
+void OwnerDrawnComboBoxTestCase::setUp()
+{
+    m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(), wxID_ANY);
+}
+
+void OwnerDrawnComboBoxTestCase::tearDown()
+{
+    delete m_combo;
+    m_combo = NULL;
+}
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+void OwnerDrawnComboBoxTestCase::Size()
+{
+    // under MSW changing combobox size is a non-trivial operation because of
+    // confusion between the size of the control with and without dropdown, so
+    // check that it does work as expected
+
+    const int heightOrig = m_combo->GetSize().y;
+
+    // check that the height doesn't change if we don't touch it
+    m_combo->SetSize(100, -1);
+    CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
+
+    // check that setting both big and small (but not too small, there is a
+    // limit on how small the control can become under MSW) heights works
+    m_combo->SetSize(-1, 50);
+    CPPUNIT_ASSERT_EQUAL( 50, m_combo->GetSize().y );
+
+    m_combo->SetSize(-1, 10);
+    CPPUNIT_ASSERT_EQUAL( 10, m_combo->GetSize().y );
+
+    // and also that restoring it works (this used to be broken before 2.9.1)
+    m_combo->SetSize(-1, heightOrig);
+    CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
+}
+
+void OwnerDrawnComboBoxTestCase::PopDismiss()
+{
+    wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
+                                          wxTestableFrame);
+
+    EventCounter count(m_combo, wxEVT_COMMAND_COMBOBOX_DROPDOWN);
+    EventCounter count1(m_combo, wxEVT_COMMAND_COMBOBOX_CLOSEUP);
+
+    m_combo->Popup();
+    m_combo->Dismiss();
+
+    CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_COMBOBOX_DROPDOWN));
+    CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_COMBOBOX_CLOSEUP));
+}
+
+void OwnerDrawnComboBoxTestCase::Sort()
+{
+    m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(),
+                                       wxID_ANY, "",
+                                       wxDefaultPosition, wxDefaultSize,
+                                       0, NULL,
+                                       wxCB_SORT);
+
+    m_combo->Append("aaa");
+    m_combo->Append("Aaa");
+    m_combo->Append("aba");
+    m_combo->Append("aaab");
+    m_combo->Append("aab");
+    m_combo->Append("AAA");
+
+    CPPUNIT_ASSERT_EQUAL("AAA", m_combo->GetString(0));
+    CPPUNIT_ASSERT_EQUAL("Aaa", m_combo->GetString(1));
+    CPPUNIT_ASSERT_EQUAL("aaa", m_combo->GetString(2));
+    CPPUNIT_ASSERT_EQUAL("aaab", m_combo->GetString(3));
+    CPPUNIT_ASSERT_EQUAL("aab", m_combo->GetString(4));
+    CPPUNIT_ASSERT_EQUAL("aba", m_combo->GetString(5));
+
+    m_combo->Append("a");
+
+    CPPUNIT_ASSERT_EQUAL("a", m_combo->GetString(0));
+}
+
+void OwnerDrawnComboBoxTestCase::ReadOnly()
+{
+    wxArrayString testitems;
+    testitems.Add("item 1");
+    testitems.Add("item 2");
+
+    m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(), wxID_ANY, "",
+                                       wxDefaultPosition, wxDefaultSize,
+                                       testitems,
+                                       wxCB_READONLY);
+
+    m_combo->SetValue("item 1");
+
+    CPPUNIT_ASSERT_EQUAL("item 1", m_combo->GetValue());
+
+    m_combo->SetValue("not an item");
+
+    CPPUNIT_ASSERT_EQUAL("item 1", m_combo->GetValue());
+
+    // Since this uses FindString it is case insensitive
+    m_combo->SetValue("ITEM 2");
+
+    CPPUNIT_ASSERT_EQUAL("item 2", m_combo->GetValue());
+}
+
+#endif // wxUSE_ODCOMBOBOX
index 5c88c9c8654c2c97322cbea555ebd9abedca18b8..2a366f22d8e285279fac22bd8c1bbe77ec1985b7 100644 (file)
@@ -163,6 +163,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.obj \\r
        $(OBJS)\test_gui_listviewtest.obj \\r
        $(OBJS)\test_gui_notebooktest.obj \\r
+       $(OBJS)\test_gui_ownerdrawncomboboxtest.obj \\r
        $(OBJS)\test_gui_pickerbasetest.obj \\r
        $(OBJS)\test_gui_pickertest.obj \\r
        $(OBJS)\test_gui_radioboxtest.obj \\r
@@ -804,6 +805,9 @@ $(OBJS)\test_gui_listviewtest.obj: .\controls\listviewtest.cpp
 $(OBJS)\test_gui_notebooktest.obj: .\controls\notebooktest.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\notebooktest.cpp\r
 \r
+$(OBJS)\test_gui_ownerdrawncomboboxtest.obj: .\controls\ownerdrawncomboboxtest.cpp\r
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\ownerdrawncomboboxtest.cpp\r
+\r
 $(OBJS)\test_gui_pickerbasetest.obj: .\controls\pickerbasetest.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\pickerbasetest.cpp\r
 \r
index d5c95565eaae6ea59175366af966b63b6fe1bc10..ee9e554aa6d070372b76be322c6cdb87f8fc6a2b 100644 (file)
@@ -156,6 +156,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.o \\r
        $(OBJS)\test_gui_listviewtest.o \\r
        $(OBJS)\test_gui_notebooktest.o \\r
+       $(OBJS)\test_gui_ownerdrawncomboboxtest.o \\r
        $(OBJS)\test_gui_pickerbasetest.o \\r
        $(OBJS)\test_gui_pickertest.o \\r
        $(OBJS)\test_gui_radioboxtest.o \\r
@@ -785,6 +786,9 @@ $(OBJS)\test_gui_listviewtest.o: ./controls/listviewtest.cpp
 $(OBJS)\test_gui_notebooktest.o: ./controls/notebooktest.cpp\r
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_gui_ownerdrawncomboboxtest.o: ./controls/ownerdrawncomboboxtest.cpp\r
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
+\r
 $(OBJS)\test_gui_pickerbasetest.o: ./controls/pickerbasetest.cpp\r
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index e4d20a04e846712b14802b0fa73132c18e6d6228..85db68d10c57acf45065b468617de0fdcb86e669 100644 (file)
@@ -158,6 +158,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.obj \\r
        $(OBJS)\test_gui_listviewtest.obj \\r
        $(OBJS)\test_gui_notebooktest.obj \\r
+       $(OBJS)\test_gui_ownerdrawncomboboxtest.obj \\r
        $(OBJS)\test_gui_pickerbasetest.obj \\r
        $(OBJS)\test_gui_pickertest.obj \\r
        $(OBJS)\test_gui_radioboxtest.obj \\r
@@ -930,6 +931,9 @@ $(OBJS)\test_gui_listviewtest.obj: .\controls\listviewtest.cpp
 $(OBJS)\test_gui_notebooktest.obj: .\controls\notebooktest.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\notebooktest.cpp\r
 \r
+$(OBJS)\test_gui_ownerdrawncomboboxtest.obj: .\controls\ownerdrawncomboboxtest.cpp\r
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\ownerdrawncomboboxtest.cpp\r
+\r
 $(OBJS)\test_gui_pickerbasetest.obj: .\controls\pickerbasetest.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\pickerbasetest.cpp\r
 \r
index 8e5019fa2ec85795ae865df0ab9bfb34fd68f81d..a9f8122117b46e02414118bb5b89fac15da54c8f 100644 (file)
@@ -398,6 +398,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_listctrltest.obj &\r
        $(OBJS)\test_gui_listviewtest.obj &\r
        $(OBJS)\test_gui_notebooktest.obj &\r
+       $(OBJS)\test_gui_ownerdrawncomboboxtest.obj &\r
        $(OBJS)\test_gui_pickerbasetest.obj &\r
        $(OBJS)\test_gui_pickertest.obj &\r
        $(OBJS)\test_gui_radioboxtest.obj &\r
@@ -843,6 +844,9 @@ $(OBJS)\test_gui_listviewtest.obj :  .AUTODEPEND .\controls\listviewtest.cpp
 $(OBJS)\test_gui_notebooktest.obj :  .AUTODEPEND .\controls\notebooktest.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_gui_ownerdrawncomboboxtest.obj :  .AUTODEPEND .\controls\ownerdrawncomboboxtest.cpp\r
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
+\r
 $(OBJS)\test_gui_pickerbasetest.obj :  .AUTODEPEND .\controls\pickerbasetest.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
 \r
index 352d05bf492d7cc8beb7b6ab2aab1736084e6242..42aaee6d142932b7427181293beed6276527f2ed 100644 (file)
             controls/listctrltest.cpp
             controls/listviewtest.cpp
             controls/notebooktest.cpp
+            controls/ownerdrawncomboboxtest.cpp
             controls/pickerbasetest.cpp
             controls/pickertest.cpp
             controls/radioboxtest.cpp
index 13438b70e5259c663d12d69eecd28a4d58f3dcc7..d130cb8647e2dbecd2393106a31cf3e87416403d 100644 (file)
@@ -401,6 +401,10 @@ SOURCE=.\controls\notebooktest.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\controls\ownerdrawncomboboxtest.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\controls\pickerbasetest.cpp\r
 # End Source File\r
 # Begin Source File\r
index 6e392ad097380f570dcd50f0b56767be66ac2dc9..0172d3a9622063ccb0761741884d0582b6a9d112 100644 (file)
                        <File\r
                                RelativePath=".\controls\notebooktest.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\ownerdrawncomboboxtest.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\controls\pickerbasetest.cpp">\r
                        </File>\r
index c01308af33ee3940fda2b39b305065020b422645..f300941b72526ac001cd6a1d35d668a294e6b281 100644 (file)
                                RelativePath=".\controls\notebooktest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\ownerdrawncomboboxtest.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\controls\pickerbasetest.cpp"\r
                                >\r
index 7d27a76723138ced6957329a5c89cf4072ec3a78..5063d1dca8fc62f03c427314ecdf4ec677464cf1 100644 (file)
                                RelativePath=".\controls\notebooktest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\ownerdrawncomboboxtest.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\controls\pickerbasetest.cpp"\r
                                >\r