[Libreoffice-commits] .: 3 commits - sc/qa sc/source unotools/inc unotools/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Thu Sep 8 20:01:53 PDT 2011


 sc/qa/unit/data/contentCSV/logicalFunctions.csv |    6 +
 sc/qa/unit/data/ods/functions.ods               |binary
 sc/qa/unit/filters-test.cxx                     |  132 ++++++++++++++++++++----
 sc/qa/unit/helper/csv_handler.hxx               |   97 +++++++++++++++++
 sc/source/ui/docshell/externalrefmgr.cxx        |    6 -
 unotools/inc/unotools/localfilehelper.hxx       |    1 
 unotools/source/ucbhelper/localfilehelper.cxx   |    8 +
 7 files changed, 228 insertions(+), 22 deletions(-)

New commits:
commit 148aeaaa9167921a419940dbb5acc872d4675560
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Sep 9 04:54:23 2011 +0200

    add logical function unit test
    
    it is now possible to add csv files to create easy filter test

diff --git a/sc/qa/unit/data/contentCSV/logicalFunctions.csv b/sc/qa/unit/data/contentCSV/logicalFunctions.csv
new file mode 100644
index 0000000..2223baf
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/logicalFunctions.csv
@@ -0,0 +1,6 @@
+FALSE, FALSE, FALSE, TRUE, FALSE
+FALSE
+TRUE, FALSE
+TRUE, FALSE
+FALSE, TRUE, TRUE, TRUE, TRUE
+TRUE
diff --git a/sc/qa/unit/data/ods/functions.ods b/sc/qa/unit/data/ods/functions.ods
new file mode 100644
index 0000000..374ca15
Binary files /dev/null and b/sc/qa/unit/data/ods/functions.ods differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index b25da72..170713f 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -59,6 +59,12 @@
 #include "document.hxx"
 #include "postit.hxx"
 
+#include "helper/csv_handler.hxx"
+#include "orcus/csv_parser.hpp"
+#include <fstream>
+#include <string>
+#include <sstream>
+
 const int indeterminate = 2;
 
 #define ODS_FORMAT_TYPE 50331943
@@ -73,6 +79,43 @@ struct {
     { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }
 };
 
+namespace {
+
+    void loadFile(const rtl::OUString& aFileName, std::string& aContent)
+    {
+        rtl::OString aOFileName = rtl::OUStringToOString(aFileName, RTL_TEXTENCODING_UTF8);
+        std::ifstream aFile(aOFileName.getStr());
+
+        CPPUNIT_ASSERT_MESSAGE("could not open csv file", aFile);
+        std::ostringstream aOStream;
+        aOStream << aFile.rdbuf();
+        aFile.close();
+        aContent = aOStream.str();
+    }
+
+    void testFile(rtl::OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
+    {
+        csv_handler aHandler(pDoc, nTab);
+        orcus::csv_parser_config aConfig;
+        aConfig.delimiters.push_back(',');
+        aConfig.delimiters.push_back(';');
+        aConfig.text_qualifier = '"';
+        std::string aContent;
+        loadFile(aFileName, aContent);
+        orcus::csv_parser<csv_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
+        try
+        {
+            parser.parse();
+        }
+        catch (const orcus::csv_parse_error& e)
+        {
+            std::cout << "reading csv content file failed" << e.what() << std::endl;
+            CPPUNIT_ASSERT_MESSAGE("csv parser error", false);
+        }
+    }
+
+}
+
 
 using namespace ::com::sun::star;
 
@@ -90,6 +133,9 @@ public:
     void recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData, int nExpected);
     ScDocShellRef load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData, const rtl::OUString& rTypeName, sal_uLong nFormatType = 0);
 
+    void createFilePath(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
+    void createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rFilePath);
+
     /**
      * Ensure CVEs remain unbroken
      */
@@ -100,11 +146,13 @@ public:
     void testRangeNameImpl(ScDocument* pDoc);
     void testContent();
     void testContentImpl(ScDocument* pDoc); //same code for ods, xls, xlsx
