tdf#159938: sc_uicalc2: Add unittest

Change-Id: Ib5bd28cf2d449924425e06bb22437af522443ed8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164145
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/qa/unit/uicalc/data/tdf159938.fods b/sc/qa/unit/uicalc/data/tdf159938.fods
new file mode 100644
index 0000000..9da1be1
--- /dev/null
+++ b/sc/qa/unit/uicalc/data/tdf159938.fods
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>

<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.spreadsheet">
 <office:font-face-decls>
  <style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
 </office:font-face-decls>
 <office:styles>
  <style:default-style style:family="table-cell">
   <style:text-properties style:font-name="Liberation Sans" fo:font-size="11pt"/>
  </style:default-style>
 </office:styles>
 <office:automatic-styles>
  <style:style style:name="co1" style:family="table-column">
   <style:table-column-properties fo:break-before="auto" style:column-width="2.25cm"/>
  </style:style>
  <style:style style:name="ro1" style:family="table-row">
   <style:table-row-properties style:row-height="5mm" fo:break-before="auto" style:use-optimal-row-height="true"/>
  </style:style>
  <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N0">
   <style:table-cell-properties style:cell-protect="protected" style:print-content="true" style:text-align-source="value-type" style:repeat-content="false" fo:wrap-option="wrap" style:direction="ltr" style:rotation-angle="0" style:rotation-align="none" style:shrink-to-fit="false" style:vertical-align="bottom" loext:vertical-justify="auto"/>
   <style:paragraph-properties css3t:text-justify="auto" fo:margin-left="0cm" style:writing-mode="page"/>
  </style:style>
  <style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N0">
   <style:table-cell-properties fo:background-color="#ffff99" style:cell-protect="protected" style:print-content="true" style:text-align-source="value-type" style:repeat-content="false" fo:wrap-option="no-wrap" style:direction="ltr" style:rotation-angle="0" style:rotation-align="none" style:shrink-to-fit="false" style:vertical-align="bottom" loext:vertical-justify="auto"/>
   <style:paragraph-properties css3t:text-justify="auto" fo:margin-left="0cm" style:writing-mode="page"/>
  </style:style>
 </office:automatic-styles>
 <office:body>
  <office:spreadsheet>
   <table:table table:name="Sheet1">
    <table:table-column table:style-name="co1" table:number-columns-repeated="16374" table:default-cell-style-name="Default"/>
    <table:table-row table:style-name="ro1">
     <table:table-cell table:style-name="ce1" office:value-type="string"><text:p>foo</text:p><text:p>bar</text:p>
     </table:table-cell>
     <table:table-cell table:number-columns-repeated="16373"/>
    </table:table-row>
    <table:table-row table:style-name="ro1">
     <table:table-cell table:style-name="ce2" office:value-type="string">
      <text:p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</text:p>
     </table:table-cell>
     <table:table-cell table:number-columns-repeated="16373"/>
    </table:table-row>
    <table:table-row table:style-name="ro1" table:number-rows-repeated="1048574">
     <table:table-cell table:number-columns-repeated="16374"/>
    </table:table-row>
   </table:table>
   <table:named-expressions/>
  </office:spreadsheet>
 </office:body>
</office:document>
\ No newline at end of file
diff --git a/sc/qa/unit/uicalc/uicalc2.cxx b/sc/qa/unit/uicalc/uicalc2.cxx
index af1ff87..2335559 100644
--- a/sc/qa/unit/uicalc/uicalc2.cxx
+++ b/sc/qa/unit/uicalc/uicalc2.cxx
@@ -471,6 +471,35 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf131073)
    CPPUNIT_ASSERT_EQUAL(nStdColWidth, pDoc->GetColWidth(2, 0));
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf159938)
{
    createScDoc("tdf159938.fods");
    ScDocument* pDoc = getScDoc();

    const sal_uInt16 nCol1Width = pDoc->GetColWidth(0, 0);
    const sal_uInt16 nCol2Width = pDoc->GetColWidth(1, 0);
    const sal_uInt16 nRow1Height = pDoc->GetRowHeight(0, 0);
    const sal_uInt16 nRow2Height = pDoc->GetRowHeight(1, 0);
    const sal_uInt16 nRow3Height = pDoc->GetRowHeight(2, 0);

    goToCell("A1");
    dispatchCommand(mxComponent, ".uno:GoDown", {});
    dispatchCommand(mxComponent, ".uno:GoDown", {});
    dispatchCommand(mxComponent, ".uno:GoDown", {});

    ScDocShell* pDocSh = getScDocShell();
    lcl_AssertCurrentCursorPosition(*pDocSh, u"A4");
    CPPUNIT_ASSERT_EQUAL(nCol1Width, pDoc->GetColWidth(0, 0));
    CPPUNIT_ASSERT_EQUAL(nCol2Width, pDoc->GetColWidth(1, 0));
    CPPUNIT_ASSERT_EQUAL(nRow1Height, pDoc->GetRowHeight(0, 0));

    // Without the fix in place, this test would have failed with
    // - Expected: 283
    // - Actual  : 1552
    CPPUNIT_ASSERT_EQUAL(nRow2Height, pDoc->GetRowHeight(1, 0));
    CPPUNIT_ASSERT_EQUAL(nRow3Height, pDoc->GetRowHeight(2, 0));
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf83901)
{
    createScDoc();