tdf#126342: sc_ucalc: Add unittest

Change-Id: I81afb8e513821253bc11e07d4bbac3a1abae2f90
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115905
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index e98c58a..222e3c0 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -168,6 +168,7 @@ public:
    void testAutoFilterTimeValue();
    void testTdf76441();
    void testTdf142186();
    void testTdf126342();
    void testAdvancedFilter();
    void testTdf98642();
    void testMergedCells();
@@ -292,6 +293,7 @@ public:
    CPPUNIT_TEST(testAutoFilterTimeValue);
    CPPUNIT_TEST(testTdf76441);
    CPPUNIT_TEST(testTdf142186);
    CPPUNIT_TEST(testTdf126342);
    CPPUNIT_TEST(testAdvancedFilter);
    CPPUNIT_TEST(testTdf98642);
    CPPUNIT_TEST(testMergedCells);
@@ -3636,6 +3638,37 @@ void Test::testTdf142186()
    m_pDoc->DeleteTab(0);
}

void Test::testTdf126342()
{
    m_pDoc->InsertTab(0, "Test");

    OUString aCode = "YYYY-MM-DD";
    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));
    m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs);

    m_pDoc->SetString(ScAddress(0,0,0), "11/7/19");

    CPPUNIT_ASSERT_EQUAL(OUString("2019-11-07"), m_pDoc->GetString(ScAddress(0,0,0)));

    // Overwrite the existing date with the exact same input
    m_pDoc->SetString(ScAddress(0,0,0), "11/7/19");

    // Without the fix in place, this test would have failed with
    // - Expected: 2019-11-07
    // - Actual  : 2011-07-19
    CPPUNIT_ASSERT_EQUAL(OUString("2019-11-07"), m_pDoc->GetString(ScAddress(0,0,0)));

    m_pDoc->DeleteTab(0);
}

void Test::testAdvancedFilter()
{
    m_pDoc->InsertTab(0, "Test");