From 1276daee3d0d4f30ee8844b6df55d72e0b54093f Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Wed, 31 Jan 2024 00:13:02 +0900 Subject: Currency pop-up: move getDocumentCurrencies to cxx, extend test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test now checks that multiple cells with the same currency still result in only one entry returned by getDocumentCurrencies. Change-Id: I34b0fd3b117ce01b3fd462f684d0927dd53f796d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162788 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sc/qa/unit/ucalc.cxx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'sc/qa') diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index be7f19f1d2b6..efd836c89190 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -6865,7 +6865,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDocumentModelAccessor_getDocumentCurrencies) { m_pDoc->InsertTab(0, "Sheet1"); - // Check Document Currencies + // Check document currencies - expect 0 auto pAccessor = m_xDocShell->GetDocumentModelAccessor(); CPPUNIT_ASSERT(pAccessor); CPPUNIT_ASSERT_EQUAL(size_t(0), pAccessor->getDocumentCurrencies().size()); @@ -6891,13 +6891,45 @@ CPPUNIT_TEST_FIXTURE(Test, testDocumentModelAccessor_getDocumentCurrencies) CPPUNIT_ASSERT_EQUAL(u"2,00€"_ustr, m_pDoc->GetString(ScAddress(0, 0, 0))); } - // Check Document Currencies Again + // Check document currencies again auto aCurrencyIDs = pAccessor->getDocumentCurrencies(); CPPUNIT_ASSERT_EQUAL(size_t(1), aCurrencyIDs.size()); CPPUNIT_ASSERT_EQUAL(LANGUAGE_SLOVENIAN, aCurrencyIDs[0].eLanguage); CPPUNIT_ASSERT_EQUAL(u"-424"_ustr, aCurrencyIDs[0].aExtension); CPPUNIT_ASSERT_EQUAL(u"€"_ustr, aCurrencyIDs[0].aSymbol); + + // Set the same currency to 2 more cells + { + m_pDoc->SetValue(ScAddress(1, 1, 0), 5.0); + m_pDoc->SetValue(ScAddress(2, 2, 0), 7.0); + + OUString aCode = u"#.##0,00[$€-424]"_ustr; + + sal_Int32 nCheckPos; + SvNumFormatType eType; + sal_uInt32 nFormat; + + m_pDoc->GetFormatTable()->PutEntry(aCode, nCheckPos, eType, nFormat, LANGUAGE_SLOVENIAN); + CPPUNIT_ASSERT_EQUAL(SvNumFormatType::CURRENCY, eType); + + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); + SfxItemSet& rSet = aNewAttrs.GetItemSet(); + rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); + m_pDoc->ApplyPattern(1, 1, 0, aNewAttrs); // B2. + m_pDoc->ApplyPattern(2, 2, 0, aNewAttrs); // C3. + + CPPUNIT_ASSERT_EQUAL(u"5,00€"_ustr, m_pDoc->GetString(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(u"7,00€"_ustr, m_pDoc->GetString(ScAddress(2, 2, 0))); + } + + // Check document currencies again - should be 1 entry only + aCurrencyIDs = pAccessor->getDocumentCurrencies(); + CPPUNIT_ASSERT_EQUAL(size_t(1), aCurrencyIDs.size()); + + CPPUNIT_ASSERT_EQUAL(LANGUAGE_SLOVENIAN, aCurrencyIDs[0].eLanguage); + CPPUNIT_ASSERT_EQUAL(u"-424"_ustr, aCurrencyIDs[0].aExtension); + CPPUNIT_ASSERT_EQUAL(u"€"_ustr, aCurrencyIDs[0].aSymbol); } -- cgit