summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2017-02-12 19:10:00 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2017-02-12 21:38:01 +0000
commite5aa7a5b5753c57969fc2e17fb334781bb2a0481 (patch)
tree707d84d63af9e7744f058f214bc70c63b936bd18
parent163435fa23fbfc237a7718c9d440a98847e4f626 (diff)
Pivot table median function test
Change-Id: I0a31733644aa6d4566566d0324d39aaf6b59b04f Reviewed-on: https://gerrit.libreoffice.org/34179 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r--sc/qa/unit/ucalc.hxx6
-rw-r--r--sc/qa/unit/ucalc_pivottable.cxx78
2 files changed, 84 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index f3247486ffa3..7b3b8fe4e210 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -325,6 +325,11 @@ public:
*/
void testPivotTableDPCollection();
+ /**
+ * Test pivot table median function
+ */
+ void testPivotTableMedianFunc();
+
void testCellCopy();
void testSheetCopy();
void testSheetMove();
@@ -627,6 +632,7 @@ public:
CPPUNIT_TEST(testPivotTableDocFunc);
CPPUNIT_TEST(testPivotTableRepeatItemLabels);
CPPUNIT_TEST(testPivotTableDPCollection);
+ CPPUNIT_TEST(testPivotTableMedianFunc);
CPPUNIT_TEST(testCellCopy);
CPPUNIT_TEST(testSheetCopy);
CPPUNIT_TEST(testSheetMove);
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 28b475d029b8..2c2cfb5f00fa 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
#include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
#include <com/sun/star/sheet/GeneralFunction.hpp>
+#include <com/sun/star/sheet/GeneralFunction2.hpp>
namespace {
@@ -2490,4 +2491,81 @@ void Test::testPivotTableDPCollection()
m_pDoc->DeleteTab(0);
}
+void Test::testPivotTableMedianFunc()
+{
+ m_pDoc->InsertTab(0, "Data");
+ m_pDoc->InsertTab(1, "Table");
+
+ // Raw data
+ const char* aData[][4] = {
+ { "Condition", "Day1Hit", "Day1Miss", "Day1FalseAlarm" },
+ { "False Memory", "7", "3", "0" },
+ { "Control", "10", "0", "1" },
+ { "False Memory", "9", "1", "0" },
+ { "Control", "9", "1", "2" },
+ { "False Memory", "7", "3", "3" },
+ { "Control", "10", "0", "0" },
+ { "False Memory", "9", "1", "1" },
+ { "Control", "6", "4", "2" },
+ { "False Memory", "8", "2", "1" },
+ { "Control", "7", "3", "3" },
+ { "False Memory", "9", "1", "1" },
+ { "Control", "10", "0", "0" },
+ { "False Memory", "10", "0", "0" },
+ { "Control", "10", "0", "0" },
+ { "False Memory", "10", "0", "0" },
+ { "Control", "9", "1", "1" },
+ { "False Memory", "10", "0", "0" },
+ { "Control", "10", "0", "0" },
+ };
+
+ // Dimension definition
+ DPFieldDef aFields[] = {
+ { "Condition", sheet::DataPilotFieldOrientation_ROW, 0, false },
+ { "Day1Hit", sheet::DataPilotFieldOrientation_DATA, sheet::GeneralFunction2::MEDIAN, false },
+ { "Day1Miss", sheet::DataPilotFieldOrientation_DATA, sheet::GeneralFunction2::MEDIAN, false },
+ { "Day1FalseAlarm", sheet::DataPilotFieldOrientation_DATA, sheet::GeneralFunction2::MEDIAN, false },
+ };
+
+ ScAddress aPos(1, 1, 0);
+ ScRange aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("failed to insert range data at correct position", aPos, aDataRange.aStart);
+
+ std::unique_ptr<ScDPObject> pDPObj(createDPFromRange(
+ m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false));
+ CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table object.", pDPObj);
+
+ // Create a new pivot table output.
+ ScDBDocFunc aFunc(getDocShell());
+ bool bSuccess = aFunc.CreatePivotTable(*pDPObj, false, true);
+ CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table output via ScDBDocFunc.", bSuccess);
+ ScDPCollection* pDPs = m_pDoc->GetDPCollection();
+ CPPUNIT_ASSERT_MESSAGE("Failed to get pivot table collection.", pDPs);
+ ScDPObject* pDPObject = &(*pDPs)[0];
+ ScRange aOutRange = pDPObject->GetOutRange();
+ {
+ // Expected output table content. 0 = empty cell
+ const char* aOutputCheck[][4] = {
+ { "Condition", "Data", nullptr },
+ { "Control", "Median - Day1Hit", "10" },
+ { nullptr, "Median - Day1Miss", "0" },
+ { nullptr, "Median - Day1FalseAlarm", "1", },
+ { "False Memory", "Median - Day1Hit", "9" },
+ { nullptr, "Median - Day1Miss", "1" },
+ { nullptr, "Median - Day1FalseAlarm", "0", "0" },
+ { "Total Median - Day1Hit", nullptr, "9", nullptr },
+ { "Total Median - Day1Miss", nullptr, "1", nullptr },
+ { "Total Median - Day1FalseAlarm", nullptr, "0.5", nullptr }
+ };
+
+ bSuccess = checkDPTableOutput<4>(m_pDoc, aOutRange, aOutputCheck, "Pivot table created via ScDBDocFunc");
+ CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+ }
+
+ bSuccess = aFunc.RemovePivotTable(*pDPObject, false, true);
+
+ m_pDoc->DeleteTab(1);
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */