diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-20 12:54:11 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-22 09:53:45 +0100 |
commit | b7654432bfeca619b7657abc8d27193e44cf4dfc (patch) | |
tree | 0935306e00e967c1dca4efc8af57f4d67c30a508 /sc/qa | |
parent | f82888653c853f236ab0035bb578a7129ec72fa5 (diff) |
loplugin:useuniqueptr in ScDocument
and fix bug where we were deleting a pointer to an object
we did not own via pFormatExchangeList
Change-Id: I488c679734c48bd21bc6be04837e037e97550647
Reviewed-on: https://gerrit.libreoffice.org/51668
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 22 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 12 |
2 files changed, 17 insertions, 17 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 0f60db22a8ba..59b9d51824a1 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1511,10 +1511,10 @@ void Test::testNamedRange() m_pDoc->SetValue (0, 0, 0, 101); - ScRangeName* pNames = new ScRangeName; - bool bSuccess = insertRangeNames(m_pDoc, pNames, aNames, aNames + SAL_N_ELEMENTS(aNames)); + std::unique_ptr<ScRangeName> pNames(new ScRangeName); + bool bSuccess = insertRangeNames(m_pDoc, pNames.get(), aNames, aNames + SAL_N_ELEMENTS(aNames)); CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess); - m_pDoc->SetRangeName(pNames); + m_pDoc->SetRangeName(std::move(pNames)); ScRangeName* pNewRanges = m_pDoc->GetRangeName(); CPPUNIT_ASSERT(pNewRanges); @@ -1537,12 +1537,12 @@ void Test::testNamedRange() ASSERT_DOUBLES_EQUAL_MESSAGE ("calculation failed", 1.0, result); // Test copy-ability of range names. - ScRangeName* pCopiedRanges = new ScRangeName(*pNewRanges); - m_pDoc->SetRangeName(pCopiedRanges); + std::unique_ptr<ScRangeName> pCopiedRanges(new ScRangeName(*pNewRanges)); + m_pDoc->SetRangeName(std::move(pCopiedRanges)); // Make sure the index lookup still works. for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i) { - const ScRangeData* p = pCopiedRanges->findByIndex(aNames[i].mnIndex); + const ScRangeData* p = m_pDoc->GetRangeName()->findByIndex(aNames[i].mnIndex); CPPUNIT_ASSERT_MESSAGE("lookup of range name by index failed with the copied instance.", p); OUString aName = p->GetName(); CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved with the copied instance.", aName.equalsAscii(aNames[i].mpName)); @@ -1588,10 +1588,10 @@ void Test::testInsertNameList() { "MyRange3", "$Test.$C$1:$C$100", 3 } }; - ScRangeName* pNames = new ScRangeName; - bool bSuccess = insertRangeNames(m_pDoc, pNames, aNames, aNames + SAL_N_ELEMENTS(aNames)); + std::unique_ptr<ScRangeName> pNames(new ScRangeName); + bool bSuccess = insertRangeNames(m_pDoc, pNames.get(), aNames, aNames + SAL_N_ELEMENTS(aNames)); CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess); - m_pDoc->SetRangeName(pNames); + m_pDoc->SetRangeName(std::move(pNames)); ScDocFunc& rDocFunc = getDocShell().GetDocFunc(); ScAddress aPos(1,1,0); @@ -3282,7 +3282,7 @@ void Test::testCopyPaste() ScRangeData* pGlobal = new ScRangeData( m_pDoc, "global", aAdr); const OUString aGlobal2Symbol("$Sheet1.$A$1:$A$23"); ScRangeData* pGlobal2 = new ScRangeData( m_pDoc, "global2", aGlobal2Symbol); - ScRangeName* pGlobalRangeName = new ScRangeName(); + std::unique_ptr<ScRangeName> pGlobalRangeName(new ScRangeName()); pGlobalRangeName->insert(pGlobal); pGlobalRangeName->insert(pGlobal2); ScRangeName* pLocalRangeName1 = new ScRangeName(); @@ -3291,7 +3291,7 @@ void Test::testCopyPaste() pLocalRangeName1->insert(pLocal3); pLocalRangeName1->insert(pLocal4); pLocalRangeName1->insert(pLocal5); - m_pDoc->SetRangeName(pGlobalRangeName); + m_pDoc->SetRangeName(std::move(pGlobalRangeName)); m_pDoc->SetRangeName(0, pLocalRangeName1); // Add formula to B1. diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index 1d801ee73fc6..0f2c50f9d204 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -1473,11 +1473,11 @@ void Test::testSharedFormulaUpdateOnNamedRangeChange() aName.mpName = pName; aName.mpExpr = pExpr1; aName.mnIndex = 1; - ScRangeName* pNames = new ScRangeName; - bool bSuccess = insertRangeNames(m_pDoc, pNames, &aName, &aName + 1); + std::unique_ptr<ScRangeName> pNames(new ScRangeName); + bool bSuccess = insertRangeNames(m_pDoc, pNames.get(), &aName, &aName + 1); CPPUNIT_ASSERT(bSuccess); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pNames->size()); - m_pDoc->SetRangeName(pNames); + m_pDoc->SetRangeName(std::move(pNames)); // Set values to A1:A4. m_pDoc->SetValue(ScAddress(0,0,0), 1.0); @@ -1525,9 +1525,9 @@ void Test::testSharedFormulaUpdateOnNamedRangeChange() CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(2,0,0))); // Update the range of MyRange. - pNames = new ScRangeName; + pNames.reset(new ScRangeName); aName.mpExpr = pExpr2; - bSuccess = insertRangeNames(m_pDoc, pNames, &aName, &aName + 1); + bSuccess = insertRangeNames(m_pDoc, pNames.get(), &aName, &aName + 1); CPPUNIT_ASSERT(bSuccess); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pNames->size()); ScDocFunc& rFunc = getDocShell().GetDocFunc(); @@ -1535,7 +1535,7 @@ void Test::testSharedFormulaUpdateOnNamedRangeChange() typedef std::map<OUString, std::unique_ptr<ScRangeName>> NameMapType; NameMapType aNewNames; OUString aScope(STR_GLOBAL_RANGE_NAME); - aNewNames.insert(std::make_pair(aScope, std::unique_ptr<ScRangeName>(pNames))); + aNewNames.insert(std::make_pair(aScope, std::move(pNames))); rFunc.ModifyAllRangeNames(aNewNames); // Check to make sure all displayed formulas are still good. |