diff options
author | Mihai Varga <mihai.varga@collabora.com> | 2015-02-19 10:46:41 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-03-05 10:25:55 +0000 |
commit | 44337a1fdae8cdc68b6cf539166e60feea879a9b (patch) | |
tree | 1411439cac29e4135aa8924ddb6edb8eb8f5be15 /sd | |
parent | 725fdd9214190da2425de9bc69264cb5b38e0443 (diff) |
Unit tests for PDF import
The PDF file consists of a text section followed by an image. So in the first
test there should be 2 shapes (text and image) while in the second test which
has the SkipImages filter option, there should be a single shape.
Change-Id: I30ba0a832b665aa2fd5182b18778b485c62d7590
Reviewed-on: https://gerrit.libreoffice.org/14552
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/CppunitTest_sd_import_tests.mk | 2 | ||||
-rw-r--r-- | sd/qa/unit/data/pdf/txtpic.pdf | bin | 0 -> 21201 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests.cxx | 43 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 12 |
4 files changed, 54 insertions, 3 deletions
diff --git a/sd/CppunitTest_sd_import_tests.mk b/sd/CppunitTest_sd_import_tests.mk index 8a84e4c556cf..c30aef6c11cc 100644 --- a/sd/CppunitTest_sd_import_tests.mk +++ b/sd/CppunitTest_sd_import_tests.mk @@ -77,6 +77,7 @@ $(eval $(call gb_CppunitTest_use_components,sd_import_tests,\ embeddedobj/util/embobj \ filter/source/config/cache/filterconfig1 \ filter/source/svg/svgfilter \ + filter/source/xmlfilteradaptor/xmlfa \ forms/util/frm \ framework/util/fwk \ i18npool/util/i18npool \ @@ -88,6 +89,7 @@ $(eval $(call gb_CppunitTest_use_components,sd_import_tests,\ sd/util/sd \ sd/util/sdfilt \ sd/util/sdd \ + sdext/source/pdfimport/pdfimport \ sfx2/util/sfx \ sot/util/sot \ svl/source/fsstor/fsstorage \ diff --git a/sd/qa/unit/data/pdf/txtpic.pdf b/sd/qa/unit/data/pdf/txtpic.pdf Binary files differnew file mode 100644 index 000000000000..220c5822b6cf --- /dev/null +++ b/sd/qa/unit/data/pdf/txtpic.pdf diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index b4016874dd11..6e0710d78451 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -23,6 +23,8 @@ #include <editeng/postitem.hxx> #include <rsc/rscsfx.hxx> +#include <sfx2/sfxsids.hrc> +#include <svl/stritem.hxx> #include <svx/svdotext.hxx> #include <svx/svdoashp.hxx> #include <svx/svdograf.hxx> @@ -92,8 +94,11 @@ public: void testShapeLineStyle(); void testBnc862510_6(); void testBnc862510_7(); + void testPDFImport(); + void testPDFImportSkipImages(); CPPUNIT_TEST_SUITE(SdImportTest); + CPPUNIT_TEST(testDocumentLayout); CPPUNIT_TEST(testSmoketest); CPPUNIT_TEST(testN759180); @@ -123,6 +128,7 @@ public: CPPUNIT_TEST(testShapeLineStyle); CPPUNIT_TEST(testBnc862510_6); CPPUNIT_TEST(testBnc862510_7); + CPPUNIT_TEST(testPDFImport); CPPUNIT_TEST_SUITE_END(); }; @@ -1068,6 +1074,43 @@ void SdImportTest::testBnc862510_7() xDocShRef->DoClose(); } +void SdImportTest::testPDFImport() +{ + ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pdf/txtpic.pdf"), PDF); + SdDrawDocument *pDoc = xDocShRef->GetDoc(); + CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL ); + uno::Reference< drawing::XDrawPagesSupplier > xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPage > xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW ); + CPPUNIT_ASSERT_MESSAGE( "no exactly two shapes", xPage->getCount() == 2 ); + + uno::Reference< drawing::XShape > xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW ); + CPPUNIT_ASSERT_MESSAGE( "failed to load shape", xShape.is() ); + uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY)->getText(); + CPPUNIT_ASSERT_MESSAGE( "not a text shape", xText.is() ); + + xDocShRef->DoClose(); +} + +void SdImportTest::testPDFImportSkipImages() +{ + SfxAllItemSet *pParams = new SfxAllItemSet( SfxGetpApp()->GetPool() ); + pParams->Put( SfxStringItem ( SID_FILE_FILTEROPTIONS, OUString("SkipImages") ) ); + + ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pdf/txtpic.pdf"), PDF, pParams); + SdDrawDocument *pDoc = xDocShRef->GetDoc(); + CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL ); + uno::Reference< drawing::XDrawPagesSupplier > xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPage > xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW ); + CPPUNIT_ASSERT_MESSAGE( "no exactly one shape", xPage->getCount() == 1 ); + + uno::Reference< drawing::XShape > xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW ); + CPPUNIT_ASSERT_MESSAGE( "failed to load shape", xShape.is() ); + uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY)->getText(); + CPPUNIT_ASSERT_MESSAGE( "not a text shape", xText.is() ); + + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index b1472ce99236..583fe09468b7 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -23,6 +23,7 @@ #include <rtl/strbuf.hxx> #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> +#include <svl/itemset.hxx> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <drawinglayer/XShapeDumper.hxx> @@ -39,10 +40,14 @@ struct FileFormat }; // These values are taken from "Flags" in filter/source/config/fragments/filters/* +// You need to turn value of oor:name="Flags" to SFX_FILTER_*, see +// include/comphelper/documentconstants.hxx for the possible values. +// Note: 3RDPARTYFILTER == SFX_FILTER_STARONEFILTER #define ODP_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_TEMPLATE | SFX_FILTER_OWN | SFX_FILTER_DEFAULT | SFX_FILTER_ENCRYPTION | SFX_FILTER_PREFERED ) #define PPT_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN ) #define PPTX_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER | SFX_FILTER_PREFERED ) #define HTML_FORMAT_TYPE ( SFX_FILTER_EXPORT | SFX_FILTER_ALIEN ) +#define PDF_FORMAT_TYPE ( SFX_FILTER_STARONEFILTER | SFX_FILTER_ALIEN | SFX_FILTER_IMPORT | SFX_FILTER_PREFERED ) /** List of file formats we support in Impress unit tests. @@ -58,6 +63,7 @@ FileFormat aFileFormats[] = { "ppt", "MS PowerPoint 97", "Microsoft PowerPoint 97/2000/XP/2003", "sdfilt", PPT_FORMAT_TYPE }, { "pptx", "Impress Office Open XML", "Office Open XML Presentation", "", PPTX_FORMAT_TYPE }, { "html", "graphic_HTML", "graphic_HTML", "", HTML_FORMAT_TYPE }, + { "pdf", "draw_pdf_import", "pdf_Portable_Document_Format", "", PDF_FORMAT_TYPE }, { 0, 0, 0, 0, 0 } }; @@ -65,6 +71,7 @@ FileFormat aFileFormats[] = #define PPT 1 #define PPTX 2 #define HTML 3 +#define PDF 4 /// Base class for filter tests loading or roundtriping a document, and asserting the document model. class SdModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest @@ -94,7 +101,7 @@ public: protected: /// Load the document. - sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat ) + sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, SfxAllItemSet *pParams = 0 ) { FileFormat *pFmt = getFormat(nFormat); CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != NULL ); @@ -112,8 +119,7 @@ protected: aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(); - SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ); - pSrcMed->SetFilter(aFilter); + SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ, aFilter, pParams); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.Is() ) { if (xDocShRef.Is()) |