Kaydet (Commit) dc4355e5 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

bnc#881025: Write test for this.

Change-Id: Ifb1f83bbe5f9bb9ecb7fca26f883d1331052f10d
üst b8c444a4
......@@ -719,27 +719,17 @@ void Chart2ExportTest::testAxisNumberFormatODS()
{
void check( const Reference<chart2::XChartDocument>& xChartDoc )
{
Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, UNO_QUERY_THROW);
Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
CPPUNIT_ASSERT(xNumberFormats.is());
Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0);
Reference<chart2::XTitled> xTitle(xAxisX, UNO_QUERY_THROW);
OUString aTitleText = getTitleString(xTitle);
CPPUNIT_ASSERT_EQUAL(OUString("Linked To Source"), aTitleText);
Reference<beans::XPropertySet> xPS(xAxisX, UNO_QUERY_THROW);
sal_Int32 nNumFmt = -1;
xPS->getPropertyValue("NumberFormat") >>= nNumFmt;
CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from X axis.", nNumFmt != -1);
Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumFmt);
CPPUNIT_ASSERT(xNumPS.is());
sal_Int16 nType = util::NumberFormat::UNDEFINED;
xNumPS->getPropertyValue("Type") >>= nType;
sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX);
sal_Int16 nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT));
bool bNumFmtLinked = false;
Reference<beans::XPropertySet> xPS(xAxisX, uno::UNO_QUERY_THROW);
xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked);
......@@ -748,18 +738,12 @@ void Chart2ExportTest::testAxisNumberFormatODS()
aTitleText = getTitleString(xTitle);
CPPUNIT_ASSERT_EQUAL(OUString("Not Linked"), aTitleText);
xPS.set(xAxisY, UNO_QUERY_THROW);
nNumFmt = -1;
xPS->getPropertyValue("NumberFormat") >>= nNumFmt;
CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from Y axis.", nNumFmt != -1);
xNumPS = xNumberFormats->getByKey(nNumFmt);
CPPUNIT_ASSERT(xNumPS.is());
nType = util::NumberFormat::UNDEFINED;
xNumPS->getPropertyValue("Type") >>= nType;
nNumFmt = getNumberFormatFromAxis(xAxisY);
nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
bNumFmtLinked = true;
xPS.set(xAxisY, uno::UNO_QUERY_THROW);
xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked);
}
......
......@@ -40,6 +40,7 @@ public:
* hidden columns for internal data table yet).
*/
void testPPTXHiddenDataSeries();
void testPPTXStackedNonStackedYAxis();
void testPPTChartSeries();
void testODPChartSeries();
void testBnc864396();
......@@ -70,6 +71,7 @@ public:
CPPUNIT_TEST(testPPTChartSeries);
CPPUNIT_TEST(testPPTXChartSeries);
CPPUNIT_TEST(testPPTXHiddenDataSeries);
CPPUNIT_TEST(testPPTXStackedNonStackedYAxis);
CPPUNIT_TEST(testODPChartSeries);
CPPUNIT_TEST(testBnc864396);
CPPUNIT_TEST(testBnc882383);
......@@ -365,6 +367,65 @@ void Chart2ImportTest::testPPTXHiddenDataSeries()
CPPUNIT_ASSERT_EQUAL(OUString("Category 4"), aCategories[3][0]);
}
void Chart2ImportTest::testPPTXStackedNonStackedYAxis()
{
load("/chart2/qa/extras/data/pptx/", "stacked-non-stacked-mix-y-axis.pptx");
// 1st chart is a normal stacked column.
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
OUString aTitle = getTitleString(xTitled);
CPPUNIT_ASSERT_EQUAL(OUString("Stacked"), aTitle);
// Get the Y-axis.
Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
CPPUNIT_ASSERT(xYAxis.is());
sal_Int32 nNumberFormat = getNumberFormatFromAxis(xYAxis);
sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
// 2nd chart is a percent-stacked column.
xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
aTitle = getTitleString(xTitled);
CPPUNIT_ASSERT_EQUAL(OUString("100% Stacked"), aTitle);
// Get the Y-axis.
xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
CPPUNIT_ASSERT(xYAxis.is());
// Get the number format of the Y-axis.
nNumberFormat = getNumberFormatFromAxis(xYAxis);
nType = getNumberFormatType(xChartDoc, nNumberFormat);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT));
// 3rd chart is a mixture of normal-stacked column with a percent-stacked
// area chart series. Excel in this case sets the Y-axis to be
// non-percent axis and we should do the same for interoperability.
xChartDoc.set(getChartDocFromDrawImpress(2, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
aTitle = getTitleString(xTitled);
CPPUNIT_ASSERT_EQUAL(OUString("Stacked column mixed with 100% stacked area"), aTitle);
// Get the Y-axis.
xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
CPPUNIT_ASSERT(xYAxis.is());
// Get the number format of the Y-axis.
nNumberFormat = getNumberFormatFromAxis(xYAxis);
nType = getNumberFormatType(xChartDoc, nNumberFormat);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
}
void Chart2ImportTest::testODPChartSeries()
{
//test chart series names for odp
......
......@@ -482,16 +482,42 @@ uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const c
return seriesList;
}
OUString getTitleString( const Reference<chart2::XTitled>& xTitled, sal_Int32 nIndex = 0 )
OUString getTitleString( const Reference<chart2::XTitled>& xTitled )
{
uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
CPPUNIT_ASSERT(xTitle.is());
uno::Sequence<uno::Reference<chart2::XFormattedString> > aFSSeq = xTitle->getText();
CPPUNIT_ASSERT(aFSSeq.getLength() > nIndex);
uno::Reference<chart2::XFormattedString> xFS = aFSSeq[nIndex];
CPPUNIT_ASSERT(xFS.is());
OUString aText;
for (sal_Int32 i = 0; i < aFSSeq.getLength(); ++i)
aText += aFSSeq[i]->getString();
return xFS->getString();
return aText;
}
sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis )
{
Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY);
CPPUNIT_ASSERT(xPS.is());
sal_Int32 nNumberFormat = -1;
bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
CPPUNIT_ASSERT(bSuccess);
return nNumberFormat;
}
sal_Int16 getNumberFormatType( const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nNumberFormat )
{
Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
CPPUNIT_ASSERT(xNumberFormats.is());
Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumberFormat);
CPPUNIT_ASSERT(xNumPS.is());
sal_Int16 nType = util::NumberFormat::UNDEFINED;
xNumPS->getPropertyValue("Type") >>= nType;
return nType;
}
#endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment