]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/controls/hyperlinkctrltest.cpp
Fixed capitalisation
[wxWidgets.git] / tests / controls / hyperlinkctrltest.cpp
... / ...
CommitLineData
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
9#include "testprec.h"
10
11#if wxUSE_HYPERLINKCTRL
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19#endif // WX_PRECOMP
20
21#include "wx/hyperlink.h"
22#include "wx/uiaction.h"
23#include "testableframe.h"
24#include "asserthelper.h"
25
26class HyperlinkCtrlTestCase : public CppUnit::TestCase
27{
28public:
29 HyperlinkCtrlTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
35 CPPUNIT_TEST_SUITE( HyperlinkCtrlTestCase );
36 CPPUNIT_TEST( Colour );
37 CPPUNIT_TEST( Url );
38 WXUISIM_TEST( Click );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Colour();
42 void Url();
43 void Click();
44
45 wxHyperlinkCtrl* m_hyperlink;
46
47 DECLARE_NO_COPY_CLASS(HyperlinkCtrlTestCase)
48};
49
50// register in the unnamed registry so that these tests are run by default
51CPPUNIT_TEST_SUITE_REGISTRATION( HyperlinkCtrlTestCase );
52
53// also include in its own registry so that these tests can be run alone
54CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HyperlinkCtrlTestCase, "HyperlinkCtrlTestCase" );
55
56void HyperlinkCtrlTestCase::setUp()
57{
58 m_hyperlink = new wxHyperlinkCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
59 "wxWidgets", "http://wxwidgets.org");
60}
61
62void HyperlinkCtrlTestCase::tearDown()
63{
64 wxDELETE(m_hyperlink);
65}
66
67void HyperlinkCtrlTestCase::Colour()
68{
69#ifndef __WXGTK__
70 CPPUNIT_ASSERT(m_hyperlink->GetHoverColour().IsOk());
71 CPPUNIT_ASSERT(m_hyperlink->GetNormalColour().IsOk());
72 CPPUNIT_ASSERT(m_hyperlink->GetVisitedColour().IsOk());
73
74 m_hyperlink->SetHoverColour(*wxGREEN);
75 m_hyperlink->SetNormalColour(*wxRED);
76 m_hyperlink->SetVisitedColour(*wxBLUE);
77
78 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_hyperlink->GetHoverColour());
79 CPPUNIT_ASSERT_EQUAL(*wxRED, m_hyperlink->GetNormalColour());
80 CPPUNIT_ASSERT_EQUAL(*wxBLUE, m_hyperlink->GetVisitedColour());
81#endif
82}
83
84void HyperlinkCtrlTestCase::Url()
85{
86 CPPUNIT_ASSERT_EQUAL("http://wxwidgets.org", m_hyperlink->GetURL());
87
88 m_hyperlink->SetURL("http://google.com");
89
90 CPPUNIT_ASSERT_EQUAL("http://google.com", m_hyperlink->GetURL());
91}
92
93void HyperlinkCtrlTestCase::Click()
94{
95#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
96 EventCounter hyperlink(m_hyperlink, wxEVT_HYPERLINK);
97
98 wxUIActionSimulator sim;
99
100 sim.MouseMove(m_hyperlink->GetScreenPosition() + wxPoint(10, 10));
101 wxYield();
102
103 sim.MouseClick();
104 wxYield();
105
106 CPPUNIT_ASSERT_EQUAL(1, hyperlink.GetCount());
107#endif
108}
109
110#endif //wxUSE_HYPERLINKCTRL