[Libreoffice-commits] core.git: sc/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Feb 9 20:02:16 UTC 2019
sc/qa/unit/pivottable_filters_test.cxx | 4
sc/qa/unit/subsequent_export-test.cxx | 133 ++++++---------------------------
sc/qa/unit/subsequent_filters-test.cxx | 78 +++++--------------
sc/qa/unit/ucalc.cxx | 4
sc/qa/unit/ucalc_formula.cxx | 8 -
5 files changed, 55 insertions(+), 172 deletions(-)
New commits:
commit 21d1d0d2340d40f646c5e3f413a33b45ab89675f
Author: Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Feb 9 20:31:10 2019 +0300
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Feb 9 21:01:55 2019 +0100
Simplify containers iterations in sc/qa/unit
Use range-based loop or replace with STL functions
Change-Id: I07835481988be3b1524ece8320c3952179cf022f
Reviewed-on: https://gerrit.libreoffice.org/67590
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx
index b7830b2e7d31..024df995e4fe 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -296,11 +296,9 @@ namespace
bool checkVisiblePageFieldMember(const ScDPSaveDimension::MemberList& rMembers,
const OUString& rVisibleMember)
{
- ScDPSaveDimension::MemberList::const_iterator it = rMembers.begin(), itEnd = rMembers.end();
bool bFound = false;
- for (; it != itEnd; ++it)
+ for (const ScDPSaveMember* pMem : rMembers)
{
- const ScDPSaveMember* pMem = *it;
if (pMem->GetName() == rVisibleMember)
{
bFound = true;
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 1b44d58235c5..ccd6b16ad4db 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -1375,139 +1375,62 @@ void ScExportTest::testRichTextExportODS()
{
static bool isBold(const editeng::Section& rAttr)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_WEIGHT)
- continue;
-
- return static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_WEIGHT &&
+ static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD; });
}
static bool isItalic(const editeng::Section& rAttr)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_ITALIC)
- continue;
-
- return static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_ITALIC &&
+ static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL; });
}
static bool isStrikeOut(const editeng::Section& rAttr)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_STRIKEOUT)
- continue;
-
- return static_cast<const SvxCrossedOutItem*>(p)->GetStrikeout() == STRIKEOUT_SINGLE;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_STRIKEOUT &&
+ static_cast<const SvxCrossedOutItem*>(p)->GetStrikeout() == STRIKEOUT_SINGLE; });
}
static bool isOverline(const editeng::Section& rAttr, FontLineStyle eStyle)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_OVERLINE)
- continue;
-
- return static_cast<const SvxOverlineItem*>(p)->GetLineStyle() == eStyle;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [&eStyle](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_OVERLINE &&
+ static_cast<const SvxOverlineItem*>(p)->GetLineStyle() == eStyle; });
}
static bool isUnderline(const editeng::Section& rAttr, FontLineStyle eStyle)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_UNDERLINE)
- continue;
-
- return static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == eStyle;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [&eStyle](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_UNDERLINE &&
+ static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == eStyle; });
}
static bool isFont(const editeng::Section& rAttr, const OUString& rFontName)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_FONTINFO)
- continue;
-
- return static_cast<const SvxFontItem*>(p)->GetFamilyName() == rFontName;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [&rFontName](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_FONTINFO &&
+ static_cast<const SvxFontItem*>(p)->GetFamilyName() == rFontName; });
}
static bool isEscapement(const editeng::Section& rAttr, short nEsc, sal_uInt8 nRelSize)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_ESCAPEMENT)
- continue;
-
- const SvxEscapementItem* pItem = static_cast<const SvxEscapementItem*>(p);
- return ((pItem->GetEsc() == nEsc) && (pItem->GetProportionalHeight() == nRelSize));
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(),
+ [&nEsc, &nRelSize](const SfxPoolItem* p) {
+ if (p->Which() != EE_CHAR_ESCAPEMENT)
+ return false;
+ const SvxEscapementItem* pItem = static_cast<const SvxEscapementItem*>(p);
+ return ((pItem->GetEsc() == nEsc) && (pItem->GetProportionalHeight() == nRelSize));
+ });
}
static bool isColor(const editeng::Section& rAttr, Color nColor)
{
- if (rAttr.maAttributes.empty())
- return false;
-
- std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
- for (; it != itEnd; ++it)
- {
- const SfxPoolItem* p = *it;
- if (p->Which() != EE_CHAR_COLOR)
- continue;
-
- return static_cast<const SvxColorItem*>(p)->GetValue() == nColor;
- }
- return false;
+ return std::any_of(rAttr.maAttributes.begin(), rAttr.maAttributes.end(), [&nColor](const SfxPoolItem* p) {
+ return p->Which() == EE_CHAR_COLOR &&
+ static_cast<const SvxColorItem*>(p)->GetValue() == nColor; });
}
bool checkB2(const EditTextObject* pText) const
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 30e0548c2cde..2a49c9265de1 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -2047,13 +2047,12 @@ void ScFiltersTest::testRichTextContentODS()
CPPUNIT_ASSERT_EQUAL(OUString("Sentence with bold and italic."), aParaText);
std::vector<EECharAttrib> aAttribs;
pEditText->GetCharAttribs(0, aAttribs);
- std::vector<EECharAttrib>::const_iterator it = aAttribs.begin(), itEnd = aAttribs.end();
{
bool bHasBold = false, bHasItalic = false;
- for (; it != itEnd; ++it)
+ for (const auto& rAttrib : aAttribs)
{
- OUString aSeg = aParaText.copy(it->nStart, it->nEnd - it->nStart);
- const SfxPoolItem* pAttr = it->pAttr;
+ OUString aSeg = aParaText.copy(rAttrib.nStart, rAttrib.nEnd - rAttrib.nStart);
+ const SfxPoolItem* pAttr = rAttrib.pAttr;
if (aSeg == "bold" && pAttr->Which() == EE_CHAR_WEIGHT && !bHasBold)
{
const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(*pAttr);
@@ -2063,7 +2062,6 @@ void ScFiltersTest::testRichTextContentODS()
{
const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>(*pAttr);
bHasItalic = (rItem.GetPosture() == ITALIC_NORMAL);
-
}
}
CPPUNIT_ASSERT_MESSAGE("This sentence is expected to have both bold and italic sequences.", bHasBold && bHasItalic);
@@ -2085,48 +2083,24 @@ void ScFiltersTest::testRichTextContentODS()
// first line is bold.
pEditText->GetCharAttribs(0, aAttribs);
{
- bool bHasBold = false;
- for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it)
- {
- if (it->pAttr->Which() == EE_CHAR_WEIGHT)
- {
- const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(*it->pAttr);
- bHasBold = (rItem.GetWeight() == WEIGHT_BOLD);
- if (bHasBold)
- break;
- }
- }
+ bool bHasBold = std::any_of(aAttribs.begin(), aAttribs.end(), [](const EECharAttrib& rAttrib) {
+ return rAttrib.pAttr->Which() == EE_CHAR_WEIGHT &&
+ static_cast<const SvxWeightItem&>(*rAttrib.pAttr).GetWeight() == WEIGHT_BOLD; });
CPPUNIT_ASSERT_MESSAGE("First line should be bold.", bHasBold);
}
// second line is italic.
pEditText->GetCharAttribs(1, aAttribs);
- bool bHasItalic = false;
- for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it)
- {
- if (it->pAttr->Which() == EE_CHAR_ITALIC)
- {
- const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>(*it->pAttr);
- bHasItalic = (rItem.GetPosture() == ITALIC_NORMAL);
- if (bHasItalic)
- break;
- }
- }
+ bool bHasItalic = std::any_of(aAttribs.begin(), aAttribs.end(), [](const EECharAttrib& rAttrib) {
+ return rAttrib.pAttr->Which() == EE_CHAR_ITALIC &&
+ static_cast<const SvxPostureItem&>(*rAttrib.pAttr).GetPosture() == ITALIC_NORMAL; });
CPPUNIT_ASSERT_MESSAGE("Second line should be italic.", bHasItalic);
// third line is underlined.
pEditText->GetCharAttribs(2, aAttribs);
- bool bHasUnderline = false;
- for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it)
- {
- if (it->pAttr->Which() == EE_CHAR_UNDERLINE)
- {
- const SvxUnderlineItem& rItem = static_cast<const SvxUnderlineItem&>(*it->pAttr);
- bHasUnderline = (rItem.GetLineStyle() == LINESTYLE_SINGLE);
- if (bHasUnderline)
- break;
- }
- }
+ bool bHasUnderline = std::any_of(aAttribs.begin(), aAttribs.end(), [](const EECharAttrib& rAttrib) {
+ return rAttrib.pAttr->Which() == EE_CHAR_UNDERLINE &&
+ static_cast<const SvxUnderlineItem&>(*rAttrib.pAttr).GetLineStyle() == LINESTYLE_SINGLE; });
CPPUNIT_ASSERT_MESSAGE("Second line should be underlined.", bHasUnderline);
// URL with formats applied. For now, we'll check whether or not the
@@ -2185,20 +2159,14 @@ void ScFiltersTest::testRichTextContentODS()
CPPUNIT_ASSERT_EQUAL(OUString("one two"), aParaText);
pEditText->GetCharAttribs(0, aAttribs);
{
- bool bHasBold = false;
- for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it)
+ auto it = std::find_if(aAttribs.begin(), aAttribs.end(), [](const EECharAttrib& rAttrib) {
+ return rAttrib.pAttr->Which() == EE_CHAR_WEIGHT &&
+ static_cast<const SvxWeightItem&>(*rAttrib.pAttr).GetWeight() == WEIGHT_BOLD; });
+ bool bHasBold = (it != aAttribs.end());
+ if (bHasBold)
{
- if (it->pAttr->Which() == EE_CHAR_WEIGHT)
- {
- const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(*it->pAttr);
- bHasBold = (rItem.GetWeight() == WEIGHT_BOLD);
- if (bHasBold)
- {
- OUString aSeg = aParaText.copy(it->nStart, it->nEnd - it->nStart);
- CPPUNIT_ASSERT_EQUAL(OUString("e t"), aSeg);
- break;
- }
- }
+ OUString aSeg = aParaText.copy(it->nStart, it->nEnd - it->nStart);
+ CPPUNIT_ASSERT_EQUAL(OUString("e t"), aSeg);
}
CPPUNIT_ASSERT_MESSAGE("Expected a bold sequence.", bHasBold);
}
@@ -3391,12 +3359,12 @@ void ScFiltersTest::testEditEngStrikeThroughXLSX()
std::vector<EECharAttrib> aAttribs;
pObj->GetCharAttribs(0, aAttribs);
- for (std::vector<EECharAttrib>::const_iterator itr = aAttribs.begin(); itr != aAttribs.end(); ++itr)
+ for (const auto& rAttrib : aAttribs)
{
- if (itr->pAttr->Which() == EE_CHAR_STRIKEOUT)
+ if (rAttrib.pAttr->Which() == EE_CHAR_STRIKEOUT)
{
- const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>(*itr->pAttr);
- if (itr->nStart == 0)
+ const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>(*rAttrib.pAttr);
+ if (rAttrib.nStart == 0)
{
CPPUNIT_ASSERT(rItem.GetStrikeout() != STRIKEOUT_NONE);
}
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 63ea088741ee..85e5f3b5a520 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4596,10 +4596,8 @@ namespace {
bool hasRange(const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange, const ScAddress& rPos)
{
- std::vector<ScTokenRef>::const_iterator it = rRefTokens.begin(), itEnd = rRefTokens.end();
- for (; it != itEnd; ++it)
+ for (const ScTokenRef& p : rRefTokens)
{
- const ScTokenRef& p = *it;
if (!ScRefTokenHelper::isRef(p) || ScRefTokenHelper::isExternalRef(p))
continue;
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index dca8abcf8d70..5b66732ec2d0 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -54,17 +54,13 @@ ScRange getCachedRange(const ScExternalRefCache::TableTypeRef& pCacheTab)
vector<SCROW> aRows;
pCacheTab->getAllRows(aRows);
- vector<SCROW>::const_iterator itrRow = aRows.begin(), itrRowEnd = aRows.end();
bool bFirst = true;
- for (; itrRow != itrRowEnd; ++itrRow)
+ for (const SCROW nRow : aRows)
{
- SCROW nRow = *itrRow;
vector<SCCOL> aCols;
pCacheTab->getAllCols(nRow, aCols);
- vector<SCCOL>::const_iterator itrCol = aCols.begin(), itrColEnd = aCols.end();
- for (; itrCol != itrColEnd; ++itrCol)
+ for (const SCCOL nCol : aCols)
{
- SCCOL nCol = *itrCol;
if (bFirst)
{
aRange.aStart = ScAddress(nCol, nRow, 0);
More information about the Libreoffice-commits
mailing list