+    void testFunctions();
 
     CPPUNIT_TEST_SUITE(FiltersTest);
     CPPUNIT_TEST(testCVEs);
     CPPUNIT_TEST(testRangeName);
     CPPUNIT_TEST(testContent);
+    CPPUNIT_TEST(testFunctions);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -112,6 +160,7 @@ private:
     uno::Reference<lang::XMultiComponentFactory> m_xFactory;
     uno::Reference<uno::XInterface> m_xCalcComponent;
     ::rtl::OUString m_aSrcRoot;
+    ::rtl::OUString m_aFileRoot; //m_aSrcRoot without "file://" prefix
     ::rtl::OUString m_aBaseString;
 };
 
@@ -184,6 +233,23 @@ void FiltersTest::recursiveScan(const rtl::OUString &rFilter, const rtl::OUStrin
     CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.close());
 }
 
+void FiltersTest::createFilePath(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
+{
+    rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
+    rtl::OUStringBuffer aBuffer(m_aSrcRoot);
+    aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
+    aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
+    rFilePath = aBuffer.makeStringAndClear();
+}
+
+void FiltersTest::createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rCSVPath)
+{
+    rtl::OUStringBuffer aBuffer(m_aFileRoot);
+    aBuffer.append(m_aBaseString).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/contentCSV/")));
+    aBuffer.append(aFileBase).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("csv")));
+    rCSVPath = aBuffer.makeStringAndClear();
+}
+
 void FiltersTest::testCVEs()
 {
     recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")),
@@ -310,6 +376,24 @@ void FiltersTest::testContent()
     }
 }
 
+void FiltersTest::testFunctions()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("functions."));
+    rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
+    rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ;
+    rtl::OUString aFileName;
+    createFilePath(aFileNameBase, aFileExtension, aFileName);
+    rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
+    std::cout << aFileFormats[0].pName << " Test" << std::endl;
+    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[0].nFormatType);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
+    ScDocument* pDoc = xDocSh->GetDocument();
+    rtl::OUString aCSVFileName;
+    createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("logicalFunctions.")), aCSVFileName);
+    testFile(aCSVFileName, pDoc, 0);
+}
+
 FiltersTest::FiltersTest()
     : m_aSrcRoot(RTL_CONSTASCII_USTRINGPARAM("file://")),
       m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
@@ -366,6 +450,7 @@ FiltersTest::FiltersTest()
         m_aSrcRoot += rtl::OUString::createFromAscii( "/" );
 #endif
     m_aSrcRoot += rtl::OUString::createFromAscii( pSrcRoot );
+    m_aFileRoot += rtl::OUString::createFromAscii( pSrcRoot );
 }
 
 void FiltersTest::setUp()
