Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / sd / qa / unit / filters-test.cxx
blob52fc6f9d70503744b2fcce2e8504eeaa66f5231a
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 <sal/config.h>
11 #include <unotest/filters-test.hxx>
12 #include <test/bootstrapfixture.hxx>
13 #include <com/sun/star/lang/XComponent.hpp>
15 #include <sfx2/docfilt.hxx>
16 #include <sfx2/docfile.hxx>
18 #include <drawdoc.hxx>
19 #include <DrawDocShell.hxx>
21 using namespace ::com::sun::star;
23 /// Test loading of files to assure they do not crash on load.
24 class SdFiltersTest
25 : public test::FiltersTest
26 , public test::BootstrapFixture
28 public:
29 SdFiltersTest();
31 virtual bool load( const OUString &rFilter,
32 const OUString &rURL, const OUString &rUserData,
33 SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
34 unsigned int nFilterVersion) override;
36 virtual void setUp() override;
37 virtual void tearDown() override;
39 // Ensure CVEs remain unbroken
40 void testCVEs();
42 CPPUNIT_TEST_SUITE(SdFiltersTest);
43 CPPUNIT_TEST(testCVEs);
44 CPPUNIT_TEST_SUITE_END();
46 private:
47 uno::Reference<uno::XInterface> m_xDrawComponent;
50 bool SdFiltersTest::load(const OUString &rFilter, const OUString &rURL,
51 const OUString &rUserData, SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
52 unsigned int nFilterVersion)
54 std::shared_ptr<const SfxFilter> pFilter(new SfxFilter(
55 rFilter,
56 OUString(), nFilterFlags, nClipboardID, OUString(), OUString(),
57 rUserData, OUString() ));
58 const_cast<SfxFilter*>(pFilter.get())->SetVersion(nFilterVersion);
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;
68 void SdFiltersTest::testCVEs()
70 #ifndef DISABLE_CVE_TESTS
71 testDir("MS PowerPoint 97",
72 m_directories.getURLFromSrc("/sd/qa/unit/data/ppt/"),
73 "sdfilt");
75 testDir("Impress Office Open XML",
76 m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/"),
77 "", (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER));
79 testDir("impress8",
80 m_directories.getURLFromSrc("/sd/qa/unit/data/odp/"),
81 "sdfilt");
83 testDir("draw8",
84 m_directories.getURLFromSrc("/sd/qa/unit/data/odg/"),
85 "sdfilt");
87 testDir("CGM - Computer Graphics Metafile",
88 m_directories.getURLFromSrc("/sd/qa/unit/data/cgm/"),
89 "icg");
90 #endif
93 SdFiltersTest::SdFiltersTest()
97 void SdFiltersTest::setUp()
99 test::BootstrapFixture::setUp();
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());
108 void SdFiltersTest::tearDown()
110 uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
111 test::BootstrapFixture::tearDown();
114 CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
116 CPPUNIT_PLUGIN_IMPLEMENT();
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */