Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #ifndef SC_SHARED_TEST_IMPL_HXX
11 : #define SC_SHARED_TEST_IMPL_HXX
12 :
13 : #include "colorscale.hxx"
14 : #include "conditio.hxx"
15 : #include "document.hxx"
16 :
17 : struct FindCondFormatByEnclosingRange
18 : {
19 34 : FindCondFormatByEnclosingRange(const ScRange& rRange):
20 34 : mrRange(rRange) {}
21 :
22 78 : bool operator()(const ScConditionalFormat& rFormat)
23 : {
24 78 : if(rFormat.GetRange().Combine() == mrRange)
25 34 : return true;
26 :
27 44 : return false;
28 : }
29 :
30 : private:
31 : const ScRange& mrRange;
32 : };
33 :
34 : struct DataBarData
35 : {
36 : ScRange aRange;
37 : ScColorScaleEntryType eLowerLimitType;
38 : ScColorScaleEntryType eUpperLimitType;
39 : databar::ScAxisPosition eAxisPosition;
40 : };
41 :
42 2 : DataBarData aData[] = {
43 : { ScRange(1,2,0,1,5,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::AUTOMATIC },
44 : { ScRange(3,2,0,3,5,0), COLORSCALE_MIN, COLORSCALE_MAX, databar::AUTOMATIC },
45 : { ScRange(5,2,0,5,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT, databar::AUTOMATIC },
46 : { ScRange(7,2,0,7,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA, databar::AUTOMATIC },
47 : { ScRange(1,9,0,1,12,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::MIDDLE }
48 2 : };
49 :
50 2 : void testDataBar_Impl(ScDocument* pDoc)
51 : {
52 2 : ScConditionalFormatList* pList = pDoc->GetCondFormList(0);
53 2 : CPPUNIT_ASSERT(pList);
54 :
55 12 : for(size_t i = 0; i < SAL_N_ELEMENTS(aData); ++i)
56 : {
57 : ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
58 10 : pList->end(), FindCondFormatByEnclosingRange(aData[i].aRange));
59 10 : CPPUNIT_ASSERT(itr != pList->end());
60 10 : CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
61 :
62 10 : const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
63 10 : CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::DATABAR);
64 10 : const ScDataBarFormat* pDataBar = static_cast<const ScDataBarFormat*>(pFormatEntry);
65 10 : CPPUNIT_ASSERT(pDataBar);
66 10 : const ScDataBarFormatData* pDataBarData = pDataBar->GetDataBarData();
67 10 : CPPUNIT_ASSERT_EQUAL(aData[i].eLowerLimitType, pDataBarData->mpLowerLimit->GetType());
68 10 : CPPUNIT_ASSERT_EQUAL(aData[i].eUpperLimitType, pDataBarData->mpUpperLimit->GetType());
69 :
70 10 : CPPUNIT_ASSERT_EQUAL(aData[i].eAxisPosition, pDataBarData->meAxisPosition);
71 : }
72 2 : }
73 :
74 : struct ColorScale2EntryData
75 : {
76 : ScRange aRange;
77 : ScColorScaleEntryType eLowerType;
78 : ScColorScaleEntryType eUpperType;
79 : };
80 :
81 2 : ColorScale2EntryData aData2Entry[] = {
82 : { ScRange(1,2,0,1,5,0), COLORSCALE_MIN, COLORSCALE_MAX },
83 : { ScRange(3,2,0,3,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT },
84 : { ScRange(5,2,0,5,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA }
85 2 : };
86 :
87 4 : void testColorScale2Entry_Impl(ScDocument* pDoc)
88 : {
89 4 : const ScConditionalFormatList* pList = pDoc->GetCondFormList(0);
90 4 : CPPUNIT_ASSERT(pList);
91 :
92 16 : for(size_t i = 0; i < SAL_N_ELEMENTS(aData2Entry); ++i)
93 : {
94 : ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
95 12 : pList->end(), FindCondFormatByEnclosingRange(aData2Entry[i].aRange));
96 12 : CPPUNIT_ASSERT(itr != pList->end());
97 12 : CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
98 :
99 12 : const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
100 12 : CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
101 12 : const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
102 12 : CPPUNIT_ASSERT_EQUAL(size_t(2), pColFormat->size());
103 :
104 12 : ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
105 12 : CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eLowerType, format_itr->GetType());
106 12 : ++format_itr;
107 12 : CPPUNIT_ASSERT(format_itr != pColFormat->end());
108 12 : CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eUpperType, format_itr->GetType());
109 : }
110 4 : }
111 :
112 : struct ColorScale3EntryData
113 : {
114 : ScRange aRange;
115 : ScColorScaleEntryType eLowerType;
116 : ScColorScaleEntryType eMiddleType;
117 : ScColorScaleEntryType eUpperType;
118 : };
119 :
120 2 : ColorScale3EntryData aData3Entry[] = {
121 : { ScRange(1,1,1,1,6,1), COLORSCALE_MIN, COLORSCALE_PERCENTILE, COLORSCALE_MAX },
122 : { ScRange(3,1,1,3,6,1), COLORSCALE_PERCENTILE, COLORSCALE_VALUE, COLORSCALE_PERCENT },
123 : { ScRange(5,1,1,5,6,1), COLORSCALE_VALUE, COLORSCALE_VALUE, COLORSCALE_FORMULA }
124 2 : };
125 :
126 4 : void testColorScale3Entry_Impl(ScDocument* pDoc)
127 : {
128 4 : ScConditionalFormatList* pList = pDoc->GetCondFormList(1);
129 4 : CPPUNIT_ASSERT(pList);
130 :
131 16 : for(size_t i = 0; i < SAL_N_ELEMENTS(aData3Entry); ++i)
132 : {
133 : ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
134 12 : pList->end(), FindCondFormatByEnclosingRange(aData3Entry[i].aRange));
135 12 : CPPUNIT_ASSERT(itr != pList->end());
136 12 : CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
137 :
138 12 : const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
139 12 : CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
140 12 : const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
141 12 : CPPUNIT_ASSERT_EQUAL(size_t(3), pColFormat->size());
142 :
143 12 : ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
144 12 : CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eLowerType, format_itr->GetType());
145 12 : ++format_itr;
146 12 : CPPUNIT_ASSERT(format_itr != pColFormat->end());
147 12 : CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eMiddleType, format_itr->GetType());
148 12 : ++format_itr;
149 12 : CPPUNIT_ASSERT(format_itr != pColFormat->end());
150 12 : CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eUpperType, format_itr->GetType());
151 : }
152 4 : }
153 :
154 : #endif
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|