hyperlinkctrltest.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/hyperlinkctrltest.cpp
  3. // Purpose: wxHyperlinkCtrl unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-08-05
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #if wxUSE_HYPERLINKCTRL
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #endif // WX_PRECOMP
  16. #include "wx/hyperlink.h"
  17. #include "wx/uiaction.h"
  18. #include "testableframe.h"
  19. #include "asserthelper.h"
  20. class HyperlinkCtrlTestCase : public CppUnit::TestCase
  21. {
  22. public:
  23. HyperlinkCtrlTestCase() { }
  24. void setUp();
  25. void tearDown();
  26. private:
  27. CPPUNIT_TEST_SUITE( HyperlinkCtrlTestCase );
  28. CPPUNIT_TEST( Colour );
  29. CPPUNIT_TEST( Url );
  30. WXUISIM_TEST( Click );
  31. CPPUNIT_TEST_SUITE_END();
  32. void Colour();
  33. void Url();
  34. void Click();
  35. wxHyperlinkCtrl* m_hyperlink;
  36. DECLARE_NO_COPY_CLASS(HyperlinkCtrlTestCase)
  37. };
  38. // register in the unnamed registry so that these tests are run by default
  39. CPPUNIT_TEST_SUITE_REGISTRATION( HyperlinkCtrlTestCase );
  40. // also include in its own registry so that these tests can be run alone
  41. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HyperlinkCtrlTestCase, "HyperlinkCtrlTestCase" );
  42. void HyperlinkCtrlTestCase::setUp()
  43. {
  44. m_hyperlink = new wxHyperlinkCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
  45. "wxWidgets", "http://wxwidgets.org");
  46. }
  47. void HyperlinkCtrlTestCase::tearDown()
  48. {
  49. wxDELETE(m_hyperlink);
  50. }
  51. void HyperlinkCtrlTestCase::Colour()
  52. {
  53. #ifndef __WXGTK__
  54. CPPUNIT_ASSERT(m_hyperlink->GetHoverColour().IsOk());
  55. CPPUNIT_ASSERT(m_hyperlink->GetNormalColour().IsOk());
  56. CPPUNIT_ASSERT(m_hyperlink->GetVisitedColour().IsOk());
  57. m_hyperlink->SetHoverColour(*wxGREEN);
  58. m_hyperlink->SetNormalColour(*wxRED);
  59. m_hyperlink->SetVisitedColour(*wxBLUE);
  60. CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_hyperlink->GetHoverColour());
  61. CPPUNIT_ASSERT_EQUAL(*wxRED, m_hyperlink->GetNormalColour());
  62. CPPUNIT_ASSERT_EQUAL(*wxBLUE, m_hyperlink->GetVisitedColour());
  63. #endif
  64. }
  65. void HyperlinkCtrlTestCase::Url()
  66. {
  67. CPPUNIT_ASSERT_EQUAL("http://wxwidgets.org", m_hyperlink->GetURL());
  68. m_hyperlink->SetURL("http://google.com");
  69. CPPUNIT_ASSERT_EQUAL("http://google.com", m_hyperlink->GetURL());
  70. }
  71. void HyperlinkCtrlTestCase::Click()
  72. {
  73. #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
  74. EventCounter hyperlink(m_hyperlink, wxEVT_HYPERLINK);
  75. wxUIActionSimulator sim;
  76. sim.MouseMove(m_hyperlink->GetScreenPosition() + wxPoint(10, 10));
  77. wxYield();
  78. sim.MouseClick();
  79. wxYield();
  80. CPPUNIT_ASSERT_EQUAL(1, hyperlink.GetCount());
  81. #endif
  82. }
  83. #endif //wxUSE_HYPERLINKCTRL