1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
12 #include "helper/scfiltertestbase.hxx"
15 #include <document.hxx>
16 #include <testlotus.hxx>
18 #include <osl/file.hxx>
19 #include <sfx2/docfilt.hxx>
20 #include <sfx2/docfile.hxx>
21 #include <tools/stream.hxx>
22 #include <tools/urlobj.hxx>
23 #include <unotools/tempfile.hxx>
25 using namespace ::com::sun::star
;
27 /* Implementation of Filters test */
30 : public ScFilterTestBase
35 virtual bool load( const OUString
&rFilter
, const OUString
&rURL
,
36 const OUString
&rUserData
, SfxFilterFlags nFilterFlags
,
37 SotClipboardFormatId nClipboardID
, unsigned int nFilterVersion
) override
;
39 * Ensure CVEs remain unbroken
43 void testContentofz9704();
46 CPPUNIT_TEST_SUITE(ScFiltersTest
);
47 CPPUNIT_TEST(testCVEs
);
48 CPPUNIT_TEST(testContentofz9704
);
49 CPPUNIT_TEST(testTdf90299
);
51 CPPUNIT_TEST_SUITE_END();
54 void createFileURL(std::u16string_view aFileBase
, std::u16string_view aFileExtension
, OUString
& rFilePath
);
57 void ScFiltersTest::createFileURL(
58 std::u16string_view aFileBase
, std::u16string_view aFileExtension
, OUString
& rFilePath
)
60 // aFileBase may contain multiple segments, so use
61 // GetNewAbsURL instead of insertName for them:
62 INetURLObject
url(m_directories
.getSrcRootURL());
64 url
.GetNewAbsURL(u
"sc/qa/unit/data"_ustr
, &url
);
65 url
.insertName(aFileExtension
, true);
66 url
.GetNewAbsURL(OUString::Concat(aFileBase
) + aFileExtension
, &url
);
67 rFilePath
= url
.GetMainURL(INetURLObject::DecodeMechanism::NONE
);
71 bool ScFiltersTest::load(const OUString
&rFilter
, const OUString
&rURL
,
72 const OUString
&rUserData
, SfxFilterFlags nFilterFlags
,
73 SotClipboardFormatId nClipboardID
, unsigned int nFilterVersion
)
75 ScDocShellRef xDocShRef
= loadDoc(rURL
, rFilter
, rUserData
,
76 OUString(), nFilterFlags
, nClipboardID
, nFilterVersion
);
77 bool bLoaded
= xDocShRef
.is();
78 //reference counting of ScDocShellRef is very confused.
84 void ScFiltersTest::testCVEs()
86 #ifndef DISABLE_CVE_TESTS
87 testDir(u
"Quattro Pro 6.0"_ustr
,
88 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/qpro/"));
90 //warning, the current "sylk filter" in sc (docsh.cxx) automatically
91 //chains on failure on trying as csv, rtf, etc. so "success" may
92 //not indicate that it imported as .slk.
94 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/slk/"));
95 #if defined _WIN32 && defined _ARM64_
96 // skip for windows arm64 build
98 testDir(u
"MS Excel 97"_ustr
,
99 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/xls/"));
102 testDir(u
"Calc Office Open XML"_ustr
,
103 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/xlsx/"), OUString(), XLSX_FORMAT_TYPE
);
105 testDir(u
"Calc Office Open XML"_ustr
,
106 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/xlsm/"), OUString(), XLSX_FORMAT_TYPE
);
108 testDir(u
"dBase"_ustr
,
109 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/dbf/"));
111 testDir(u
"Lotus"_ustr
,
112 m_directories
.getURLFromSrc(u
"/sc/qa/unit/data/wks/"));
117 void ScFiltersTest::testContentofz9704()
120 createFileURL(u
"ofz9704.", u
"123", aFileName
);
121 SvFileStream
aFileStream(aFileName
, StreamMode::READ
);
122 TestImportWKS(aFileStream
);
125 void ScFiltersTest::testTdf90299()
127 const OUString aTmpDirectory1URL
= utl::CreateTempURL(nullptr, true);
128 const OUString aTmpDirectory2URL
= utl::CreateTempURL(nullptr, true);
129 const OUString aSavedFileURL
= utl::CreateTempURL(&aTmpDirectory1URL
);
131 OUString aReferencedFileURL
;
132 OUString aReferencingFileURL
;
133 createFileURL(u
"tdf90299.", u
"xls", aReferencingFileURL
);
135 auto eError
= osl::File::copy(aReferencingFileURL
, aTmpDirectory1URL
+ "/tdf90299.xls");
136 CPPUNIT_ASSERT_EQUAL(osl::File::E_None
, eError
);
138 aReferencingFileURL
= aTmpDirectory1URL
+ "/tdf90299.xls";
139 aReferencedFileURL
= aTmpDirectory1URL
+ "/dummy.xls";
141 ScDocShellRef xShell
= loadDoc(aReferencingFileURL
, u
"MS Excel 97"_ustr
, OUString(), OUString(),
142 XLS_FORMAT_TYPE
, SotClipboardFormatId::STARCALC_8
);
144 ScDocument
& rDoc
= xShell
->GetDocument();
145 CPPUNIT_ASSERT_EQUAL(OUString("='" + aReferencedFileURL
+ "'#$Sheet1.A1"), rDoc
.GetFormula(0, 0, 0));
147 aReferencingFileURL
= aSavedFileURL
;
149 SfxMedium
aStoreMedium(aReferencingFileURL
, StreamMode::STD_WRITE
);
151 auto pExportFilter
= std::make_shared
<SfxFilter
>(
152 "MS Excel 97", OUString(), XLS_FORMAT_TYPE
, SotClipboardFormatId::NONE
, OUString(),
153 OUString(), OUString(), "private:factory/scalc*");
154 pExportFilter
->SetVersion(SOFFICE_FILEFORMAT_CURRENT
);
156 aStoreMedium
.SetFilter(pExportFilter
);
158 xShell
->DoSaveAs(aStoreMedium
);
161 eError
= osl::File::copy(aReferencingFileURL
, aTmpDirectory2URL
+ "/tdf90299.xls");
162 CPPUNIT_ASSERT_EQUAL(osl::File::E_None
, eError
);
164 aReferencingFileURL
= aTmpDirectory2URL
+ "/tdf90299.xls";
165 aReferencedFileURL
= aTmpDirectory2URL
+ "/dummy.xls";
167 xShell
= loadDoc(aReferencingFileURL
, u
"MS Excel 97"_ustr
, OUString(), OUString(),
168 XLS_FORMAT_TYPE
, SotClipboardFormatId::STARCALC_8
);
169 ScDocument
& rDoc2
= xShell
->GetDocument();
170 CPPUNIT_ASSERT_EQUAL(OUString("='" + aReferencedFileURL
+ "'#$Sheet1.A1"), rDoc2
.GetFormula(0, 0, 0));
175 ScFiltersTest::ScFiltersTest()
180 CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest
);
182 CPPUNIT_PLUGIN_IMPLEMENT();
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */