/* -*- 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/.
*/
/** Split these tests into their own file because they are really really slow
*/
namespace
{ class Test : public SwModelTestBase
{ public:
Test()
: SwModelTestBase(u"/sw/qa/extras/rtfexport/data/"_ustr, u"Rich Text Format"_ustr)
{
}
};
auto& rFlys = *pDoc->GetSpzFrameFormats(); if (bIsExport)
{ // 2, not 3: the form control becomes a field on export...
CPPUNIT_ASSERT_EQUAL(size_t(2), rFlys.size());
} else
{
CPPUNIT_ASSERT_EQUAL(size_t(3), rFlys.size());
}
CPPUNIT_TEST_FIXTURE(Test, testParaAdjustDistribute)
{ auto verify = [this]() { // Without the accompanying fix in place, this test would have failed with // 'Expected: 2; Actual : 0', i.e. the first paragraph's ParaAdjust was // left, not block.
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_BLOCK, static_cast<style::ParagraphAdjust>(
getProperty<sal_Int16>(getParagraph(1), u"ParaAdjust"_ustr)));
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_BLOCK, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(
getParagraph(1), u"ParaLastLineAdjust"_ustr)));
CPPUNIT_TEST_FIXTURE(Test, testBtlrCell)
{ auto verify = [this]() { // Without the accompanying fix in place, this test would have failed, as // the btlr text direction in the A1 cell was lost.
uno::Reference<text::XTextTablesSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xTables = xSupplier->getTextTables();
uno::Reference<text::XTextTable> xTable(xTables->getByName(u"Table1"_ustr), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xA1(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR,
getProperty<sal_Int16>(xA1, u"WritingMode"_ustr));
// Without the fix in place, this test would have failed with // - Expected: 0 // - Actual : 1
CPPUNIT_ASSERT_EQUAL(text::VertOrientation::NONE,
getProperty<sal_Int16>(getShape(1), u"VertOrient"_ustr));
};
createSwDoc("tdf114303.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testTbrlFrame)
{ auto verify = [this]() {
CPPUNIT_ASSERT_EQUAL(1, getShapes());
CPPUNIT_ASSERT_EQUAL(1, getPages());
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); auto nActual = getProperty<sal_Int16>(xShape, u"WritingMode"_ustr); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2 // - Actual : 0 // i.e. custom writing mode was lost.
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, nActual);
};
createSwDoc("tbrl-frame.odt");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testBtlrFrame)
{ auto verify = [this]() {
CPPUNIT_ASSERT_EQUAL(1, getShapes());
CPPUNIT_ASSERT_EQUAL(1, getPages());
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); auto nActual = getProperty<sal_Int16>(xShape, u"WritingMode"_ustr); // Without the accompanying fix in place, this test would have failed with: // - Expected: 5 // - Actual : 0 // i.e. custom writing mode was lost.
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR, nActual);
};
createSwDoc("btlr-frame.odt");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testTdf129631_lostBorders)
{ auto verify = [this]() {
uno::Reference<container::XNameAccess> paragraphStyles = getStyles(u"ParagraphStyles"_ustr);
uno::Reference<beans::XPropertySet> xStyleProps(paragraphStyles->getByName(u"Border"_ustr),
uno::UNO_QUERY_THROW);
table::BorderLine2 aBorderLine
= getProperty<table::BorderLine2>(xStyleProps, u"RightBorder"_ustr);
CPPUNIT_ASSERT(sal_uInt32(0) != aBorderLine.LineWidth);
CPPUNIT_ASSERT_EQUAL_MESSAGE( "The border style has normal black borders", COL_BLACK,
Color(ColorTransparency,
getProperty<table::BorderLine>(xStyleProps, u"RightBorder"_ustr).Color));
aBorderLine = getProperty<table::BorderLine2>(getParagraph(2), u"RightBorder"_ustr);
CPPUNIT_ASSERT(sal_uInt32(0) != aBorderLine.LineWidth);
CPPUNIT_ASSERT_EQUAL_MESSAGE( "The second paragraph should have dark green borders", sal_Int32(432686),
getProperty<table::BorderLine>(getParagraph(2), u"RightBorder"_ustr).Color);
};
createSwDoc("tdf129631_lostBorders.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
xRun.set(getRun(getParagraph(1), 4, u"shadow"_ustr));
aShadow = getProperty<table::ShadowFormat>(xRun, u"CharShadowFormat"_ustr);
CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location);
table::BorderLine2 aBorderLine
= getProperty<table::BorderLine2>(xRun, u"CharRightBorder"_ustr); // MS formats can't have a shadow without a border. // Char borders are all or none, so have to decide to add borders, or throw away shadow... if (bIsExport)
CPPUNIT_ASSERT(sal_uInt32(0) != aBorderLine.LineWidth);
CPPUNIT_TEST_FIXTURE(Test, testTdf136587_noStyleName)
{ auto verify = [this]() { // An exception stopped all style definitions.
uno::Reference<container::XNameAccess> paragraphStyles = getStyles(u"ParagraphStyles"_ustr);
uno::Reference<beans::XPropertySet> xStyleProps(paragraphStyles->getByName(u"Style15"_ustr),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER),
getProperty<sal_Int16>(xStyleProps, u"ParaAdjust"_ustr));
// The problem was that the default style wasn't imported at all, so the fontsize was only 12.
xStyleProps.set(paragraphStyles->getByName(u"Standard"_ustr), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(32.0f, getProperty<float>(xStyleProps, u"CharHeight"_ustr));
};
createSwDoc("tdf136587_noStyleName.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
auto aLeftBorder = getProperty<table::BorderLine2>(xPageStyle, u"LeftBorder"_ustr);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(35), aLeftBorder.LineWidth);
auto aBottomBorder = getProperty<table::BorderLine2>(xPageStyle, u"BottomBorder"_ustr);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(53), aBottomBorder.LineWidth);
auto aRightBorder = getProperty<table::BorderLine2>(xPageStyle, u"RightBorder"_ustr);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(71), aRightBorder.LineWidth);
}
CPPUNIT_TEST_FIXTURE(Test, testTbrlPage)
{ auto verify = [this]() {
uno::Reference<beans::XPropertySet> xPageStyle(
getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); auto nActual = getProperty<sal_Int16>(xPageStyle, u"WritingMode"_ustr); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2 // - Actual : 0 // i.e. custom writing mode was lost.
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, nActual);
};
createSwDoc("tbrl-page.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testTdf126309)
{
createSwDoc("tdf126309.rtf"); // Without the accompanying fix in place, this test would have failed, as // the paragraph was aligned to left, not right.
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_RIGHT, static_cast<style::ParagraphAdjust>(
getProperty<sal_Int16>(getParagraph(1), u"ParaAdjust"_ustr)));
}
// Insert a paragraph break
pWrtShell->SplitNode(false);
// Entire table should go to page 2, no remains on first page
xmlDocUniquePtr pDump = parseLayoutDump();
assertXPath(pDump, "/root/page[1]/body/tab", 0);
assertXPath(pDump, "/root/page[2]/body/tab", 1);
};
createSwDoc("tdf116358.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testGutterLeft)
{
createSwDoc("gutter-left.rtf");
saveAndReload(u"Rich Text Format"_ustr);
uno::Reference<beans::XPropertySet> xPageStyle;
getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr) >>= xPageStyle;
sal_Int32 nGutterMargin{};
xPageStyle->getPropertyValue(u"GutterMargin"_ustr) >>= nGutterMargin; // Without the accompanying fix in place, this test would have failed with: // - Expected: 1270 // - Actual : 0 // i.e. gutter margin was lost.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), nGutterMargin);
}
CPPUNIT_TEST_FIXTURE(Test, testGutterTop)
{
createSwDoc("gutter-top.rtf");
saveAndReload(u"Rich Text Format"_ustr);
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xSettings(
xFactory->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY); bool bGutterAtTop{};
xSettings->getPropertyValue(u"GutterAtTop"_ustr) >>= bGutterAtTop; // Without the accompanying fix in place, this test would have failed, because the gutter was // at the left.
CPPUNIT_ASSERT(bGutterAtTop);
}
CPPUNIT_TEST_FIXTURE(Test, testClearingBreak)
{ auto verify = [this]() {
uno::Reference<container::XEnumerationAccess> xParagraph(getParagraph(1), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
xPortions->nextElement();
xPortions->nextElement(); // Without the accompanying fix in place, this test would have failed with: // An uncaught exception of type com.sun.star.container.NoSuchElementException // i.e. the first para was just a fly + text portion, the clearing break was lost.
uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY);
OUString aPortionType;
xPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType;
CPPUNIT_ASSERT_EQUAL(u"LineBreak"_ustr, aPortionType);
uno::Reference<text::XTextContent> xLineBreak;
xPortion->getPropertyValue(u"LineBreak"_ustr) >>= xLineBreak;
sal_Int16 eClear{};
uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, uno::UNO_QUERY);
xLineBreakProps->getPropertyValue(u"Clear"_ustr) >>= eClear;
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SwLineBreakClear::ALL), eClear);
};
// Given a document with a clearing break: // When loading that file:
createSwDoc("clearing-break.rtf"); // Then make sure that the clear property of the break is not ignored:
verify();
saveAndReload(u"Rich Text Format"_ustr); // Make sure that the clear property of the break is not ignored during export:
verify();
}
uno::Reference<text::XTextRange> xRun7
= getRun(getParagraph(7), 1, u"\u05b0\u05b1\u05b2\u05b3\u05b4"_ustr); // Do not check font for Hebrew: it can be substituted by smth able to handle these chars //CPPUNIT_ASSERT_EQUAL(OUString("Arial"), getProperty<OUString>(xRun7, "CharFontName"));
uno::Reference<text::XTextRange> xRun8
= getRun(getParagraph(8), 1, u"\u06c1\u0621\u0622\u0623\u0624"_ustr); // Do not check font for Arabic: it can be substituted by smth able to handle these chars //CPPUNIT_ASSERT_EQUAL(OUString("Arial"), getProperty<OUString>(xRun8, "CharFontName"));
// Ensure strange font remains strange. No reason to check content: in this case it can vary on locale
uno::Reference<text::XTextRange> xRun10 = getRun(getParagraph(10), 1);
CPPUNIT_ASSERT_EQUAL(u"Arial BlaBlaBla"_ustr,
getProperty<OUString>(xRun10, u"CharFontName"_ustr));
// Check some random not standard shading values and ensure some non-white background color
uno::Reference<text::XTextRange> xCell3(xTable->getCellByName(u"C1"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"c"_ustr, xCell3->getString());
Color nShadingColor3 = getProperty<Color>(xCell3, u"BackColor"_ustr);
CPPUNIT_ASSERT(COL_WHITE > nShadingColor3);
CPPUNIT_ASSERT(COL_BLACK < nShadingColor3);
// Values 10000 and more - black
uno::Reference<text::XTextRange> xCell5(xTable->getCellByName(u"E1"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"e"_ustr, xCell5->getString());
CPPUNIT_ASSERT_EQUAL(COL_BLACK, getProperty<Color>(xCell5, u"BackColor"_ustr));
// And let's ensure that there are no other horizontal borders
CPPUNIT_ASSERT_EQUAL(
sal_uInt32(0),
getProperty<table::BorderLine2>(getParagraph(1), u"BottomBorder"_ustr).LineWidth);
CPPUNIT_ASSERT_EQUAL(
sal_uInt32(0),
getProperty<table::BorderLine2>(getParagraph(2), u"BottomBorder"_ustr).LineWidth);
CPPUNIT_ASSERT_EQUAL(
sal_uInt32(0),
getProperty<table::BorderLine2>(getParagraph(3), u"BottomBorder"_ustr).LineWidth);
CPPUNIT_ASSERT_EQUAL(
sal_uInt32(0),
getProperty<table::BorderLine2>(getParagraph(4), u"BottomBorder"_ustr).LineWidth);
CPPUNIT_ASSERT_EQUAL(
sal_uInt32(0),
getProperty<table::BorderLine2>(getParagraph(5), u"BottomBorder"_ustr).LineWidth);
};
createSwDoc("tdf139948.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testTdf103956)
{ auto verify = [this]() { // Ensure that RTF tables without column width (\cellx or \cellx0) are displayed with some // suitable width. Currently there is no good support for autofit for RTF docs, so ensure // that table cells are somehow visible. Width for it is not clear, so here we will check // table & cell widths are more than default minimal value of 41.
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT_MESSAGE( "Table #1 is too narrow!",
82 < getXPath(pXmlDoc, "/root/page/body/tab[1]/row/infos/bounds", "width").toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #1 cell#1 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[1]/row/cell[1]/infos/bounds", "width")
.toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #1 cell#2 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[1]/row/cell[2]/infos/bounds", "width")
.toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #2 is too narrow!",
82 < getXPath(pXmlDoc, "/root/page/body/tab[2]/row/infos/bounds", "width").toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #2 cell#1 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[2]/row/cell[1]/infos/bounds", "width")
.toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #2 cell#2 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[2]/row/cell[2]/infos/bounds", "width")
.toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #3 is too narrow!",
82 < getXPath(pXmlDoc, "/root/page/body/tab[3]/row/infos/bounds", "width").toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #3 cell#1 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[3]/row/cell[1]/infos/bounds", "width")
.toInt32());
CPPUNIT_ASSERT_MESSAGE( "Table #3 cell#2 is too narrow!",
41 < getXPath(pXmlDoc, "/root/page/body/tab[3]/row/cell[2]/infos/bounds", "width")
.toInt32());
};
createSwDoc("tdf103956.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.