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 <sal/config.h>
11 : #include <unotest/filters-test.hxx>
12 : #include <test/bootstrapfixture.hxx>
13 : #include <rtl/strbuf.hxx>
14 : #include <osl/file.hxx>
15 : #include <com/sun/star/lang/XComponent.hpp>
16 : #include <com/sun/star/document/XFilter.hpp>
17 :
18 : #include <sfx2/app.hxx>
19 : #include <sfx2/docfilt.hxx>
20 : #include <sfx2/docfile.hxx>
21 : #include <sfx2/sfxmodelfactory.hxx>
22 : #include <svl/stritem.hxx>
23 :
24 : #include <svx/svdtext.hxx>
25 : #include <svx/svdotext.hxx>
26 :
27 : #include "drawdoc.hxx"
28 : #include "../source/ui/inc/DrawDocShell.hxx"
29 :
30 : #include <osl/process.h>
31 : #include <osl/thread.h>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : /// Test loading of files to assure they do not crash on load.
36 2 : class SdFiltersTest
37 : : public test::FiltersTest
38 : , public test::BootstrapFixture
39 : {
40 : public:
41 : SdFiltersTest();
42 :
43 : virtual bool load( const OUString &rFilter,
44 : const OUString &rURL, const OUString &rUserData,
45 : SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
46 : unsigned int nFilterVersion) SAL_OVERRIDE;
47 :
48 : virtual void setUp() SAL_OVERRIDE;
49 : virtual void tearDown() SAL_OVERRIDE;
50 :
51 : // Ensure CVEs remain unbroken
52 : void testCVEs();
53 :
54 2 : CPPUNIT_TEST_SUITE(SdFiltersTest);
55 1 : CPPUNIT_TEST(testCVEs);
56 5 : CPPUNIT_TEST_SUITE_END();
57 :
58 : private:
59 : uno::Reference<uno::XInterface> m_xDrawComponent;
60 : };
61 :
62 13 : bool SdFiltersTest::load(const OUString &rFilter, const OUString &rURL,
63 : const OUString &rUserData, SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
64 : unsigned int nFilterVersion)
65 : {
66 : SfxFilter aFilter(
67 : rFilter,
68 : OUString(), nFilterFlags, nClipboardID, OUString(), 0, OUString(),
69 13 : rUserData, OUString() );
70 13 : aFilter.SetVersion(nFilterVersion);
71 :
72 26 : ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
73 13 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
74 13 : pSrcMed->SetFilter(&aFilter);
75 13 : bool bLoaded = xDocShRef->DoLoad(pSrcMed);
76 13 : xDocShRef->DoClose();
77 26 : return bLoaded;
78 : }
79 :
80 1 : void SdFiltersTest::testCVEs()
81 : {
82 : #ifndef DISABLE_CVE_TESTS
83 : testDir(OUString("MS PowerPoint 97"),
84 : getURLFromSrc("/sd/qa/unit/data/ppt/"),
85 1 : OUString("sdfilt"));
86 :
87 : testDir(OUString("Impress Office Open XML"),
88 : getURLFromSrc("/sd/qa/unit/data/pptx/"),
89 1 : OUString(""), (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER));
90 :
91 : testDir(OUString("impress8"),
92 : getURLFromSrc("/sd/qa/unit/data/odp/"),
93 1 : OUString("sdfilt"));
94 :
95 : testDir(OUString("draw8"),
96 : getURLFromSrc("/sd/qa/unit/data/odg/"),
97 1 : OUString("sdfilt"));
98 :
99 : testDir(OUString("CGM - Computer Graphics Metafile"),
100 : getURLFromSrc("/sd/qa/unit/data/cgm/"),
101 1 : OUString("icg"));
102 : #endif
103 1 : }
104 :
105 1 : SdFiltersTest::SdFiltersTest()
106 : {
107 1 : }
108 :
109 1 : void SdFiltersTest::setUp()
110 : {
111 1 : test::BootstrapFixture::setUp();
112 :
113 : // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
114 : // which is a private symbol to us, gets called
115 2 : m_xDrawComponent =
116 3 : getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
117 1 : CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
118 1 : }
119 :
120 1 : void SdFiltersTest::tearDown()
121 : {
122 1 : uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
123 1 : test::BootstrapFixture::tearDown();
124 1 : }
125 :
126 1 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
127 :
128 4 : CPPUNIT_PLUGIN_IMPLEMENT();
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|