nss: upgrade to release 3.73
[LibreOffice.git] / svtools / qa / unit / testHtmlReader.cxx
blob4e5638cc59b7afd94b450c97c9f29267ef0af531
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <cppunit/TestFixture.h>
12 #include <unotest/bootstrapfixturebase.hxx>
13 #include <svtools/parhtml.hxx>
14 #include <tools/ref.hxx>
15 #include <tools/stream.hxx>
17 namespace
19 /// Subclass of HTMLParser that can sense the import result.
20 class TestHTMLParser : public HTMLParser
22 public:
23 TestHTMLParser(SvStream& rStream);
24 virtual void NextToken(HtmlTokenId nToken) override;
25 /// Make this public for test purposes.
26 using HTMLParser::SetNamespace;
28 OUString m_aDocument;
29 int m_nLineBreakCount = 0;
32 TestHTMLParser::TestHTMLParser(SvStream& rStream)
33 : HTMLParser(rStream)
37 void TestHTMLParser::NextToken(HtmlTokenId nToken)
39 if (nToken == HtmlTokenId::TEXTTOKEN)
40 m_aDocument += aToken;
41 else if (nToken == HtmlTokenId::LINEBREAK)
42 ++m_nLineBreakCount;
45 /// Tests HTMLParser.
46 class Test : public CppUnit::TestFixture
50 CPPUNIT_TEST_FIXTURE(Test, testTdf114428)
52 SvMemoryStream aStream;
53 OString aDocument("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<html>hello</html>");
54 aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
55 aStream.Seek(0);
57 tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
58 xParser->CallParser();
60 // This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration
61 // was not ignored.
62 CPPUNIT_ASSERT_EQUAL(OUString("hello"), xParser->m_aDocument.trim());
65 CPPUNIT_TEST_FIXTURE(Test, testLineBreak)
67 SvMemoryStream aStream;
68 OString aDocument("aaa<br></br>bbb");
69 aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
70 aStream.Seek(0);
72 tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
73 xParser->SetNamespace("reqif-xhtml");
74 xParser->CallParser();
76 // This was 2, <br></br> was interpreted as 2 line breaks in XHTML mode.
77 CPPUNIT_ASSERT_EQUAL(1, xParser->m_nLineBreakCount);
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */