summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2017-03-01 08:56:58 +0100
committerEike Rathke <erack@redhat.com>2017-04-10 15:48:27 +0200
commite9d13f703f212b317682c35877571903da18b4af (patch)
tree6e9a32a1758d7b1b67f58a3763a24ee7e440a591
parent09478b2211bbc9ec34d8de8452e30cf1254a250c (diff)
Tests for "Precision as shown" following tdf#105657 tdf#106052
I was unabled to add these test svl/qa/unit/svl.cxx because they required ScDocument::RoundValueAsShown() Found that other formats are not supported by "Precision as shown" option: - engineering tdf#106252 - thousand tdf#106253 Change-Id: Iaf98c404cabec0f5c69f94f2bf863351487fe9d7 Reviewed-on: https://gerrit.libreoffice.org/34750 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> (cherry picked from commit 7496f7d3cae8a932dc43ede8a30a99289366a264) Reviewed-on: https://gerrit.libreoffice.org/36368
-rw-r--r--sc/qa/unit/ucalc.cxx103
-rw-r--r--sc/qa/unit/ucalc.hxx4
2 files changed, 107 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 65d5892b4c5a..dbdd549b3ba6 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6403,6 +6403,109 @@ void Test::setCalcAsShown(ScDocument* pDoc, bool bCalcAsShown)
pDoc->SetDocOptions(aOpt);
}
+void Test::checkPrecisionAsShown( OUString& rCode, double fValue, double fExpectedRoundVal )
+{
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ sal_uInt32 nFormat = pFormatter->GetEntryKey( rCode );
+ if ( nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
+ {
+ sal_Int32 nCheckPos = 0;
+ short nType;
+ pFormatter->PutEntry( rCode, nCheckPos, nType, nFormat );
+ CPPUNIT_ASSERT_EQUAL( nCheckPos, sal_Int32(0) );
+ }
+ double fRoundValue = m_pDoc->RoundValueAsShown( fValue, nFormat );
+ rtl::OString aMessage = "Format \"";
+ aMessage += rtl::OUStringToOString( rCode, RTL_TEXTENCODING_ASCII_US );
+ aMessage += "\" is not correctly rounded";
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( aMessage.getStr(), fExpectedRoundVal, fRoundValue );
+}
+
+void Test::testPrecisionAsShown()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ // Turn on "precision as shown" option.
+ setCalcAsShown( m_pDoc, true);
+
+ OUString aCode;
+ double fValue, fExpectedRoundVal;
+ { // decimal rounding
+ aCode = "0.00";
+ fValue = 1.0/3.0;
+ fExpectedRoundVal = 0.33;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -10.001;
+ fExpectedRoundVal = -10.0;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // thousand rounding buguous!!!! tdf#106253
+ aCode = "0,,";
+ fValue = 4.0e9 / 7.0;
+ fExpectedRoundVal = 571e6; // actual is 571428571
+ //checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -4.0e8 / 7.0;
+ fExpectedRoundVal = -57e6; // actual is 57142857
+ //checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // percent rounding
+ aCode = "0.00%";
+ fValue = 4.0 / 7.0;
+ fExpectedRoundVal = 0.5714;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -4.0 / 7.0;
+ fExpectedRoundVal = -0.5714;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // scientific rounding
+ aCode = "0.00E0";
+ fValue = 400000.0 / 7.0;
+ fExpectedRoundVal = 57100.0;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = 4.0 / 70000.0;
+ fExpectedRoundVal = 5.71e-5;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ // engineering rounding bugous!!! tdf#106252
+ aCode = "##0.000E0";
+ fValue = 400000.0 / 7.0;
+ fExpectedRoundVal = 57143.0; // actual is 57140
+ //checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = 4.0 / 70000.0;
+ fExpectedRoundVal = 5.7143e-5; // actual is 5.714e-05
+ //checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // fraction rounding tdf#105657
+ aCode = "# ?/?";
+ fValue = 0.35;
+ fExpectedRoundVal = 1.0/3.0;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -0.35;
+ fExpectedRoundVal = -1.0/3.0;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // exact fraction
+ aCode = "# ?/??";
+ fValue = 0.35;
+ fExpectedRoundVal = 0.35;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -0.35;
+ fExpectedRoundVal = -0.35;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+ { // several sub-formats tdf#106052
+ aCode = "0.00;-0.000";
+ fValue = 1.0/3.0;
+ fExpectedRoundVal = 0.33;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ fValue = -1.0/3.0;
+ fExpectedRoundVal = -0.333;
+ checkPrecisionAsShown( aCode, fValue, fExpectedRoundVal );
+ }
+
+ setCalcAsShown( m_pDoc, false);
+ m_pDoc->DeleteTab(0);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 041a8277a110..705536e74bad 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -60,6 +60,7 @@ public:
static void setCalcAsShown(ScDocument* pDoc, bool bCalcAsShown);
+ void checkPrecisionAsShown( OUString& rCode, double fValue, double fExpectedRoundVal );
template<size_t Size>
static ScRange insertRangeData(
@@ -488,6 +489,8 @@ public:
void testEmptyCalcDocDefaults();
+ void testPrecisionAsShown();
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testSharedStringPool);
@@ -735,6 +738,7 @@ public:
CPPUNIT_TEST(testTdf97369);
CPPUNIT_TEST(testTdf97587);
CPPUNIT_TEST(testEmptyCalcDocDefaults);
+ CPPUNIT_TEST(testPrecisionAsShown);
CPPUNIT_TEST_SUITE_END();
private: