diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-05-21 11:30:27 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-05-21 15:33:56 +0200 |
commit | e8b2849f2d336e903992ff7a3483364085594d12 (patch) | |
tree | 8fb7f470454d8430bb6e0a877ec7dd3759eff3af | |
parent | 62728a315b762440f76477e036a8dacc5bb6d12d (diff) |
tdf#142186: sc_ucalc: Add unittest
Change-Id: I376cb9d6853eb89ca35875d66275b5e534eec013
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115904
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 1a73df7f32cf..e98c58a02306 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -167,6 +167,7 @@ public: void testAutofilter(); void testAutoFilterTimeValue(); void testTdf76441(); + void testTdf142186(); void testAdvancedFilter(); void testTdf98642(); void testMergedCells(); @@ -290,6 +291,7 @@ public: CPPUNIT_TEST(testAutofilter); CPPUNIT_TEST(testAutoFilterTimeValue); CPPUNIT_TEST(testTdf76441); + CPPUNIT_TEST(testTdf142186); CPPUNIT_TEST(testAdvancedFilter); CPPUNIT_TEST(testTdf98642); CPPUNIT_TEST(testMergedCells); @@ -3593,6 +3595,47 @@ void Test::testTdf76441() m_pDoc->DeleteTab(0); } +void Test::testTdf142186() +{ + m_pDoc->InsertTab(0, "Test"); + + // The result will be different depending on whether the format is set before + // or after inserting the string + + OUString aCode = "0\".\"0"; + sal_Int32 nCheckPos; + SvNumFormatType nType; + sal_uInt32 nFormat; + SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); + pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat ); + + ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + SfxItemSet& rSet = aNewAttrs.GetItemSet(); + rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); + { + // First insert the string, then the format + m_pDoc->SetString(ScAddress(0,0,0), "123.45"); + + m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs); + + CPPUNIT_ASSERT_EQUAL(OUString("12.3"), m_pDoc->GetString(ScAddress(0,0,0))); + } + + { + // First set the format, then insert the string + m_pDoc->ApplyPattern(0, 1, 0, aNewAttrs); + + m_pDoc->SetString(ScAddress(0,1,0), "123.45"); + + // Without the fix in place, this test would have failed with + // - Expected: 12.3 + // - Actual : 1234.5 + CPPUNIT_ASSERT_EQUAL(OUString("12.3"), m_pDoc->GetString(ScAddress(0,1,0))); + } + + m_pDoc->DeleteTab(0); +} + void Test::testAdvancedFilter() { m_pDoc->InsertTab(0, "Test"); |