[Libreoffice-commits] core.git: Branch 'feature/unitver' - 3 commits - external/udunits2 sc/inc sc/qa sc/source

Andrzej Hunt andrzej at ahunt.org
Tue Jun 2 04:37:37 PDT 2015


 external/udunits2/ExternalPackage_udunits2.mk |    2 -
 sc/inc/units.hxx                              |    2 -
 sc/qa/unit/units.cxx                          |   24 ++++++------
 sc/source/core/units/unitsimpl.cxx            |   50 +++++++++++++-------------
 sc/source/core/units/unitsimpl.hxx            |    9 ----
 sc/source/ui/view/viewfunc.cxx                |    2 -
 6 files changed, 41 insertions(+), 48 deletions(-)

New commits:
commit 5e1cd739dc61755cce62655a38a46004ba5192c7
Author: Andrzej Hunt <andrzej at ahunt.org>
Date:   Tue Jun 2 12:34:16 2015 +0100

    Enable udunits2 on OSX
    
    My original guess of library was wrong, other than that no special
    treatment is needed for the OSX build.
    
    Change-Id: I2a697c65a6e272bfa3f8070a85b4bbd8b01b5e23

diff --git a/external/udunits2/ExternalPackage_udunits2.mk b/external/udunits2/ExternalPackage_udunits2.mk
index 4073463..3ac5920 100644
--- a/external/udunits2/ExternalPackage_udunits2.mk
+++ b/external/udunits2/ExternalPackage_udunits2.mk
@@ -14,7 +14,7 @@ $(eval $(call gb_ExternalPackage_use_external_project,udunits2,udunits2))
 ifeq ($(OS)-$(COM),WNT-MSC)
 $(eval $(call gb_ExternalPackage_add_file,udunits2,$(LIBO_LIB_FOLDER)/iudunits2.dll,lib/.libs/iudunits2.dll))
 else ifeq ($(OS),MACOSX)
-$(eval $(call gb_ExternalPackage_add_file,udunits2,$(LIBO_LIB_FOLDER)/libudunits2.dylib,lib/.libs/libudunits2.dylib))
+$(eval $(call gb_ExternalPackage_add_file,udunits2,$(LIBO_LIB_FOLDER)/libudunits2.0.dylib,lib/.libs/libudunits2.0.dylib))
 else
 $(eval $(call gb_ExternalPackage_add_file,udunits2,$(LIBO_LIB_FOLDER)/libudunits2.so,lib/.libs/libudunits2.so))
 $(eval $(call gb_ExternalPackage_add_file,udunits2,$(LIBO_LIB_FOLDER)/libudunits2.so.0,lib/.libs/libudunits2.so.0))
commit 17f1869709f1ae8a7cfce11ec5b55f585ddab5b7
Author: Andrzej Hunt <andrzej at ahunt.org>
Date:   Mon Jun 1 22:12:54 2015 +0100

    Rename VERIFIED->VALID for formula status.
    
    Change-Id: I93a07e11546ebecf912449c72e57404731c346e9

