bitmaptogglebuttontest.cpp 2.9 KB

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