]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/treectrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treectrltest.cpp
3 // Purpose: wxTreeCtrl unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/treectrl.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class TreeCtrlTestCase
: public CppUnit::TestCase
33 TreeCtrlTestCase() { }
36 virtual void tearDown();
39 CPPUNIT_TEST_SUITE( TreeCtrlTestCase
);
40 CPPUNIT_TEST( HasChildren
);
41 CPPUNIT_TEST( PseudoTest_SetHiddenRoot
);
42 CPPUNIT_TEST( HasChildren
);
43 CPPUNIT_TEST_SUITE_END();
46 void PseudoTest_SetHiddenRoot() { ms_hiddenRoot
= true; }
48 static bool ms_hiddenRoot
;
52 DECLARE_NO_COPY_CLASS(TreeCtrlTestCase
)
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( TreeCtrlTestCase
);
58 // also include in it's own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreeCtrlTestCase
, "TreeCtrlTestCase" );
61 // ----------------------------------------------------------------------------
62 // test initialization
63 // ----------------------------------------------------------------------------
65 bool TreeCtrlTestCase::ms_hiddenRoot
= false;
67 void TreeCtrlTestCase::setUp()
69 m_tree
= new wxTreeCtrl(wxTheApp
->GetTopWindow());
71 m_tree
->ToggleWindowStyle(wxTR_HIDE_ROOT
); // actually set it
74 void TreeCtrlTestCase::tearDown()
80 // ----------------------------------------------------------------------------
81 // the tests themselves
82 // ----------------------------------------------------------------------------
84 void TreeCtrlTestCase::HasChildren()
86 const wxTreeItemId root
= m_tree
->AddRoot("root");
87 const wxTreeItemId child1
= m_tree
->AppendItem(root
, "child1");
88 const wxTreeItemId child2
= m_tree
->AppendItem(root
, "child2");
89 const wxTreeItemId grandchild
= m_tree
->AppendItem(child1
, "grandchild");
91 CPPUNIT_ASSERT( m_tree
->HasChildren(root
) );
92 CPPUNIT_ASSERT( m_tree
->HasChildren(child1
) );
93 CPPUNIT_ASSERT( !m_tree
->HasChildren(child2
) );
94 CPPUNIT_ASSERT( !m_tree
->HasChildren(grandchild
) );