[Libreoffice-commits] core.git: 3 commits - comphelper/source sc/CppunitTest_sc_dataprovider.mk sc/CppunitTest_sc_dataproviders_test.mk sc/inc sc/Module_sc.mk sc/qa

Markus Mohrhard markus.mohrhard at googlemail.com
Sun Aug 13 14:50:24 UTC 2017


 comphelper/source/windows/windows_process.cxx |   12 +--
 sc/CppunitTest_sc_dataprovider.mk             |   24 +++---
 sc/Module_sc.mk                               |    1 
 sc/inc/document.hxx                           |    2 
 sc/qa/unit/data/dataprovider/csv/test1.csv    |    4 +
 sc/qa/unit/dataproviders_test.cxx             |  103 +++++++++++++++-----------
 6 files changed, 88 insertions(+), 58 deletions(-)

New commits:
commit 07a9c704fc6b0022a06597c514019e12466711c4
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 13 16:47:15 2017 +0200

    Revert "cppcheck: variableScope"
    
    This reverts the updater related code changes. I still might need to
    merge Mozilla changes into the code once more which becomes much more difficult
    with unrelated changes.
    
    Only helpful fixes for now please.
    
    Change-Id: I67b386d12d03250323cce21f4f65b262ce4abcf9

diff --git a/comphelper/source/windows/windows_process.cxx b/comphelper/source/windows/windows_process.cxx
index ccebbd712bf0..1c782d7a289f 100644
--- a/comphelper/source/windows/windows_process.cxx
+++ b/comphelper/source/windows/windows_process.cxx
@@ -19,6 +19,7 @@
  */
 static int ArgStrLen(const wchar_t *s)
 {
+    int backslashes = 0;
     int i = wcslen(s);
     BOOL hasDoubleQuote = wcschr(s, L'"') != nullptr;
     // Only add doublequotes if the string contains a space or a tab
@@ -31,7 +32,6 @@ static int ArgStrLen(const wchar_t *s)
 
     if (hasDoubleQuote)
     {
-        int backslashes = 0;
         while (*s)
         {
             if (*s == '\\')
@@ -67,6 +67,7 @@ static int ArgStrLen(const wchar_t *s)
  */
 static wchar_t* ArgToString(wchar_t *d, const wchar_t *s)
 {
+    int backslashes = 0;
     BOOL hasDoubleQuote = wcschr(s, L'"') != nullptr;
     // Only add doublequotes if the string contains a space or a tab
     BOOL addDoubleQuotes = wcspbrk(s, L" \t") != nullptr;
@@ -79,7 +80,7 @@ static wchar_t* ArgToString(wchar_t *d, const wchar_t *s)
 
     if (hasDoubleQuote)
     {
-        int backslashes = 0;
+        int i;
         while (*s)
         {
             if (*s == '\\')
@@ -91,7 +92,7 @@ static wchar_t* ArgToString(wchar_t *d, const wchar_t *s)
                 if (*s == '"')
                 {
                     // Escape the doublequote and all backslashes preceding the doublequote
-                    for (int i = 0; i <= backslashes; ++i)
+                    for (i = 0; i <= backslashes; ++i)
                     {
                         *d = '\\';
                         ++d;
@@ -130,10 +131,11 @@ static wchar_t* ArgToString(wchar_t *d, const wchar_t *s)
 wchar_t*
 MakeCommandLine(int argc, wchar_t **argv)
 {
+    int i;
     int len = 0;
 
     // The + 1 of the last argument handles the allocation for null termination
-    for (int i = 0; i < argc; ++i)
+    for (i = 0; i < argc; ++i)
         len += ArgStrLen(argv[i]) + 1;
 
     // Protect against callers that pass 0 arguments
@@ -145,7 +147,7 @@ MakeCommandLine(int argc, wchar_t **argv)
         return nullptr;
 
     wchar_t *c = s;
-    for (int i = 0; i < argc; ++i)
+    for (i = 0; i < argc; ++i)
     {
         c = ArgToString(c, argv[i]);
         if (i + 1 != argc)
commit 8c72ab48bf150da05435d93991e1e9c9f47ce4fd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 12 20:09:18 2017 +0200

    external data: add a test that shows that cropping to DB area works
    
    Change-Id: Ic883a5f625d54bf8cc95785a9ab1a83f0c8aa2ec

diff --git a/sc/qa/unit/dataproviders_test.cxx b/sc/qa/unit/dataproviders_test.cxx
index 737362618845..11dd5f97c49e 100644
--- a/sc/qa/unit/dataproviders_test.cxx
+++ b/sc/qa/unit/dataproviders_test.cxx
@@ -29,9 +29,11 @@ public:
     virtual void tearDown() override;
 
     void testCSVImport();
+    void testDataLargerThanDB();
 
     CPPUNIT_TEST_SUITE(ScDataProvidersTest);
     CPPUNIT_TEST(testCSVImport);
+    CPPUNIT_TEST(testDataLargerThanDB);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -67,6 +69,34 @@ void ScDataProvidersTest::testCSVImport()
     CPPUNIT_ASSERT_EQUAL(OUString("test3"), m_pDoc->GetString(2, 1, 0));
 }
 
+void ScDataProvidersTest::testDataLargerThanDB()
+{
+    ScDBData* pDBData = new ScDBData("testDB", 0, 0, 0, 1, 1);
+    bool bInserted = m_pDoc->GetDBCollection()->getNamedDBs().insert(pDBData);
+    CPPUNIT_ASSERT(bInserted);
+
+    OUString aFileURL;
+    createFileURL("test1.", "csv", aFileURL);
+    sc::ExternalDataSource aDataSource(aFileURL, "org.libreoffice.calc.csv", m_pDoc);
+    aDataSource.setDBData(pDBData);
+
+
+    m_pDoc->GetExternalDataMapper().insertDataSource(aDataSource);
+    auto& rDataSources = m_pDoc->GetExternalDataMapper().getDataSources();
+    CPPUNIT_ASSERT(!rDataSources.empty());
+
+    rDataSources[0].refresh(m_pDoc, true);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(0, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(1, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(3, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("test1"), m_pDoc->GetString(0, 1, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("test2"), m_pDoc->GetString(1, 1, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString(), m_pDoc->GetString(2, 1, 0));
+}
+
 ScDataProvidersTest::ScDataProvidersTest() :
     ScBootstrapFixture( "/sc/qa/unit/data/dataprovider" ),
     m_pDoc(nullptr)
commit 2a9814090c260a2e3154bff36792fcd7d86cf60c
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 12 19:13:10 2017 +0200

    external data: reenable the test and adapt to new interfaces
    
    Change-Id: I2d82b560e0bd499eb85c6ce22f5969f82dfe8937

diff --git a/sc/CppunitTest_sc_dataproviders_test.mk b/sc/CppunitTest_sc_dataprovider.mk
similarity index 75%
rename from sc/CppunitTest_sc_dataproviders_test.mk
rename to sc/CppunitTest_sc_dataprovider.mk
index 58222408b623..fe389fdb3ee5 100644
--- a/sc/CppunitTest_sc_dataproviders_test.mk
+++ b/sc/CppunitTest_sc_dataprovider.mk
@@ -7,19 +7,19 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 
-$(eval $(call gb_CppunitTest_CppunitTest,sc_dataproviders_test))
+$(eval $(call gb_CppunitTest_CppunitTest,sc_dataprovider))
 
-$(eval $(call gb_CppunitTest_add_exception_objects,sc_dataproviders_test, \
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_dataprovider, \
     sc/qa/unit/dataproviders_test \
 ))
 
-$(eval $(call gb_CppunitTest_use_externals,sc_dataproviders_test, \
+$(eval $(call gb_CppunitTest_use_externals,sc_dataprovider, \
 	boost_headers \
 	mdds_headers \
 	libxml2 \
 ))
 
-$(eval $(call gb_CppunitTest_use_libraries,sc_dataproviders_test, \
+$(eval $(call gb_CppunitTest_use_libraries,sc_dataprovider, \
     basegfx \
     comphelper \
     cppu \
@@ -56,23 +56,23 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_dataproviders_test, \
 	$(gb_UWINAPI) \
 ))
 
-$(eval $(call gb_CppunitTest_set_include,sc_dataproviders_test,\
+$(eval $(call gb_CppunitTest_set_include,sc_dataprovider,\
     -I$(SRCDIR)/sc/source/ui/inc \
     -I$(SRCDIR)/sc/inc \
 	-I$(SRCDIR)/sc/source/filter/inc \
     $$(INCLUDE) \
 ))
 
-$(eval $(call gb_CppunitTest_use_custom_headers,sc_dataproviders_test,\
+$(eval $(call gb_CppunitTest_use_custom_headers,sc_dataprovider,\
 	officecfg/registry \
 ))
 
-$(eval $(call gb_CppunitTest_use_sdk_api,sc_dataproviders_test))
+$(eval $(call gb_CppunitTest_use_sdk_api,sc_dataprovider))
 
-$(eval $(call gb_CppunitTest_use_ure,sc_dataproviders_test))
-$(eval $(call gb_CppunitTest_use_vcl,sc_dataproviders_test))
+$(eval $(call gb_CppunitTest_use_ure,sc_dataprovider))
+$(eval $(call gb_CppunitTest_use_vcl,sc_dataprovider))
 
-$(eval $(call gb_CppunitTest_use_components,sc_dataproviders_test,\
+$(eval $(call gb_CppunitTest_use_components,sc_dataprovider,\
 	basic/util/sb \
     chart2/source/chartcore \
     chart2/source/controller/chartcontroller \
@@ -112,7 +112,7 @@ $(eval $(call gb_CppunitTest_use_components,sc_dataproviders_test,\
     xmlsecurity/util/xmlsecurity \
 ))
 
-$(eval $(call gb_CppunitTest_use_externals,sc_dataproviders_test,\
+$(eval $(call gb_CppunitTest_use_externals,sc_dataprovider,\
 	orcus \
 	orcus-parser \
 	boost_filesystem \
@@ -121,6 +121,6 @@ $(eval $(call gb_CppunitTest_use_externals,sc_dataproviders_test,\
 	zlib \
 ))
 
-$(eval $(call gb_CppunitTest_use_configuration,sc_dataproviders_test))
+$(eval $(call gb_CppunitTest_use_configuration,sc_dataprovider))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 6a6a538d189c..0526764df2c5 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Module_add_check_targets,sc,\
 	CppunitTest_sc_range_test \
 	CppunitTest_sc_mark_test \
 	CppunitTest_sc_core \
+	CppunitTest_sc_dataprovider \
 ))
 
 ifneq ($(ENABLE_HEADLESS),TRUE)
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 6071fe642c45..0e6cf79b1b6a 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -710,7 +710,7 @@ public:
     const ScDBData*              GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
     ScDBData*                    GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
     void                         RefreshDirtyTableColumnNames();
-    sc::ExternalDataMapper&      GetExternalDataMapper();
+    SC_DLLPUBLIC sc::ExternalDataMapper& GetExternalDataMapper();
 
     SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, OUString* pName ) const;
 
diff --git a/sc/qa/unit/data/dataprovider/csv/test1.csv b/sc/qa/unit/data/dataprovider/csv/test1.csv
new file mode 100644
index 000000000000..a9242346603f
--- /dev/null
+++ b/sc/qa/unit/data/dataprovider/csv/test1.csv
@@ -0,0 +1,4 @@
+1,2,3,4
+test1,test2,test3
+"some longer text
+"
diff --git a/sc/qa/unit/dataproviders_test.cxx b/sc/qa/unit/dataproviders_test.cxx
index df5b248d4021..737362618845 100644
--- a/sc/qa/unit/dataproviders_test.cxx
+++ b/sc/qa/unit/dataproviders_test.cxx
@@ -17,11 +17,6 @@
 
 #include <memory>
 
-struct TestImpl
-{
-    ScDocShellRef m_xDocShell;
-};
-
 class ScDataProvidersTest : public ScBootstrapFixture
 {
 public:
@@ -40,45 +35,42 @@ public:
     CPPUNIT_TEST_SUITE_END();
 
 private:
-    std::unique_ptr<TestImpl> m_pImpl;
+    ScDocShellRef m_xDocShell;
     ScDocument *m_pDoc;
 };
 
-ScDataProvidersTest::ScDataProvidersTest() :
-    ScBootstrapFixture( "/sc/qa/unit/data" ),
-    m_pImpl(new TestImpl),
-    m_pDoc(nullptr)
+void ScDataProvidersTest::testCSVImport()
 {
-}
+    ScDBData* pDBData = new ScDBData("testDB", 0, 0, 0, 10, 10);
+    bool bInserted = m_pDoc->GetDBCollection()->getNamedDBs().insert(pDBData);
+    CPPUNIT_ASSERT(bInserted);
 
-ScDocShell& ScDataProvidersTest::getDocShell()
-{
-    return *m_pImpl->m_xDocShell;
+    OUString aFileURL;
+    createFileURL("test1.", "csv", aFileURL);
+    sc::ExternalDataSource aDataSource(aFileURL, "org.libreoffice.calc.csv", m_pDoc);
+    aDataSource.setDBData(pDBData);
+
+
+    m_pDoc->GetExternalDataMapper().insertDataSource(aDataSource);
+    auto& rDataSources = m_pDoc->GetExternalDataMapper().getDataSources();
+    CPPUNIT_ASSERT(!rDataSources.empty());
+
+    rDataSources[0].refresh(m_pDoc, true);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(0, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(1, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(2, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(3, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("test1"), m_pDoc->GetString(0, 1, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("test2"), m_pDoc->GetString(1, 1, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("test3"), m_pDoc->GetString(2, 1, 0));
 }
 
-void ScDataProvidersTest::testCSVImport()
+ScDataProvidersTest::ScDataProvidersTest() :
+    ScBootstrapFixture( "/sc/qa/unit/data/dataprovider" ),
+    m_pDoc(nullptr)
 {
-    m_pDoc->InsertTab(0, "foo");
-    bool success;
-    OUString aCSVPath;
-    createCSVPath( "dataprovider.", aCSVPath );
-    OUString aDBName = "TEST";
-    sc::ExternalDataMapper aExternalDataMapper (&getDocShell(), aCSVPath, aDBName, 0, 0, 0, 5, 5, false, success);
-    aExternalDataMapper.StartImport();
-    Scheduler::ProcessEventsToIdle();
-    CPPUNIT_ASSERT_EQUAL (-2012.0, m_pDoc->GetValue(0, 0, 0));
-    CPPUNIT_ASSERT_EQUAL (-1.0, m_pDoc->GetValue(1, 0, 0));
-    CPPUNIT_ASSERT_EQUAL (0.0, m_pDoc->GetValue(2, 0, 0));
-    CPPUNIT_ASSERT_EQUAL (1.0, m_pDoc->GetValue(3, 0, 0));
-    CPPUNIT_ASSERT_EQUAL (2012.0, m_pDoc->GetValue(4, 0, 0));
-    CPPUNIT_ASSERT_EQUAL (-3.14, m_pDoc->GetValue(0, 1, 0));
-    CPPUNIT_ASSERT_EQUAL (-0.99, m_pDoc->GetValue(1, 1, 0));
-    CPPUNIT_ASSERT_EQUAL (0.01, m_pDoc->GetValue(2, 1, 0));
-    CPPUNIT_ASSERT_EQUAL (3.14, m_pDoc->GetValue(3, 1, 0));
-    CPPUNIT_ASSERT_EQUAL (OUString("H"), m_pDoc->GetString(0, 2, 0));
-    CPPUNIT_ASSERT_EQUAL (OUString("Hello, Calc!"), m_pDoc->GetString(1, 2, 0));
-    CPPUNIT_ASSERT_EQUAL (0.0, m_pDoc->GetValue(2, 2, 0));
-    CPPUNIT_ASSERT_EQUAL (0.0, m_pDoc->GetValue(0, 3, 0));
 }
 
 void ScDataProvidersTest::setUp()
@@ -86,20 +78,21 @@ void ScDataProvidersTest::setUp()
     ScBootstrapFixture::setUp();
 
     ScDLL::Init();
-    m_pImpl->m_xDocShell = new ScDocShell(
+    m_xDocShell = new ScDocShell(
         SfxModelFlags::EMBEDDED_OBJECT |
         SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
         SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
 
-    m_pImpl->m_xDocShell->SetIsInUcalc();
-    m_pImpl->m_xDocShell->DoInitUnitTest();
-    m_pDoc = &m_pImpl->m_xDocShell->GetDocument();
+    m_xDocShell->SetIsInUcalc();
+    m_xDocShell->DoInitUnitTest();
+    m_pDoc = &m_xDocShell->GetDocument();
+    m_pDoc->InsertTab(0, "Tab");
 }
 
 void ScDataProvidersTest::tearDown()
 {
-    m_pImpl->m_xDocShell->DoClose();
-    m_pImpl->m_xDocShell.clear();
+    m_xDocShell->DoClose();
+    m_xDocShell.clear();
     ScBootstrapFixture::tearDown();
 }
 


More information about the Libreoffice-commits mailing list