diff --git a/sc/inc/units.hxx b/sc/inc/units.hxx
index 411fb84..1e0c5ea 100644
--- a/sc/inc/units.hxx
+++ b/sc/inc/units.hxx
@@ -45,7 +45,7 @@ struct RangeUnits {
  * is used).
  */
 enum class FormulaStatus {
-    VERIFIED,
+    VALID,
     UNKNOWN,
     ERROR_INPUT_SCALING,
     ERROR_INPUT_INCOMPATIBLE,
diff --git a/sc/qa/unit/units.cxx b/sc/qa/unit/units.cxx
index e2ad7cc..1dbf74f 100644
--- a/sc/qa/unit/units.cxx
+++ b/sc/qa/unit/units.cxx
@@ -221,7 +221,7 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=A1+A2");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // Test that addition of different units fails - incompatible types
     address = ScAddress(0, 6, 0);
@@ -235,14 +235,14 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=A1*B1+A2*B2");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // Test another combination (i.e. cm/s+'cm/s')
     address = ScAddress(0, 8, 0);
     mpDoc->SetFormula(address, "=A1/C1+D1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // Test that another combination fails (cm*kg/s+'cm/s')
     address = ScAddress(0, 9, 0);
@@ -256,7 +256,7 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=A1+100*E1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
     // 10cm + 100*1m = 110cm
     CPPUNIT_ASSERT_EQUAL(mpDoc->GetValue(address), 110.0);
 
@@ -287,7 +287,7 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=SUM(B1:B3)");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // SUM("cm"&"kg")
     address.IncRow();
@@ -315,14 +315,14 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=SUM(A1:A3)/SUM(C1:C3)+SUM(D1:D3)");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // PRODUCT("cm/","s")+"cm"
     address.IncRow();
     mpDoc->SetFormula(address, "=PRODUCT(C1:D1)+A1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // PRODUCT("cm/","s")+"kg"
     address.IncRow();
@@ -337,7 +337,7 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=SUM(A1,A2:A3)");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // But mixing the columns fails because of mixed units
     // (This test is primarily to ensure that we can handle arbitrary numbers
@@ -358,7 +358,7 @@ void UnitsTest::testUnitVerification() {
         mpDoc->SetFormula(address, "=" + aFunc + "(A1:A2)+A3");
         pCell = mpDoc->GetFormulaCell(address);
         pTokens = pCell->GetCode();
-        CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+        CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
         // FOO(cm) + kg
         address.IncRow();
@@ -376,7 +376,7 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=A1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
 
     // header in [cm], cell with 100*cm
@@ -405,14 +405,14 @@ void UnitsTest::testUnitVerification() {
     mpDoc->SetFormula(address, "=100*E1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 
     // header in (cm/s), formula resulting in cm/s
     address = ScAddress(6, 1, 0);
     mpDoc->SetFormula(address, "=A1/C1");
     pCell = mpDoc->GetFormulaCell(address);
     pTokens = pCell->GetCode();
-    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+    CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VALID);
 }
 
 void UnitsTest::testUnitFromFormatStringExtraction() {
diff --git a/sc/source/core/units/unitsimpl.cxx b/sc/source/core/units/unitsimpl.cxx
index d160e17..6332747 100644
--- a/sc/source/core/units/unitsimpl.cxx
+++ b/sc/source/core/units/unitsimpl.cxx
@@ -246,7 +246,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
 
             }
 
-            return { FormulaStatus::VERIFIED, aFirstUnit };
+            return { FormulaStatus::VALID, aFirstUnit };
         }
         case ocProduct:
         {
@@ -269,7 +269,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
                 } while (aIt.next());
             }
 
-            return { FormulaStatus::VERIFIED, aUnit };
+            return { FormulaStatus::VALID, aUnit };
         }
         default:
             return { FormulaStatus::UNKNOWN, boost::none };
@@ -278,7 +278,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
         SAL_INFO("sc.units", "unit verification not supported for opcode: " << nOpCode);
         return { FormulaStatus::UNKNOWN, boost::none };
     }
-    return { FormulaStatus::VERIFIED, pOut };
+    return { FormulaStatus::VALID, pOut };
 }
 
 OUString UnitsImpl::extractUnitStringFromFormat(const OUString& rFormatString) {
@@ -566,7 +566,7 @@ FormulaStatus UnitsImpl::verifyFormula(ScTokenArray* pArray, const ScAddress& rF
             case FormulaStatus::ERROR_INPUT_INCOMPATIBLE:
             case FormulaStatus::UNKNOWN:
                return aResult.status;
-            case FormulaStatus::VERIFIED:
+            case FormulaStatus::VALID:
                 assert(aResult.units); // ensure that we have the optional unit
                 assert(aResult.units->isValid());
                 aStack.push( { RAUSItemType::UNITS, aResult.units.get() } );
@@ -619,7 +619,7 @@ FormulaStatus UnitsImpl::verifyFormula(ScTokenArray* pArray, const ScAddress& rF
         }
     }
 
-    return FormulaStatus::VERIFIED;
+    return FormulaStatus::VALID;
 }
 
 bool IsDigit(sal_Unicode c) {
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 31b3870..a22aff0 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -471,7 +471,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
 #ifdef ENABLE_CALC_UNITVERIFICATION
             boost::shared_ptr< Units > pUnits = Units::GetUnits();
             FormulaStatus aStatus = pUnits->verifyFormula( pArr, aPos, pDoc );
-            if ( aStatus == FormulaStatus::VERIFIED || aStatus == FormulaStatus::UNKNOWN )
+            if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatus::UNKNOWN )
             {
                 SAL_INFO( "sc.units", "verification successful" );
 
commit f73da073101560f68260cc017c4c45512afeeb5b
Author: Andrzej Hunt <andrzej at ahunt.org>
Date:   Mon Jun 1 22:11:22 2015 +0100

    Kill unnecessary UnitsStatus
    
    Is redundant now that we've got the public FormulaStatus.
    FormulaStatus adds two new variants that we don't need internally
    however they are only relevant in one location hence it makes sense
    to share the enum.
    
    Change-Id: Idb08a41574e56a2f994c7e8bc816ffd370d86766

diff --git a/sc/source/core/units/unitsimpl.cxx b/sc/source/core/units/unitsimpl.cxx
index 84d5c0e..d160e17 100644
--- a/sc/source/core/units/unitsimpl.cxx
+++ b/sc/source/core/units/unitsimpl.cxx
@@ -96,7 +96,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
         nOpCode < SC_OPCODE_STOP_UN_OP) {
 
         if ((rStack.size() == 0) || (rStack.top().type != RAUSItemType::UNITS)) {
-            return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+            return { FormulaStatus::UNKNOWN, boost::none };
         }
 
         UtUnit pUnit = boost::get<UtUnit>(rStack.top().item);//rStack.top().item.get< UtUnit >();
@@ -105,7 +105,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
         switch (aOpCode) {
         case ocNot:
             if (!pUnit.isDimensionless()) {
-                return { UnitsStatus::UNITS_INVALID_INCOMPATIBLE, boost::none };
+                return { FormulaStatus::ERROR_INPUT_INCOMPATIBLE, boost::none };
             }
             // We just keep the same unit (in this case no unit) so can
             // fall through.
@@ -127,13 +127,13 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
         nOpCode < SC_OPCODE_STOP_BIN_OP) {
 
         if ((rStack.size() < 2) || (rStack.top().type != RAUSItemType::UNITS)) {
-            return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+            return { FormulaStatus::UNKNOWN, boost::none };
         }
         UtUnit pSecondUnit = boost::get<UtUnit>(rStack.top().item);
         rStack.pop();
 
         if (rStack.top().type != RAUSItemType::UNITS) {
-            return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+            return { FormulaStatus::UNKNOWN, boost::none };
         }
         UtUnit pFirstUnit = boost::get<UtUnit>(rStack.top().item);
         rStack.pop();
@@ -148,9 +148,9 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
                 pOut = pFirstUnit;
                 SAL_INFO("sc.units", "verified equality for unit " << pFirstUnit);
             } else if (pFirstUnit.areConvertibleTo(pSecondUnit)) {
-                return { UnitsStatus::UNITS_INVALID_SCALING, boost::none };
+                return { FormulaStatus::ERROR_INPUT_SCALING, boost::none };
             } else {
-                return { UnitsStatus::UNITS_INVALID_INCOMPATIBLE, boost::none };
+                return { FormulaStatus::ERROR_INPUT_INCOMPATIBLE, boost::none };
             }
 
             break;
@@ -174,7 +174,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
         // (In practice this would probably be nonsensical, but isn't a unit
         //  error per-se.)
         if (nParams == 0) {
-            return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+            return { FormulaStatus::UNKNOWN, boost::none };
         }
 
         // This is still quite an ugly solution, even better would maybe be to have
@@ -218,9 +218,9 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
 
                     if (aFirstUnit.get() != aCurrentUnit) {
                         if (aFirstUnit.get().areConvertibleTo(aCurrentUnit)) {
-                            return { UnitsStatus::UNITS_INVALID_SCALING, boost::none };
+                            return { FormulaStatus::ERROR_INPUT_SCALING, boost::none };
                         } else {
-                            return { UnitsStatus::UNITS_INVALID_INCOMPATIBLE, boost::none };
+                            return { FormulaStatus::ERROR_INPUT_INCOMPATIBLE, boost::none };
                         }
                     }
                 }
@@ -236,9 +236,9 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
 
                         if (aFirstUnit.get() != aCurrentUnit) {
                             if (aFirstUnit.get().areConvertibleTo(aCurrentUnit)) {
-                                return { UnitsStatus::UNITS_INVALID_SCALING, boost::none };
+                                return { FormulaStatus::ERROR_INPUT_SCALING, boost::none };
                             } else {
-                                return { UnitsStatus::UNITS_INVALID_INCOMPATIBLE, boost::none };
+                                return { FormulaStatus::ERROR_INPUT_INCOMPATIBLE, boost::none };
                             }
                         }
                     }
@@ -246,7 +246,7 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
 
             }
 
-            return { UnitsStatus::UNITS_VALID, aFirstUnit };
+            return { FormulaStatus::VERIFIED, aFirstUnit };
         }
         case ocProduct:
         {
@@ -269,16 +269,16 @@ UnitsResult UnitsImpl::getOutputUnitsForOpCode(stack< RAUSItem >& rStack, const
                 } while (aIt.next());
             }
 
-            return { UnitsStatus::UNITS_VALID, aUnit };
+            return { FormulaStatus::VERIFIED, aUnit };
         }
         default:
-            return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+            return { FormulaStatus::UNKNOWN, boost::none };
         }
     } else {
         SAL_INFO("sc.units", "unit verification not supported for opcode: " << nOpCode);
-        return { UnitsStatus::UNITS_UNKNOWN, boost::none };
+        return { FormulaStatus::UNKNOWN, boost::none };
     }
-    return { UnitsStatus::UNITS_VALID, pOut };
+    return { FormulaStatus::VERIFIED, pOut };
 }
 
 OUString UnitsImpl::extractUnitStringFromFormat(const OUString& rFormatString) {
@@ -562,18 +562,18 @@ FormulaStatus UnitsImpl::verifyFormula(ScTokenArray* pArray, const ScAddress& rF
             UnitsResult aResult = getOutputUnitsForOpCode(aStack, pToken, pDoc);
 
             switch (aResult.status) {
-            case UnitsStatus::UNITS_INVALID_SCALING:
-                return FormulaStatus::ERROR_INPUT_SCALING;
-            case UnitsStatus::UNITS_INVALID_INCOMPATIBLE:
-                return FormulaStatus::ERROR_INPUT_INCOMPATIBLE;
-            case UnitsStatus::UNITS_UNKNOWN:
-                // Unsupported hence we stop processing.
-                return FormulaStatus::UNKNOWN;
-            case UnitsStatus::UNITS_VALID:
+            case FormulaStatus::ERROR_INPUT_SCALING:
+            case FormulaStatus::ERROR_INPUT_INCOMPATIBLE:
+            case FormulaStatus::UNKNOWN:
+               return aResult.status;
+            case FormulaStatus::VERIFIED:
                 assert(aResult.units); // ensure that we have the optional unit
                 assert(aResult.units->isValid());
                 aStack.push( { RAUSItemType::UNITS, aResult.units.get() } );
                 break;
+            case FormulaStatus::ERROR_OUTPUT_SCALING:
+            case FormulaStatus::ERROR_OUTPUT_INCOMPATIBLE:
+                assert(false);
             }
 
             break;
diff --git a/sc/source/core/units/unitsimpl.hxx b/sc/source/core/units/unitsimpl.hxx
index b0fb137..934bb26 100644
--- a/sc/source/core/units/unitsimpl.hxx
+++ b/sc/source/core/units/unitsimpl.hxx
@@ -42,20 +42,13 @@ namespace test {
     class UnitsTest;
 }
 
-enum class UnitsStatus {
-    UNITS_VALID,
-    UNITS_UNKNOWN,
-    UNITS_INVALID_SCALING,
-    UNITS_INVALID_INCOMPATIBLE
-};
-
 /**
  * The result for a given units operation.
  * If UNITS_VALID then the resulting unit is also included,
  * otherwise units is empty.
  */
 struct UnitsResult {
-    UnitsStatus status;
+    FormulaStatus status;
     boost::optional<UtUnit> units;
 };
 


More information about the Libreoffice-commits mailing list