bump product version to 5.0.4.1
[LibreOffice.git] / sc / qa / unit / helper / shared_test_impl.hxx
blobbc2ee65c036d61a45985b00bd769653c32636440
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 #ifndef INCLUDED_SC_QA_UNIT_HELPER_SHARED_TEST_IMPL_HXX
11 #define INCLUDED_SC_QA_UNIT_HELPER_SHARED_TEST_IMPL_HXX
13 #include "colorscale.hxx"
14 #include "conditio.hxx"
15 #include "document.hxx"
16 #include "formulacell.hxx"
18 struct FindCondFormatByEnclosingRange
20 FindCondFormatByEnclosingRange(const ScRange& rRange):
21 mrRange(rRange) {}
23 bool operator()(const ScConditionalFormat& rFormat)
25 if(rFormat.GetRange().Combine() == mrRange)
26 return true;
28 return false;
31 private:
32 const ScRange& mrRange;
35 struct DataBarData
37 ScRange aRange;
38 ScColorScaleEntryType eLowerLimitType;
39 ScColorScaleEntryType eUpperLimitType;
40 databar::ScAxisPosition eAxisPosition;
43 DataBarData aData[] = {
44 { ScRange(1,2,0,1,5,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::AUTOMATIC },
45 { ScRange(3,2,0,3,5,0), COLORSCALE_MIN, COLORSCALE_MAX, databar::AUTOMATIC },
46 { ScRange(5,2,0,5,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT, databar::AUTOMATIC },
47 { ScRange(7,2,0,7,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA, databar::AUTOMATIC },
48 { ScRange(1,9,0,1,12,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::MIDDLE }
51 void testDataBar_Impl(ScDocument& rDoc)
53 ScConditionalFormatList* pList = rDoc.GetCondFormList(0);
54 CPPUNIT_ASSERT(pList);
56 for(size_t i = 0; i < SAL_N_ELEMENTS(aData); ++i)
58 ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
59 pList->end(), FindCondFormatByEnclosingRange(aData[i].aRange));
60 CPPUNIT_ASSERT(itr != pList->end());
61 CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
63 const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
64 CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::DATABAR);
65 const ScDataBarFormat* pDataBar = static_cast<const ScDataBarFormat*>(pFormatEntry);
66 CPPUNIT_ASSERT(pDataBar);
67 const ScDataBarFormatData* pDataBarData = pDataBar->GetDataBarData();
68 CPPUNIT_ASSERT_EQUAL(aData[i].eLowerLimitType, pDataBarData->mpLowerLimit->GetType());
69 CPPUNIT_ASSERT_EQUAL(aData[i].eUpperLimitType, pDataBarData->mpUpperLimit->GetType());
71 CPPUNIT_ASSERT_EQUAL(aData[i].eAxisPosition, pDataBarData->meAxisPosition);
75 struct ColorScale2EntryData
77 ScRange aRange;
78 ScColorScaleEntryType eLowerType;
79 ScColorScaleEntryType eUpperType;
82 ColorScale2EntryData aData2Entry[] = {
83 { ScRange(1,2,0,1,5,0), COLORSCALE_MIN, COLORSCALE_MAX },
84 { ScRange(3,2,0,3,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT },
85 { ScRange(5,2,0,5,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA }
88 void testColorScale2Entry_Impl(ScDocument& rDoc)
90 const ScConditionalFormatList* pList = rDoc.GetCondFormList(0);
91 CPPUNIT_ASSERT(pList);
93 for(size_t i = 0; i < SAL_N_ELEMENTS(aData2Entry); ++i)
95 ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
96 pList->end(), FindCondFormatByEnclosingRange(aData2Entry[i].aRange));
97 CPPUNIT_ASSERT(itr != pList->end());
98 CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
100 const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
101 CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
102 const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
103 CPPUNIT_ASSERT_EQUAL(size_t(2), pColFormat->size());
105 ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
106 CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eLowerType, format_itr->GetType());
107 ++format_itr;
108 CPPUNIT_ASSERT(format_itr != pColFormat->end());
109 CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eUpperType, format_itr->GetType());
113 struct ColorScale3EntryData
115 ScRange aRange;
116 ScColorScaleEntryType eLowerType;
117 ScColorScaleEntryType eMiddleType;
118 ScColorScaleEntryType eUpperType;
121 ColorScale3EntryData aData3Entry[] = {
122 { ScRange(1,1,1,1,6,1), COLORSCALE_MIN, COLORSCALE_PERCENTILE, COLORSCALE_MAX },
123 { ScRange(3,1,1,3,6,1), COLORSCALE_PERCENTILE, COLORSCALE_VALUE, COLORSCALE_PERCENT },
124 { ScRange(5,1,1,5,6,1), COLORSCALE_VALUE, COLORSCALE_VALUE, COLORSCALE_FORMULA }
127 void testColorScale3Entry_Impl(ScDocument& rDoc)
129 ScConditionalFormatList* pList = rDoc.GetCondFormList(1);
130 CPPUNIT_ASSERT(pList);
132 for(size_t i = 0; i < SAL_N_ELEMENTS(aData3Entry); ++i)
134 ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
135 pList->end(), FindCondFormatByEnclosingRange(aData3Entry[i].aRange));
136 CPPUNIT_ASSERT(itr != pList->end());
137 CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
139 const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
140 CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
141 const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
142 CPPUNIT_ASSERT_EQUAL(size_t(3), pColFormat->size());
144 ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
145 CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eLowerType, format_itr->GetType());
146 ++format_itr;
147 CPPUNIT_ASSERT(format_itr != pColFormat->end());
148 CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eMiddleType, format_itr->GetType());
149 ++format_itr;
150 CPPUNIT_ASSERT(format_itr != pColFormat->end());
151 CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eUpperType, format_itr->GetType());
155 void testFunctionsExcel2010_Impl( ScDocument& rDoc )
157 // Original test case document is functions-excel-2010.xlsx
158 // Which test rows to evaluate, 1-based as in UI to ease maintenance.
159 struct
161 SCROW nRow;
162 bool bEvaluate;
163 } aTests[] = {
164 { 2, false }, // name=[ AGGREGATE ], result=0, expected=1
165 { 3, true },
166 { 4, true },
167 { 5, true },
168 { 6, true },
169 { 7, true },
170 { 8, true },
171 { 9, true },
172 { 10, true },
173 { 11, true },
174 { 12, true },
175 { 13, true },
176 { 14, true },
177 { 15, true },
178 { 16, true },
179 { 17, true },
180 { 18, true },
181 { 19, true },
182 { 20, true },
183 { 21, true },
184 { 22, true },
185 { 23, true },
186 { 24, true },
187 { 25, true },
188 { 26, true },
189 { 27, true },
190 { 28, true },
191 { 29, true },
192 { 30, true },
193 { 31, true },
194 { 32, true },
195 { 33, true },
196 { 34, true },
197 { 35, true },
198 { 36, true },
199 { 37, true },
200 { 38, true },
201 { 39, true },
202 { 40, true },
203 { 41, true },
204 { 42, true },
205 { 43, true },
206 { 44, true },
207 { 45, false }, // name=[ NETWORKDAYS.INTL ], result=18, expected=19
208 { 46, true },
209 { 47, true },
210 { 48, true },
211 { 49, true },
212 { 50, true },
213 { 51, true },
214 { 52, true },
215 { 53, true },
216 { 54, true },
217 { 55, true },
218 { 56, true },
219 { 57, true },
220 { 58, true },
221 { 59, true },
222 { 60, true },
223 { 61, true },
224 { 62, true },
225 { 63, true },
226 { 64, true },
227 { 65, true },
228 { 66, true },
229 { 67, true },
230 { 68, true },
231 { 69, true },
232 { 70, true },
233 { 71, true },
234 { 72, true },
235 { 73, true },
236 { 74, true },
237 { 75, true },
238 { 76, true },
239 { 77, true },
240 { 78, true },
241 { 79, false }, // name=[ WORKDAY.INTL ], result=41755 , expected=41754
242 { 80, true }
245 for (size_t i=0; i < SAL_N_ELEMENTS(aTests); ++i)
247 if (aTests[i].bEvaluate)
249 // Column 0 is description, 1 is formula, 2 is Excel result, 3 is
250 // comparison.
251 SCROW nRow = aTests[i].nRow - 1; // 0-based
253 OString aStr = OString::number( aTests[i].nRow) +
254 ", function name=[ " +
255 OUStringToOString( rDoc.GetString( ScAddress( 0, nRow, 0)), RTL_TEXTENCODING_UTF8 ) +
256 " ], result=" +
257 OString::number( rDoc.GetValue( ScAddress( 1, nRow, 0)) ) +
258 ", expected=" +
259 OString::number( rDoc.GetValue( ScAddress( 2, nRow, 0)) );
261 ScFormulaCell* pFC = rDoc.GetFormulaCell( ScAddress( 1, nRow, 0) );
262 if ( pFC && pFC->GetErrCode() != 0 )
263 aStr += ", error code =" + OString::number( pFC->GetErrCode() );
265 CPPUNIT_ASSERT_MESSAGE( OString( "Expected a formula cell without error at row " +
266 aStr ).getStr(), isFormulaWithoutError( rDoc, ScAddress( 1, nRow, 0)));
267 CPPUNIT_ASSERT_MESSAGE( OString( "Expected a TRUE value at row " +
268 aStr ).getStr(), 0 != rDoc.GetValue( ScAddress( 3, nRow, 0)));
274 #endif
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */