1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treebooktest.cpp
3 // Purpose: wxtreebook unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
23 #include "wx/treebook.h"
24 #include "bookctrlbasetest.h"
26 class TreebookTestCase
: public BookCtrlBaseTestCase
, public CppUnit::TestCase
29 TreebookTestCase() { }
32 virtual void tearDown();
35 virtual wxBookCtrlBase
*GetBase() const { return m_treebook
; }
37 virtual wxEventType
GetChangedEvent() const
38 { return wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
; }
40 virtual wxEventType
GetChangingEvent() const
41 { return wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
; }
43 CPPUNIT_TEST_SUITE( TreebookTestCase
);
44 wxBOOK_CTRL_BASE_TESTS();
45 CPPUNIT_TEST( Image
);
46 CPPUNIT_TEST( SubPages
);
47 CPPUNIT_TEST( Expand
);
48 CPPUNIT_TEST( Delete
);
49 CPPUNIT_TEST_SUITE_END();
55 wxTreebook
*m_treebook
;
57 DECLARE_NO_COPY_CLASS(TreebookTestCase
)
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( TreebookTestCase
);
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreebookTestCase
, "TreebookTestCase" );
66 void TreebookTestCase::setUp()
68 m_treebook
= new wxTreebook(wxTheApp
->GetTopWindow(), wxID_ANY
);
72 void TreebookTestCase::tearDown()
77 void TreebookTestCase::SubPages()
79 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
80 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
81 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
83 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
85 CPPUNIT_ASSERT_EQUAL(2, m_treebook
->GetPageParent(3));
87 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
89 CPPUNIT_ASSERT_EQUAL(1, m_treebook
->GetPageParent(2));
91 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
93 CPPUNIT_ASSERT_EQUAL(3, m_treebook
->GetPageParent(5));
96 void TreebookTestCase::Expand()
98 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
99 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
100 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
102 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
103 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
104 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
106 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(1));
107 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(3));
109 m_treebook
->CollapseNode(1);
111 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(1));
113 m_treebook
->ExpandNode(3, false);
115 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(3));
117 m_treebook
->ExpandNode(1);
119 CPPUNIT_ASSERT(m_treebook
->IsNodeExpanded(1));
122 void TreebookTestCase::Delete()
124 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
125 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
126 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
128 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
129 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
130 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
132 CPPUNIT_ASSERT_EQUAL(6, m_treebook
->GetPageCount());
134 m_treebook
->DeletePage(3);
136 CPPUNIT_ASSERT_EQUAL(3, m_treebook
->GetPageCount());
138 m_treebook
->DeletePage(1);
140 CPPUNIT_ASSERT_EQUAL(1, m_treebook
->GetPageCount());
142 m_treebook
->DeletePage(0);
144 CPPUNIT_ASSERT_EQUAL(0, m_treebook
->GetPageCount());
147 #endif // wxUSE_TREEBOOK