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 EventCounter
clicked(m_win
, wxEVT_COMMAND_HTML_CELL_CLICKED
);
125 wxUIActionSimulator sim
;
127 m_win
->SetPage(TEST_MARKUP
);
131 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
137 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
140 void HtmlWindowTestCase::LinkClick()
142 EventCounter
clicked(m_win
, wxEVT_COMMAND_HTML_LINK_CLICKED
);
144 wxUIActionSimulator sim
;
146 m_win
->SetPage(TEST_MARKUP_LINK
);
150 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
156 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
158 #endif // wxUSE_UIACTIONSIMULATOR
160 void HtmlWindowTestCase::AppendToPage()
162 m_win
->SetPage(TEST_MARKUP_LINK
);
163 m_win
->AppendToPage("A new paragraph");
165 CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win
->ToText());