Debian Codegraph @

sw/qa/writerfilter/filters-test/filters-test.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10 #include <unotest/filters-test.hxx>
11 #include <test/bootstrapfixture.hxx>
12 #include <com/sun/star/document/XFilter.hpp>
13 #include <com/sun/star/io/WrongFormatException.hpp>
14 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
15
16 using namespace ::com::sun::star;
17
18 /**
19 * Unit test invoking sw/source/writerfilter/ only.
20 *
21 * This does only minimal testing, checking if the filter crashes and returns
22 * the expected bool value for given inputs. More fine-grained tests can be
23 * found under sw/qa/extras/rtfimport/.
24 */
25 class RtfTest : public test::FiltersTest, public test::BootstrapFixture
26 {
27 public:
28 virtual void setUp() override;
29
30 virtual bool load(const OUString&, const OUString& rURL, const OUString&, SfxFilterFlags,
31 SotClipboardFormatId, unsigned int) override;
32
33 private:
34 uno::Reference<document::XFilter> m_xFilter;
35 };
36
37 void RtfTest::setUp()
38 {
39 test::BootstrapFixture::setUp();
40
41 m_xFilter.set(m_xSFactory->createInstance(u"com.sun.star.comp.Writer.RtfFilter"_ustr),
42 uno::UNO_QUERY_THROW);
43 }
44
45 bool RtfTest::load(const OUString&, const OUString& rURL, const OUString&, SfxFilterFlags,
46 SotClipboardFormatId, unsigned int)
47 {
48 uno::Sequence<beans::PropertyValue> aDescriptor = { beans::PropertyValue(
49 u"URL"_ustr, sal_Int32(0), uno::Any(rURL), beans::PropertyState_DIRECT_VALUE) };
50 try
51 {
52 return m_xFilter->filter(aDescriptor);
53 }
54 catch (const lang::WrappedTargetRuntimeException& rWrapped)
55 {
56 io::WrongFormatException e;
57 if (rWrapped.TargetException >>= e)
58 {
59 return false;
60 }
61 throw;
62 }
63 catch (const std::exception&)
64 {
65 return false;
66 }
67 }
68
69 CPPUNIT_TEST_FIXTURE(RtfTest, testFilter)
70 {
71 #ifndef DISABLE_CVE_TESTS
72 #if defined _WIN32 && defined _ARM64_
73 // skip for windows arm64 build
74 #else
75 testDir(OUString(), m_directories.getURLFromSrc(u"/sw/qa/writerfilter/filters-test/data/"));
76 #endif
77 #endif
78 }
79
80 CPPUNIT_PLUGIN_IMPLEMENT();
81
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */