1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/html/htmlwindow.cpp
3 // Purpose: wxHtmlWindow tests
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
26 #include "wx/html/htmlwin.h"
27 #include "wx/uiaction.h"
28 #include "testableframe.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class HtmlWindowTestCase
: public CppUnit::TestCase
37 HtmlWindowTestCase() { }
40 virtual void tearDown();
43 CPPUNIT_TEST_SUITE( HtmlWindowTestCase
);
44 CPPUNIT_TEST( SelectionToText
);
45 CPPUNIT_TEST( Title
);
46 #if wxUSE_UIACTIONSIMULATOR
47 WXUISIM_TEST( CellClick
);
48 WXUISIM_TEST( LinkClick
);
49 #endif // wxUSE_UIACTIONSIMULATOR
50 CPPUNIT_TEST( AppendToPage
);
51 CPPUNIT_TEST_SUITE_END();
53 void SelectionToText();
61 DECLARE_NO_COPY_CLASS(HtmlWindowTestCase
)
64 // register in the unnamed registry so that these tests are run by default
65 CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase
);
67 // also include in its own registry so that these tests can be run alone
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase
, "HtmlWindowTestCase" );
70 // ----------------------------------------------------------------------------
71 // test initialization
72 // ----------------------------------------------------------------------------
74 void HtmlWindowTestCase::setUp()
76 m_win
= new wxHtmlWindow(wxTheApp
->GetTopWindow(), wxID_ANY
,
77 wxDefaultPosition
, wxSize(400, 200));
80 void HtmlWindowTestCase::tearDown()
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 static const char *TEST_MARKUP
=
97 static const char *TEST_MARKUP_LINK
=
99 "<a href=\"link\">link<\\a> "
102 static const char *TEST_PLAIN_TEXT
=
103 "Title\nA longer line\nand the last line.";
105 void HtmlWindowTestCase::SelectionToText()
107 m_win
->SetPage(TEST_MARKUP
);
110 CPPUNIT_ASSERT_EQUAL( TEST_PLAIN_TEXT
, m_win
->SelectionToText() );
113 void HtmlWindowTestCase::Title()
115 m_win
->SetPage(TEST_MARKUP
);
117 CPPUNIT_ASSERT_EQUAL("Page", m_win
->GetOpenedPageTitle());
120 #if wxUSE_UIACTIONSIMULATOR
121 void HtmlWindowTestCase::CellClick()
123 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
126 EventCounter
count1(m_win
, wxEVT_COMMAND_HTML_CELL_CLICKED
);
128 wxUIActionSimulator sim
;
130 m_win
->SetPage(TEST_MARKUP
);
134 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
140 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
143 void HtmlWindowTestCase::LinkClick()
145 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
148 EventCounter
count1(m_win
, wxEVT_COMMAND_HTML_LINK_CLICKED
);
150 wxUIActionSimulator sim
;
152 m_win
->SetPage(TEST_MARKUP_LINK
);
156 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
162 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
164 #endif // wxUSE_UIACTIONSIMULATOR
166 void HtmlWindowTestCase::AppendToPage()
168 m_win
->SetPage(TEST_MARKUP_LINK
);
169 m_win
->AppendToPage("A new paragraph");
171 CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win
->ToText());