summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-03-30 23:50:38 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-03-31 11:18:55 +0200
commit85f9f06f5904b57a23a56416e4477bb5f6703369 (patch)
tree36d2f84a103e3262724c36e79ec3be465232c912
parentcc0a8c929683ae477bdeb02a01845509b0f73809 (diff)
chart2: pivot chart round-trip test, pivot table update test
Change-Id: Ia96bae4f24e7031929ceb9dc9fbeaa841def7547
-rw-r--r--chart2/CppunitTest_chart2_pivot_chart_test.mk131
-rw-r--r--chart2/Module_chart2.mk1
-rw-r--r--chart2/qa/extras/PivotChartTest.cxx244
-rw-r--r--chart2/qa/extras/data/ods/PivotChart.odsbin0 -> 21988 bytes
-rw-r--r--chart2/qa/extras/data/ods/PivotChart2.odsbin0 -> 21988 bytes
5 files changed, 376 insertions, 0 deletions
diff --git a/chart2/CppunitTest_chart2_pivot_chart_test.mk b/chart2/CppunitTest_chart2_pivot_chart_test.mk
new file mode 100644
index 000000000000..418db1af9cc9
--- /dev/null
+++ b/chart2/CppunitTest_chart2_pivot_chart_test.mk
@@ -0,0 +1,131 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,chart2_pivot_chart_test))
+
+$(eval $(call gb_CppunitTest_use_externals,chart2_pivot_chart_test, \
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,chart2_pivot_chart_test, \
+ chart2/qa/extras/PivotChartTest \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,chart2_pivot_chart_test, \
+ basegfx \
+ comphelper \
+ cppu \
+ cppuhelper \
+ drawinglayer \
+ editeng \
+ for \
+ forui \
+ i18nlangtag \
+ msfilter \
+ vcl \
+ oox \
+ sal \
+ salhelper \
+ sax \
+ sb \
+ sc \
+ sw \
+ sd \
+ sfx \
+ sot \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ test \
+ tl \
+ tk \
+ ucbhelper \
+ unotest \
+ utl \
+ vbahelper \
+ xo \
+ sw \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,chart2_pivot_chart_test,\
+ -I$(SRCDIR)/chart2/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,chart2_pivot_chart_test))
+$(eval $(call gb_CppunitTest_use_ure,chart2_pivot_chart_test))
+$(eval $(call gb_CppunitTest_use_vcl,chart2_pivot_chart_test))
+
+$(eval $(call gb_CppunitTest_use_components,chart2_pivot_chart_test,\
+ basic/util/sb \
+ animations/source/animcore/animcore \
+ chart2/source/controller/chartcontroller \
+ chart2/source/chartcore \
+ comphelper/util/comphelp \
+ configmgr/source/configmgr \
+ dtrans/util/mcnttype \
+ dbaccess/util/dba \
+ embeddedobj/util/embobj \
+ eventattacher/source/evtatt \
+ filter/source/config/cache/filterconfig1 \
+ filter/source/odfflatxml/odfflatxml \
+ filter/source/storagefilterdetect/storagefd \
+ filter/source/xmlfilteradaptor/xmlfa \
+ filter/source/xmlfilterdetect/xmlfd \
+ forms/util/frm \
+ framework/util/fwk \
+ i18npool/util/i18npool \
+ linguistic/source/lng \
+ oox/util/oox \
+ package/source/xstor/xstor \
+ package/util/package2 \
+ sax/source/expatwrap/expwrap \
+ sc/util/sc \
+ sc/util/scd \
+ sc/util/scfilt \
+ sw/util/sw \
+ sw/util/swd \
+ sw/util/msword \
+ sd/util/sd \
+ sd/util/sdfilt \
+ sd/util/sdd \
+ $(call gb_Helper_optional,SCRIPTING, \
+ sc/util/vbaobj) \
+ scaddins/source/analysis/analysis \
+ scaddins/source/datefunc/date \
+ scripting/source/basprov/basprov \
+ scripting/util/scriptframe \
+ sfx2/util/sfx \
+ sot/util/sot \
+ svl/source/fsstor/fsstorage \
+ svl/util/svl \
+ svtools/util/svt \
+ svx/util/svx \
+ svx/util/svxcore \
+ toolkit/util/tk \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
+ unotools/util/utl \
+ unoxml/source/rdf/unordf \
+ unoxml/source/service/unoxml \
+ uui/util/uui \
+ writerfilter/util/writerfilter \
+ xmloff/util/xo \
+ xmlscript/util/xmlscript \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,chart2_pivot_chart_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/chart2/Module_chart2.mk b/chart2/Module_chart2.mk
index f39140d61002..3273055d5373 100644
--- a/chart2/Module_chart2.mk
+++ b/chart2/Module_chart2.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,chart2,\
CppunitTest_chart2_import \
CppunitTest_chart2_trendcalculators \
CppunitTest_chart2_dump \
+ CppunitTest_chart2_pivot_chart_test \
))
ifeq ($(ENABLE_CHART_TESTS),TRUE)
diff --git a/chart2/qa/extras/PivotChartTest.cxx b/chart2/qa/extras/PivotChartTest.cxx
new file mode 100644
index 000000000000..ad98c60869da
--- /dev/null
+++ b/chart2/qa/extras/PivotChartTest.cxx
@@ -0,0 +1,244 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "charttest.hxx"
+
+#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
+#include <com/sun/star/sheet/XDataPilotTable.hpp>
+#include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
+#include <com/sun/star/sheet/XDataPilotTables.hpp>
+#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
+#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/sheet/XSpreadsheets.hpp>
+
+#include <rtl/strbuf.hxx>
+
+#include <algorithm>
+
+class PivotChartTest : public ChartTest
+{
+public:
+ PivotChartTest() : ChartTest()
+ {}
+
+ void testRoundtrip();
+ void testChangePivotTable();
+
+ CPPUNIT_TEST_SUITE(PivotChartTest);
+ CPPUNIT_TEST(testRoundtrip);
+ CPPUNIT_TEST(testChangePivotTable);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void lclModifyOrientation(uno::Reference<sheet::XDataPilotDescriptor> xDescriptor,
+ OUString sFieldName,
+ sheet::DataPilotFieldOrientation eOrientation)
+{
+ uno::Reference<container::XIndexAccess> xPilotIndexAccess(xDescriptor->getDataPilotFields(), UNO_QUERY_THROW);
+ sal_Int32 nCount = xPilotIndexAccess->getCount();
+ for (sal_Int32 i = 0; i < nCount; ++i)
+ {
+ uno::Reference<container::XNamed> xNamed(xPilotIndexAccess->getByIndex(i), UNO_QUERY_THROW);
+ OUString aName = xNamed->getName();
+ uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
+ if (aName == sFieldName)
+ xPropSet->setPropertyValue("Orientation", uno::makeAny(eOrientation));
+ }
+}
+
+bool lclCheckSequence(std::vector<double> const & reference,
+ uno::Sequence<uno::Any> const & values,
+ double delta)
+{
+ if (reference.size() != size_t(values.getLength()))
+ return false;
+
+ for (size_t i = 0; i < reference.size(); ++i)
+ {
+ double value = values[i].get<double>();
+
+ if (std::fabs(reference[i] - value) > delta)
+ {
+ printf ("Value %f is not the same as reference %f (delta %f)\n", value, reference[i], delta);
+ return false;
+ }
+ }
+ return true;
+}
+
+void PivotChartTest::testRoundtrip()
+{
+ uno::Sequence<uno::Any> xSequence;
+ Reference<chart2::XChartDocument> xChartDoc;
+
+ load("/chart2/qa/extras/data/ods/", "PivotChart.ods");
+
+ xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, mxComponent), uno::UNO_QUERY);
+
+ std::vector<double> aReference1 { 10162.033139, 16614.523063, 27944.146101 };
+ OUString aExpectedLabel1("Exp.");
+
+ std::vector<double> aReference2 { 101879.458079, 178636.929704, 314626.484864 };
+ OUString aExpectedLabel2("Rev.");
+
+ CPPUNIT_ASSERT(xChartDoc.is());
+ {
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0);
+ xSequence = xDataSequence->getData();
+
+ CPPUNIT_ASSERT(lclCheckSequence(aReference1, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
+ xSequence = xLabelDataSequence->getData();
+
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel1, xSequence[0].get<OUString>());
+ }
+ {
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1);
+ xSequence = xDataSequence->getData();
+
+ CPPUNIT_ASSERT(lclCheckSequence(aReference2, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
+ xSequence = xLabelDataSequence->getData();
+
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel2, xSequence[0].get<OUString>());
+ }
+
+ reload("calc8");
+
+ xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, mxComponent), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ {
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0);
+ xSequence = xDataSequence->getData();
+
+ CPPUNIT_ASSERT(lclCheckSequence(aReference1, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
+ xSequence = xLabelDataSequence->getData();
+
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel1, xSequence[0].get<OUString>());
+ }
+ {
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1);
+ xSequence = xDataSequence->getData();
+
+ CPPUNIT_ASSERT(lclCheckSequence(aReference2, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
+ xSequence = xLabelDataSequence->getData();
+
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel2, xSequence[0].get<OUString>());
+ }
+}
+
+
+void PivotChartTest::testChangePivotTable()
+{
+ uno::Sequence<uno::Any> xSequence;
+ Reference<chart2::XChartDocument> xChartDoc;
+
+ load("/chart2/qa/extras/data/ods/", "PivotChart2.ods");
+
+ xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, mxComponent), uno::UNO_QUERY);
+
+ CPPUNIT_ASSERT(xChartDoc.is());
+ {
+ std::vector<double> aReference { 10162.033139, 16614.523063, 27944.146101 };
+ OUString aExpectedLabel("Exp.");
+
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0);
+ xSequence = xDataSequence->getData();
+ CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
+ xSequence = xLabelDataSequence->getData();
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+ }
+ {
+ std::vector<double> aReference { 101879.458079, 178636.929704, 314626.484864 };
+ OUString aExpectedLabel("Rev.");
+
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1);
+ xSequence = xDataSequence->getData();
+ CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-4));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
+ xSequence = xLabelDataSequence->getData();
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+ }
+
+ // modify the pivot table
+
+ {
+ uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
+ uno::Reference<container::XIndexAccess> xSheetIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
+ uno::Any aAny = xSheetIndexAccess->getByIndex(1);
+ uno::Reference<sheet::XSpreadsheet> xSheet;
+ CPPUNIT_ASSERT(aAny >>= xSheet);
+ uno::Reference<sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
+ uno::Reference<sheet::XDataPilotTables> xDataPilotTables = xDataPilotTablesSupplier->getDataPilotTables();
+ uno::Reference<sheet::XDataPilotTable> xDataPilotTable(xDataPilotTables->getByName("DataPilot1"), UNO_QUERY_THROW);
+ uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
+ uno::Reference<container::XIndexAccess> xPilotIndexAccess(xDataPilotDescriptor->getDataPilotFields(), UNO_QUERY_THROW);
+
+ lclModifyOrientation(xDataPilotDescriptor, "Service Month", sheet::DataPilotFieldOrientation_ROW);
+ lclModifyOrientation(xDataPilotDescriptor, "Group Segment", sheet::DataPilotFieldOrientation_COLUMN);
+ lclModifyOrientation(xDataPilotDescriptor, "Rev.", sheet::DataPilotFieldOrientation_HIDDEN);
+ }
+
+ // check again
+
+ xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, mxComponent), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ {
+ std::vector<double> aReference { 2855.559, 1780.326, 2208.713, 2130.064, 1187.371 };
+ OUString aExpectedLabel("Big");
+
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0);
+ xSequence = xDataSequence->getData();
+ CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
+ xSequence = xLabelDataSequence->getData();
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+ }
+ {
+ std::vector<double> aReference { 4098.908, 2527.286, 4299.716, 2362.225, 3326.389 };
+ OUString aExpectedLabel("Medium");
+
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1);
+ xSequence = xDataSequence->getData();
+ CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
+ xSequence = xLabelDataSequence->getData();
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+ }
+ {
+ std::vector<double> aReference { 4926.303, 5684.060, 4201.398, 7290.795, 5841.591 };
+ OUString aExpectedLabel("Small");
+
+ Reference<chart2::data::XDataSequence> xDataSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2);
+ xSequence = xDataSequence->getData();
+ CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
+
+ Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
+ xSequence = xLabelDataSequence->getData();
+ CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+ }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PivotChartTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/qa/extras/data/ods/PivotChart.ods b/chart2/qa/extras/data/ods/PivotChart.ods
new file mode 100644
index 000000000000..c34521e0bc52
--- /dev/null
+++ b/chart2/qa/extras/data/ods/PivotChart.ods
Binary files differ
diff --git a/chart2/qa/extras/data/ods/PivotChart2.ods b/chart2/qa/extras/data/ods/PivotChart2.ods
new file mode 100644
index 000000000000..c34521e0bc52
--- /dev/null
+++ b/chart2/qa/extras/data/ods/PivotChart2.ods
Binary files differ