Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / filter / qa / unit / textfilterdetect.cxx
blobf5bf6fc98b42a09f553b5200ca175a3e5db12a93
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/.
8 */
10 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
12 #include <comphelper/processfactory.hxx>
13 #include <comphelper/propertyvalue.hxx>
14 #include <test/bootstrapfixture.hxx>
15 #include <unotools/mediadescriptor.hxx>
16 #include <unotools/streamwrap.hxx>
17 #include <tools/stream.hxx>
19 namespace com::sun::star::io
21 class XInputStream;
24 using namespace com::sun::star;
26 namespace
28 /// Test class for PlainTextFilterDetect.
29 class TextFilterDetectTest : public test::BootstrapFixture
33 char const DATA_DIRECTORY[] = "/filter/qa/unit/data/";
35 CPPUNIT_TEST_FIXTURE(TextFilterDetectTest, testTdf114428)
37 uno::Reference<uno::XComponentContext> xComponentContext
38 = comphelper::getComponentContext(getMultiServiceFactory());
39 uno::Reference<document::XExtendedFilterDetection> xDetect(
40 getMultiServiceFactory()->createInstance("com.sun.star.comp.filters.PlainTextFilterDetect"),
41 uno::UNO_QUERY);
42 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf114428.xhtml";
43 SvFileStream aStream(aURL, StreamMode::READ);
44 uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(aStream));
45 uno::Sequence<beans::PropertyValue> aDescriptor
46 = { comphelper::makePropertyValue("DocumentService",
47 OUString("com.sun.star.text.TextDocument")),
48 comphelper::makePropertyValue("InputStream", xStream),
49 comphelper::makePropertyValue("TypeName", OUString("generic_HTML")) };
50 xDetect->detect(aDescriptor);
51 utl::MediaDescriptor aMediaDesc(aDescriptor);
52 OUString aFilterName = aMediaDesc.getUnpackedValueOrDefault("FilterName", OUString());
53 // This was empty, XML declaration caused HTML detect to not handle XHTML.
54 CPPUNIT_ASSERT_EQUAL(OUString("HTML (StarWriter)"), aFilterName);
58 CPPUNIT_PLUGIN_IMPLEMENT();
60 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */