virtlistctrltest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/virtlistctrltest.cpp
  3. // Purpose: wxListCtrl unit tests for virtual mode
  4. // Author: Vadim Zeitlin
  5. // Created: 2010-11-13
  6. // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #if wxUSE_LISTCTRL
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifndef WX_PRECOMP
  17. #include "wx/app.h"
  18. #endif // WX_PRECOMP
  19. #include "wx/listctrl.h"
  20. // ----------------------------------------------------------------------------
  21. // test class
  22. // ----------------------------------------------------------------------------
  23. class VirtListCtrlTestCase : public CppUnit::TestCase
  24. {
  25. public:
  26. VirtListCtrlTestCase() { }
  27. virtual void setUp();
  28. virtual void tearDown();
  29. private:
  30. CPPUNIT_TEST_SUITE( VirtListCtrlTestCase );
  31. CPPUNIT_TEST( UpdateSelection );
  32. CPPUNIT_TEST_SUITE_END();
  33. void UpdateSelection();
  34. wxListCtrl *m_list;
  35. wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase);
  36. };
  37. // register in the unnamed registry so that these tests are run by default
  38. CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase );
  39. // also include in its own registry so that these tests can be run alone
  40. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" );
  41. // ----------------------------------------------------------------------------
  42. // test initialization
  43. // ----------------------------------------------------------------------------
  44. void VirtListCtrlTestCase::setUp()
  45. {
  46. // Define a class overriding OnGetItemText() which must be overridden for
  47. // any virtual list control.
  48. class VirtListCtrl : public wxListCtrl
  49. {
  50. public:
  51. VirtListCtrl()
  52. : wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
  53. wxPoint(0, 0), wxSize(400, 200),
  54. wxLC_REPORT | wxLC_VIRTUAL)
  55. {
  56. }
  57. protected:
  58. virtual wxString OnGetItemText(long item, long column) const
  59. {
  60. return wxString::Format("Row %ld, col %ld", item, column);
  61. }
  62. };
  63. m_list = new VirtListCtrl;
  64. }
  65. void VirtListCtrlTestCase::tearDown()
  66. {
  67. delete m_list;
  68. m_list = NULL;
  69. }
  70. void VirtListCtrlTestCase::UpdateSelection()
  71. {
  72. m_list->SetItemCount(10);
  73. CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() );
  74. m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
  75. CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
  76. m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
  77. CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() );
  78. // The item 7 is now invalid and so shouldn't be counted as selected any
  79. // more.
  80. m_list->SetItemCount(5);
  81. CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
  82. }
  83. #endif // wxUSE_LISTCTRL