2011-01-13 09:49:55 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/html/htmlparser.cpp
|
|
|
|
// Purpose: wxHtmlParser tests
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2011-01-13
|
|
|
|
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#if wxUSE_HTML
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2016-02-26 14:11:55 -05:00
|
|
|
#include "wx/dcmemory.h"
|
2011-01-13 09:49:55 -05:00
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2016-02-26 14:11:55 -05:00
|
|
|
#include "wx/html/winpars.h"
|
2011-01-13 09:49:55 -05:00
|
|
|
|
|
|
|
// Test that parsing invalid HTML simply fails but doesn't crash for example.
|
2018-08-25 15:00:11 -04:00
|
|
|
TEST_CASE("wxHtmlParser::ParseInvalid", "[html][parser][error]")
|
2011-01-13 09:49:55 -05:00
|
|
|
{
|
2016-02-26 14:11:55 -05:00
|
|
|
class NullParser : public wxHtmlWinParser
|
2011-01-13 09:49:55 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual wxObject *GetProduct() wxOVERRIDE { return NULL; }
|
2011-01-13 09:49:55 -05:00
|
|
|
|
|
|
|
protected:
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual void AddText(const wxString& WXUNUSED(txt)) wxOVERRIDE { }
|
2011-01-13 09:49:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
NullParser p;
|
2016-02-26 14:11:55 -05:00
|
|
|
wxMemoryDC dc;
|
|
|
|
p.SetDC(&dc);
|
|
|
|
|
2011-01-13 09:49:55 -05:00
|
|
|
p.Parse("<");
|
|
|
|
p.Parse("<foo");
|
|
|
|
p.Parse("<!--");
|
|
|
|
p.Parse("<!---");
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:16:55 -04:00
|
|
|
TEST_CASE("wxHtmlCell::Detach", "[html][cell]")
|
|
|
|
{
|
|
|
|
wxMemoryDC dc;
|
|
|
|
|
|
|
|
wxHtmlContainerCell* const top = new wxHtmlContainerCell(NULL);
|
|
|
|
wxHtmlContainerCell* const cont = new wxHtmlContainerCell(NULL);
|
|
|
|
wxHtmlCell* const cell1 = new wxHtmlWordCell("Hello", dc);
|
|
|
|
wxHtmlCell* const cell2 = new wxHtmlColourCell(*wxRED);
|
|
|
|
wxHtmlCell* const cell3 = new wxHtmlWordCell("world", dc);
|
|
|
|
|
|
|
|
cont->InsertCell(cell1);
|
|
|
|
cont->InsertCell(cell2);
|
|
|
|
cont->InsertCell(cell3);
|
|
|
|
top->InsertCell(cont);
|
|
|
|
|
|
|
|
SECTION("container")
|
|
|
|
{
|
|
|
|
top->Detach(cont);
|
|
|
|
CHECK( top->GetFirstChild() == NULL );
|
|
|
|
|
|
|
|
delete cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("first-child")
|
|
|
|
{
|
|
|
|
cont->Detach(cell1);
|
|
|
|
CHECK( cont->GetFirstChild() == cell2 );
|
|
|
|
|
|
|
|
delete cell1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("middle-child")
|
|
|
|
{
|
|
|
|
cont->Detach(cell2);
|
|
|
|
CHECK( cont->GetFirstChild() == cell1 );
|
|
|
|
CHECK( cell1->GetNext() == cell3 );
|
|
|
|
|
|
|
|
delete cell2;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("last-child")
|
|
|
|
{
|
|
|
|
cont->Detach(cell3);
|
|
|
|
CHECK( cont->GetFirstChild() == cell1 );
|
|
|
|
CHECK( cell1->GetNext() == cell2 );
|
|
|
|
CHECK( cell2->GetNext() == NULL );
|
|
|
|
|
|
|
|
delete cell3;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("invalid")
|
|
|
|
{
|
|
|
|
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE
|
|
|
|
(
|
|
|
|
"Expected assertion for detaching non-child",
|
|
|
|
top->Detach(cell1);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:49:55 -05:00
|
|
|
#endif //wxUSE_HTML
|