summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-17 03:11:46 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-17 06:48:24 +0200
commita5f65a5c2836b000bc0b6f92d5a2a3d13133de71 (patch)
tree3e7707251546db95d61304d36c1ace1a0307b1e1 /sc
parent31719b052740766c43df508999b691af9075aa3d (diff)
extract code into own method
Change-Id: I13fe9fcdbc056480b7eb66304f9ddef48bab3bd4
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc.cxx68
-rw-r--r--sc/source/core/data/colorscale.cxx2
2 files changed, 45 insertions, 25 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index c9a46f83a9c4..4a76629253ef 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5879,50 +5879,70 @@ void Test::testIconSet()
m_pDoc->DeleteTab(0);
}
-void Test::testDataBarLength()
+namespace {
+
+struct ScDataBarLengthData
{
- m_pDoc->InsertTab(0, "Test");
+ double nVal;
+ double nLength;
+};
- ScConditionalFormat* pFormat = new ScConditionalFormat(1, m_pDoc);
- ScRangeList aRangeList(ScRange(0,0,0,0,7,0));
+void testDataBarLengthImpl(ScDocument* pDoc, ScDataBarLengthData* pData, const ScRange& rRange,
+ double nMinVal, ScColorScaleEntryType eMinType,
+ double nMaxVal, ScColorScaleEntryType eMaxType)
+{
+ ScConditionalFormat* pFormat = new ScConditionalFormat(1, pDoc);
+ ScRangeList aRangeList(rRange);
pFormat->SetRange(aRangeList);
- ScDataBarFormat* pDatabar = new ScDataBarFormat(m_pDoc);
+ SCCOL nCol = rRange.aStart.Col();
+
+ ScDataBarFormat* pDatabar = new ScDataBarFormat(pDoc);
pFormat->AddEntry(pDatabar);
ScDataBarFormatData* pFormatData = new ScDataBarFormatData();
pFormatData->mpLowerLimit.reset(new ScColorScaleEntry());
- pFormatData->mpLowerLimit->SetValue(3);
- pFormatData->mpLowerLimit->SetType(COLORSCALE_VALUE);
+ pFormatData->mpLowerLimit->SetValue(nMinVal);
+ pFormatData->mpLowerLimit->SetType(eMinType);
pFormatData->mpUpperLimit.reset(new ScColorScaleEntry());
- pFormatData->mpUpperLimit->SetValue(7);
- pFormatData->mpUpperLimit->SetType(COLORSCALE_VALUE);
+ pFormatData->mpUpperLimit->SetValue(nMaxVal);
+ pFormatData->mpUpperLimit->SetType(eMaxType);
pDatabar->SetDataBarData(pFormatData);
- struct {
- double nVal; double nLength;
- } aValues[] = {
+ for (size_t i = 0; pData[i].nVal != 0; ++i)
+ {
+ pDoc->SetValue(nCol, i, 0, pData[i].nVal);
+ }
+
+ for (size_t i = 0; pData[i].nVal != 0; ++i)
+ {
+ ScDataBarInfo* pInfo = pDatabar->GetDataBarInfo(ScAddress(nCol, i, 0));
+ CPPUNIT_ASSERT(pInfo);
+ ASSERT_DOUBLES_EQUAL(pData[i].nLength, pInfo->mnLength);
+ }
+ delete pFormat;
+}
+
+}
+
+void Test::testDataBarLength()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ ScDataBarLengthData aValues[] = {
{ 2, 0 },
{ 3, 0 },
{ 4, 25.0 },
{ 5, 50.0 },
{ 6, 75.0 },
{ 7, 100.0 },
- { 8, 100.0 }
+ { 8, 100.0 },
+ { 0, 0 }
};
- for (size_t i = 0; i < SAL_N_ELEMENTS(aValues); ++i)
- {
- m_pDoc->SetValue(0, i, 0, aValues[i].nVal);
- }
+ testDataBarLengthImpl(m_pDoc, aValues, ScRange(0,0,0,0,7,0),
+ 3, COLORSCALE_VALUE, 7, COLORSCALE_VALUE);
- for (size_t i = 0; i < SAL_N_ELEMENTS(aValues); ++i)
- {
- ScDataBarInfo* pInfo = pDatabar->GetDataBarInfo(ScAddress(0, i, 0));
- CPPUNIT_ASSERT(pInfo);
- ASSERT_DOUBLES_EQUAL(aValues[i].nLength, pInfo->mnLength);
- }
- delete pFormat;
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 2369bac99450..4652587a1641 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -913,7 +913,7 @@ ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
pInfo->mnZero = 0;
//calculate the length
- if(nValue < 0)
+ if(nValue < 0 && nMin < 0)
{
if (nValue < nMin)
pInfo->mnLength = -100;