From 8ae0ce1bfa9fe6fa7fa54bafb5541c3f78d9e9b5 Mon Sep 17 00:00:00 2001 From: Kevin Suo Date: Fri, 21 Oct 2022 00:40:19 +0800 Subject: sdext.pdfimport: refactor this unit test and active it for Windows This unit test was disabled for Windows build in commit fc45e54be6ba5d4685ae4ef3c3ea696fc99cccd4, due to the "crashes on the windows jenkins boxes". In this patch, I: 1. Rename the test name to show its purpose for easier reading; 2. Test the whole string all at once using xpath, rather than use indexOf(). This way we can not only test the existance of the characters, but also the order they appear. 3. Activate it for Windows build and hope it passes on Jenkins. 4. Remove the std::cout debug code, and use CPPUNIT_ASSERT_EQUAL_MESSAGE instead, so that the xml content (i.e. aOutput) is only shown when the assertion fails. 5. Move the test document to testdocs directory. Change-Id: I39084eb4ddc451ecac5183213b7e6166facf617b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141601 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sdext/source/pdfimport/test/testTdf141709.pdf | Bin 11119 -> 0 bytes .../test/testdocs/testTdf141709_chinesechar.pdf | Bin 0 -> 11119 bytes sdext/source/pdfimport/test/tests.cxx | 28 ++++++++------------- 3 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 sdext/source/pdfimport/test/testTdf141709.pdf create mode 100644 sdext/source/pdfimport/test/testdocs/testTdf141709_chinesechar.pdf (limited to 'sdext') diff --git a/sdext/source/pdfimport/test/testTdf141709.pdf b/sdext/source/pdfimport/test/testTdf141709.pdf deleted file mode 100644 index 3198782faa73..000000000000 Binary files a/sdext/source/pdfimport/test/testTdf141709.pdf and /dev/null differ diff --git a/sdext/source/pdfimport/test/testdocs/testTdf141709_chinesechar.pdf b/sdext/source/pdfimport/test/testdocs/testTdf141709_chinesechar.pdf new file mode 100644 index 000000000000..3198782faa73 Binary files /dev/null and b/sdext/source/pdfimport/test/testdocs/testTdf141709_chinesechar.pdf differ diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx index 7cff15a36d0f..71661ae9e6d5 100644 --- a/sdext/source/pdfimport/test/tests.cxx +++ b/sdext/source/pdfimport/test/tests.cxx @@ -556,32 +556,26 @@ namespace #endif } - void testTdf141709() + void testTdf141709_chinesechar() { // this test crashes on the windows jenkins boxes, but no-one can catch it locally -#if HAVE_FEATURE_POPPLER && !defined(_WIN32) +#if HAVE_FEATURE_POPPLER rtl::Reference xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext())); xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory()); OString aOutput; CPPUNIT_ASSERT_MESSAGE("Exporting to ODF", - xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testTdf141709.pdf"), + xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testdocs/testTdf141709_chinesechar.pdf"), new OutputWrapString(aOutput), nullptr)); - std::cout << aOutput << std::endl; + xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast(aOutput.getStr()))); // This ensures that the imported text contains all of the characters - CPPUNIT_ASSERT(aOutput.indexOf("敏") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("捷") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("的") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("狐") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("狸") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("跨") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("过") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("慵") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("懒") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("的") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("狗") != -1); - CPPUNIT_ASSERT(aOutput.indexOf("。") != -1); + OString xpath = "//draw:frame[@draw:z-index='3'][1]/draw:text-box/text:p/text:span[1]"; + OUString sContent = getXPathContent(pXmlDoc, xpath).replaceAll("\n", ""); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), OUString(u"敏捷的狐狸跨过慵懒的"), sContent); + xpath = "//draw:frame[@draw:z-index='4'][1]/draw:text-box/text:p/text:span[1]"; + sContent = getXPathContent(pXmlDoc, xpath).replaceAll("\n", ""); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), OUString(u"狗。"), sContent); #endif } @@ -854,7 +848,7 @@ namespace CPPUNIT_TEST(testTdf96993); CPPUNIT_TEST(testTdf98421); CPPUNIT_TEST(testTdf105536); - CPPUNIT_TEST(testTdf141709); + CPPUNIT_TEST(testTdf141709_chinesechar); CPPUNIT_TEST(testTdf78427_FontFeatures); CPPUNIT_TEST(testTdf78427_FontWeight_MyraidProSemibold); CPPUNIT_TEST(testTdf143959_nameFromFontFile); -- cgit