From 72bb1c410fd63de68d699b7b4bd28abb4f1da9b7 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Thu, 24 Jan 2013 15:16:59 -0500 Subject: New test for importing chart object with references to cell ranges. Change-Id: I2167d1a2c7ea70415581caf29acf620e4b116e69 --- sc/CppunitTest_sc_subsequent_filters_test.mk | 1 + sc/inc/address.hxx | 2 +- sc/qa/unit/data/ods/chart-import-basic.ods | Bin 0 -> 12232 bytes sc/qa/unit/subsequent_filters-test.cxx | 77 ++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 sc/qa/unit/data/ods/chart-import-basic.ods (limited to 'sc') diff --git a/sc/CppunitTest_sc_subsequent_filters_test.mk b/sc/CppunitTest_sc_subsequent_filters_test.mk index 7092b315a56e..68e943d0d811 100644 --- a/sc/CppunitTest_sc_subsequent_filters_test.mk +++ b/sc/CppunitTest_sc_subsequent_filters_test.mk @@ -122,6 +122,7 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_filters_test,\ unotools/util/utl \ unoxml/source/rdf/unordf \ unoxml/source/service/unoxml \ + xmloff/util/xo \ xmlsecurity/util/xsec_fw \ xmlsecurity/util/xmlsecurity \ )) diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx index 13a144352937..5f7c83f07397 100644 --- a/sc/inc/address.hxx +++ b/sc/inc/address.hxx @@ -456,7 +456,7 @@ public: inline bool In( const ScAddress& ) const; ///< is Address& in Range? inline bool In( const ScRange& ) const; ///< is Range& in Range? - sal_uInt16 Parse( const String&, ScDocument* = NULL, + SC_DLLPUBLIC sal_uInt16 Parse( const String&, ScDocument* = NULL, const ScAddress::Details& rDetails = ScAddress::detailsOOOa1, ScAddress::ExternalInfo* pExtInfo = NULL, const ::com::sun::star::uno::Sequence< diff --git a/sc/qa/unit/data/ods/chart-import-basic.ods b/sc/qa/unit/data/ods/chart-import-basic.ods new file mode 100644 index 000000000000..cfc86f349782 Binary files /dev/null and b/sc/qa/unit/data/ods/chart-import-basic.ods differ diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 233340696e0d..c8dcf40ddd72 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -39,6 +39,7 @@ #include #include #include "svx/svdpage.hxx" +#include "svx/svdoole2.hxx" #include "editeng/wghtitem.hxx" #include "editeng/postitem.hxx" @@ -64,6 +65,8 @@ #include #include #include +#include +#include #define CALC_DEBUG_OUTPUT 0 #define TEST_BUG_FILES 0 @@ -166,6 +169,7 @@ public: //test shape import void testControlImport(); + void testChartImportODS(); void testNumberFormatHTML(); void testNumberFormatCSV(); @@ -207,6 +211,7 @@ public: CPPUNIT_TEST(testSharedFormulaXLSX); CPPUNIT_TEST(testCellValueXLSX); CPPUNIT_TEST(testControlImport); + CPPUNIT_TEST(testChartImportODS); //CPPUNIT_TEST(testColorScaleODS); //CPPUNIT_TEST(testColorScaleXLSX); @@ -1329,7 +1334,7 @@ void ScFiltersTest::testPasswordOld() void ScFiltersTest::testControlImport() { ScDocShellRef xDocSh = loadDoc("singlecontrol.", XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load cell-value.xlsx", xDocSh.Is()); + CPPUNIT_ASSERT_MESSAGE("Failed to load singlecontrol.xlsx", xDocSh.Is()); uno::Reference< frame::XModel > xModel = xDocSh->GetModel(); uno::Reference< sheet::XSpreadsheetDocument > xDoc(xModel, UNO_QUERY_THROW); @@ -1342,6 +1347,76 @@ void ScFiltersTest::testControlImport() xDocSh->DoClose(); } +void ScFiltersTest::testChartImportODS() +{ + ScDocShellRef xDocSh = loadDoc("chart-import-basic.", ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load chart-import-basic.ods.", xDocSh.Is()); + + ScDocument* pDoc = xDocSh->GetDocument(); + + // Ensure that the document contains "Empty", "Chart", "Data" and "Title" sheets in this exact order. + CPPUNIT_ASSERT_MESSAGE("There should be 4 sheets in this document.", pDoc->GetTableCount() == 4); + OUString aName; + pDoc->GetName(0, aName); + CPPUNIT_ASSERT_EQUAL(OUString("Empty"), aName); + pDoc->GetName(1, aName); + CPPUNIT_ASSERT_EQUAL(OUString("Chart"), aName); + pDoc->GetName(2, aName); + CPPUNIT_ASSERT_EQUAL(OUString("Data"), aName); + pDoc->GetName(3, aName); + 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 retreive 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 retreive the drawing object.", pObj); + CPPUNIT_ASSERT_MESSAGE("This is not an OLE2 object.", pObj->GetObjIdentifier() == OBJ_OLE2); + const SdrOle2Obj& rOleObj = static_cast(*pObj); + CPPUNIT_ASSERT_MESSAGE("This should be a chart object.", rOleObj.IsChart()); + + // Make sure the chart object has correct range references. + Reference xModel = rOleObj.getXModel(); + CPPUNIT_ASSERT_MESSAGE("Failed to get the embedded object interface.", xModel.is()); + Reference xChartDoc(xModel, UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("Failed to get the chart document interface.", xChartDoc.is()); + Reference xDataSource(xChartDoc, UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("Failed to get the data source interface.", xDataSource.is()); + Sequence > xDataSeqs = xDataSource->getDataSequences(); + CPPUNIT_ASSERT_MESSAGE("There should be at least one data sequences.", xDataSeqs.getLength() > 0); + Reference xDataRec(xChartDoc, UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("Failed to get the data receiver interface.", xDataRec.is()); + Sequence 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); + } + } + + 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 + CPPUNIT_ASSERT_MESSAGE("Data series value range not found.", aRanges.In(ScRange(1,1,2,1,3,2))); // B2:B4 on Data + + xDocSh->DoClose(); +} + void ScFiltersTest::testNumberFormatHTML() { ScDocShellRef xDocSh = loadDoc("numberformat.", HTML); -- cgit v1.2.3