implement wxTreeCtrl::ItemHasChildren() properly for virtual root item; added unit test for it
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58177 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9ebfc96354
commit
fa97ee2490
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
96
tests/controls/treectrltest.cpp
Normal file
96
tests/controls/treectrltest.cpp
Normal file
@ -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) );
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) $<
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) $<
|
||||
|
||||
|
@ -112,6 +112,7 @@
|
||||
controls/listctrltest.cpp
|
||||
controls/textctrltest.cpp
|
||||
controls/textentrytest.cpp
|
||||
controls/treectrltest.cpp
|
||||
events/propagation.cpp
|
||||
image/rawbmp.cpp
|
||||
html/htmlwindow.cpp
|
||||
|
@ -319,6 +319,10 @@ SOURCE=.\controls\textctrltest.cpp
|
||||
|
||||
SOURCE=.\controls\textentrytest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\controls\treectrltest.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
@ -657,6 +657,9 @@
|
||||
<File
|
||||
RelativePath=".\controls\textentrytest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\treectrltest.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
@ -955,6 +955,10 @@
|
||||
RelativePath=".\controls\textentrytest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\treectrltest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
@ -927,6 +927,10 @@
|
||||
RelativePath=".\controls\textentrytest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\treectrltest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
Loading…
Reference in New Issue
Block a user