Line data Source code
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 : #include <osl/file.hxx>
17 : #include <osl/process.h>
18 :
19 : using namespace ::com::sun::star;
20 :
21 : /**
22 : * Unit test invoking the Writer RTF import filter.
23 : *
24 : * This does only minimal testing, checking if the filter crashes and returns
25 : * the expected bool value for given inputs. More fine-grained tests can be
26 : * found under sw/qa/extras/rtfimport/.
27 : */
28 6 : class RtfTest
29 : : public test::FiltersTest
30 : , public test::BootstrapFixture
31 : {
32 : public:
33 :
34 : virtual void setUp() SAL_OVERRIDE;
35 :
36 : virtual bool load(const OUString&,
37 : const OUString& rURL, const OUString&,
38 : unsigned int, unsigned int, unsigned int) SAL_OVERRIDE;
39 :
40 : void test();
41 :
42 4 : CPPUNIT_TEST_SUITE(RtfTest);
43 2 : CPPUNIT_TEST(test);
44 4 : CPPUNIT_TEST_SUITE_END();
45 : private:
46 : uno::Reference<document::XFilter> m_xFilter;
47 : };
48 :
49 2 : void RtfTest::setUp()
50 : {
51 2 : test::BootstrapFixture::setUp();
52 :
53 2 : m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), uno::UNO_QUERY_THROW);
54 2 : }
55 :
56 52 : bool RtfTest::load(const OUString&,
57 : const OUString& rURL, const OUString&,
58 : unsigned int, unsigned int, unsigned int)
59 : {
60 52 : uno::Sequence< beans::PropertyValue > aDescriptor(1);
61 52 : aDescriptor[0].Name = "URL";
62 52 : aDescriptor[0].Value <<= rURL;
63 : try
64 : {
65 52 : return m_xFilter->filter(aDescriptor);
66 : }
67 6 : catch (const lang::WrappedTargetRuntimeException& rWrapped)
68 : {
69 6 : io::WrongFormatException e;
70 6 : if (rWrapped.TargetException >>= e)
71 : {
72 6 : return false;
73 : }
74 6 : throw;
75 52 : }
76 : }
77 :
78 2 : void RtfTest::test()
79 : {
80 : testDir(OUString(),
81 : getURLFromSrc("/writerfilter/qa/cppunittests/rtftok/data/"),
82 2 : OUString());
83 2 : }
84 :
85 2 : CPPUNIT_TEST_SUITE_REGISTRATION(RtfTest);
86 :
87 8 : CPPUNIT_PLUGIN_IMPLEMENT();
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|