diff --git a/sc/qa/unit/helper/csv_handler.hxx b/sc/qa/unit/helper/csv_handler.hxx
new file mode 100644
index 0000000..5626984
--- /dev/null
+++ b/sc/qa/unit/helper/csv_handler.hxx
@@ -0,0 +1,97 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ *  Copyright (C) 2011 Markus Mohrhard <markus.mohrhard at googlemail.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <iostream>
+
+#define DEBUG_CSV_HANDLER 0
+
+class csv_handler
+{
+public:
+    csv_handler(ScDocument* pDoc, SCTAB nTab):
+            mpDoc(pDoc),
+            mnCol(0),
+            mnRow(0),
+            mnTab(nTab)     {}
+
+    void begin_parse()
+    {
+
+    }
+
+    void end_parse()
+    {
+
+    }
+
+    void begin_row()
+    {
+
+    }
+
+    void end_row()
+    {
+        ++mnRow;
+        mnCol = 0;
+    }
+
+    void cell(const char* p, size_t n)
+    {
+#if DEBUG_CSV_HANDLER
+        std::cout << "Col: " << mnCol << " Row: " << mnRow << std::endl;
+#endif //DEBUG_CSV_HANDLER
+        char* pRemainingChars = NULL;
+        std::string aStr(p, n);
+        double nValue = strtod(&aStr[0], &pRemainingChars);
+        if (*pRemainingChars)
+        {
+            rtl::OUString aString;
+            mpDoc->GetString(mnCol, mnRow, mnTab, aString);
+            rtl::OUString aCSVString(p, n, RTL_TEXTENCODING_UTF8);
+#if DEBUG_CSV_HANDLER
+            std::cout << "String: " << rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+            std::cout << "CSVString: " << rtl::OUStringToOString(aCSVString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+            std::cout << "result: " << (int)(aCSVString == aString) << std::endl;
+#endif //DEBUG_CSV_HANDLER
+
+            CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aString == aCSVString);
+        }
+        else
+        {
+            double aValue;
+            mpDoc->GetValue(mnCol, mnRow, mnTab, aValue);
+            CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aValue == nValue);
+        }
+        ++mnCol;
+    }
+
+private:
+    ScDocument* mpDoc;
+    SCCOL mnCol;
+    SCROW mnRow;
+    SCTAB mnTab;
+};
commit 8445ce0e6185b575f1f4bf6bbc41d9eda2a5391b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Sep 8 15:26:28 2011 +0200

    externalrefmgr.cxx is String free
    
    String->rtl::OUString and solve problem with old patch

diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index a66dd35..62fe0dd 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2272,12 +2272,11 @@ bool ScExternalRefManager::isFileLoadable(const OUString& rFile) const
 
     if (isOwnDocument(rFile))
         return false;
-    String aPhysical;
-    if (utl::LocalFileHelper::ConvertURLToPhysicalName(rFile, aPhysical) && aPhysical.Len())
+    rtl::OUString aPhysical;
+    if (utl::LocalFileHelper::ConvertURLToPhysicalName(rFile, aPhysical) && aPhysical.getLength())
     {
         // #i114504# try IsFolder/Exists only for file URLs
 
-    return utl::UCBContentHelper::Exists(rFile);
         if (utl::UCBContentHelper::IsFolder(rFile))
             return false;
 
@@ -2285,7 +2284,6 @@ bool ScExternalRefManager::isFileLoadable(const OUString& rFile) const
     }
     else
         return true;    // for http and others, Exists doesn't work, but the URL can still be opened
-    return utl::UCBContentHelper::Exists(rFile);
 }
 
 void ScExternalRefManager::maybeLinkExternalFile(sal_uInt16 nFileId)
