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