sc/qa/unit/pivottable_filters_test.cxx | 8 ++++---- sc/qa/unit/subsequent_export_test3.cxx | 18 +++++++++--------- sc/qa/unit/ucalc_condformat.cxx | 7 ++++--- 3 files changed, 17 insertions(+), 16 deletions(-)
New commits: commit f37fe2fbea795fc1275d82a061e367874fa1b5dc Author: Elena Livadaru <[email protected]> AuthorDate: Sat Dec 6 12:33:51 2025 +0200 Commit: Ilmari Lauhakangas <[email protected]> CommitDate: Fri Dec 12 10:15:44 2025 +0100 tdf#147021 Use std::size() and range based loops instead of SAL_N_ELEMENTS() macro Change-Id: I712ca434143b1b85fe77b5f5e39a3671e0ea343a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195157 Reviewed-by: Ilmari Lauhakangas <[email protected]> Tested-by: Jenkins diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx index 12a360790d13..e358166e2fc5 100644 --- a/sc/qa/unit/pivottable_filters_test.cxx +++ b/sc/qa/unit/pivottable_filters_test.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <iterator> #include <sal/config.h> #include "helper/qahelper.hxx" @@ -903,7 +904,7 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFiltersTest, testPivotTableXLSX) const char* pNames[] = { "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10" }; size_t nCount = pCache->GetFieldCount(); - if (nCount != SAL_N_ELEMENTS(pNames)) + if (nCount != std::size(pNames)) { std::cout << "Incorrect number of fields in pivot cache." << std::endl; return false; @@ -1036,10 +1037,9 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFiltersTest, testPivotTableTwoDataFieldsXLSX) } const char* pNames[] = { "Name", "Value" }; - (void)pNames; size_t nCount = pCache->GetFieldCount(); - if (nCount != SAL_N_ELEMENTS(pNames)) + if (nCount != std::size(pNames)) { std::cout << "Incorrect number of fields in pivot cache." << std::endl; return false; @@ -2335,7 +2335,7 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFiltersTest, testTdf124736) const int vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 0, 44 }; - for (size_t i = 0; i < SAL_N_ELEMENTS(vals); ++i) + for (size_t i = 0; i < std::size(vals); ++i) { assertXPath(pTable, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[1]/x:items/x:item[" diff --git a/sc/qa/unit/subsequent_export_test3.cxx b/sc/qa/unit/subsequent_export_test3.cxx index 88715155fcd4..17b26d9dff82 100644 --- a/sc/qa/unit/subsequent_export_test3.cxx +++ b/sc/qa/unit/subsequent_export_test3.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <iterator> #include "helper/qahelper.hxx" #include <formulacell.hxx> @@ -342,9 +343,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTrackChangesSimpleXLSX) return false; } - for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i) + for (const auto& rCheck : aChecks) { - sal_uInt16 nActId = aChecks[i].mnActionId; + sal_uInt16 nActId = rCheck.mnActionId; const ScChangeAction* pAction = pCT->GetAction(nActId); if (!pAction) { @@ -352,7 +353,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTrackChangesSimpleXLSX) return false; } - if (pAction->GetType() != aChecks[i].meType) + if (pAction->GetType() != rCheck.meType) { std::cerr << "Unexpected action type for action number " << nActId << "." << std::endl; @@ -360,9 +361,8 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTrackChangesSimpleXLSX) } const ScBigRange& rRange = pAction->GetBigRange(); - ScBigRange aCheck(aChecks[i].mnStartCol, aChecks[i].mnStartRow, - aChecks[i].mnStartTab, aChecks[i].mnEndCol, aChecks[i].mnEndRow, - aChecks[i].mnEndTab); + ScBigRange aCheck(rCheck.mnStartCol, rCheck.mnStartRow, rCheck.mnStartTab, + rCheck.mnEndCol, rCheck.mnEndRow, rCheck.mnEndTab); if (!checkRange(pAction->GetType(), aCheck, rRange)) { @@ -377,7 +377,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTrackChangesSimpleXLSX) case SC_CAT_INSERT_ROWS: { const ScChangeActionIns* p = static_cast<const ScChangeActionIns*>(pAction); - if (p->IsEndOfList() != aChecks[i].mbRowInsertedAtBottom) + if (p->IsEndOfList() != rCheck.mbRowInsertedAtBottom) { std::cerr << "Unexpected end-of-list flag for action number " << nActId << "." << std::endl; @@ -509,7 +509,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetTabColorsXLSX) } const char* pNames[] = { "Green", "Red", "Blue", "Yellow" }; - for (size_t i = 0; i < SAL_N_ELEMENTS(pNames); ++i) + for (size_t i = 0; i < std::size(pNames); ++i) { OUString aExpected = OUString::createFromAscii(pNames[i]); if (aExpected != aTabNames[i]) @@ -527,7 +527,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetTabColorsXLSX) 0x00FFFF00, // yellow }; - for (size_t i = 0; i < SAL_N_ELEMENTS(aXclColors); ++i) + for (size_t i = 0; i < std::size(aXclColors); ++i) { if (aXclColors[i] != rDoc.GetTabBgColor(i)) { diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index eea080d2652a..c6e41b5044a5 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <iterator> #include "helper/qahelper.hxx" #include <conditio.hxx> @@ -836,11 +837,11 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testIconSet) { 2.0, 2 }, { 3.0, 1 } }; - for(size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i) + for(const auto& rTest : aTests) { - m_pDoc->SetValue(0,0,0,aTests[i].nVal); + m_pDoc->SetValue(0,0,0,rTest.nVal); std::unique_ptr<ScIconSetInfo> pInfo = pEntry->GetIconSetInfo(ScAddress(0,0,0)); - CPPUNIT_ASSERT_EQUAL(aTests[i].nIndex, pInfo->nIconIndex); + CPPUNIT_ASSERT_EQUAL(rTest.nIndex, pInfo->nIconIndex); } delete pEntry;
