]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/treebooktest.cpp
Add test for absence of events from wxSpinCtrlDouble ctor.
[wxWidgets.git] / tests / controls / treebooktest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treebooktest.cpp
3 // Purpose: wxtreebook unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-02
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #if wxUSE_TREEBOOK
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/panel.h"
20 #endif // WX_PRECOMP
21
22 #include "wx/treebook.h"
23 #include "bookctrlbasetest.h"
24
25 class TreebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
26 {
27 public:
28 TreebookTestCase() { }
29
30 virtual void setUp();
31 virtual void tearDown();
32
33 private:
34 virtual wxBookCtrlBase *GetBase() const { return m_treebook; }
35
36 virtual wxEventType GetChangedEvent() const
37 { return wxEVT_TREEBOOK_PAGE_CHANGED; }
38
39 virtual wxEventType GetChangingEvent() const
40 { return wxEVT_TREEBOOK_PAGE_CHANGING; }
41
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();
49
50 void SubPages();
51 void Expand();
52 void Delete();
53
54 wxTreebook *m_treebook;
55
56 DECLARE_NO_COPY_CLASS(TreebookTestCase)
57 };
58
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( TreebookTestCase );
61
62 // also include in its own registry so that these tests can be run alone
63 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreebookTestCase, "TreebookTestCase" );
64
65 void TreebookTestCase::setUp()
66 {
67 m_treebook = new wxTreebook(wxTheApp->GetTopWindow(), wxID_ANY);
68 AddPanels();
69 }
70
71 void TreebookTestCase::tearDown()
72 {
73 wxDELETE(m_treebook);
74 }
75
76 void TreebookTestCase::SubPages()
77 {
78 wxPanel* subpanel1 = new wxPanel(m_treebook);
79 wxPanel* subpanel2 = new wxPanel(m_treebook);
80 wxPanel* subpanel3 = new wxPanel(m_treebook);
81
82 m_treebook->AddSubPage(subpanel1, "Subpanel 1", false, 0);
83
84 CPPUNIT_ASSERT_EQUAL(2, m_treebook->GetPageParent(3));
85
86 m_treebook->InsertSubPage(1, subpanel2, "Subpanel 2", false, 1);
87
88 CPPUNIT_ASSERT_EQUAL(1, m_treebook->GetPageParent(2));
89
90 m_treebook->AddSubPage(subpanel3, "Subpanel 3", false, 2);
91
92 CPPUNIT_ASSERT_EQUAL(3, m_treebook->GetPageParent(5));
93 }
94
95 void TreebookTestCase::Expand()
96 {
97 wxPanel* subpanel1 = new wxPanel(m_treebook);
98 wxPanel* subpanel2 = new wxPanel(m_treebook);
99 wxPanel* subpanel3 = new wxPanel(m_treebook);
100
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);
104
105 CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(1));
106 CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(3));
107
108 m_treebook->CollapseNode(1);
109
110 CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(1));
111
112 m_treebook->ExpandNode(3, false);
113
114 CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(3));
115
116 m_treebook->ExpandNode(1);
117
118 CPPUNIT_ASSERT(m_treebook->IsNodeExpanded(1));
119 }
120
121 void TreebookTestCase::Delete()
122 {
123 wxPanel* subpanel1 = new wxPanel(m_treebook);
124 wxPanel* subpanel2 = new wxPanel(m_treebook);
125 wxPanel* subpanel3 = new wxPanel(m_treebook);
126
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);
130
131 CPPUNIT_ASSERT_EQUAL(6, m_treebook->GetPageCount());
132
133 m_treebook->DeletePage(3);
134
135 CPPUNIT_ASSERT_EQUAL(3, m_treebook->GetPageCount());
136
137 m_treebook->DeletePage(1);
138
139 CPPUNIT_ASSERT_EQUAL(1, m_treebook->GetPageCount());
140
141 m_treebook->DeletePage(0);
142
143 CPPUNIT_ASSERT_EQUAL(0, m_treebook->GetPageCount());
144 }
145
146 #endif // wxUSE_TREEBOOK