[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/CppunitTest_sc_subsequent_export_test.mk sc/Library_scqahelper.mk sc/qa sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Fri Jul 26 11:55:54 PDT 2013


 sc/CppunitTest_sc_subsequent_export_test.mk |    3 
 sc/Library_scqahelper.mk                    |    2 
 sc/qa/unit/data/xls/embedded-chart.xls      |binary
 sc/qa/unit/data/xls/inline-array.xls        |binary
 sc/qa/unit/helper/qahelper.cxx              |  128 ++++++++++++++++++++++++++++
 sc/qa/unit/helper/qahelper.hxx              |    9 +
 sc/qa/unit/subsequent_export-test.cxx       |   33 +++++++
 sc/qa/unit/subsequent_filters-test.cxx      |   50 +---------
 sc/source/filter/excel/xechart.cxx          |    8 -
 9 files changed, 180 insertions(+), 53 deletions(-)

New commits:
commit 368bea65c9db604d481b1146f96ea1683957f461
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Jul 26 14:55:47 2013 -0400

    Add test for exporting of chart to xls format.
    
    Change-Id: I49adfcabec4b8bafa8f1b25e7771acca9ccf0ead

diff --git a/sc/CppunitTest_sc_subsequent_export_test.mk b/sc/CppunitTest_sc_subsequent_export_test.mk
index 12565a5..1896bbd 100644
--- a/sc/CppunitTest_sc_subsequent_export_test.mk
+++ b/sc/CppunitTest_sc_subsequent_export_test.mk
@@ -83,6 +83,7 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\
     framework/util/fwk \
     i18npool/util/i18npool \
     i18npool/source/search/i18nsearch \
+    linguistic/source/lng \
     oox/util/oox \
     package/source/xstor/xstor \
     package/util/package2 \
@@ -103,9 +104,9 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\
     unotools/util/utl \
     unoxml/source/rdf/unordf \
     unoxml/source/service/unoxml \
+    xmloff/util/xo \
     xmlsecurity/util/xsec_fw \
     xmlsecurity/util/xmlsecurity \
-    xmloff/util/xo \
 ))
 
 ifeq ($(OS),WNT)
diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk
index c978c95..fd1d4a1 100644
--- a/sc/Library_scqahelper.mk
+++ b/sc/Library_scqahelper.mk
@@ -39,6 +39,8 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\
 	sot \
 	svl \
 	svt \
+	svx \
+        svxcore \
 	test \
 	tl \
 	unotest \
diff --git a/sc/qa/unit/data/xls/embedded-chart.xls b/sc/qa/unit/data/xls/embedded-chart.xls
new file mode 100644
index 0000000..ca5a2a4
Binary files /dev/null and b/sc/qa/unit/data/xls/embedded-chart.xls differ
diff --git a/sc/qa/unit/data/xls/inline-array.xls b/sc/qa/unit/data/xls/inline-array.xls
index 64574f8..151fb38 100644
Binary files a/sc/qa/unit/data/xls/inline-array.xls and b/sc/qa/unit/data/xls/inline-array.xls differ
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 9583f04..e145f58 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -9,6 +9,9 @@
 
 #include "qahelper.hxx"
 #include "csv_handler.hxx"
+#include "drwlayer.hxx"
+#include "svx/svdpage.hxx"
+#include "svx/svdoole2.hxx"
 
 #if defined WNT
 #define __ORCUS_STATIC_LIB
@@ -17,6 +20,14 @@
 
 #include <fstream>
 
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/text/textfield/Type.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/chart2/data/XDataReceiver.hpp>
+
+using namespace com::sun::star;
+using namespace ::com::sun::star::uno;
+
 FileFormat aFileFormats[] = {
     { "ods" , "calc8", "", ODS_FORMAT_TYPE },
     { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
@@ -107,6 +118,123 @@ void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
     }
 }
 
