]>
git.saurik.com Git - wxWidgets.git/blob - tests/html/htmlwindow.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/html/htmlwindow.cpp
3 // Purpose: wxHtmlWindow tests
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
25 #include "wx/html/htmlwin.h"
26 #include "wx/uiaction.h"
27 #include "testableframe.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class HtmlWindowTestCase
: public CppUnit::TestCase
36 HtmlWindowTestCase() { }
39 virtual void tearDown();
42 CPPUNIT_TEST_SUITE( HtmlWindowTestCase
);
43 CPPUNIT_TEST( SelectionToText
);
44 CPPUNIT_TEST( Title
);
45 #if wxUSE_UIACTIONSIMULATOR
46 WXUISIM_TEST( CellClick
);
47 WXUISIM_TEST( LinkClick
);
48 #endif // wxUSE_UIACTIONSIMULATOR
49 CPPUNIT_TEST( AppendToPage
);
50 CPPUNIT_TEST_SUITE_END();
52 void SelectionToText();
60 DECLARE_NO_COPY_CLASS(HtmlWindowTestCase
)
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase
);
66 // also include in its own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase
, "HtmlWindowTestCase" );
69 // ----------------------------------------------------------------------------
70 // test initialization
71 // ----------------------------------------------------------------------------
73 void HtmlWindowTestCase::setUp()
75 m_win
= new wxHtmlWindow(wxTheApp
->GetTopWindow(), wxID_ANY
,
76 wxDefaultPosition
, wxSize(400, 200));
79 void HtmlWindowTestCase::tearDown()
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 static const char *TEST_MARKUP
=
96 static const char *TEST_MARKUP_LINK
=
98 "<a href=\"link\">link<\\a> "
101 static const char *TEST_PLAIN_TEXT
=
102 "Title\nA longer line\nand the last line.";
104 void HtmlWindowTestCase::SelectionToText()
106 m_win
->SetPage(TEST_MARKUP
);
109 CPPUNIT_ASSERT_EQUAL( TEST_PLAIN_TEXT
, m_win
->SelectionToText() );
112 void HtmlWindowTestCase::Title()
114 m_win
->SetPage(TEST_MARKUP
);
116 CPPUNIT_ASSERT_EQUAL("Page", m_win
->GetOpenedPageTitle());
119 #if wxUSE_UIACTIONSIMULATOR
120 void HtmlWindowTestCase::CellClick()
122 EventCounter
clicked(m_win
, wxEVT_HTML_CELL_CLICKED
);
124 wxUIActionSimulator sim
;
126 m_win
->SetPage(TEST_MARKUP
);
130 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
136 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
139 void HtmlWindowTestCase::LinkClick()
141 EventCounter
clicked(m_win
, wxEVT_HTML_LINK_CLICKED
);
143 wxUIActionSimulator sim
;
145 m_win
->SetPage(TEST_MARKUP_LINK
);
149 sim
.MouseMove(m_win
->ClientToScreen(wxPoint(15, 15)));
155 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
157 #endif // wxUSE_UIACTIONSIMULATOR
159 void HtmlWindowTestCase::AppendToPage()
161 m_win
->SetPage(TEST_MARKUP_LINK
);
162 m_win
->AppendToPage("A new paragraph");
164 CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win
->ToText());