sc/qa/unit/ucalc.hxx | 6 +++ sc/qa/unit/ucalc_pivottable.cxx | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+)
New commits: commit e5aa7a5b5753c57969fc2e17fb334781bb2a0481 Author: Tamás Zolnai <tamas.zol...@collabora.com> Date: Sun Feb 12 19:10:00 2017 +0100 Pivot table median function test Change-Id: I0a31733644aa6d4566566d0324d39aaf6b59b04f Reviewed-on: https://gerrit.libreoffice.org/34179 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f324748..7b3b8fe 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 28b475d..2c2cfb5 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: */
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits