From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sw/qa/extras/rtfexport/rtfexport2.cxx | 954 ++++++++++++++++++++++++++++++++++ 1 file changed, 954 insertions(+) create mode 100644 sw/qa/extras/rtfexport/rtfexport2.cxx (limited to 'sw/qa/extras/rtfexport/rtfexport2.cxx') diff --git a/sw/qa/extras/rtfexport/rtfexport2.cxx b/sw/qa/extras/rtfexport/rtfexport2.cxx new file mode 100644 index 000000000..38d355043 --- /dev/null +++ b/sw/qa/extras/rtfexport/rtfexport2.cxx @@ -0,0 +1,954 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format") + { + } + + virtual std::unique_ptr preTest(const char* filename) override + { + m_aSavedSettings = Application::GetSettings(); + if (filename == std::string_view("fdo48023.rtf")) + { + std::unique_ptr pResetter( + new Resetter([this]() { Application::SetSettings(this->m_aSavedSettings); })); + AllSettings aSettings(m_aSavedSettings); + aSettings.SetLanguageTag(LanguageTag("ru")); + Application::SetSettings(aSettings); + return pResetter; + } + else if (filename == std::string_view("fdo44211.rtf")) + { + std::unique_ptr pResetter( + new Resetter([this]() { Application::SetSettings(this->m_aSavedSettings); })); + AllSettings aSettings(m_aSavedSettings); + aSettings.SetLanguageTag(LanguageTag("lt")); + Application::SetSettings(aSettings); + return pResetter; + } + return nullptr; + } + +protected: + AllSettings m_aSavedSettings; +}; + +DECLARE_RTFEXPORT_TEST(testFdo45553, "fdo45553.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + while (xParaEnum->hasMoreElements()) + { + uno::Reference xRangeEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference xRangeEnum = xRangeEnumAccess->createEnumeration(); + while (xRangeEnum->hasMoreElements()) + { + uno::Reference xRange(xRangeEnum->nextElement(), uno::UNO_QUERY); + OUString aStr = xRange->getString(); + if (aStr == "space-before") + CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(120)), + getProperty(xRange, "ParaTopMargin")); + else if (aStr == "space-after") + CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(240)), + getProperty(xRange, "ParaBottomMargin")); + } + } +} + +DECLARE_RTFEXPORT_TEST(testN192129, "n192129.rtf") +{ + // We expect that the result will be 16x16px. + Size aExpectedSize(16, 16); + MapMode aMap(MapUnit::Map100thMM); + aExpectedSize = Application::GetDefaultDevice()->PixelToLogic(aExpectedSize, aMap); + + uno::Reference xTextGraphicObjectsSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference xIndexAccess( + xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY); + uno::Reference xShape(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + awt::Size aActualSize(xShape->getSize()); + if ((aExpectedSize.Width() - aActualSize.Width) / 2 != 0) + { + CPPUNIT_ASSERT_EQUAL(sal_Int32(aExpectedSize.Width()), aActualSize.Width); + } + if ((aExpectedSize.Height() - aActualSize.Height) / 2 != 0) + { + CPPUNIT_ASSERT_EQUAL(sal_Int32(aExpectedSize.Height()), aActualSize.Height); + } +} + +DECLARE_RTFEXPORT_TEST(testFdo45543, "fdo45543.rtf") { CPPUNIT_ASSERT_EQUAL(5, getLength()); } + +DECLARE_RTFEXPORT_TEST(testFdo42465, "fdo42465.rtf") { CPPUNIT_ASSERT_EQUAL(3, getLength()); } + +DECLARE_RTFEXPORT_TEST(testFdo45187, "fdo45187.rtf") +{ + // There should be two shapes. + CPPUNIT_ASSERT_EQUAL(2, getShapes()); + + // They should be anchored to different paragraphs. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xTextRangeCompare(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xAnchor0 + = uno::Reference(getShape(1), uno::UNO_QUERY_THROW)->getAnchor(); + uno::Reference xAnchor1 + = uno::Reference(getShape(2), uno::UNO_QUERY_THROW)->getAnchor(); + // Was 0 ("starts at the same position"), should be 1 ("starts before") + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xTextRangeCompare->compareRegionStarts(xAnchor0, xAnchor1)); +} + +DECLARE_RTFEXPORT_TEST(testN750757, "n750757.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + + CPPUNIT_ASSERT_EQUAL(false, getProperty(xParaEnum->nextElement(), "ParaContextMargin")); + CPPUNIT_ASSERT_EQUAL(true, getProperty(xParaEnum->nextElement(), "ParaContextMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo45563, "fdo45563.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + int i = 0; + while (xParaEnum->hasMoreElements()) + { + xParaEnum->nextElement(); + i++; + } + CPPUNIT_ASSERT_EQUAL(4, i); +} + +DECLARE_RTFEXPORT_TEST(testFdo43965, "fdo43965.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + + // First paragraph: the parameter of \up was ignored + uno::Reference xRangeEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference xRangeEnum = xRangeEnumAccess->createEnumeration(); + uno::Reference xPropertySet(xRangeEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(36), getProperty(xPropertySet, "CharEscapement")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100), + getProperty(xPropertySet, "CharEscapementHeight")); + + // Second paragraph: Word vs Writer border default problem + CPPUNIT_ASSERT_EQUAL( + sal_uInt32(26), + getProperty(xParaEnum->nextElement(), "TopBorder").LineWidth); + + // Finally, make sure that we have two pages + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + +DECLARE_RTFEXPORT_TEST(testN751020, "n751020.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + CPPUNIT_ASSERT(xParaEnum->hasMoreElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(200)), + getProperty(xParaEnum->nextElement(), "ParaBottomMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo79384, "fdo79384.rtf") +{ + uno::Reference xTextRange = getRun(getParagraph(1), 1); + + CPPUNIT_ASSERT_EQUAL(OUString(u"Маркеры спискамЫ"), xTextRange->getString()); +} + +DECLARE_RTFEXPORT_TEST(testFdo47326, "fdo47326.rtf") +{ + // This was 15 only, as \super buffered text, then the contents of it got lost. + CPPUNIT_ASSERT_EQUAL(19, getLength()); +} + +DECLARE_RTFEXPORT_TEST(testFdo46955, "fdo46955.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + while (xParaEnum->hasMoreElements()) + { + uno::Reference xRangeEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference xRangeEnum = xRangeEnumAccess->createEnumeration(); + while (xRangeEnum->hasMoreElements()) + CPPUNIT_ASSERT_EQUAL(style::CaseMap::UPPERCASE, + getProperty(xRangeEnum->nextElement(), "CharCaseMap")); + } +} + +DECLARE_RTFEXPORT_TEST(testFdo81892, "fdo81892.rtf") +{ + // table was not centered + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, + getProperty(xTable, "HoriOrient")); + + // fdo#81893: paragraph with \page was not centered + uno::Reference xPara(getParagraph(2, "Performance")); + CPPUNIT_ASSERT_EQUAL( + style::ParagraphAdjust_CENTER, + static_cast(getProperty(xPara, "ParaAdjust"))); +} + +DECLARE_RTFEXPORT_TEST(testFdo45394, "fdo45394.rtf") +{ + uno::Reference xHeaderText = getProperty>( + getStyles("PageStyles")->getByName("Standard"), "HeaderText"); + OUString aActual = xHeaderText->getString(); + // Encoding in the header was wrong. + CPPUNIT_ASSERT_EQUAL(OUString(u"\u041F\u041A \u0420\u0418\u041A"), aActual); + + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); +} + +DECLARE_RTFEXPORT_TEST(testFdo48104, "fdo48104.rtf") { CPPUNIT_ASSERT_EQUAL(2, getPages()); } + +DECLARE_RTFEXPORT_TEST(testFdo47107, "fdo47107.rtf") +{ + uno::Reference xNumberingStyles(getStyles("NumberingStyles")); + // Make sure numbered and bullet legacy syntax is recognized, this used to throw a NoSuchElementException + xNumberingStyles->getByName("WWNum1"); + xNumberingStyles->getByName("WWNum2"); +} + +DECLARE_RTFEXPORT_TEST(testFdo44176, "fdo44176.rtf") +{ + uno::Reference xPageStyles(getStyles("PageStyles")); + uno::Reference xFirstPage(xPageStyles->getByName("First Page"), + uno::UNO_QUERY); + uno::Reference xDefault(xPageStyles->getByName("Standard"), + uno::UNO_QUERY); + sal_Int32 nFirstTop = 0, nDefaultTop = 0, nDefaultHeader = 0; + xFirstPage->getPropertyValue("TopMargin") >>= nFirstTop; + xDefault->getPropertyValue("TopMargin") >>= nDefaultTop; + xDefault->getPropertyValue("HeaderHeight") >>= nDefaultHeader; + CPPUNIT_ASSERT_EQUAL(nFirstTop, nDefaultTop + nDefaultHeader); +} + +DECLARE_RTFEXPORT_TEST(testFdo39053, "fdo39053.rtf") +{ + int nShapes = getShapes(); + CPPUNIT_ASSERT_EQUAL(1, nShapes); + int nAsCharacter = 0; + for (int i = 0; i < nShapes; ++i) + if (getProperty(getShape(i + 1), "AnchorType") + == text::TextContentAnchorType_AS_CHARACTER) + nAsCharacter++; + // The image in binary format was ignored. + CPPUNIT_ASSERT_EQUAL(1, nAsCharacter); +} + +DECLARE_RTFEXPORT_TEST(testFdo48356, "fdo48356.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + int i = 0; + while (xParaEnum->hasMoreElements()) + { + xParaEnum->nextElement(); + i++; + } + // The document used to be imported as two paragraphs. + CPPUNIT_ASSERT_EQUAL(1, i); +} + +DECLARE_RTFEXPORT_TEST(testFdo48023, "fdo48023.rtf") +{ + uno::Reference xTextRange = getRun(getParagraph(1), 1); + + // Implicit encoding detection based on locale was missing + CPPUNIT_ASSERT_EQUAL( + OUString(u"\u041F\u0440\u043E\u0433\u0440\u0430\u043C\u043C\u0438\u0441\u0442"), + xTextRange->getString()); +} + +DECLARE_RTFEXPORT_TEST(testFdo48876, "fdo48876.rtf") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + CPPUNIT_ASSERT(xParaEnum->hasMoreElements()); + CPPUNIT_ASSERT_EQUAL( + style::LineSpacingMode::MINIMUM, + getProperty(xParaEnum->nextElement(), "ParaLineSpacing").Mode); +} + +DECLARE_RTFEXPORT_TEST(testFdo48193, "fdo48193.rtf") { CPPUNIT_ASSERT_EQUAL(7, getLength()); } + +DECLARE_RTFEXPORT_TEST(testFdo44211, "fdo44211.rtf") +{ + uno::Reference xTextRange = getRun(getParagraph(1), 1); + + CPPUNIT_ASSERT_EQUAL(OUString(u"\u0105\u010D\u0119"), xTextRange->getString()); +} + +DECLARE_RTFEXPORT_TEST(testFdo48037, "fdo48037.rtf") +{ + uno::Reference xNumberSupplier(mxComponent, uno::UNO_QUERY_THROW); + lang::Locale aUSLocale, aFRLocale; + aUSLocale.Language = "en"; + aFRLocale.Language = "fr"; + sal_Int32 nExpected + = xNumberSupplier->getNumberFormats()->addNewConverted("d MMMM yyyy", aUSLocale, aFRLocale); + + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + uno::Reference xPropertySet(xFields->nextElement(), uno::UNO_QUERY); + sal_Int32 nActual = 0; + xPropertySet->getPropertyValue("NumberFormat") >>= nActual; + + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} + +DECLARE_RTFEXPORT_TEST(testFdo47764, "fdo47764.rtf") +{ + // \cbpat with zero argument should mean the auto (-1) color, not a default color (black) + CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty(getParagraph(1), "ParaBackColor")); +} + +DECLARE_RTFEXPORT_TEST(testFdo38786, "fdo38786.rtf") +{ + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + // \chpgn was ignored, so exception was thrown + xFields->nextElement(); +} + +DECLARE_RTFEXPORT_TEST(testN757651, "n757651.rtf") +{ + // The bug was that due to buggy layout the text expanded to two pages. + if (Application::GetDefaultDevice()->IsFontAvailable(u"Times New Roman")) + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + +DECLARE_RTFEXPORT_TEST(testFdo49501, "fdo49501.rtf") +{ + uno::Reference xStyle(getStyles("PageStyles")->getByName("Standard"), + uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(true, getProperty(xStyle, "IsLandscape")); + sal_Int32 nExpected(convertTwipToMm100(567)); + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty(xStyle, "LeftMargin")); + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty(xStyle, "RightMargin")); + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty(xStyle, "TopMargin")); + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty(xStyle, "BottomMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo49271, "fdo49271.rtf") +{ + CPPUNIT_ASSERT_EQUAL(25.f, getProperty(getParagraph(2), "CharHeight")); +} + +DECLARE_RTFEXPORT_TEST(testFdo50539, "fdo50539.rtf") +{ + // \chcbpat with zero argument should mean the auto (-1) color, not a default color (black) + CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty(getRun(getParagraph(1), 1), "CharBackColor")); +} + +DECLARE_RTFEXPORT_TEST(testFdo50665, "fdo50665.rtf") +{ + // Access the second run, which is a textfield + uno::Reference xRun(getRun(getParagraph(1), 2), uno::UNO_QUERY); + // This used to be the default, as character properties were ignored. + CPPUNIT_ASSERT_EQUAL(OUString("Book Antiqua"), getProperty(xRun, "CharFontName")); +} + +DECLARE_RTFEXPORT_TEST(testFdo49659, "fdo49659.rtf") +{ + // Both tables were ignored: 1) was in the header, 2) was ignored due to missing empty par at the end of the doc + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); + + // The graphic was also empty + uno::Reference xGraphic + = getProperty>(getShape(1), "Graphic"); + CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, + getProperty(xGraphic, "GraphicType")); +} + +DECLARE_RTFEXPORT_TEST(testFdo46966, "fdo46966.rtf") +{ + /* + * The problem was the top margin was 1440 (1 inch), but it should be 720 (0.5 inch). + * + * xray ThisComponent.StyleFamilies.PageStyles.Default.TopMargin + */ + uno::Reference xPropertySet(getStyles("PageStyles")->getByName("Standard"), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(720)), + getProperty(xPropertySet, "TopMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo76633, "fdo76633.rtf") +{ + // check that there is only a graphic object, not an additional rectangle + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShape.is()); + CPPUNIT_ASSERT(xShape->supportsService("com.sun.star.text.TextGraphicObject")); +} + +DECLARE_RTFEXPORT_TEST(testFdo48033, "fdo48033.rtf") +{ + /* + * The problem was that the picture (48033) or OLE object (53594) was in the first cell, + * instead of the second one. + * + * oTable = ThisComponent.TextTables(0) + * oParas = oTable.getCellByName("B1").Text.createEnumeration + * oPara = oParas.nextElement + * oRuns = oPara.createEnumeration + * oRun = oRuns.nextElement + * xray oRun.TextPortionType ' Frame, was Text + */ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xCell->getText(), uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Frame"), + getProperty(getRun(xPara, 1), "TextPortionType")); +} + +DECLARE_RTFEXPORT_TEST(testFdo53594, "fdo53594.rtf") +{ + /* + * The problem was that the picture (48033) or OLE object (53594) was in the first cell, + * instead of the second one. + * + * oTable = ThisComponent.TextTables(0) + * oParas = oTable.getCellByName("B1").Text.createEnumeration + * oPara = oParas.nextElement + * oRuns = oPara.createEnumeration + * oRun = oRuns.nextElement + * xray oRun.TextPortionType ' Frame, was Text + */ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xCell->getText(), uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Frame"), + getProperty(getRun(xPara, 1), "TextPortionType")); +} + +DECLARE_RTFEXPORT_TEST(testFdo36089, "fdo36089.rtf") +{ + CPPUNIT_ASSERT_EQUAL(sal_Int16(-50), + getProperty(getRun(getParagraph(1), 2), "CharEscapement")); +} + +DECLARE_RTFEXPORT_TEST(testFdo48446, "fdo48446.rtf") { getParagraph(1, u"\u0418\u043C\u044F"); } + +DECLARE_RTFEXPORT_TEST(testFdo47495, "fdo47495.rtf") +{ + // Used to have 4 paragraphs, as a result the original bugdoc had 2 pages instead of 1. + CPPUNIT_ASSERT_EQUAL(2, getParagraphs()); +} + +DECLARE_RTFEXPORT_TEST(testAllGapsWord, "all_gaps_word.rtf") +{ + BorderTest borderTest; + BorderTest::testTheBorders(mxComponent, false); +} + +DECLARE_RTFEXPORT_TEST(testFdo52389, "fdo52389.rtf") +{ + // The last '!' character at the end of the document was lost + CPPUNIT_ASSERT_EQUAL(6, getLength()); +} + +DECLARE_RTFEXPORT_TEST(testFdo49655, "fdo49655.rtf") +{ + /* + * 49655 : + * The problem was that the table was not imported due to the ' ' string in the middle of the table definition. + * + * xray ThisComponent.TextTables.Count 'was 0 + */ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); +} + +DECLARE_RTFEXPORT_TEST(testFdo62805, "fdo62805.rtf") +{ + /* + * 62805 : + * The problem was that the table was not imported due to the absence of \pard after \row. + * The table was instead in a group (the '}' replace the \pard). + */ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); +} + +DECLARE_RTFEXPORT_TEST(testFdo52475, "fdo52475.rtf") +{ + // The problem was that \chcbpat0 resulted in no color, instead of COL_AUTO. + CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty(getRun(getParagraph(1), 3), "CharBackColor")); +} + +DECLARE_RTFEXPORT_TEST(testFdo55493, "fdo55493.rtf") +{ + // The problem was that the width of the PNG was detected as 15,24cm, instead of 3.97cm + uno::Reference xShape = getShape(1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3969), xShape->getSize().Width); +} + +CPPUNIT_TEST_FIXTURE(Test, testCopyPastePageStyle) +{ + load(mpTestDocumentPath, "copypaste-pagestyle.rtf"); + // The problem was that RTF import during copy&paste did not ignore page styles. + // Once we have more copy&paste tests, makes sense to refactor this to some helper method. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xEnd = xText->getEnd(); + paste(u"rtfexport/data/copypaste-pagestyle-paste.rtf", xEnd); + + uno::Reference xPropertySet(getStyles("PageStyles")->getByName("Standard"), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(21001), + getProperty(xPropertySet, "Width")); // Was letter, i.e. 21590 +} + +CPPUNIT_TEST_FIXTURE(Test, testCopyPasteFootnote) +{ + load(mpTestDocumentPath, "copypaste-footnote.rtf"); + // The RTF import did not handle the case when the position wasn't the main document XText, but something different, e.g. a footnote. + uno::Reference xFootnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFootnotes = xFootnotesSupplier->getFootnotes(); + uno::Reference xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY); + paste(u"rtfexport/data/copypaste-footnote-paste.rtf", xTextRange); + + CPPUNIT_ASSERT_EQUAL(OUString("bbb"), xTextRange->getString()); +} + +CPPUNIT_TEST_FIXTURE(Test, testFdo63428) +{ + load(mpTestDocumentPath, "hello.rtf"); + // Pasting content that contained an annotation caused a crash. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xEnd = xText->getEnd(); + paste(u"rtfexport/data/fdo63428.rtf", xEnd); + + // Additionally, commented range was imported as a normal comment. + CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), + getProperty(getRun(getParagraph(1), 2), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), + getProperty(getRun(getParagraph(1), 4), "TextPortionType")); +} + +DECLARE_RTFEXPORT_TEST(testFdo69384, "fdo69384-paste.rtf") +{ + // Ensure non-default style is loaded + getStyles("ParagraphStyles")->getByName("Text body justified"); + // Ensure default styles were modified, vs testFdo69384Inserted where it is not + uno::Reference xPropertySet( + getStyles("ParagraphStyles")->getByName("Text Body"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(68.f, getProperty(xPropertySet, "CharHeight")); +} + +CPPUNIT_TEST_FIXTURE(Test, testFdo69384Inserted) +{ + load(mpTestDocumentPath, "hello.rtf"); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xEnd = xText->getEnd(); + paste(u"rtfexport/data/fdo69384-paste.rtf", xEnd); + + // During insert of the RTF document we do not change pre-existing styles + // vs testFdo69384 where it is + uno::Reference xPropertySet( + getStyles("ParagraphStyles")->getByName("Text Body"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(12.f, getProperty(xPropertySet, "CharHeight")); +} + +CPPUNIT_TEST_FIXTURE(Test, testFdo61193) +{ + load(mpTestDocumentPath, "hello.rtf"); + // Pasting content that contained a footnote caused a crash. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xEnd = xText->getEnd(); + paste(u"rtfexport/data/fdo61193.rtf", xEnd); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf108123) +{ + load(mpTestDocumentPath, "hello.rtf"); + // This crashed, the shape push/pop and table manager stack went out of + // sync -> we tried to de-reference an empty stack. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xEnd = xText->getEnd(); + paste(u"rtfexport/data/tdf108123.rtf", xEnd); +} + +DECLARE_RTFEXPORT_TEST(testShptxtPard, "shptxt-pard.rtf") +{ + // The problem was that \pard inside \shptxt caused loss of shape text + uno::Reference xText(getShape(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("shape text"), xText->getString()); +} + +DECLARE_RTFEXPORT_TEST(testDoDhgt, "do-dhgt.rtf") +{ + int nShapes = getShapes(); + CPPUNIT_ASSERT_EQUAL(3, nShapes); + for (int i = 0; i < nShapes; ++i) + { + Color nFillColor = getProperty(getShape(i + 1), "FillColor"); + if (nFillColor == 0xc0504d) // red + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(getShape(i + 1), "ZOrder")); + else if (nFillColor == 0x9bbb59) // green + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty(getShape(i + 1), "ZOrder")); + else if (nFillColor == 0x4f81bd) // blue + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty(getShape(i + 1), "ZOrder")); + } +} + +DECLARE_RTFEXPORT_TEST(testDplinehollow, "dplinehollow.rtf") +{ + uno::Reference xPropertySet(getShape(1), uno::UNO_QUERY); + table::BorderLine2 line(getProperty(xPropertySet, "TopBorder")); + CPPUNIT_ASSERT_EQUAL(table::BorderLineStyle::NONE, line.LineStyle); +} + +DECLARE_RTFEXPORT_TEST(testLeftmarginDefault, "leftmargin-default.rtf") +{ + // The default left/right margin was incorrect when the top margin was set to zero. + CPPUNIT_ASSERT_EQUAL( + sal_Int32(2540), + getProperty(getStyles("PageStyles")->getByName("Standard"), "LeftMargin")); +} + +DECLARE_RTFEXPORT_TEST(testDppolyline, "dppolyline.rtf") +{ + // This was completely ignored, for now, just make sure we have all 4 lines. + CPPUNIT_ASSERT_EQUAL(4, getShapes()); +} + +DECLARE_RTFEXPORT_TEST(testFdo56512, "fdo56512.rtf") +{ + uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), + uno::UNO_QUERY); + uno::Reference xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"\u05E2\u05D5\u05E1\u05E7 \u05DE\u05D5\u05E8\u05E9\u05D4 "), + xTextRange->getString()); +} + +DECLARE_RTFEXPORT_TEST(testFdo52989, "fdo52989.rtf") +{ + // Same as n#192129, but for JPEG files. + uno::Reference xShape = getShape(1); + OString aMessage = "xShape->getSize().Width() = " + OString::number(xShape->getSize().Width); + + // This was 2, should be 423 (or 369?). + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), xShape->getSize().Width >= 273); +} + +DECLARE_RTFEXPORT_TEST(testFdo54473, "fdo54473.rtf") +{ + // The problem was that character styles were not imported due to a typo. + CPPUNIT_ASSERT_EQUAL( + OUString("Anot"), + getProperty(getRun(getParagraph(1), 1, "Text "), "CharStyleName")); + CPPUNIT_ASSERT_EQUAL( + OUString("ForeignTxt"), + getProperty(getRun(getParagraph(1), 3, "character "), "CharStyleName")); +} + +DECLARE_RTFEXPORT_TEST(testFdo49934, "fdo49934.rtf") +{ + // Column break without columns defined should be a page break, but it was just ignored. + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + +DECLARE_RTFEXPORT_TEST(testFdo57886, "fdo57886.rtf") +{ + // Was 'int from to '. + CPPUNIT_ASSERT_EQUAL(OUString("int from {firstlower} to {firstupper} {firstbody}"), + getFormula(getRun(getParagraph(1), 1))); +} + +DECLARE_RTFEXPORT_TEST(testFdo58076, "fdo58076.rtf") +{ + // An additional section was created, so the default page style didn't have the custom margins. + uno::Reference xStyle(getStyles("PageStyles")->getByName("Standard"), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2251), getProperty(xStyle, "LeftMargin")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1752), getProperty(xStyle, "RightMargin")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(635), getProperty(xStyle, "TopMargin")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(635), getProperty(xStyle, "BottomMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo57678, "fdo57678.rtf") +{ + // Paragraphs of the two tables were not converted to tables. + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); +} + +DECLARE_RTFEXPORT_TEST(testFdo54612, "fdo54612.rtf") +{ + // \dpptx without a \dppolycount caused a crash. + CPPUNIT_ASSERT_EQUAL(8, getShapes()); +} + +DECLARE_RTFEXPORT_TEST(testFdo58933, "fdo58933.rtf") +{ + // The problem was that the table had an additional cell in its first line. + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + // This was 4. + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getCellNames().getLength()); +} + +DECLARE_RTFEXPORT_TEST(testFdo44053, "fdo44053.rtf") +{ + uno::Reference xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTextTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xTableRows = xTextTable->getRows(); + // The with of the table's A1 and A2 cell should equal. + CPPUNIT_ASSERT_EQUAL(getProperty>( + xTableRows->getByIndex(0), "TableColumnSeparators")[0] + .Position, + getProperty>( + xTableRows->getByIndex(1), "TableColumnSeparators")[0] + .Position); +} + +DECLARE_RTFEXPORT_TEST(testFdo48440, "fdo48440.rtf") +{ + // Page break was ignored. + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + +DECLARE_RTFEXPORT_TEST(testFdo58646line, "fdo58646line.rtf") +{ + // \line symbol was ignored + getParagraph(1, "foo\nbar"); +} + +DECLARE_RTFEXPORT_TEST(testFdo78502, "fdo78502.rtf") +{ + // ";" separators were inserted as text + getParagraph(1, "foo"); +} + +DECLARE_RTFEXPORT_TEST(testFdo58646, "fdo58646.rtf") +{ + // Page break was ignored inside a continuous section, on title page. + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + +DECLARE_RTFEXPORT_TEST(testFdo59419, "fdo59419.rtf") +{ + // Junk to be ignored broke import of the table. + uno::Reference xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); +} + +DECLARE_RTFEXPORT_TEST(testHexCRLF, "hexcrlf.rtf") +{ + // hex-escaped \r and \n should create a paragraph break + getParagraph(1, "foo"); + getParagraph(2, "bar"); + getParagraph(3, "baz"); + getParagraph(4, ""); + getParagraph(5, "quux"); +} + +DECLARE_RTFEXPORT_TEST(testFdo58076_2, "fdo58076-2.rtf") +{ + // Position of the picture wasn't correct. + CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(8345)), + getProperty(getShape(1), "HoriOrientPosition")); +} + +DECLARE_RTFEXPORT_TEST(testFdo59638, "fdo59638.rtf") +{ + // The problem was that w:lvlOverride inside w:num was ignores by dmapper. + + uno::Reference xPropertySet( + getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY); + uno::Reference xLevels( + xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + uno::Sequence aProps; + xLevels->getByIndex(0) >>= aProps; // 1st level + + for (beans::PropertyValue const& rProp : std::as_const(aProps)) + { + if (rProp.Name == "BulletChar") + { + // Was '*', should be 'o'. + CPPUNIT_ASSERT_EQUAL(OUString(u"\uF0B7"), rProp.Value.get()); + return; + } + } + CPPUNIT_FAIL("no BulletChar property"); +} + +DECLARE_RTFEXPORT_TEST(testFdo60722, "fdo60722.rtf") +{ + // The problem was that the larger shape was over the smaller one, and not the other way around. + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("larger"), getProperty(xShape, "Description")); + + xShape.set(getShape(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("smaller"), getProperty(xShape, "Description")); + + // Color of the line was blue, and it had zero width. + xShape.set(getShape(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(26), getProperty(xShape, "LineWidth")); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, getProperty(xShape, "LineColor")); +} + +DECLARE_RTFEXPORT_TEST(testDoDhgtOld, "do-dhgt-old.rtf") +{ + // The file contains 3 shapes which have the same dhgt (z-order). + // Test that the order is 1) a 2) black rectangle 3) b, and not something else + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("a"), xShape->getString()); + + xShape.set(getShape(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, getProperty(xShape, "FillColor")); + + xShape.set(getShape(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("b"), xShape->getString()); +} + +DECLARE_RTFEXPORT_TEST(testFdo61909, "fdo61909.rtf") +{ + uno::Reference xTextRange = getRun(getParagraph(1), 1); + // Was the Writer default font. + CPPUNIT_ASSERT_EQUAL(OUString("Courier New"), + getProperty(xTextRange, "CharFontName")); + CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty(xTextRange, "CharBackColor")); +} + +DECLARE_RTFEXPORT_TEST(testFdo62288, "fdo62288.rtf") +{ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xCell->getText(), uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + // Margins were inherited from the previous cell, even there was a \pard there. + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xPara, "ParaLeftMargin")); +} + +DECLARE_RTFEXPORT_TEST(testFdo37716, "fdo37716.rtf") +{ + uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFrames(xTextFramesSupplier->getTextFrames(), + uno::UNO_QUERY); + // \nowrap got ignored, so Surround was text::WrapTextMode_PARALLEL + CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_NONE, + getProperty(xFrames->getByIndex(0), "Surround")); +} + +DECLARE_RTFEXPORT_TEST(testFdo51916, "fdo51916.rtf") +{ + // Complex nested table caused a crash. +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3