From 27a4fb657fad157d26d07934ecd0cce578a99f38 Mon Sep 17 00:00:00 2001 From: Jean-Tiare Le Bigot Date: Tue, 18 Oct 2016 23:36:51 +0200 Subject: chart2: fix unserialization of empty cells Change-Id: Ib7e5c8c4db6cac7ef1255246eea13325cf7cca69 Reviewed-on: https://gerrit.libreoffice.org/30030 Reviewed-by: jan iversen Tested-by: jan iversen --- chart2/qa/extras/chart2import.cxx | 50 ++++++++++++++++++++++++++++ chart2/source/tools/InternalDataProvider.cxx | 11 ++---- 2 files changed, 52 insertions(+), 9 deletions(-) (limited to 'chart2') diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 7d0f8f204a6a..bff7e81a521b 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -90,6 +90,8 @@ public: void testSecondaryAxisTitleDefaultRotationXLSX(); void testAxisTitleRotationXLSX(); + void testInternalDataProvider(); + CPPUNIT_TEST_SUITE(Chart2ImportTest); CPPUNIT_TEST(Fdo60083); CPPUNIT_TEST(testSteppedLines); @@ -139,6 +141,9 @@ public: CPPUNIT_TEST(testAxisTitleDefaultRotationXLSX); CPPUNIT_TEST(testSecondaryAxisTitleDefaultRotationXLSX); CPPUNIT_TEST(testAxisTitleRotationXLSX); + + CPPUNIT_TEST(testInternalDataProvider); + CPPUNIT_TEST_SUITE_END(); private: @@ -1125,6 +1130,51 @@ void Chart2ImportTest::testAxisTitleRotationXLSX() } +void Chart2ImportTest::testInternalDataProvider() { + uno::Reference< chart2::XChartDocument > xChartDoc(getChartDocFromImpress("/chart2/qa/extras/data/odp/", "chart.odp"), uno::UNO_QUERY_THROW); + const uno::Reference< chart2::data::XDataProvider >& rxDataProvider = xChartDoc->getDataProvider(); + + // Parse 42 array + Reference xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;42;42;42}"); + Sequence xSequence = xDataSeq->getData(); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[0]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[1]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[2]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[3]); + + // Parse empty first and last + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{\"\";42;42;\"\"}"); + xSequence = xDataSeq->getData(); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[0]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[1]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[2]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[3]); + + // Parse empty middle + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"\";\"\";42}"); + xSequence = xDataSeq->getData(); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[0]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[1]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[2]); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[3]); + + // Parse mixed types, numeric only role + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"hello\";0;\"world\"}"); + xSequence = xDataSeq->getData(); + CPPUNIT_ASSERT_EQUAL(uno::Any(42), xSequence[0]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[1]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[2]); + CPPUNIT_ASSERT_EQUAL(uno::Any(0), xSequence[3]); + + // Parse mixed types, mixed role + xDataSeq = rxDataProvider->createDataSequenceByValueArray("categories", "{42;\"hello\";0;\"world\"}"); + xSequence = xDataSeq->getData(); + CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("42")), xSequence[0]); + CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("hello")), xSequence[1]); + CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("0")), xSequence[2]); + CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("world")), xSequence[3]); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx index 32dd3c715ab2..7bcb65f0e997 100644 --- a/chart2/source/tools/InternalDataProvider.cxx +++ b/chart2/source/tools/InternalDataProvider.cxx @@ -533,10 +533,7 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, co { // Opening quote. bAllNumeric = false; - ++p; - if (p == pEnd) - break; - pElem = p; + pElem = nullptr; } else { @@ -552,11 +549,7 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, co break; } } - else if (bInQuote) - { - // Do nothing. - } - else if (*p == ';') + else if (*p == ';' and !bInQuote) { // element separator. if (pElem) -- cgit