listviewtest.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/listviewtest.cpp
  3. // Purpose: wxListView unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-07-10
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #ifdef __BORLANDC__
  10. #pragma hdrstop
  11. #endif
  12. #ifndef WX_PRECOMP
  13. #include "wx/app.h"
  14. #endif // WX_PRECOMP
  15. #include "wx/listctrl.h"
  16. #include "listbasetest.h"
  17. class ListViewTestCase : public ListBaseTestCase, public CppUnit::TestCase
  18. {
  19. public:
  20. ListViewTestCase() { }
  21. virtual void setUp();
  22. virtual void tearDown();
  23. virtual wxListCtrl *GetList() const { return m_list; }
  24. private:
  25. CPPUNIT_TEST_SUITE( ListViewTestCase );
  26. wxLIST_BASE_TESTS();
  27. CPPUNIT_TEST( Selection );
  28. CPPUNIT_TEST( Focus );
  29. CPPUNIT_TEST_SUITE_END();
  30. void Selection();
  31. void Focus();
  32. wxListView *m_list;
  33. DECLARE_NO_COPY_CLASS(ListViewTestCase)
  34. };
  35. // register in the unnamed registry so that these tests are run by default
  36. CPPUNIT_TEST_SUITE_REGISTRATION( ListViewTestCase );
  37. // also include in its own registry so that these tests can be run alone
  38. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListViewTestCase, "ListViewTestCase" );
  39. void ListViewTestCase::setUp()
  40. {
  41. m_list = new wxListView(wxTheApp->GetTopWindow());
  42. m_list->SetWindowStyle(wxLC_REPORT);
  43. m_list->SetSize(400, 200);
  44. }
  45. void ListViewTestCase::tearDown()
  46. {
  47. wxDELETE(m_list);
  48. }
  49. void ListViewTestCase::Selection()
  50. {
  51. m_list->InsertColumn(0, "Column 0");
  52. m_list->InsertItem(0, "Item 0");
  53. m_list->InsertItem(1, "Item 1");
  54. m_list->InsertItem(2, "Item 2");
  55. m_list->InsertItem(3, "Item 3");
  56. m_list->Select(0);
  57. m_list->Select(2);
  58. m_list->Select(3);
  59. CPPUNIT_ASSERT(m_list->IsSelected(0));
  60. CPPUNIT_ASSERT(!m_list->IsSelected(1));
  61. long sel = m_list->GetFirstSelected();
  62. CPPUNIT_ASSERT_EQUAL(0, sel);
  63. sel = m_list->GetNextSelected(sel);
  64. CPPUNIT_ASSERT_EQUAL(2, sel);
  65. sel = m_list->GetNextSelected(sel);
  66. CPPUNIT_ASSERT_EQUAL(3, sel);
  67. sel = m_list->GetNextSelected(sel);
  68. CPPUNIT_ASSERT_EQUAL(-1, sel);
  69. m_list->Select(0, false);
  70. CPPUNIT_ASSERT(!m_list->IsSelected(0));
  71. CPPUNIT_ASSERT_EQUAL(2, m_list->GetFirstSelected());
  72. }
  73. void ListViewTestCase::Focus()
  74. {
  75. m_list->InsertColumn(0, "Column 0");
  76. m_list->InsertItem(0, "Item 0");
  77. m_list->InsertItem(1, "Item 1");
  78. m_list->InsertItem(2, "Item 2");
  79. m_list->InsertItem(3, "Item 3");
  80. CPPUNIT_ASSERT_EQUAL(-1, m_list->GetFocusedItem());
  81. m_list->Focus(0);
  82. CPPUNIT_ASSERT_EQUAL(0, m_list->GetFocusedItem());
  83. }