1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: tests/html/htmlparser.cpp 3 // Purpose: wxHtmlParser tests 4 // Author: Vadim Zeitlin 5 // Created: 2011-01-13 6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org> 7 /////////////////////////////////////////////////////////////////////////////// 8 9 // ---------------------------------------------------------------------------- 10 // headers 11 // ---------------------------------------------------------------------------- 12 13 #include "testprec.h" 14 15 #if wxUSE_HTML 16 17 18 #ifndef WX_PRECOMP 19 #include "wx/dcmemory.h" 20 #endif // WX_PRECOMP 21 22 #include "wx/html/winpars.h" 23 #include "wx/scopedptr.h" 24 25 // Test that parsing invalid HTML simply fails but doesn't crash for example. 26 TEST_CASE("wxHtmlParser::ParseInvalid", "[html][parser][error]") 27 { 28 class NullParser : public wxHtmlWinParser 29 { 30 protected: AddText(const wxString & WXUNUSED (txt))31 virtual void AddText(const wxString& WXUNUSED(txt)) wxOVERRIDE { } 32 }; 33 34 NullParser p; 35 wxMemoryDC dc; 36 p.SetDC(&dc); 37 38 delete p.Parse("<"); 39 delete p.Parse("<foo"); 40 delete p.Parse("<!--"); 41 delete p.Parse("<!---"); 42 } 43 44 TEST_CASE("wxHtmlCell::Detach", "[html][cell]") 45 { 46 wxMemoryDC dc; 47 48 wxScopedPtr<wxHtmlContainerCell> const top(new wxHtmlContainerCell(NULL)); 49 wxHtmlContainerCell* const cont = new wxHtmlContainerCell(NULL); 50 wxHtmlCell* const cell1 = new wxHtmlWordCell("Hello", dc); 51 wxHtmlCell* const cell2 = new wxHtmlColourCell(*wxRED); 52 wxHtmlCell* const cell3 = new wxHtmlWordCell("world", dc); 53 54 cont->InsertCell(cell1); 55 cont->InsertCell(cell2); 56 cont->InsertCell(cell3); 57 top->InsertCell(cont); 58 59 SECTION("container") 60 { 61 top->Detach(cont); 62 CHECK( top->GetFirstChild() == NULL ); 63 64 delete cont; 65 } 66 67 SECTION("first-child") 68 { 69 cont->Detach(cell1); 70 CHECK( cont->GetFirstChild() == cell2 ); 71 72 delete cell1; 73 } 74 75 SECTION("middle-child") 76 { 77 cont->Detach(cell2); 78 CHECK( cont->GetFirstChild() == cell1 ); 79 CHECK( cell1->GetNext() == cell3 ); 80 81 delete cell2; 82 } 83 84 SECTION("last-child") 85 { 86 cont->Detach(cell3); 87 CHECK( cont->GetFirstChild() == cell1 ); 88 CHECK( cell1->GetNext() == cell2 ); 89 CHECK( cell2->GetNext() == NULL ); 90 91 delete cell3; 92 } 93 94 SECTION("invalid") 95 { 96 WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE 97 ( 98 "Expected assertion for detaching non-child", 99 top->Detach(cell1); 100 ); 101 } 102 } 103 104 #endif //wxUSE_HTML 105