diff --git a/unotools/inc/unotools/localfilehelper.hxx b/unotools/inc/unotools/localfilehelper.hxx
index 08be260..634c7de 100644
--- a/unotools/inc/unotools/localfilehelper.hxx
+++ b/unotools/inc/unotools/localfilehelper.hxx
@@ -55,6 +55,7 @@ public:
                     file system is present ( watch: this doesn't mean that this file really exists! )
                     */
     static sal_Bool ConvertURLToPhysicalName( const String& rName, String& rReturn );
+    static bool     ConvertURLToPhysicalName( const rtl::OUString& rName, rtl::OUString& rReturn );
     static sal_Bool ConvertURLToSystemPath( const String& rName, String& rReturn );
 
     static sal_Bool IsLocalFile( const String& rName );
diff --git a/unotools/source/ucbhelper/localfilehelper.cxx b/unotools/source/ucbhelper/localfilehelper.cxx
index f1026f7..26b90a7 100644
--- a/unotools/source/ucbhelper/localfilehelper.cxx
+++ b/unotools/source/ucbhelper/localfilehelper.cxx
@@ -131,6 +131,14 @@ sal_Bool LocalFileHelper::ConvertPhysicalNameToURL( const String& rName, String&
     return ( rReturn.Len() != 0 );
 }
 
+bool LocalFileHelper::ConvertURLToPhysicalName( const rtl::OUString& rName, rtl::OUString& rReturn )
+{
+    String aReturn;
+    bool bReturn = ConvertURLToPhysicalName( rName, aReturn );
+    rReturn = rtl::OUString( aReturn );
+    return bReturn;
+}
+
 sal_Bool LocalFileHelper::ConvertURLToPhysicalName( const String& rName, String& rReturn )
 {
     rReturn = ::rtl::OUString();
commit 9a6c3bb6a4b00ec958091e29f96397854a7a0e5b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Sep 8 03:35:34 2011 +0200

    add range name xls test
    
    xlsx does not work yet because local range name export is not
    implemented

diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index ec37714..b25da72 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -65,6 +65,14 @@ const int indeterminate = 2;
 #define XLS_FORMAT_TYPE 318767171
 #define XLSX_FORMAT_TYPE 268959811
 
+struct {
+    const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
+} aFileFormats[] = {
+    { "ods" , "calc8", "", ODS_FORMAT_TYPE },
+    { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
+    { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }
+};
+
 
 using namespace ::com::sun::star;
 
@@ -89,6 +97,7 @@ public:
 
     //ods filter tests
     void testRangeName();
+    void testRangeNameImpl(ScDocument* pDoc);
     void testContent();
     void testContentImpl(ScDocument* pDoc); //same code for ods, xls, xlsx
 
@@ -200,17 +209,8 @@ void FiltersTest::testCVEs()
 
 }
 
-void FiltersTest::testRangeName()
+void FiltersTest::testRangeNameImpl(ScDocument* pDoc)
 {
-    rtl::OUString aFilter(RTL_CONSTASCII_USTRINGPARAM("calc8"));
-    rtl::OUString aFileName = m_aSrcRoot + m_aBaseString + rtl::OUString(
-        RTL_CONSTASCII_USTRINGPARAM("/ods/named-ranges-global.ods"));
-
-    ScDocShellRef xDocSh = load( aFilter, aFileName , rtl::OUString(), rtl::OUString(), ODS_FORMAT_TYPE);
-
-    CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-global.ods.", xDocSh.Is());
-
-    ScDocument* pDoc = xDocSh->GetDocument();
     //check one range data per sheet and one global more detailed
     //add some more checks here
     ScRangeData* pRangeData = pDoc->GetRangeName()->findByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Global1")));
@@ -237,6 +237,25 @@ void FiltersTest::testRangeName()
     CPPUNIT_ASSERT_MESSAGE("range name Sheet2.local1 should reference Sheet1.A5", aValue == 5);
 }
 
+void FiltersTest::testRangeName()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
+    //XLSX does not work yet
+    for (sal_uInt32 i = 0; i < 2; ++i)
+    {
+        rtl::OUString aFileExtension(aFileFormats[i].pName, strlen(aFileFormats[i].pName), RTL_TEXTENCODING_UTF8 );
+        rtl::OUString aFilterName(aFileFormats[i].pFilterName, strlen(aFileFormats[i].pFilterName), RTL_TEXTENCODING_UTF8) ;
+        rtl::OUString aFileName = m_aSrcRoot + m_aBaseString + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + aFileExtension + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + aFileNameBase + aFileExtension;
+        rtl::OUString aFilterType(aFileFormats[i].pTypeName, strlen(aFileFormats[i].pTypeName), RTL_TEXTENCODING_UTF8);
+        std::cout << aFileFormats[i].pName << " Test" << std::endl;
+        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[i].nFormatType);
+
+        CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
+        ScDocument* pDoc = xDocSh->GetDocument();
+        testRangeNameImpl(pDoc);
+    }
+}
+
 void FiltersTest::testContentImpl(ScDocument* pDoc)
 {
     double aValue;
@@ -275,14 +294,6 @@ void FiltersTest::testContentImpl(ScDocument* pDoc)
 
 void FiltersTest::testContent()
 {
-    struct {
-        const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
-    } aFileFormats[] = {
-        { "ods" , "calc8", "", ODS_FORMAT_TYPE },
-        { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
-        { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }
-    };
-
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
     for (sal_uInt32 i = 0; i < 3; ++i)
     {


More information about the Libreoffice-commits mailing list