/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/"; class Test : public SwModelTestBase { public: Test() : SwModelTestBase(DATA_DIRECTORY, "Office Open XML Text") {} protected: /** * Denylist handling */ bool mustTestImportOf(const char* filename) const override { // If the testcase is stored in some other format, it's pointless to test. return OString(filename).endsWith(".docx"); } }; DECLARE_OOXMLEXPORT_TEST(testTdf138892_noNumbering, "tdf138892_noNumbering.docx") { CPPUNIT_ASSERT_MESSAGE("Para1: Bullet point", !getProperty(getParagraph(1), "NumberingStyleName").isEmpty()); CPPUNIT_ASSERT_MESSAGE("Para2: ", getProperty(getParagraph(2), "NumberingStyleName").isEmpty()); CPPUNIT_ASSERT_MESSAGE("Para3: ", getProperty(getParagraph(3), "NumberingStyleName").isEmpty()); } DECLARE_OOXMLEXPORT_TEST(testTdf140668, "tdf140668.docx") { // Don't crash when document is opened CPPUNIT_ASSERT_EQUAL(1, getPages()); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134619_numberingProps, "tdf134619_numberingProps.doc") { // Get the third paragraph's numbering style's 1st level's bullet size uno::Reference xParagraph = getParagraph(3); auto xLevels = getProperty< uno::Reference >(xParagraph, "NumberingRules"); uno::Sequence aLevel; xLevels->getByIndex(0) >>= aLevel; // 1st level OUString aCharStyleName = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get(); // Make sure that the blue bullet's font size is 72 points, not 12 points. uno::Reference xStyle(getStyles("CharacterStyles")->getByName(aCharStyleName), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(72.f, getProperty(xStyle, "CharHeight")); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFooterMarginLost, "footer-margin-lost.docx") { xmlDocUniquePtr pXmlDoc = parseExport(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 709 // - Actual : 0 // i.e. import + export lost the footer margin value. assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:pgMar", "footer", "709"); } CPPUNIT_TEST_FIXTURE(Test, testEffectExtentLineWidth) { auto verify = [this]() { CPPUNIT_ASSERT_EQUAL(static_cast(508), getProperty(getShape(1), "TopMargin")); }; // Given a document with a shape that has a non-zero line width and effect extent: // When loading the document: load(mpTestDocumentPath, "effect-extent-line-width.docx"); // Then make sure that the line width is not taken twice (once as part of the margin, and then // also as the line width): // Without the accompanying fix in place, this test would have failed with: // - Expected: 508 // - Actual : 561 // i.e. the upper spacing was too large, the last line of the text moved below the shape. verify(); reload(mpFilter, "effect-extent-line-width.docx"); verify(); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf140572_docDefault_superscript, "tdf140572_docDefault_superscript.docx") { // A round-trip was crashing. // Without the fix, everything was DFLT_ESC_AUTO_SUPER (default superscript) CPPUNIT_ASSERT_EQUAL( sal_Int16(0), getProperty(getRun(getParagraph(1), 1), "CharEscapement") ); } DECLARE_OOXMLEXPORT_TEST(testTdf138953, "croppedAndRotated.odt") { CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Make sure the rotation is exported correctly, and size not distorted auto xShape(getShape(1)); CPPUNIT_ASSERT_EQUAL(27000.0, getProperty(xShape, "RotateAngle")); auto frameRect = getProperty(xShape, "FrameRect"); // Before the fix, original object size (i.e., before cropping) was written to spPr in OOXML, // and the resulting object size was much larger than should be. CPPUNIT_ASSERT_EQUAL(sal_Int32(12961), frameRect.Height); CPPUNIT_ASSERT_EQUAL(sal_Int32(8664), frameRect.Width); } DECLARE_OOXMLEXPORT_TEST(testTdf140137, "tdf140137.docx") { // Don't throw exception during load } DECLARE_OOXMLEXPORT_TEST(testTdf133473_shadowSize, "tdf133473.docx") { uno::Reference xShape = getShape(1); SdrObject* pObj(GetSdrObjectFromXShape(xShape)); const SfxItemSet& rSet = pObj->GetMergedItemSet(); sal_Int32 nSize1 = rSet.Get(SDRATTR_SHADOWSIZEX).GetValue(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 200000 // - Actual : 113386 // I.e. Shadow size will be smaller than actual. CPPUNIT_ASSERT_EQUAL(static_cast(200000), nSize1); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */