/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
*/
namespace
{ /// Subclass of HTMLParser that can sense the import result. class TestHTMLParser : public HTMLParser
{ public:
TestHTMLParser(SvStream& rStream); virtualvoid NextToken(HtmlTokenId nToken) override; /// Make this public for test purposes. using HTMLParser::SetNamespace;
OUString m_aDocument; int m_nLineBreakCount = 0;
OUString m_aCdata;
};
tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
xParser->CallParser();
// This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration // was not ignored.
CPPUNIT_ASSERT_EQUAL(u"hello"_ustr, xParser->m_aDocument.trim());
}
tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
xParser->SetNamespace(u"reqif-xhtml");
xParser->CallParser();
// This was 2, <br></br> was interpreted as 2 line breaks in XHTML mode.
CPPUNIT_ASSERT_EQUAL(1, xParser->m_nLineBreakCount);
}
CPPUNIT_TEST_FIXTURE(Test, testCdata)
{ // Given a document with CDATA:
SvMemoryStream aStream;
OString aDocument("AC"_ostr);
aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
aStream.Seek(0);
// When parsing that HTML:
tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
xParser->CallParser();
// Then make sure that we get a cdata token with the correct content: // Without the accompanying fix in place, this test would have failed with: // - Expected: B ü < // - Actual : // i.e. the content inside CDATA was lost.
CPPUNIT_ASSERT_EQUAL(u"B ü <"_ustr, xParser->m_aCdata);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.