1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treebooktest.cpp
3 // Purpose: wxtreebook unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
22 #include "wx/treebook.h"
23 #include "bookctrlbasetest.h"
25 class TreebookTestCase
: public BookCtrlBaseTestCase
, public CppUnit::TestCase
28 TreebookTestCase() { }
31 virtual void tearDown();
34 virtual wxBookCtrlBase
*GetBase() const { return m_treebook
; }
36 virtual wxEventType
GetChangedEvent() const
37 { return wxEVT_TREEBOOK_PAGE_CHANGED
; }
39 virtual wxEventType
GetChangingEvent() const
40 { return wxEVT_TREEBOOK_PAGE_CHANGING
; }
42 CPPUNIT_TEST_SUITE( TreebookTestCase
);
43 wxBOOK_CTRL_BASE_TESTS();
44 CPPUNIT_TEST( Image
);
45 CPPUNIT_TEST( SubPages
);
46 CPPUNIT_TEST( Expand
);
47 CPPUNIT_TEST( Delete
);
48 CPPUNIT_TEST_SUITE_END();
54 wxTreebook
*m_treebook
;
56 DECLARE_NO_COPY_CLASS(TreebookTestCase
)
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( TreebookTestCase
);
62 // also include in its own registry so that these tests can be run alone
63 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreebookTestCase
, "TreebookTestCase" );
65 void TreebookTestCase::setUp()
67 m_treebook
= new wxTreebook(wxTheApp
->GetTopWindow(), wxID_ANY
);
71 void TreebookTestCase::tearDown()
76 void TreebookTestCase::SubPages()
78 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
79 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
80 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
82 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
84 CPPUNIT_ASSERT_EQUAL(2, m_treebook
->GetPageParent(3));
86 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
88 CPPUNIT_ASSERT_EQUAL(1, m_treebook
->GetPageParent(2));
90 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
92 CPPUNIT_ASSERT_EQUAL(3, m_treebook
->GetPageParent(5));
95 void TreebookTestCase::Expand()
97 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
98 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
99 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
101 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
102 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
103 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
105 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(1));
106 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(3));
108 m_treebook
->CollapseNode(1);
110 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(1));
112 m_treebook
->ExpandNode(3, false);
114 CPPUNIT_ASSERT(!m_treebook
->IsNodeExpanded(3));
116 m_treebook
->ExpandNode(1);
118 CPPUNIT_ASSERT(m_treebook
->IsNodeExpanded(1));
121 void TreebookTestCase::Delete()
123 wxPanel
* subpanel1
= new wxPanel(m_treebook
);
124 wxPanel
* subpanel2
= new wxPanel(m_treebook
);
125 wxPanel
* subpanel3
= new wxPanel(m_treebook
);
127 m_treebook
->AddSubPage(subpanel1
, "Subpanel 1", false, 0);
128 m_treebook
->InsertSubPage(1, subpanel2
, "Subpanel 2", false, 1);
129 m_treebook
->AddSubPage(subpanel3
, "Subpanel 3", false, 2);
131 CPPUNIT_ASSERT_EQUAL(6, m_treebook
->GetPageCount());
133 m_treebook
->DeletePage(3);
135 CPPUNIT_ASSERT_EQUAL(3, m_treebook
->GetPageCount());
137 m_treebook
->DeletePage(1);
139 CPPUNIT_ASSERT_EQUAL(1, m_treebook
->GetPageCount());
141 m_treebook
->DeletePage(0);
143 CPPUNIT_ASSERT_EQUAL(0, m_treebook
->GetPageCount());
146 #endif // wxUSE_TREEBOOK