]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/hyperlinkctrltest.cpp
make sure the quit item is only shown where appropriate on osx
[wxWidgets.git] / tests / controls / hyperlinkctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/hyperlinkctrltest.cpp
3 // Purpose: wxHyperlinkCtrl unit test
4 // Author: Steven Lamerton
5 // Created: 2010-08-05
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_HYPERLINKCTRL
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #endif // WX_PRECOMP
21
22 #include "wx/hyperlink.h"
23 #include "wx/uiaction.h"
24 #include "testableframe.h"
25 #include "asserthelper.h"
26
27 class HyperlinkCtrlTestCase : public CppUnit::TestCase
28 {
29 public:
30 HyperlinkCtrlTestCase() { }
31
32 void setUp();
33 void tearDown();
34
35 private:
36 CPPUNIT_TEST_SUITE( HyperlinkCtrlTestCase );
37 CPPUNIT_TEST( Colour );
38 CPPUNIT_TEST( Url );
39 WXUISIM_TEST( Click );
40 CPPUNIT_TEST_SUITE_END();
41
42 void Colour();
43 void Url();
44 void Click();
45
46 wxHyperlinkCtrl* m_hyperlink;
47
48 DECLARE_NO_COPY_CLASS(HyperlinkCtrlTestCase)
49 };
50
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( HyperlinkCtrlTestCase );
53
54 // also include in it's own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HyperlinkCtrlTestCase, "HyperlinkCtrlTestCase" );
56
57 void HyperlinkCtrlTestCase::setUp()
58 {
59 m_hyperlink = new wxHyperlinkCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
60 "wxWidgets", "http://wxwidgets.org");
61 }
62
63 void HyperlinkCtrlTestCase::tearDown()
64 {
65 wxDELETE(m_hyperlink);
66 }
67
68 void HyperlinkCtrlTestCase::Colour()
69 {
70 #ifndef __WXGTK__
71 CPPUNIT_ASSERT(m_hyperlink->GetHoverColour().IsOk());
72 CPPUNIT_ASSERT(m_hyperlink->GetNormalColour().IsOk());
73 CPPUNIT_ASSERT(m_hyperlink->GetVisitedColour().IsOk());
74
75 m_hyperlink->SetHoverColour(*wxGREEN);
76 m_hyperlink->SetNormalColour(*wxRED);
77 m_hyperlink->SetVisitedColour(*wxBLUE);
78
79 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_hyperlink->GetHoverColour());
80 CPPUNIT_ASSERT_EQUAL(*wxRED, m_hyperlink->GetNormalColour());
81 CPPUNIT_ASSERT_EQUAL(*wxBLUE, m_hyperlink->GetVisitedColour());
82 #endif
83 }
84
85 void HyperlinkCtrlTestCase::Url()
86 {
87 CPPUNIT_ASSERT_EQUAL("http://wxwidgets.org", m_hyperlink->GetURL());
88
89 m_hyperlink->SetURL("http://google.com");
90
91 CPPUNIT_ASSERT_EQUAL("http://google.com", m_hyperlink->GetURL());
92 }
93
94 void HyperlinkCtrlTestCase::Click()
95 {
96 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
97 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
98 wxTestableFrame);
99
100 EventCounter count(m_hyperlink, wxEVT_COMMAND_HYPERLINK);
101
102 wxUIActionSimulator sim;
103
104 sim.MouseMove(m_hyperlink->GetScreenPosition() + wxPoint(10, 10));
105 wxYield();
106
107 sim.MouseClick();
108 wxYield();
109
110 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount());
111 #endif
112 }
113
114 #endif //wxUSE_HYPERLINKCTRL