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_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
):
23 bool operator()(const ScConditionalFormat
& rFormat
)
25 if(rFormat
.GetRange().Combine() == mrRange
)
32 const ScRange
& mrRange
;
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
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());
108 CPPUNIT_ASSERT(format_itr
!= pColFormat
->end());
109 CPPUNIT_ASSERT_EQUAL(aData2Entry
[i
].eUpperType
, format_itr
->GetType());
113 struct ColorScale3EntryData
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());
147 CPPUNIT_ASSERT(format_itr
!= pColFormat
->end());
148 CPPUNIT_ASSERT_EQUAL(aData3Entry
[i
].eMiddleType
, format_itr
->GetType());
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.
164 { 2, false }, // name=[ AGGREGATE ], result=0, expected=1
207 { 45, false }, // name=[ NETWORKDAYS.INTL ], result=18, expected=19
241 { 79, false }, // name=[ WORKDAY.INTL ], result=41755 , expected=41754
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
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
) +
257 OString::number( rDoc
.GetValue( ScAddress( 1, nRow
, 0)) ) +
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)));
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */