]> git.saurik.com Git - wxWidgets.git/commitdiff
implement wxTreeCtrl::ItemHasChildren() properly for virtual root item; added unit...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 17 Jan 2009 13:16:25 +0000 (13:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 17 Jan 2009 13:16:25 +0000 (13:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58177 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
src/msw/treectrl.cpp
tests/Makefile.in
tests/controls/treectrltest.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 7aa4079cf659ceb0082b46044e91e83311e5ec3a..d358be2f328155f21f264b872c8c273e5c7f47da 100644 (file)
@@ -1213,6 +1213,12 @@ bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const
 {
     wxCHECK_MSG( item.IsOk(), false, wxT("invalid tree item") );
 
+    if ( IS_VIRTUAL_ROOT(item) )
+    {
+        wxTreeItemIdValue cookie;
+        return GetFirstChild(item, cookie).IsOk();
+    }
+
     wxTreeViewItem tvItem(item, TVIF_CHILDREN);
     DoGetItem(&tvItem);
 
index fa91752321aa7a5ddcb2c24f158fa2ce9cfc0a6e..bf0ba869ec73af01f181262f5e12868bc448c645 100644 (file)
@@ -130,6 +130,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_listctrltest.o \
        test_gui_textctrltest.o \
        test_gui_textentrytest.o \
+       test_gui_treectrltest.o \
        test_gui_propagation.o \
        test_gui_rawbmp.o \
        test_gui_htmlwindow.o \
@@ -566,6 +567,9 @@ test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP)
 test_gui_textentrytest.o: $(srcdir)/controls/textentrytest.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textentrytest.cpp
 
+test_gui_treectrltest.o: $(srcdir)/controls/treectrltest.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/treectrltest.cpp
+
 test_gui_propagation.o: $(srcdir)/events/propagation.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/events/propagation.cpp
 
diff --git a/tests/controls/treectrltest.cpp b/tests/controls/treectrltest.cpp
new file mode 100644 (file)
index 0000000..4d0bee2
--- /dev/null
@@ -0,0 +1,96 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/controls/treectrltest.cpp
+// Purpose:     wxTreeCtrl unit test
+// Author:      Vadim Zeitlin
+// Created:     2008-11-26
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+#endif // WX_PRECOMP
+
+#include "wx/treectrl.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class TreeCtrlTestCase : public CppUnit::TestCase
+{
+public:
+    TreeCtrlTestCase() { }
+
+    virtual void setUp();
+    virtual void tearDown();
+
+private:
+    CPPUNIT_TEST_SUITE( TreeCtrlTestCase );
+        CPPUNIT_TEST( HasChildren );
+        CPPUNIT_TEST( PseudoTest_SetHiddenRoot );
+        CPPUNIT_TEST( HasChildren );
+    CPPUNIT_TEST_SUITE_END();
+
+    void HasChildren();
+    void PseudoTest_SetHiddenRoot() { ms_hiddenRoot = true; }
+
+    static bool ms_hiddenRoot;
+
+    wxTreeCtrl *m_tree;
+
+    DECLARE_NO_COPY_CLASS(TreeCtrlTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( TreeCtrlTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreeCtrlTestCase, "TreeCtrlTestCase" );
+
+// ----------------------------------------------------------------------------
+// test initialization
+// ----------------------------------------------------------------------------
+
+bool TreeCtrlTestCase::ms_hiddenRoot = false;
+
+void TreeCtrlTestCase::setUp()
+{
+    m_tree = new wxTreeCtrl(wxTheApp->GetTopWindow());
+    if ( ms_hiddenRoot )
+        m_tree->ToggleWindowStyle(wxTR_HIDE_ROOT); // actually set it
+}
+
+void TreeCtrlTestCase::tearDown()
+{
+    delete m_tree;
+    m_tree = NULL;
+}
+
+// ----------------------------------------------------------------------------
+// the tests themselves
+// ----------------------------------------------------------------------------
+
+void TreeCtrlTestCase::HasChildren()
+{
+    const wxTreeItemId root = m_tree->AddRoot("root");
+    const wxTreeItemId child1 = m_tree->AppendItem(root, "child1");
+    const wxTreeItemId child2 = m_tree->AppendItem(root, "child2");
+    const wxTreeItemId grandchild = m_tree->AppendItem(child1, "grandchild");
+
+    CPPUNIT_ASSERT( m_tree->HasChildren(root) );
+    CPPUNIT_ASSERT( m_tree->HasChildren(child1) );
+    CPPUNIT_ASSERT( !m_tree->HasChildren(child2) );
+    CPPUNIT_ASSERT( !m_tree->HasChildren(grandchild) );
+}
+
index 57b50ecb1b6a78427ad1d92f9c806f312ff55c38..9271298a018d5480f2ae5e0cefcb40632f6d101e 100644 (file)
@@ -115,6 +115,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.obj \
        $(OBJS)\test_gui_textctrltest.obj \
        $(OBJS)\test_gui_textentrytest.obj \
+       $(OBJS)\test_gui_treectrltest.obj \
        $(OBJS)\test_gui_propagation.obj \
        $(OBJS)\test_gui_rawbmp.obj \
        $(OBJS)\test_gui_htmlwindow.obj \
@@ -606,6 +607,9 @@ $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
 $(OBJS)\test_gui_textentrytest.obj: .\controls\textentrytest.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textentrytest.cpp
 
+$(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp
+
 $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp
 
index 5d5018057af583a60a380678b39c44bee3598af2..db755e8a1ce0899abb537600a35b0e0426273a7c 100644 (file)
@@ -108,6 +108,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.o \
        $(OBJS)\test_gui_textctrltest.o \
        $(OBJS)\test_gui_textentrytest.o \
+       $(OBJS)\test_gui_treectrltest.o \
        $(OBJS)\test_gui_propagation.o \
        $(OBJS)\test_gui_rawbmp.o \
        $(OBJS)\test_gui_htmlwindow.o \
@@ -586,6 +587,9 @@ $(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp
 $(OBJS)\test_gui_textentrytest.o: ./controls/textentrytest.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_gui_treectrltest.o: ./controls/treectrltest.cpp
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_gui_propagation.o: ./events/propagation.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
index 4370ab158cff42bb514516db20887da8d824ff03..ae369520e3c8585e645466f6f39b767ede472aa1 100644 (file)
@@ -111,6 +111,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_listctrltest.obj \
        $(OBJS)\test_gui_textctrltest.obj \
        $(OBJS)\test_gui_textentrytest.obj \
+       $(OBJS)\test_gui_treectrltest.obj \
        $(OBJS)\test_gui_propagation.obj \
        $(OBJS)\test_gui_rawbmp.obj \
        $(OBJS)\test_gui_htmlwindow.obj \
@@ -691,6 +692,9 @@ $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
 $(OBJS)\test_gui_textentrytest.obj: .\controls\textentrytest.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textentrytest.cpp
 
+$(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp
+
 $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp
 
index 59c74ef3d1c4316ea6072a447c0b00c092d87d82..195a2072d97e2e24ac1c0d569c918d88540e410d 100644 (file)
@@ -342,6 +342,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_listctrltest.obj &
        $(OBJS)\test_gui_textctrltest.obj &
        $(OBJS)\test_gui_textentrytest.obj &
+       $(OBJS)\test_gui_treectrltest.obj &
        $(OBJS)\test_gui_propagation.obj &
        $(OBJS)\test_gui_rawbmp.obj &
        $(OBJS)\test_gui_htmlwindow.obj &
@@ -643,6 +644,9 @@ $(OBJS)\test_gui_textctrltest.obj :  .AUTODEPEND .\controls\textctrltest.cpp
 $(OBJS)\test_gui_textentrytest.obj :  .AUTODEPEND .\controls\textentrytest.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
+$(OBJS)\test_gui_treectrltest.obj :  .AUTODEPEND .\controls\treectrltest.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
 $(OBJS)\test_gui_propagation.obj :  .AUTODEPEND .\events\propagation.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
index 7122b54a83ad4b75a6670da2c39bd771ff06aa71..56ef3ef897822565f37b890345bfd98f2f808b0c 100644 (file)
             controls/listctrltest.cpp
             controls/textctrltest.cpp
             controls/textentrytest.cpp
+            controls/treectrltest.cpp
             events/propagation.cpp
             image/rawbmp.cpp
             html/htmlwindow.cpp
index 56db639fbe514554e9a63e12641e02b9faf5ec80..28eb179fe374318fefaa364b649d1329256630bc 100644 (file)
@@ -319,6 +319,10 @@ SOURCE=.\controls\textctrltest.cpp
 \r
 SOURCE=.\controls\textentrytest.cpp\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\controls\treectrltest.cpp\r
+# End Source File\r
 # End Group\r
 # End Target\r
 # End Project\r
index 66a78cc7cd934dfaa57e695cfbc0cc7dbdecd12f..ea1232cfab01ee1a313fa1ac3762fdde6acf77e7 100644 (file)
                        <File\r
                                RelativePath=".\controls\textentrytest.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\treectrltest.cpp">\r
+                       </File>\r
                </Filter>\r
                <Filter\r
                        Name="Resource Files"\r
index b3a4c68524ecea79d1ecde83b6edd5a958c801fd..f5a15dd0f4a8b98fdee9980fc4ed33f8f3c059bf 100644 (file)
                                RelativePath=".\controls\textentrytest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\treectrltest.cpp"\r
+                               >\r
+                       </File>\r
                </Filter>\r
                <Filter\r
                        Name="Resource Files"\r
index 0890d6efedfb7eb9f5953715e9e7c3ce751625ed..31c7de222e4b57385b00b293ced962bbc512a850 100644 (file)
                                RelativePath=".\controls\textentrytest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\controls\treectrltest.cpp"\r
+                               >\r
+                       </File>\r
                </Filter>\r
                <Filter\r
                        Name="Resource Files"\r