sc/qa/unit/SparklineTest.cxx | 61 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-)
New commits: commit f7fbce57fe62e21c0370ac8d545ef4cf2bbbe3cf Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Mar 15 15:50:10 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Apr 12 01:22:29 2022 +0200 sc: add unit test to delete Sparkline, update add Sparkline test Change-Id: Ib0e60ea5aa246b29a06ae90be2cb4b905722b1a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132469 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit cbd4e2852545b5f67896dc9062ddda4d5744f751) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132793 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx index d4a8d2d119a8..74f40579d99f 100644 --- a/sc/qa/unit/SparklineTest.cxx +++ b/sc/qa/unit/SparklineTest.cxx @@ -19,6 +19,8 @@ class SparklineTest : public ScBootstrapFixture private: uno::Reference<uno::XInterface> m_xCalcComponent; + sc::Sparkline* createTestSparkline(ScDocument& rDocument); + public: SparklineTest() : ScBootstrapFixture("sc/qa/unit/data") @@ -43,22 +45,77 @@ public: } void testAddSparkline(); + void testDeleteSprkline(); CPPUNIT_TEST_SUITE(SparklineTest); CPPUNIT_TEST(testAddSparkline); + CPPUNIT_TEST(testDeleteSprkline); CPPUNIT_TEST_SUITE_END(); }; +sc::Sparkline* SparklineTest::createTestSparkline(ScDocument& rDocument) +{ + auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); + + sc::Sparkline* pSparkline = rDocument.CreateSparkline(ScAddress(0, 6, 0), pSparklineGroup); + if (!pSparkline) + return nullptr; + + rDocument.SetValue(0, 0, 0, 4); + rDocument.SetValue(0, 1, 0, -2); + rDocument.SetValue(0, 2, 0, 1); + rDocument.SetValue(0, 3, 0, -3); + rDocument.SetValue(0, 4, 0, 5); + rDocument.SetValue(0, 5, 0, 3); + + ScRangeList aList; + aList.push_back(ScRange(0, 0, 0, 0, 5, 0)); + pSparkline->setInputRange(aList); + + return pSparkline; +} + void SparklineTest::testAddSparkline() { ScDocShellRef xDocSh = loadEmptyDocument(); CPPUNIT_ASSERT(xDocSh); ScDocument& rDocument = xDocSh->GetDocument(); - auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); - sc::Sparkline* pSparkline = rDocument.CreateSparkline(ScAddress(0, 0, 0), pSparklineGroup); + sc::Sparkline* pSparkline = createTestSparkline(rDocument); CPPUNIT_ASSERT(pSparkline); + + sc::Sparkline* pGetSparkline = rDocument.GetSparkline(ScAddress(0, 6, 0)); + CPPUNIT_ASSERT(pGetSparkline); + + CPPUNIT_ASSERT_EQUAL(pGetSparkline, pSparkline); + + sc::SparklineList* pList = rDocument.GetSparklineList(0); + CPPUNIT_ASSERT(pList); + + std::vector<std::shared_ptr<sc::Sparkline>> aSparklineVector = pList->getSparklines(); + CPPUNIT_ASSERT_EQUAL(size_t(1), aSparklineVector.size()); + CPPUNIT_ASSERT_EQUAL(aSparklineVector[0].get(), pSparkline); + + xDocSh->DoClose(); +} + +void SparklineTest::testDeleteSprkline() +{ + ScDocShellRef xDocSh = loadEmptyDocument(); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDocument = xDocSh->GetDocument(); + + sc::Sparkline* pSparkline = createTestSparkline(rDocument); + CPPUNIT_ASSERT(pSparkline); + + clearRange(&rDocument, ScRange(0, 6, 0, 0, 6, 0)); + + sc::Sparkline* pGetSparkline = rDocument.GetSparkline(ScAddress(0, 6, 0)); + CPPUNIT_ASSERT(!pGetSparkline); + + xDocSh->DoClose(); } CPPUNIT_TEST_SUITE_REGISTRATION(SparklineTest);