sc/qa/unit/units.cxx | 149 +++++++++++++++++++-------- sc/source/ui/miscdlgs/unitsconversiondlg.cxx | 7 + 2 files changed, 116 insertions(+), 40 deletions(-)
New commits: commit b290ccb0b3979e7ad344709b4d1018fee071f52a Author: Benjamin Ni <benjaminn...@hotmail.com> Date: Tue Jun 30 06:40:38 2015 +0100 Added more range conversion tests Change-Id: If4898e6c70cb9731af35d51457de28410f808b96 diff --git a/sc/qa/unit/units.cxx b/sc/qa/unit/units.cxx index ee6af8a..28cffa2 100644 --- a/sc/qa/unit/units.cxx +++ b/sc/qa/unit/units.cxx @@ -321,6 +321,13 @@ void UnitsTest::testUnitVerification() { pTokens = pCell->GetCode(); CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID); + // SUM("cm","m") + address.IncRow(); + mpDoc->SetFormula(address, "=SUM(A1,E1)"); + pCell = mpDoc->GetFormulaCell(address); + pTokens = pCell->GetCode(); + CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::ERROR_INPUT_SCALING); + // PRODUCT("cm/","s")+"cm" address.IncRow(); mpDoc->SetFormula(address, "=PRODUCT(C1:D1)+A1"); @@ -803,82 +810,144 @@ void UnitsTest::testRangeConversion() { mpDoc->EnsureTable(nTab); // Column 1: convert [cm] to [cm]. - ScAddress headerAddress(0, 0, nTab); - mpDoc->SetString(headerAddress, "length [cm]"); + ScAddress headerAddressCol1(0, 0, nTab); + mpDoc->SetString(headerAddressCol1, "length [cm]"); - ScAddress address(headerAddress); + ScAddress addressCol1(headerAddressCol1); vector<double> values({10, 20, 30, 40, 1, 0.5, 0.25}); - address.IncRow(); - mpDoc->SetValues(address, values); + addressCol1.IncRow(); + mpDoc->SetValues(addressCol1, values); // Test conversion of range _not_ including header - ScAddress endAddress( address.Col(), address.Row() + values.size() - 1, nTab); + ScAddress endAddressCol1( addressCol1.Col(), addressCol1.Row() + values.size() - 1, nTab); - ScRange aRange(address, endAddress); + ScRange aRange(addressCol1, endAddressCol1); CPPUNIT_ASSERT(mpUnitsImpl->convertCellUnits(aRange, mpDoc, "cm")); CPPUNIT_ASSERT(!mpUnitsImpl->convertCellUnits(aRange, mpDoc, "kg")); - CPPUNIT_ASSERT(mpDoc->GetString(headerAddress) == "length [cm]"); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol1) == "length [cm]"); - for (double d: values) { + for (double d: values) + { // Test that the value is unchanged - CPPUNIT_ASSERT(mpDoc->GetValue(address) == d); + CPPUNIT_ASSERT(mpDoc->GetValue(addressCol1) == d); // And NO annotation has been added - CPPUNIT_ASSERT(mpDoc->GetString(address) == OUString::number(d)); - address.IncRow(); + CPPUNIT_ASSERT(mpDoc->GetString(addressCol1) == OUString::number(d)); + addressCol1.IncRow(); } // Test conversion of range including header (from cm to cm) - aRange = ScRange(headerAddress, endAddress); + aRange = ScRange(headerAddressCol1, endAddressCol1); CPPUNIT_ASSERT(mpUnitsImpl->convertCellUnits(aRange, mpDoc, "cm")); CPPUNIT_ASSERT(!mpUnitsImpl->convertCellUnits(aRange, mpDoc, "kg")); - CPPUNIT_ASSERT(mpDoc->GetString(headerAddress) == "length [cm]"); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol1) == "length [cm]"); - address = headerAddress; - address.IncRow(); - for (double d: values) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetValue(address), d, 1e-7); + addressCol1 = headerAddressCol1; + addressCol1.IncRow(); + for (double d: values) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetValue(addressCol1), d, 1e-7); // And NO annotation has been added - CPPUNIT_ASSERT(mpDoc->GetString(address) == OUString::number(d)); - address.IncRow(); + CPPUNIT_ASSERT(mpDoc->GetString(addressCol1) == OUString::number(d)); + addressCol1.IncRow(); } // Convert just the values (but not header): [cm] to [m] - address.SetRow(1); - aRange = ScRange(address, endAddress); + addressCol1.SetRow(1); + aRange = ScRange(addressCol1, endAddressCol1); CPPUNIT_ASSERT(mpUnitsImpl->convertCellUnits(aRange, mpDoc, "m")); - CPPUNIT_ASSERT(mpDoc->GetString(headerAddress) == "length [cm]"); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol1) == "length [cm]"); - for (double d: values) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetValue(address), d/100, 1e-7); - // AND test annotation - // Disabled for now until the precision problems are figured out - // CPPUNIT_ASSERT(mpDoc->GetString(address) == OUString::number(d/100) + "m"); - address.IncRow(); + for (double d: values) + { + OUString aResultStr = mpDoc->GetString(addressCol1); + OUString aValStr = aResultStr.copy( 0, aResultStr.getLength() - 1 ); // value portion of result + OUString aUnitStr = aResultStr.copy( aResultStr.getLength() - 1, 1 ); // annotation portion of result + CPPUNIT_ASSERT_DOUBLES_EQUAL(aValStr.toDouble(), d/100, 1e-7); + CPPUNIT_ASSERT(aUnitStr == "m"); + addressCol1.IncRow(); } // Convert everything (including header) to mm: [m] to [mm] - aRange = ScRange(headerAddress, endAddress); + aRange = ScRange(headerAddressCol1, endAddressCol1); CPPUNIT_ASSERT(mpUnitsImpl->convertCellUnits(aRange, mpDoc, "mm")); - CPPUNIT_ASSERT(mpDoc->GetString(headerAddress) == "length [mm]"); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol1) == "length [mm]"); - address.SetRow(1); + addressCol1.SetRow(1); - for (double d: values) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetValue(address), d*10, 1e-7); + for (double d: values) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetValue(addressCol1), d*10, 1e-7); // And the annotation has been REMOVED - CPPUNIT_ASSERT(mpDoc->GetString(address) == OUString::number(d*10)); - address.IncRow(); + CPPUNIT_ASSERT(mpDoc->GetString(addressCol1) == OUString::number(d*10)); + addressCol1.IncRow(); } - // TODO: we need to test: - // 1. mixture of units that can't be converted - // 2. mixtures of local and header annotations - // 3. actual sensible ranges + // Column 2: [kg] + ScAddress headerAddressCol2(1, 0, nTab); + mpDoc->SetString(headerAddressCol2, "weight [kg]"); + + ScAddress addressCol2(headerAddressCol2); + addressCol2.IncRow(); + mpDoc->SetValues(addressCol2, values); + + ScAddress endAddressCol2( addressCol2.Col(), addressCol2.Row() + values.size() - 1, nTab); + + // Column 3: [kg] (replica of Col2, but offset downwards by 1 cell) + ScAddress headerAddressCol3(2, 1, nTab); + mpDoc->SetString(headerAddressCol3, "weight [kg]"); + + ScAddress addressCol3(headerAddressCol3); + addressCol3.IncRow(); + mpDoc->SetValues(addressCol3, values); + + ScAddress endAddressCol3( addressCol3.Col(), addressCol3.Row() + values.size() - 1, nTab); + + // test mixture [mm, kg] convert to [m] + addressCol1.SetRow(1); + aRange = ScRange(addressCol1, endAddressCol2); // over range of cm and kg values + + CPPUNIT_ASSERT(!mpUnitsImpl->convertCellUnits(aRange, mpDoc, "m")); + for (double d: values) // test that convertible units are still converted + { + OUString aResultStr = mpDoc->GetString(addressCol1); + OUString aValStr = aResultStr.copy( 0, aResultStr.getLength() - 1 ); // value portion of result + OUString aUnitStr = aResultStr.copy( aResultStr.getLength() - 1, 1 ); // annotation portion of result + CPPUNIT_ASSERT_DOUBLES_EQUAL(aValStr.toDouble(), d/100, 1e-7); + CPPUNIT_ASSERT(aUnitStr == "m"); + addressCol1.IncRow(); + } + + // test mixture of local (Col2) and header (Col3) annotations + addressCol2.SetRow(1); + addressCol3.SetRow(2); + + aRange = ScRange(addressCol2, endAddressCol3); // Col2 local, Col3 header + CPPUNIT_ASSERT(mpUnitsImpl->convertCellUnits(aRange, mpDoc, "g")); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol2) == "weight [kg]"); + CPPUNIT_ASSERT(mpDoc->GetString(headerAddressCol3) == "weight [g]" ); + for (double d: values) + { + OUString aResultStr = mpDoc->GetString(addressCol2); + OUString aValStr = aResultStr.copy( 0, aResultStr.getLength() - 1 ); // value portion of result + OUString aUnitStr = aResultStr.copy( aResultStr.getLength() - 1, 1 ); // annotation portion of result + CPPUNIT_ASSERT_DOUBLES_EQUAL(aValStr.toDouble(), d*1000, 1e-7); + CPPUNIT_ASSERT(aUnitStr == "g"); + addressCol2.IncRow(); + + if (addressCol3 != endAddressCol3) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(mpDoc->GetString(addressCol3).toDouble(), d*1000, 1e-7); + addressCol3.IncRow(); + } + + // TODO: we need to test: + // 1. actual sensible ranges + } } void UnitsTest::testConvertCellUnits() commit 5e2962a92244e6c815e96e60250a6e12b91d7fa2 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Tue Jun 30 14:38:09 2015 +0200 refresh cell rendering after changing unit Change-Id: I6f68c319df89906b29d1f8409f6170a0b68c8b87 diff --git a/sc/source/ui/miscdlgs/unitsconversiondlg.cxx b/sc/source/ui/miscdlgs/unitsconversiondlg.cxx index edd611e..a3a6744 100644 --- a/sc/source/ui/miscdlgs/unitsconversiondlg.cxx +++ b/sc/source/ui/miscdlgs/unitsconversiondlg.cxx @@ -13,6 +13,7 @@ #include "reffact.hxx" #include "units.hxx" #include "viewdata.hxx" +#include "docsh.hxx" using namespace sc::units; @@ -266,7 +267,13 @@ void ScUnitsConversionDialog::PerformConversion() { OUString sOutputUnit = mpOutputUnitsEdit->GetText(); + ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDoc->GetDocumentShell()); + ScDocShellModificator aModificator(*pDocShell); mpUnits->convertCellUnits( *mInputRange, mpDoc, sOutputUnit ); + pDocShell->PostPaint(*mInputRange, PAINT_GRID); + + aModificator.SetDocumentModified(); + SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits