togglebuttontest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/togglebuttontest.cpp
  3. // Purpose: wxToggleButton unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-07-14
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #if wxUSE_TOGGLEBTN
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #endif // WX_PRECOMP
  16. #include "testableframe.h"
  17. #include "wx/uiaction.h"
  18. #include "wx/tglbtn.h"
  19. class ToggleButtonTestCase : public CppUnit::TestCase
  20. {
  21. public:
  22. ToggleButtonTestCase() { }
  23. void setUp();
  24. void tearDown();
  25. private:
  26. CPPUNIT_TEST_SUITE( ToggleButtonTestCase );
  27. WXUISIM_TEST( Click );
  28. CPPUNIT_TEST( Value );
  29. CPPUNIT_TEST_SUITE_END();
  30. void Click();
  31. void Value();
  32. wxToggleButton* m_button;
  33. DECLARE_NO_COPY_CLASS(ToggleButtonTestCase)
  34. };
  35. // register in the unnamed registry so that these tests are run by default
  36. CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase );
  37. // also include in its own registry so that these tests can be run alone
  38. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase, "ToggleButtonTestCase" );
  39. void ToggleButtonTestCase::setUp()
  40. {
  41. m_button = new wxToggleButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxToggleButton");
  42. }
  43. void ToggleButtonTestCase::tearDown()
  44. {
  45. wxDELETE(m_button);
  46. }
  47. void ToggleButtonTestCase::Click()
  48. {
  49. #if wxUSE_UIACTIONSIMULATOR
  50. EventCounter clicked(m_button, wxEVT_TOGGLEBUTTON);
  51. wxUIActionSimulator sim;
  52. //We move in slightly to account for window decorations
  53. sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
  54. wxYield();
  55. sim.MouseClick();
  56. wxYield();
  57. CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
  58. CPPUNIT_ASSERT(m_button->GetValue());
  59. clicked.Clear();
  60. sim.MouseClick();
  61. wxYield();
  62. CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
  63. CPPUNIT_ASSERT(!m_button->GetValue());
  64. #endif
  65. }
  66. void ToggleButtonTestCase::Value()
  67. {
  68. EventCounter clicked(m_button, wxEVT_BUTTON);
  69. m_button->SetValue(true);
  70. CPPUNIT_ASSERT(m_button->GetValue());
  71. m_button->SetValue(false);
  72. CPPUNIT_ASSERT(!m_button->GetValue());
  73. CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
  74. }
  75. #endif //wxUSE_TOGGLEBTN