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 :
13 : #include <cppuhelper/implbase1.hxx>
14 :
15 : #include <comphelper/processfactory.hxx>
16 :
17 : #include <sfx2/app.hxx>
18 : #include <sfx2/docfilt.hxx>
19 : #include <sfx2/docfile.hxx>
20 : #include <sfx2/sfxmodelfactory.hxx>
21 : #include <sfx2/sfxsids.hrc>
22 :
23 : #include <svl/stritem.hxx>
24 :
25 : #include "init.hxx"
26 : #include "iodetect.hxx"
27 : #include "swtypes.hxx"
28 : #include "doc.hxx"
29 : #include "docsh.hxx"
30 : #include "shellres.hxx"
31 : #include "docufld.hxx"
32 :
33 102 : SV_DECL_REF(SwDocShell)
34 68 : SV_IMPL_REF(SwDocShell)
35 :
36 : using namespace ::com::sun::star;
37 :
38 : /* Implementation of Filters test */
39 :
40 3 : class SwFiltersTest
41 : : public test::FiltersTest
42 : , public test::BootstrapFixture
43 : {
44 : public:
45 : virtual bool load( const OUString &rFilter, const OUString &rURL,
46 : const OUString &rUserData, unsigned int nFilterFlags,
47 : unsigned int nClipboardID, unsigned int nFilterVersion);
48 : virtual void setUp();
49 :
50 : // Ensure CVEs remain unbroken
51 : void testCVEs();
52 :
53 2 : CPPUNIT_TEST_SUITE(SwFiltersTest);
54 1 : CPPUNIT_TEST(testCVEs);
55 2 : CPPUNIT_TEST_SUITE_END();
56 :
57 : private:
58 : uno::Reference<uno::XInterface> m_xWriterComponent;
59 : };
60 :
61 34 : bool SwFiltersTest::load(const OUString &rFilter, const OUString &rURL,
62 : const OUString &rUserData, unsigned int nFilterFlags,
63 : unsigned int nClipboardID, unsigned int nFilterVersion)
64 : {
65 : SfxFilter* pFilter = new SfxFilter(
66 : rFilter, OUString(), nFilterFlags,
67 : nClipboardID, OUString(), 0, OUString(),
68 34 : rUserData, OUString());
69 34 : pFilter->SetVersion(nFilterVersion);
70 :
71 34 : SwDocShellRef xDocShRef = new SwDocShell;
72 34 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
73 34 : pSrcMed->SetFilter(pFilter);
74 :
75 34 : if (rUserData == FILTER_TEXT_DLG)
76 : {
77 : pSrcMed->GetItemSet()->Put(
78 3 : SfxStringItem(SID_FILE_FILTEROPTIONS, OUString("UTF8,LF,Liberation Mono,en-US")));
79 : }
80 :
81 34 : bool bLoaded = xDocShRef->DoLoad(pSrcMed);
82 34 : if (xDocShRef.Is())
83 34 : xDocShRef->DoClose();
84 34 : return bLoaded;
85 : }
86 :
87 : #define isstorage 1
88 :
89 1 : void SwFiltersTest::testCVEs()
90 : {
91 : testDir(OUString("Staroffice XML (Writer)"),
92 : getURLFromSrc("/sw/qa/core/data/xml/"),
93 : OUString(FILTER_XML),
94 : SFX_FILTER_IMPORT | SFX_FILTER_OWN | SFX_FILTER_DEFAULT,
95 1 : isstorage, SOFFICE_FILEFORMAT_CURRENT);
96 :
97 : testDir(OUString("writer8"),
98 : getURLFromSrc("/sw/qa/core/data/odt/"),
99 : OUString(FILTER_XML),
100 : SFX_FILTER_IMPORT | SFX_FILTER_OWN | SFX_FILTER_DEFAULT,
101 1 : isstorage, SOFFICE_FILEFORMAT_CURRENT);
102 :
103 : testDir(OUString("MS Word 97"),
104 : getURLFromSrc("/sw/qa/core/data/ww8/"),
105 1 : OUString(FILTER_WW8));
106 :
107 : testDir(OUString("Text (encoded)"),
108 : getURLFromSrc("/sw/qa/core/data/txt/"),
109 1 : OUString(FILTER_TEXT_DLG));
110 :
111 : testDir(OUString("MS Word 2007 XML"),
112 : getURLFromSrc("/sw/qa/core/data/ooxml/"),
113 : OUString(),
114 1 : SFX_FILTER_STARONEFILTER);
115 :
116 : testDir(OUString("Rich Text Format"),
117 : getURLFromSrc("/sw/qa/core/data/rtf/"),
118 : OUString(),
119 1 : SFX_FILTER_STARONEFILTER);
120 1 : }
121 :
122 1 : void SwFiltersTest::setUp()
123 : {
124 1 : test::BootstrapFixture::setUp();
125 :
126 : //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
127 : //which is a private symbol to us, gets called
128 2 : m_xWriterComponent =
129 2 : getMultiServiceFactory()->createInstance(OUString(
130 2 : "com.sun.star.comp.Writer.TextDocument"));
131 1 : CPPUNIT_ASSERT_MESSAGE("no writer component!", m_xWriterComponent.is());
132 1 : }
133 :
134 1 : CPPUNIT_TEST_SUITE_REGISTRATION(SwFiltersTest);
135 :
136 4 : CPPUNIT_PLUGIN_IMPLEMENT();
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|