+const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
+{
+    // Retrieve the chart object instance from the 2nd page (for the 2nd sheet).
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    if (!pDrawLayer)
+    {
+        cout << "Failed to retrieve the drawing layer object." << endl;
+        return NULL;
+    }
+
+    const SdrPage* pPage = pDrawLayer->GetPage(nPage);
+    if (!pPage)
+    {
+        cout << "Failed to retrieve the page object." << endl;
+        return NULL;
+    }
+
+    if (pPage->GetObjCount() != 1)
+    {
+        cout << "This page should contain one drawing object." << endl;
+        return NULL;
+    }
+
+    const SdrObject* pObj = pPage->GetObj(0);
+    if (!pObj)
+    {
+        cout << "Failed to retrieve the drawing object." << endl;
+        return NULL;
+    }
+
+    if (pObj->GetObjIdentifier() != OBJ_OLE2)
+    {
+        cout << "This is not an OLE2 object." << endl;
+        return NULL;
+    }
+
+    const SdrOle2Obj& rOleObj = static_cast<const SdrOle2Obj&>(*pObj);
+    if (!rOleObj.IsChart())
+    {
+        cout << "This should be a chart object." << endl;
+        return NULL;
+    }
+
+    return &rOleObj;
+}
+
+std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj)
+{
+    std::vector<OUString> aRangeReps;
+
+    // Make sure the chart object has correct range references.
+    Reference<frame::XModel> xModel = rChartObj.getXModel();
+    if (!xModel.is())
+    {
+        cout << "Failed to get the embedded object interface." << endl;
+        return aRangeReps;
+    }
+
+    Reference<chart2::XChartDocument> xChartDoc(xModel, UNO_QUERY);
+    if (!xChartDoc.is())
+    {
+        cout << "Failed to get the chart document interface." << endl;
+        return aRangeReps;
+    }
+
+    Reference<chart2::data::XDataSource> xDataSource(xChartDoc, UNO_QUERY);
+    if (!xDataSource.is())
+    {
+        cout << "Failed to get the data source interface." << endl;
+        return aRangeReps;
+    }
+
+    Sequence<Reference<chart2::data::XLabeledDataSequence> > xDataSeqs = xDataSource->getDataSequences();
+    if (!xDataSeqs.getLength())
+    {
+        cout << "There should be at least one data sequences." << endl;
+        return aRangeReps;
+    }
+
+    Reference<chart2::data::XDataReceiver> xDataRec(xChartDoc, UNO_QUERY);
+    if (!xDataRec.is())
+    {
+        cout << "Failed to get the data receiver interface." << endl;
+        return aRangeReps;
+    }
+
+    Sequence<OUString> aRangeRepSeqs = xDataRec->getUsedRangeRepresentations();
+    for (sal_Int32 i = 0, n = aRangeRepSeqs.getLength(); i < n; ++i)
+        aRangeReps.push_back(aRangeRepSeqs[i]);
+
+    return aRangeReps;
+}
+
+ScRangeList getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj)
+{
+    std::vector<OUString> aRangeReps = getChartRangeRepresentations(rChartObj);
+    ScRangeList aRanges;
+    for (size_t i = 0, n = aRangeReps.size(); i < n; ++i)
+    {
+        ScRange aRange;
+        sal_uInt16 nRes = aRange.Parse(aRangeReps[i], &rDoc, rDoc.GetAddressConvention());
+        if (nRes & SCA_VALID)
+            // This is a range address.
+            aRanges.Append(aRange);
+        else
+        {
+            // Parse it as a single cell address.
+            ScAddress aAddr;
+            nRes = aAddr.Parse(aRangeReps[i], &rDoc, rDoc.GetAddressConvention());
+            CPPUNIT_ASSERT_MESSAGE("Failed to parse a range representation.", (nRes & SCA_VALID));
+            aRanges.Append(aAddr);
+        }
+    }
+
+    return aRanges;
+}
+
 ScDocShellRef ScBootstrapFixture::load( bool bReadWrite,
     const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index 7eb4d45..6e332fe 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -50,6 +50,9 @@ SC_DLLPUBLIC bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol );
 
 #define CHECK_OPTIMAL 0x1
 
+class SdrOle2Obj;
+class ScRangeList;
+
 // data format for row height tests
 struct TestParam
 {
@@ -86,7 +89,11 @@ SC_DLLPUBLIC void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, St
 //need own handler because conditional formatting strings must be generated
 SC_DLLPUBLIC void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
 
-SC_DLLPUBLIC void clearRange(ScDocument* pDoc, const ScRange& rRange);
+SC_DLLPUBLIC const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
+
+SC_DLLPUBLIC std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj);
+
+SC_DLLPUBLIC ScRangeList getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj);
 
 inline std::string print(const ScAddress& rAddr)
 {
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index ad7a514..1a8eca8 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -28,6 +28,8 @@
 #include "cellform.hxx"
 #include "formulacell.hxx"
 
+#include "svx/svdoole2.hxx"
+
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
 
@@ -53,6 +55,7 @@ public:
     void testNamedRangeBugfdo62729();
 
     void testInlineArrayXLS();
+    void testEmbeddedChartXLS();
 
     CPPUNIT_TEST_SUITE(ScExportTest);
     CPPUNIT_TEST(test);
@@ -66,6 +69,7 @@ public:
     CPPUNIT_TEST(testMiscRowHeightExport);
     CPPUNIT_TEST(testNamedRangeBugfdo62729);
     CPPUNIT_TEST(testInlineArrayXLS);
+    CPPUNIT_TEST(testEmbeddedChartXLS);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -355,6 +359,7 @@ void ScExportTest::testInlineArrayXLS()
     CPPUNIT_ASSERT(xShell.Is());
 
     ScDocShellRef xDocSh = saveAndReload(xShell, XLS);
+    xShell->DoClose();
     CPPUNIT_ASSERT(xDocSh.Is());
 
     ScDocument* pDoc = xDocSh->GetDocument();
@@ -372,6 +377,34 @@ void ScExportTest::testInlineArrayXLS()
     xDocSh->DoClose();
 }
 
+void ScExportTest::testEmbeddedChartXLS()
+{
+    ScDocShellRef xShell = loadDoc("embedded-chart.", XLS);
+    CPPUNIT_ASSERT(xShell.Is());
+
+    ScDocShellRef xDocSh = saveAndReload(xShell, XLS);
+    xShell->DoClose();
+    CPPUNIT_ASSERT(xDocSh.Is());
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    // Make sure the 2nd sheet is named 'Chart1'.
+    OUString aName;
+    pDoc->GetName(1, aName);
+    CPPUNIT_ASSERT_EQUAL(OUString("Chart1"), aName);
+
+    const SdrOle2Obj* pOleObj = getSingleChartObject(*pDoc, 1);
+    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve a chart object from the 2nd sheet.", pOleObj);
+
+    ScRangeList aRanges = getChartRanges(*pDoc, *pOleObj);
+    CPPUNIT_ASSERT_MESSAGE("Label range (B3:B5) not found.", aRanges.In(ScRange(1,2,1,1,4,1)));
+    CPPUNIT_ASSERT_MESSAGE("Data label (C2) not found.", aRanges.In(ScAddress(2,1,1)));
+    CPPUNIT_ASSERT_MESSAGE("Data range (C3:C5) not found.", aRanges.In(ScRange(2,2,1,2,4,1)));
+
+    xDocSh->DoClose();
+}
+
 ScExportTest::ScExportTest()
       : ScBootstrapFixture("/sc/qa/unit/data")
 {
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 79d31c8..9e9463d 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -18,9 +18,10 @@
 #include <sfx2/docfile.hxx>
 #include <sfx2/sfxmodelfactory.hxx>
 #include <svl/stritem.hxx>
+
+#include "drwlayer.hxx"
 #include "svx/svdpage.hxx"
 #include "svx/svdoole2.hxx"
-
 #include "editeng/wghtitem.hxx"
 #include "editeng/postitem.hxx"
 #include "editeng/udlnitem.hxx"
@@ -33,7 +34,6 @@
 #include <dbdata.hxx>
 #include "validat.hxx"
 #include "formulacell.hxx"
-#include "drwlayer.hxx"
 #include "userdat.hxx"
 #include "dpobject.hxx"
 #include "dpsave.hxx"
@@ -1301,48 +1301,10 @@ void ScFiltersTest::testChartImportODS()
     CPPUNIT_ASSERT_EQUAL(OUString("Title"), aName);
 
     // Retrieve the chart object instance from the 2nd page (for the 2nd sheet).
-    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
-    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve the drawing layer object.", pDrawLayer);
-    const SdrPage* pPage = pDrawLayer->GetPage(1); // for the 2nd sheet.
-    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve the page object.", pPage);
-    CPPUNIT_ASSERT_MESSAGE("This page should contain one drawing object.", pPage->GetObjCount() == 1);
-    const SdrObject* pObj = pPage->GetObj(0);
-    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve the drawing object.", pObj);
-    CPPUNIT_ASSERT_MESSAGE("This is not an OLE2 object.", pObj->GetObjIdentifier() == OBJ_OLE2);
-    const SdrOle2Obj& rOleObj = static_cast<const SdrOle2Obj&>(*pObj);
-    CPPUNIT_ASSERT_MESSAGE("This should be a chart object.", rOleObj.IsChart());
-
-    // Make sure the chart object has correct range references.
-    Reference<frame::XModel> xModel = rOleObj.getXModel();
-    CPPUNIT_ASSERT_MESSAGE("Failed to get the embedded object interface.", xModel.is());
-    Reference<chart2::XChartDocument> xChartDoc(xModel, UNO_QUERY);
-    CPPUNIT_ASSERT_MESSAGE("Failed to get the chart document interface.", xChartDoc.is());
-    Reference<chart2::data::XDataSource> xDataSource(xChartDoc, UNO_QUERY);
-    CPPUNIT_ASSERT_MESSAGE("Failed to get the data source interface.", xDataSource.is());
-    Sequence<Reference<chart2::data::XLabeledDataSequence> > xDataSeqs = xDataSource->getDataSequences();
-    CPPUNIT_ASSERT_MESSAGE("There should be at least one data sequences.", xDataSeqs.getLength() > 0);
-    Reference<chart2::data::XDataReceiver> xDataRec(xChartDoc, UNO_QUERY);
-    CPPUNIT_ASSERT_MESSAGE("Failed to get the data receiver interface.", xDataRec.is());
-    Sequence<OUString> aRangeReps = xDataRec->getUsedRangeRepresentations();
-    CPPUNIT_ASSERT_MESSAGE("There should be at least one range representations.", aRangeReps.getLength() > 0);
-
-    ScRangeList aRanges;
-    for (sal_Int32 i = 0, n = aRangeReps.getLength(); i < n; ++i)
-    {
-        ScRange aRange;
-        sal_uInt16 nRes = aRange.Parse(aRangeReps[i], pDoc, pDoc->GetAddressConvention());
-        if (nRes & SCA_VALID)
-            // This is a range address.
-            aRanges.Append(aRange);
-        else
-        {
-            // Parse it as a single cell address.
-            ScAddress aAddr;
-            nRes = aAddr.Parse(aRangeReps[i], pDoc, pDoc->GetAddressConvention());
-            CPPUNIT_ASSERT_MESSAGE("Failed to parse a range representation.", (nRes & SCA_VALID));
-            aRanges.Append(aAddr);
-        }
-    }
+    const SdrOle2Obj* pOleObj = getSingleChartObject(*pDoc, 1);
+    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve a chart object from the 2nd sheet.", pOleObj);
+
+    ScRangeList aRanges = getChartRanges(*pDoc, *pOleObj);
 
     CPPUNIT_ASSERT_MESSAGE("Data series title cell not found.", aRanges.In(ScAddress(1,0,3))); // B1 on Title
     CPPUNIT_ASSERT_MESSAGE("Data series label range not found.", aRanges.In(ScRange(0,1,2,0,3,2))); // A2:A4 on Data
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index e8b4c1e..92bb939 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -877,14 +877,8 @@ void lclAddDoubleRefData(
         SCsTAB nScTab2, SCsCOL nScCol2, SCsROW nScRow2 )
 {
     ScComplexRefData aComplexRef;
-    aComplexRef.InitFlags();
+    aComplexRef.InitRange(ScRange(nScCol1,nScRow1,nScTab1,nScCol2,nScRow2,nScTab2));
     aComplexRef.Ref1.SetFlag3D( true );
-    aComplexRef.Ref1.nTab = nScTab1;
-    aComplexRef.Ref1.nCol = nScCol1;
-    aComplexRef.Ref1.nRow = nScRow1;
-    aComplexRef.Ref2.nTab = nScTab2;
-    aComplexRef.Ref2.nCol = nScCol2;
-    aComplexRef.Ref2.nRow = nScRow2;
 
     if( orArray.GetLen() > 0 )
         orArray.AddOpCode( ocUnion );


More information about the Libreoffice-commits mailing list