checklistboxtest.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/checklistlistbox.cpp
  3. // Purpose: wxCheckListBox unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-06-30
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #if wxUSE_CHECKLISTBOX
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #include "wx/checklst.h"
  16. #endif // WX_PRECOMP
  17. #include "itemcontainertest.h"
  18. #include "testableframe.h"
  19. class CheckListBoxTestCase : public ItemContainerTestCase, public CppUnit::TestCase
  20. {
  21. public:
  22. CheckListBoxTestCase() { }
  23. virtual void setUp();
  24. virtual void tearDown();
  25. private:
  26. virtual wxItemContainer *GetContainer() const { return m_check; }
  27. virtual wxWindow *GetContainerWindow() const { return m_check; }
  28. CPPUNIT_TEST_SUITE( CheckListBoxTestCase );
  29. wxITEM_CONTAINER_TESTS();
  30. CPPUNIT_TEST( Check );
  31. CPPUNIT_TEST_SUITE_END();
  32. void Check();
  33. wxCheckListBox* m_check;
  34. DECLARE_NO_COPY_CLASS(CheckListBoxTestCase)
  35. };
  36. // register in the unnamed registry so that these tests are run by default
  37. CPPUNIT_TEST_SUITE_REGISTRATION( CheckListBoxTestCase );
  38. // also include in its own registry so that these tests can be run alone
  39. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckListBoxTestCase, "CheckListBoxTestCase" );
  40. void CheckListBoxTestCase::setUp()
  41. {
  42. m_check = new wxCheckListBox(wxTheApp->GetTopWindow(), wxID_ANY);
  43. }
  44. void CheckListBoxTestCase::tearDown()
  45. {
  46. wxDELETE(m_check);
  47. }
  48. void CheckListBoxTestCase::Check()
  49. {
  50. EventCounter toggled(m_check, wxEVT_CHECKLISTBOX);
  51. wxArrayInt checkedItems;
  52. wxArrayString testitems;
  53. testitems.Add("item 0");
  54. testitems.Add("item 1");
  55. testitems.Add("item 2");
  56. testitems.Add("item 3");
  57. m_check->Append(testitems);
  58. m_check->Check(0);
  59. m_check->Check(1);
  60. m_check->Check(1, false);
  61. //We should not get any events when changing this from code
  62. CPPUNIT_ASSERT_EQUAL(0, toggled.GetCount());
  63. CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
  64. CPPUNIT_ASSERT_EQUAL(false, m_check->IsChecked(1));
  65. CPPUNIT_ASSERT_EQUAL(1, m_check->GetCheckedItems(checkedItems));
  66. CPPUNIT_ASSERT_EQUAL(0, checkedItems[0]);
  67. //Make sure a double check of an items doesn't deselect it
  68. m_check->Check(0);
  69. CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
  70. }
  71. #endif // wxUSE_CHECKLISTBOX