treebooktest.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include "testprec.h"
  9. #if wxUSE_TREEBOOK
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #include "wx/panel.h"
  16. #endif // WX_PRECOMP
  17. #include "wx/treebook.h"
  18. #include "bookctrlbasetest.h"
  19. class TreebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
  20. {
  21. public:
  22. TreebookTestCase() { }
  23. virtual void setUp();
  24. virtual void tearDown();
  25. private:
  26. virtual wxBookCtrlBase *GetBase() const { return m_treebook; }
  27. virtual wxEventType GetChangedEvent() const
  28. { return wxEVT_TREEBOOK_PAGE_CHANGED; }
  29. virtual wxEventType GetChangingEvent() const
  30. { return wxEVT_TREEBOOK_PAGE_CHANGING; }
  31. CPPUNIT_TEST_SUITE( TreebookTestCase );
  32. wxBOOK_CTRL_BASE_TESTS();
  33. CPPUNIT_TEST( Image );
  34. CPPUNIT_TEST( SubPages );
  35. CPPUNIT_TEST( Expand );
  36. CPPUNIT_TEST( Delete );
  37. CPPUNIT_TEST_SUITE_END();
  38. void SubPages();
  39. void Expand();
  40. void Delete();
  41. wxTreebook *m_treebook;
  42. DECLARE_NO_COPY_CLASS(TreebookTestCase)
  43. };
  44. // register in the unnamed registry so that these tests are run by default
  45. CPPUNIT_TEST_SUITE_REGISTRATION( TreebookTestCase );
  46. // also include in its own registry so that these tests can be run alone
  47. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreebookTestCase, "TreebookTestCase" );
  48. void TreebookTestCase::setUp()
  49. {
  50. m_treebook = new wxTreebook(wxTheApp->GetTopWindow(), wxID_ANY);
  51. AddPanels();
  52. }
  53. void TreebookTestCase::tearDown()
  54. {
  55. wxDELETE(m_treebook);
  56. }
  57. void TreebookTestCase::SubPages()
  58. {
  59. wxPanel* subpanel1 = new wxPanel(m_treebook);
  60. wxPanel* subpanel2 = new wxPanel(m_treebook);
  61. wxPanel* subpanel3 = new wxPanel(m_treebook);
  62. m_treebook->AddSubPage(subpanel1, "Subpanel 1", false, 0);
  63. CPPUNIT_ASSERT_EQUAL(2, m_treebook->GetPageParent(3));
  64. m_treebook->InsertSubPage(1, subpanel2, "Subpanel 2", false, 1);
  65. CPPUNIT_ASSERT_EQUAL(1, m_treebook->GetPageParent(2));
  66. m_treebook->AddSubPage(subpanel3, "Subpanel 3", false, 2);
  67. CPPUNIT_ASSERT_EQUAL(3, m_treebook->GetPageParent(5));
  68. }
  69. void TreebookTestCase::Expand()
  70. {
  71. wxPanel* subpanel1 = new wxPanel(m_treebook);
  72. wxPanel* subpanel2 = new wxPanel(m_treebook);
  73. wxPanel* subpanel3 = new wxPanel(m_treebook);
  74. m_treebook->AddSubPage(subpanel1, "Subpanel 1", false, 0);
  75. m_treebook->InsertSubPage(1, subpanel2, "Subpanel 2", false, 1);
  76. m_treebook->AddSubPage(subpanel3, "Subpanel 3", false, 2);
  77. CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(1));
  78. CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(3));
  79. m_treebook->CollapseNode(1);
  80. CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(1));
  81. m_treebook->ExpandNode(3, false);
  82. CPPUNIT_ASSERT(!m_treebook->IsNodeExpanded(3));
  83. m_treebook->ExpandNode(1);
  84. CPPUNIT_ASSERT(m_treebook->IsNodeExpanded(1));
  85. }
  86. void TreebookTestCase::Delete()
  87. {
  88. wxPanel* subpanel1 = new wxPanel(m_treebook);
  89. wxPanel* subpanel2 = new wxPanel(m_treebook);
  90. wxPanel* subpanel3 = new wxPanel(m_treebook);
  91. m_treebook->AddSubPage(subpanel1, "Subpanel 1", false, 0);
  92. m_treebook->InsertSubPage(1, subpanel2, "Subpanel 2", false, 1);
  93. m_treebook->AddSubPage(subpanel3, "Subpanel 3", false, 2);
  94. CPPUNIT_ASSERT_EQUAL(6, m_treebook->GetPageCount());
  95. m_treebook->DeletePage(3);
  96. CPPUNIT_ASSERT_EQUAL(3, m_treebook->GetPageCount());
  97. m_treebook->DeletePage(1);
  98. CPPUNIT_ASSERT_EQUAL(1, m_treebook->GetPageCount());
  99. m_treebook->DeletePage(0);
  100. CPPUNIT_ASSERT_EQUAL(0, m_treebook->GetPageCount());
  101. }
  102. #endif // wxUSE_TREEBOOK