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 #ifndef INCLUDED_SC_QA_UNIT_HELPER_QAHELPER_HXX
11 #define INCLUDED_SC_QA_UNIT_HELPER_QAHELPER_HXX
14 #include "debughelper.hxx"
16 #include "address.hxx"
18 #include <test/bootstrapfixture.hxx>
19 #include <comphelper/documentconstants.hxx>
21 #include <osl/detail/android-bootstrap.h>
23 #include <unotools/tempfile.hxx>
24 #include <comphelper/storagehelper.hxx>
25 #include <sfx2/docfilt.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <svl/stritem.hxx>
28 #include <formula/grammar.hxx>
33 #include <sal/types.h>
35 #include <boost/shared_ptr.hpp>
37 #if defined(SCQAHELPER_DLLIMPLEMENTATION)
38 #define SCQAHELPER_DLLPUBLIC SAL_DLLPUBLIC_EXPORT
40 #define SCQAHELPER_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
43 #define ODS_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::TEMPLATE | SfxFilterFlags::OWN | SfxFilterFlags::DEFAULT | SfxFilterFlags::ENCRYPTION | SfxFilterFlags::PASSWORDTOMODIFY)
44 #define XLS_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::ENCRYPTION | SfxFilterFlags::PASSWORDTOMODIFY | SfxFilterFlags::PREFERED)
45 #define XLSX_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER | SfxFilterFlags::PREFERED)
46 #define LOTUS123_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::USESOPTIONS | SfxFilterFlags::PREFERED)
47 #define CSV_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::USESOPTIONS)
48 #define HTML_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::USESOPTIONS)
49 #define DIF_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::USESOPTIONS)
50 #define XLS_XML_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::ALIEN)
51 #define XLSB_XML_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER | SfxFilterFlags::PREFERED)
64 enum StringType
{ PureString
, FormulaValue
, StringValue
};
66 SCQAHELPER_DLLPUBLIC
bool testEqualsWithTolerance( long nVal1
, long nVal2
, long nTol
);
68 #define CHECK_OPTIMAL 0x1
74 // data format for row height tests
82 int nExpectedHeight
; // -1 for default height
83 int nCheck
; // currently only CHECK_OPTIMAL ( we could add CHECK_MANUAL etc.)
88 int nExportType
; // -1 for import test, otherwise this is an export test
94 const char* pName
; const char* pFilterName
; const char* pTypeName
; SfxFilterFlags nFormatType
;
97 // Printers for the calc data structures. Needed for the EQUAL assertion
98 // macros from CPPUNIT.
100 SCQAHELPER_DLLPUBLIC
std::ostream
& operator<<(std::ostream
& rStrm
, const ScAddress
& rAddr
);
102 SCQAHELPER_DLLPUBLIC
std::ostream
& operator<<(std::ostream
& rStrm
, const ScRange
& rRange
);
104 SCQAHELPER_DLLPUBLIC
std::ostream
& operator<<(std::ostream
& rStrm
, const ScRangeList
& rList
);
106 SCQAHELPER_DLLPUBLIC
std::ostream
& operator<<(std::ostream
& rStrm
, const Color
& rColor
);
108 SCQAHELPER_DLLPUBLIC
std::ostream
& operator<<(std::ostream
& rStrm
, const OpCode
& rCode
);
110 // Why is this here and not in osl, and using the already existing file
111 // handling APIs? Do we really want to add arbitrary new file handling
112 // wrappers here and there (and then having to handle the Android (and
113 // eventually perhaps iOS) special cases here, too)? Please move this to osl,
114 // it sure looks gemerally useful. Or am I missing something?
116 SCQAHELPER_DLLPUBLIC
void loadFile(const OUString
& aFileName
, std::string
& aContent
);
118 SCQAHELPER_DLLPUBLIC
void testFile(OUString
& aFileName
, ScDocument
& rDoc
, SCTAB nTab
, StringType aStringFormat
= StringValue
);
120 //need own handler because conditional formatting strings must be generated
121 SCQAHELPER_DLLPUBLIC
void testCondFile(OUString
& aFileName
, ScDocument
* pDoc
, SCTAB nTab
);
123 SCQAHELPER_DLLPUBLIC
const SdrOle2Obj
* getSingleChartObject(ScDocument
& rDoc
, sal_uInt16 nPage
);
125 SCQAHELPER_DLLPUBLIC
std::vector
<OUString
> getChartRangeRepresentations(const SdrOle2Obj
& rChartObj
);
127 SCQAHELPER_DLLPUBLIC ScRangeList
getChartRanges(ScDocument
& rDoc
, const SdrOle2Obj
& rChartObj
);
129 SCQAHELPER_DLLPUBLIC
bool checkFormula(ScDocument
& rDoc
, const ScAddress
& rPos
, const char* pExpected
);
131 SCQAHELPER_DLLPUBLIC
bool checkFormulaPosition(ScDocument
& rDoc
, const ScAddress
& rPos
);
132 SCQAHELPER_DLLPUBLIC
bool checkFormulaPositions(
133 ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
, const SCROW
* pRows
, size_t nRowCount
);
135 SCQAHELPER_DLLPUBLIC ScTokenArray
* compileFormula(
136 ScDocument
* pDoc
, const OUString
& rFormula
, const ScAddress
* pPos
= NULL
,
137 formula::FormulaGrammar::Grammar eGram
= formula::FormulaGrammar::GRAM_NATIVE
);
139 template<size_t _Size
>
140 bool checkOutput(ScDocument
* pDoc
, const ScRange
& aOutRange
, const char* aOutputCheck
[][_Size
], const char* pCaption
)
143 const ScAddress
& s
= aOutRange
.aStart
;
144 const ScAddress
& e
= aOutRange
.aEnd
;
145 svl::GridPrinter
printer(e
.Row() - s
.Row() + 1, e
.Col() - s
.Col() + 1, CALC_DEBUG_OUTPUT
!= 0);
146 SCROW nOutRowSize
= e
.Row() - s
.Row() + 1;
147 SCCOL nOutColSize
= e
.Col() - s
.Col() + 1;
148 for (SCROW nRow
= 0; nRow
< nOutRowSize
; ++nRow
)
150 for (SCCOL nCol
= 0; nCol
< nOutColSize
; ++nCol
)
152 OUString aVal
= pDoc
->GetString(nCol
+ s
.Col(), nRow
+ s
.Row(), s
.Tab());
153 printer
.set(nRow
, nCol
, aVal
);
154 const char* p
= aOutputCheck
[nRow
][nCol
];
157 OUString aCheckVal
= OUString::createFromAscii(p
);
158 bool bEqual
= aCheckVal
.equals(aVal
);
161 cout
<< "Expected: " << aCheckVal
<< " Actual: " << aVal
<< endl
;
165 else if (!aVal
.isEmpty())
167 cout
<< "Empty cell expected" << endl
;
172 printer
.print(pCaption
);
176 SCQAHELPER_DLLPUBLIC
void clearFormulaCellChangedFlag( ScDocument
& rDoc
, const ScRange
& rRange
);
179 * Check if the cell at specified position is a formula cell that doesn't
180 * have an error value.
182 SCQAHELPER_DLLPUBLIC
bool isFormulaWithoutError(ScDocument
& rDoc
, const ScAddress
& rPos
);
185 * Convert formula token array to a formula string.
187 SCQAHELPER_DLLPUBLIC OUString
toString(
188 ScDocument
& rDoc
, const ScAddress
& rPos
, ScTokenArray
& rArray
,
189 formula::FormulaGrammar::Grammar eGram
= formula::FormulaGrammar::GRAM_NATIVE
);
191 inline std::string
print(const ScAddress
& rAddr
)
193 std::ostringstream str
;
194 str
<< "Col: " << rAddr
.Col();
195 str
<< " Row: " << rAddr
.Row();
196 str
<< " Tab: " << rAddr
.Tab();
203 struct assertion_traits
<ScRange
>
205 static bool equal( const ScRange
& x
, const ScRange
& y
)
210 static std::string
toString( const ScRange
& x
)
212 std::stringstream str
;
213 str
<< "Start: " << print(x
.aStart
);
214 str
<< "\nEnd: " << print(x
.aEnd
);
221 class SCQAHELPER_DLLPUBLIC ScBootstrapFixture
: public test::BootstrapFixture
223 static const FileFormat aFileFormats
[];
225 OUString m_aBaseString
;
228 bool bReadWrite
, const OUString
& rURL
, const OUString
& rFilter
, const OUString
&rUserData
,
229 const OUString
& rTypeName
, SfxFilterFlags nFilterFlags
, SotClipboardFormatId nClipboardID
,
230 sal_uIntPtr nFilterVersion
= SOFFICE_FILEFORMAT_CURRENT
, const OUString
* pPassword
= NULL
);
233 const OUString
& rURL
, const OUString
& rFilter
, const OUString
&rUserData
,
234 const OUString
& rTypeName
, SfxFilterFlags nFilterFlags
, SotClipboardFormatId nClipboardID
,
235 sal_uIntPtr nFilterVersion
= SOFFICE_FILEFORMAT_CURRENT
, const OUString
* pPassword
= NULL
);
237 ScDocShellRef
loadDoc(const OUString
& rFileName
, sal_Int32 nFormat
, bool bReadWrite
= false );
240 static const FileFormat
* getFileFormats() { return aFileFormats
; }
242 ScBootstrapFixture( const OUString
& rsBaseString
);
243 virtual ~ScBootstrapFixture();
245 void createFileURL(const OUString
& aFileBase
, const OUString
& aFileExtension
, OUString
& rFilePath
);
247 void createCSVPath(const OUString
& aFileBase
, OUString
& rCSVPath
);
249 ScDocShellRef
saveAndReload(ScDocShell
* pShell
, const OUString
&rFilter
,
250 const OUString
&rUserData
, const OUString
& rTypeName
, SfxFilterFlags nFormatType
);
252 ScDocShellRef
saveAndReload( ScDocShell
* pShell
, sal_Int32 nFormat
);
254 static boost::shared_ptr
<utl::TempFile
> exportTo( ScDocShell
* pShell
, sal_Int32 nFormat
);
256 void miscRowHeightsTest( TestParam
* aTestValues
, unsigned int numElems
);
259 #define ASSERT_DOUBLES_EQUAL( expected, result ) \
260 CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 )
262 #define ASSERT_DOUBLES_EQUAL_MESSAGE( message, expected, result ) \
263 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( (message), (expected), (result), 1e-14 )
265 #define ASSERT_EQUAL_TYPE( type, expected, result ) \
266 CPPUNIT_ASSERT_EQUAL( static_cast<type>(expected), static_cast<type>(result) );
268 SCQAHELPER_DLLPUBLIC
void testFormats(ScBootstrapFixture
* pTest
, ScDocument
* pDoc
, sal_Int32 nFormat
);
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */