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