/* -*- 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 using namespace ::com::sun::star; namespace { /// Tests for writerfilter/source/rtftok/rtfdocumentimpl.cxx. class Test : public test::BootstrapFixture, public unotest::MacrosTest { private: uno::Reference mxComponent; public: void setUp() override; void tearDown() override; uno::Reference& getComponent() { return mxComponent; } }; void Test::setUp() { test::BootstrapFixture::setUp(); mxDesktop.set(frame::Desktop::create(mxComponentContext)); } void Test::tearDown() { if (mxComponent.is()) mxComponent->dispose(); test::BootstrapFixture::tearDown(); } constexpr OUStringLiteral DATA_DIRECTORY = u"/writerfilter/qa/cppunittests/rtftok/data/"; CPPUNIT_TEST_FIXTURE(Test, testPicwPich) { // Given a document with a WMF file where picwgoal and picscalex is provided, so picw is not // relevant: OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "picw-pich.rtf"; // When loading that document: getComponent() = loadFromDesktop(aURL); // Then make sure the graphic's preferred size is correct: uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage = xTextDocument->getDrawPage(); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference xGraphic; xShape->getPropertyValue("Graphic") >>= xGraphic; Graphic aGraphic(xGraphic); Size aPrefSize = aGraphic.GetPrefSize(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2619 // - Actual : 132 // i.e. the graphic width didn't match 2.62 cm from the Word UI. CPPUNIT_ASSERT_EQUAL(static_cast(2619), aPrefSize.Width()); } CPPUNIT_TEST_FIXTURE(Test, testCharHiddenInTable) { // Given a document with a table, and a hidden \line in it: OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "char-hidden-intbl.rtf"; // When loading that document: getComponent() = loadFromDesktop(aURL); // Then make sure that line is indeed hidden: uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); uno::Reference xTables(xTextDocument->getTextTables(), uno::UNO_QUERY); uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); uno::Reference xParagraphs = xCell->createEnumeration(); uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); uno::Reference xPortions = xParagraph->createEnumeration(); uno::Reference xPortion(xPortions->nextElement(), uno::UNO_QUERY); bool bCharHidden{}; xPortion->getPropertyValue("CharHidden") >>= bCharHidden; // Without the accompanying fix in place, this test would have failed, the newline was not // hidden. CPPUNIT_ASSERT(bCharHidden); } CPPUNIT_TEST_FIXTURE(Test, testDuplicatedImage) { // Given a document with 2 images: OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "duplicated-image.rtf"; // When importing that document: getComponent() = loadFromDesktop(aURL); // Then make sure no duplicated images are created: uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage = xTextDocument->getDrawPage(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2 // - Actual : 3 // i.e. there was a 3rd, duplicated image. CPPUNIT_ASSERT_EQUAL(static_cast(2), xDrawPage->getCount()); } CPPUNIT_TEST_FIXTURE(Test, testOldParaNumLeftMargin) { // Given a document with 3 paragraphs, the third one with a left indent: OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "old-para-num-left-margin.rtf"; // When importing that document: getComponent() = loadFromDesktop(aURL); // Then make sure that the third paragraph has a left indent: uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); uno::Reference xText(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParagraphs = xText->createEnumeration(); xParagraphs->nextElement(); xParagraphs->nextElement(); uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); sal_Int32 nParaLeftMargin{}; xParagraph->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin; // Without the accompanying fix in place, this test would have failed with: // - Expected: 2101 // - Actual : 0 // i.e. the left indent was 0, not 1191 twips (from the file) in mm100. CPPUNIT_ASSERT_EQUAL(static_cast(2101), nParaLeftMargin); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */