[Libreoffice-commits] core.git: 2 commits - sc/CppunitTest_sc_subsequent_filters_test.mk sc/inc sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Jun 25 13:40:42 PDT 2014


 sc/CppunitTest_sc_subsequent_filters_test.mk |    3 ++
 sc/inc/tokenstringcontext.hxx                |    2 -
 sc/qa/unit/data/xlsm/vba-user-function.xlsm  |binary
 sc/qa/unit/helper/qahelper.cxx               |    1 
 sc/qa/unit/helper/qahelper.hxx               |   11 +++++-----
 sc/qa/unit/subsequent_filters-test.cxx       |   28 +++++++++++++++++++++++++++
 sc/source/filter/oox/workbookhelper.cxx      |   13 ++++++------
 7 files changed, 46 insertions(+), 12 deletions(-)

New commits:
commit 5e83804da815a982aed567a8cae4cc078491dcbd
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Jun 25 16:38:52 2014 -0400

    bnc#882595: Process VBA blobs before formula cells.
    
    So that formula cells with user-defined functions will be interpreted
    correctly.
    
    Change-Id: I49c10109575f9f82d7f85dea63590bf02b70e041

diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index d7c6443..3ebf702 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -747,6 +747,13 @@ void WorkbookHelper::finalizeWorkbookImport()
     mrBookGlob.getWorkbookSettings().finalizeImport();
     mrBookGlob.getViewSettings().finalizeImport();
 
+    // Import the VBA project (after finalizing workbook settings which
+    // contains the workbook code name).  Do it before processing formulas in
+    // order to correctly resolve VBA custom function names.
+    StorageRef xVbaPrjStrg = mrBookGlob.getVbaProjectStorage();
+    if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() )
+        getBaseFilter().getVbaProject().importModulesAndForms( *xVbaPrjStrg, getBaseFilter().getGraphicHelper() );
+
     // need to import formulas before scenarios
     mrBookGlob.getFormulaBuffer().finalizeImport();
 
@@ -766,12 +773,6 @@ void WorkbookHelper::finalizeWorkbookImport()
         sheets. Automatic numbering is set by passing the value 0. */
     PropertySet aDefPageStyle( getStyleObject( "Default", true ) );
     aDefPageStyle.setProperty< sal_Int16 >( PROP_FirstPageNumber, 0 );
-
-    /*  Import the VBA project (after finalizing workbook settings which
-        contains the workbook code name). */
-    StorageRef xVbaPrjStrg = mrBookGlob.getVbaProjectStorage();
-    if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() )
-        getBaseFilter().getVbaProject().importModulesAndForms( *xVbaPrjStrg, getBaseFilter().getGraphicHelper() );
 }
 
 // document model -------------------------------------------------------------
commit 671566d0612a26c844501f0cf042138b5fe5c040
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Jun 25 16:36:53 2014 -0400

    bnc#882595: Write test for this.  Disabled due to VBA not working in cppunit.
    
    Change-Id: Ie70232e56235fcf5a313aadffa269ef843bdee18

diff --git a/sc/CppunitTest_sc_subsequent_filters_test.mk b/sc/CppunitTest_sc_subsequent_filters_test.mk
index b53bb24..a272047 100644
--- a/sc/CppunitTest_sc_subsequent_filters_test.mk
+++ b/sc/CppunitTest_sc_subsequent_filters_test.mk
@@ -35,6 +35,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_filters_test, \
     sal \
     salhelper \
     sax \
+    sb \
     sc \
     scqahelper \
     sfx \
@@ -43,12 +44,14 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_filters_test, \
     svt \
     svx \
     svxcore \
+    subsequenttest \
 	test \
     tl \
     tk \
     ucbhelper \
 	unotest \
     utl \
+    vbahelper \
     vcl \
     xo \
 	$(gb_UWINAPI) \
diff --git a/sc/inc/tokenstringcontext.hxx b/sc/inc/tokenstringcontext.hxx
index a94844d..4ccc40b 100644
--- a/sc/inc/tokenstringcontext.hxx
+++ b/sc/inc/tokenstringcontext.hxx
@@ -46,7 +46,7 @@ struct SC_DLLPUBLIC TokenStringContext
     TokenStringContext( const ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram );
 };
 
-class CompileFormulaContext
+class SC_DLLPUBLIC CompileFormulaContext
 {
     ScDocument* mpDoc;
     formula::FormulaGrammar::Grammar meGram;
diff --git a/sc/qa/unit/data/xlsm/vba-user-function.xlsm b/sc/qa/unit/data/xlsm/vba-user-function.xlsm
new file mode 100644
index 0000000..a43a8eb
Binary files /dev/null and b/sc/qa/unit/data/xlsm/vba-user-function.xlsm differ
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 79d5716..0b19843 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -69,6 +69,7 @@ FileFormat aFileFormats[] = {
     { "ods" , "calc8", "", ODS_FORMAT_TYPE },
     { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
     { "xlsx", "Calc Office Open XML" , "Office Open XML Spreadsheet", XLSX_FORMAT_TYPE },
+    { "xlsm", "Calc Office Open XML" , "Office Open XML Spreadsheet", XLSX_FORMAT_TYPE },
     { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE },
     { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE },
     { "123" , "Lotus", "calc_Lotus", LOTUS123_FORMAT_TYPE },
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index 193fc48..a4273bc 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -50,11 +50,12 @@
 #define ODS      0
 #define XLS      1
 #define XLSX     2
-#define CSV      3
-#define HTML     4
-#define LOTUS123 5
-#define DIF      6
-#define XLS_XML  7
+#define XLSM     3
+#define CSV      4
+#define HTML     5
+#define LOTUS123 6
+#define DIF      7
+#define XLS_XML  8
 
 enum StringType { PureString, FormulaValue, StringValue };
 
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index d84b895..cd32967 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -49,6 +49,7 @@
 #include "dpshttab.hxx"
 #include <scopetools.hxx>
 #include <columnspanset.hxx>
+#include <tokenstringcontext.hxx>
 
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/XControlShape.hpp>
@@ -175,6 +176,7 @@ public:
     void testExternalRefCacheODS();
     void testHybridSharedStringODS();
     void testCopyMergedNumberFormats();
+    void testVBAUserFunctionXLSM();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testBasicCellContentODS);
@@ -254,6 +256,7 @@ public:
     CPPUNIT_TEST(testExternalRefCacheODS);
     CPPUNIT_TEST(testHybridSharedStringODS);
     CPPUNIT_TEST(testCopyMergedNumberFormats);
+//  CPPUNIT_TEST(testVBAUserFunctionXLSM); // TODO : Macro not working in unit test. Get this to work.
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2596,6 +2599,31 @@ void ScFiltersTest::testCopyMergedNumberFormats()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testVBAUserFunctionXLSM()
+{
+    ScDocShellRef xDocSh = loadDoc("vba-user-function.", XLSM);
+    CPPUNIT_ASSERT(xDocSh.Is());
+    ScDocument& rDoc = xDocSh->GetDocument();
+
+    // A1 contains formula with user-defined function, and the function is defined in VBA.
+    ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0));
+    CPPUNIT_ASSERT(pFC);
+
+    sc::CompileFormulaContext aCxt(&rDoc);
+    OUString aFormula = pFC->GetFormula(aCxt);
+
+    CPPUNIT_ASSERT_EQUAL(OUString("=MYFUNC()"), aFormula);
+
+    // Check the formula state after the load.
+    sal_uInt16 nErrCode = pFC->GetErrCode();
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), nErrCode);
+
+    // Check the result.
+    CPPUNIT_ASSERT_EQUAL(42.0, rDoc.GetValue(ScAddress(0,0,0)));
+
+    xDocSh->DoClose();
+}
+
 ScFiltersTest::ScFiltersTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {


More information about the Libreoffice-commits mailing list