Resolves: tdf#162093 TableRef item specifier may occur standalone
[LibreOffice.git] / sc / qa / unit / helper / qahelper.hxx
blob3bb12e701c70a8ae8becb80c0ab8f23fda27cef3
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 #pragma once
12 #include <docsh.hxx>
13 #include <address.hxx>
15 #include <cppunit/SourceLine.h>
17 #include <test/unoapixml_test.hxx>
18 #include <test/bootstrapfixture.hxx>
19 #include <comphelper/documentconstants.hxx>
21 #include <comphelper/fileformat.h>
22 #include <formula/grammar.hxx>
23 #include "scqahelperdllapi.h"
25 #include <string>
26 #include <string_view>
27 #include <sstream>
28 #include <undoblk.hxx>
30 #include <sal/types.h>
32 #include <memory>
33 #include <tuple>
35 enum class StringType { PureString, StringValue };
37 #define CHECK_OPTIMAL 0x1
39 class SdrOle2Obj;
40 class ScRangeList;
41 class ScTokenArray;
43 // data format for row height tests
44 struct TestParam
46 struct RowData
48 SCROW nStartRow;
49 SCROW nEndRow;
50 SCTAB nTab;
51 int nExpectedHeight; // -1 for default height
52 int nCheck; // currently only CHECK_OPTIMAL ( we could add CHECK_MANUAL etc.)
53 bool bOptimal;
55 const std::u16string_view sTestDoc;
56 const OUString sExportType; // empty for import test, otherwise this is an export test
57 int nRowData;
58 RowData const * pData;
61 struct RangeNameDef
63 const char* mpName;
64 const char* mpExpr;
65 sal_uInt16 mnIndex;
68 // Printers for the calc data structures. Needed for the EQUAL assertion
69 // macros from CPPUNIT.
71 SCQAHELPER_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr);
73 SCQAHELPER_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const ScRange& rRange);
75 SCQAHELPER_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const ScRangeList& rList);
77 SCQAHELPER_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const OpCode& rCode);
79 SCQAHELPER_DLLPUBLIC bool checkOutput(
80 const ScDocument* pDoc, const ScRange& aOutRange,
81 const std::vector<std::vector<const char*>>& aCheck, const char* pCaption );
83 inline std::string print(const ScAddress& rAddr)
85 std::ostringstream str;
86 str << "Col: " << rAddr.Col();
87 str << " Row: " << rAddr.Row();
88 str << " Tab: " << rAddr.Tab();
89 return str.str();
92 /**
93 * Temporarily set formula grammar.
95 class SCQAHELPER_DLLPUBLIC FormulaGrammarSwitch
97 ScDocument* mpDoc;
98 formula::FormulaGrammar::Grammar meOldGrammar;
100 public:
101 FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar);
102 ~FormulaGrammarSwitch();
105 class SCQAHELPER_DLLPUBLIC ScUcalcTestBase : public test::BootstrapFixture
107 public:
108 virtual void setUp() override;
109 virtual void tearDown() override;
111 ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos,
112 const std::vector<std::vector<const char*>>& rData);
113 void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc);
114 void pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange,
115 ScDocument* pClipDoc);
116 ScUndoPaste* createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange,
117 ScDocumentUniquePtr pUndoDoc);
118 void pasteOneCellFromClip(ScDocument* pDestDoc, const ScRange& rDestRange,
119 ScDocument* pClipDoc,
120 InsertDeleteFlags eFlags = InsertDeleteFlags::ALL);
121 void setCalcAsShown(ScDocument* pDoc, bool bCalcAsShown);
122 ScDocShell* findLoadedDocShellByName(std::u16string_view rName);
123 ScUndoCut* cutToClip(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pClipDoc,
124 bool bCreateUndo);
125 bool insertRangeNames(ScDocument* pDoc, ScRangeName* pNames, const RangeNameDef* p,
126 const RangeNameDef* pEnd);
127 OUString getRangeByName(ScDocument* pDoc, const OUString& aRangeName);
128 void printFormula(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
129 const char* pCaption = nullptr);
130 void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption,
131 const bool printFormula = false);
132 void printRange(ScDocument* pDoc, const ScRange& rRange,
133 const OString& rCaption, const bool printFormula = false);
134 void clearRange(ScDocument* pDoc, const ScRange& rRange);
135 void clearSheet(ScDocument* pDoc, SCTAB nTab);
136 bool checkFormulaPosition(ScDocument& rDoc, const ScAddress& rPos);
137 bool checkFormulaPositions(
138 ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SCROW* pRows, size_t nRowCount);
139 std::unique_ptr<ScTokenArray> compileFormula(
140 ScDocument* pDoc, const OUString& rFormula,
141 formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_NATIVE );
142 void clearFormulaCellChangedFlag( ScDocument& rDoc, const ScRange& rRange );
144 protected:
145 ScDocShellRef m_xDocShell;
146 ScDocument* m_pDoc;
149 class SCQAHELPER_DLLPUBLIC ScModelTestBase : public UnoApiXmlTest
151 public:
152 ScModelTestBase(OUString path)
153 : UnoApiXmlTest(path)
157 void createScDoc(const char* pName = nullptr, const char* pPassword = nullptr, bool bCheckErrorCode = true);
158 ScDocument* getScDoc();
159 ScDocument* getScDoc2();
160 ScDocShell* getScDocShell();
161 ScTabViewShell* getViewShell();
162 void miscRowHeightsTest( TestParam const * aTestValues, unsigned int numElems);
164 void enableOpenCL();
165 void disableOpenCL();
166 void initTestEnv(std::u16string_view fileName);
168 void testFile(const OUString& aFileName, ScDocument& rDoc, SCTAB nTab, StringType aStringFormat = StringType::StringValue);
170 //need own handler because conditional formatting strings must be generated
171 void testCondFile(const OUString& aFileName, ScDocument* pDoc, SCTAB nTab, bool bCommaAsDelimiter = true);
173 const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage);
175 const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
177 ScRangeList getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj);
179 void testFormats(ScDocument* pDoc,std::u16string_view sFormat);
181 void goToCell(const OUString& rCell);
182 void typeString(const std::u16string_view& rStr);
183 void insertStringToCell(const OUString& rCell, const std::u16string_view& rStr);
184 void insertArrayToCell(const OUString& rCell, const std::u16string_view& rStr);
185 void insertNewSheet(ScDocument& rDoc);
186 void executeAutoSum();
188 private:
189 // Why is this here and not in osl, and using the already existing file
190 // handling APIs? Do we really want to add arbitrary new file handling
191 // wrappers here and there (and then having to handle the Android (and
192 // eventually perhaps iOS) special cases here, too)? Please move this to osl,
193 // it sure looks generally useful. Or am I missing something?
195 void loadFile(const OUString& aFileName, std::string& aContent);
198 #define ASSERT_DOUBLES_EQUAL( expected, result ) \
199 CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 )
201 #define ASSERT_DOUBLES_EQUAL_MESSAGE( message, expected, result ) \
202 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( (message), (expected), (result), 1e-14 )
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */