| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <swmodeltestbase.hxx> |
| 11 |
|
| 12 |
#include <com/sun/star/text/XTextDocument.hpp> |
| 13 |
#include <com/sun/star/beans/XPropertySet.hpp> |
| 14 |
#include <com/sun/star/style/BreakType.hpp> |
| 15 |
#include <com/sun/star/drawing/XDrawPageSupplier.hpp> |
| 16 |
#include <com/sun/star/text/WritingMode2.hpp> |
| 17 |
#include <com/sun/star/text/XTextTablesSupplier.hpp> |
| 18 |
#include <com/sun/star/text/XTextTable.hpp> |
| 19 |
#include <com/sun/star/lang/XServiceInfo.hpp> |
| 20 |
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
| 21 |
#include <com/sun/star/document/XDocumentInsertable.hpp> |
| 22 |
#include <com/sun/star/text/XTextViewCursorSupplier.hpp> |
| 23 |
#include <com/sun/star/text/XPageCursor.hpp> |
| 24 |
|
| 25 |
#include <vcl/scheduler.hxx> |
| 26 |
#include <editeng/fhgtitem.hxx> |
| 27 |
|
| 28 |
#include <docsh.hxx> |
| 29 |
#include <ndtxt.hxx> |
| 30 |
#include <swtable.hxx> |
| 31 |
#include <txatbase.hxx> |
| 32 |
#include <wrtsh.hxx> |
| 33 |
#include <IDocumentRedlineAccess.hxx> |
| 34 |
|
| 35 |
using namespace ::com::sun::star; |
| 36 |
|
| 37 |
namespace |
| 38 |
{ |
| 39 |
/// Tests for sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx. |
| 40 |
class Test : public SwModelTestBase |
| 41 |
{ |
| 42 |
public: |
| 43 |
Test() |
| 44 |
: SwModelTestBase(u"/sw/qa/writerfilter/dmapper/data/"_ustr) |
| 45 |
{ |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
// TODO HEADER FOOTER TEST |
| 50 |
CPPUNIT_TEST_FIXTURE(Test, testPageBreakFooterTable) |
| 51 |
{ |
| 52 |
// Load a document which refers to a footer which ends with a table, and there is a page break |
| 53 |
// in the body text right after the footer reference. |
| 54 |
loadFromFile(u"page-break-footer-table.docx"); |
| 55 |
|
| 56 |
// Check the last paragraph. |
| 57 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 58 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 59 |
uno::UNO_QUERY); |
| 60 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 61 |
uno::Reference<beans::XPropertySet> xPara; |
| 62 |
while (xParaEnum->hasMoreElements()) |
| 63 |
{ |
| 64 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 65 |
} |
| 66 |
style::BreakType eType = style::BreakType_NONE; |
| 67 |
xPara->getPropertyValue(u"BreakType"_ustr) >>= eType; |
| 68 |
|
| 69 |
// Without the accompanying fix in place, this test would have failed with: |
| 70 |
// - Expected: 4 |
| 71 |
// - Actual : 0 |
| 72 |
// i.e. there was no page break before the last paragraph. |
| 73 |
CPPUNIT_ASSERT_EQUAL(style::BreakType_PAGE_BEFORE, eType); |
| 74 |
} |
| 75 |
|
| 76 |
CPPUNIT_TEST_FIXTURE(Test, testNumberingRestartStyleParent) |
| 77 |
{ |
| 78 |
loadFromFile(u"num-restart-style-parent.docx"); |
| 79 |
|
| 80 |
// The paragraphs are A 1 2 B 1 2. |
| 81 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 82 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 83 |
uno::UNO_QUERY); |
| 84 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 85 |
uno::Reference<beans::XPropertySet> xPara; |
| 86 |
static constexpr OUString aProp(u"ListLabelString"_ustr); |
| 87 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 88 |
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 89 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 90 |
CPPUNIT_ASSERT_EQUAL(u"1."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 91 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 92 |
CPPUNIT_ASSERT_EQUAL(u"2."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 93 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 94 |
CPPUNIT_ASSERT_EQUAL(u"B."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 95 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 96 |
// Without the accompanying fix in place, this test would have failed with: |
| 97 |
// - Expected: 1. |
| 98 |
// - Actual : 3. |
| 99 |
// i.e. the numbering was not restarted after B. |
| 100 |
CPPUNIT_ASSERT_EQUAL(u"1."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 101 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 102 |
CPPUNIT_ASSERT_EQUAL(u"2."_ustr, xPara->getPropertyValue(aProp).get<OUString>()); |
| 103 |
} |
| 104 |
|
| 105 |
CPPUNIT_TEST_FIXTURE(Test, testFrameDirection) |
| 106 |
{ |
| 107 |
loadFromFile(u"frame-direction.docx"); |
| 108 |
|
| 109 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 110 |
uno::Reference<container::XIndexAccess> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 111 |
uno::Reference<beans::XPropertySet> xFrame0(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 112 |
uno::Reference<beans::XPropertySet> xFrame1(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 113 |
uno::Reference<beans::XPropertySet> xFrame2(xDrawPage->getByIndex(2), uno::UNO_QUERY); |
| 114 |
// Without the accompanying fix in place, all of the following values would be text::WritingMode2::CONTEXT |
| 115 |
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::CONTEXT, |
| 116 |
xFrame0->getPropertyValue(u"WritingMode"_ustr).get<sal_Int16>()); |
| 117 |
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR, |
| 118 |
xFrame1->getPropertyValue(u"WritingMode"_ustr).get<sal_Int16>()); |
| 119 |
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, |
| 120 |
xFrame2->getPropertyValue(u"WritingMode"_ustr).get<sal_Int16>()); |
| 121 |
} |
| 122 |
|
| 123 |
CPPUNIT_TEST_FIXTURE(Test, testAltChunk) |
| 124 |
{ |
| 125 |
loadFromFile(u"alt-chunk.docx"); |
| 126 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 127 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 128 |
uno::UNO_QUERY); |
| 129 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 130 |
uno::Reference<text::XTextRange> xPara; |
| 131 |
uno::Reference<beans::XPropertySet> xParaProps; |
| 132 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 133 |
xParaProps.set(xPara, uno::UNO_QUERY); |
| 134 |
CPPUNIT_ASSERT_EQUAL(u"outer, before sect break"_ustr, xPara->getString()); |
| 135 |
CPPUNIT_ASSERT_EQUAL(u"Standard"_ustr, |
| 136 |
xParaProps->getPropertyValue(u"PageStyleName"_ustr).get<OUString>()); |
| 137 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 138 |
xParaProps.set(xPara, uno::UNO_QUERY); |
| 139 |
CPPUNIT_ASSERT_EQUAL(u"outer, after sect break"_ustr, xPara->getString()); |
| 140 |
|
| 141 |
// Without the accompanying fix in place, this test would have failed with: |
| 142 |
// - Expected: Converted1 |
| 143 |
// - Actual : Standard |
| 144 |
// i.e. the page break between the first and the second paragraph was missing. |
| 145 |
CPPUNIT_ASSERT_EQUAL(u"Converted1"_ustr, |
| 146 |
xParaProps->getPropertyValue(u"PageStyleName"_ustr).get<OUString>()); |
| 147 |
|
| 148 |
// Without the accompanying fix in place, this test would have failed with a |
| 149 |
// container.NoSuchElementException, as the document had only 2 paragraphs, all the "inner" |
| 150 |
// content was lost. |
| 151 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 152 |
CPPUNIT_ASSERT_EQUAL(u"inner doc, first para"_ustr, xPara->getString()); |
| 153 |
} |
| 154 |
|
| 155 |
CPPUNIT_TEST_FIXTURE(Test, testAltChunkHtml) |
| 156 |
{ |
| 157 |
loadFromFile(u"alt-chunk-html.docx"); |
| 158 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY_THROW); |
| 159 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 160 |
uno::UNO_QUERY_THROW); |
| 161 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 162 |
uno::Reference<text::XTextRange> xPara; |
| 163 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY_THROW); |
| 164 |
CPPUNIT_ASSERT_EQUAL(u"outer para 1"_ustr, xPara->getString()); |
| 165 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY_THROW); |
| 166 |
CPPUNIT_ASSERT_EQUAL(u"HTML AltChunk"_ustr, xPara->getString()); |
| 167 |
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY_THROW); |
| 168 |
CPPUNIT_ASSERT_EQUAL(u"outer para 2"_ustr, xPara->getString()); |
| 169 |
} |
| 170 |
|
| 171 |
CPPUNIT_TEST_FIXTURE(Test, testFieldIfInsideIf) |
| 172 |
{ |
| 173 |
// Load a document with a field in a table cell: it contains an IF field with various nested |
| 174 |
// fields. |
| 175 |
loadFromFile(u"field-if-inside-if.docx"); |
| 176 |
uno::Reference<text::XTextTablesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 177 |
uno::Reference<container::XIndexAccess> xTables(xTextDocument->getTextTables(), uno::UNO_QUERY); |
| 178 |
uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); |
| 179 |
|
| 180 |
// Get the result of the topmost field. |
| 181 |
uno::Reference<text::XTextRange> xCell(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY); |
| 182 |
|
| 183 |
// Without the accompanying fix in place, this test would have failed with: |
| 184 |
// - Expected: 2 |
| 185 |
// - Actual : 0** Expression is faulty **2 |
| 186 |
// i.e. some of the inner fields escaped outside the outer field. |
| 187 |
CPPUNIT_ASSERT_EQUAL(u"2"_ustr, xCell->getString()); |
| 188 |
|
| 189 |
// Test the second cell: it contains "IF ", not the usual " IF ". |
| 190 |
xCell.set(xTable->getCellByName(u"A2"_ustr), uno::UNO_QUERY); |
| 191 |
|
| 192 |
// Without the accompanying fix in place, this test would have failed with: |
| 193 |
// - Expected: 25 |
| 194 |
// - Actual : 025 |
| 195 |
// i.e. some of the inner fields escaped outside the outer field. |
| 196 |
CPPUNIT_ASSERT_EQUAL(u"25"_ustr, xCell->getString()); |
| 197 |
} |
| 198 |
|
| 199 |
CPPUNIT_TEST_FIXTURE(Test, testCreateDatePreserve) |
| 200 |
{ |
| 201 |
loadFromFile(u"create-date-preserve.docx"); |
| 202 |
// Trigger idle layout. |
| 203 |
Scheduler::ProcessEventsToIdle(); |
| 204 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 205 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 206 |
uno::UNO_QUERY); |
| 207 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 208 |
uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(), |
| 209 |
uno::UNO_QUERY); |
| 210 |
uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration(); |
| 211 |
uno::Reference<text::XTextRange> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 212 |
// Without the accompanying fix in place, this test would have failed with: |
| 213 |
// - Expected: 7/7/2020 10:11:00 AM |
| 214 |
// - Actual : 07/07/2020 |
| 215 |
// i.e. the formatting of the create date field was lost. |
| 216 |
CPPUNIT_ASSERT_EQUAL(u"7/7/2020 10:11:00 AM"_ustr, xPortion->getString()); |
| 217 |
} |
| 218 |
|
| 219 |
CPPUNIT_TEST_FIXTURE(Test, testChartZOrder) |
| 220 |
{ |
| 221 |
// Given a document with a chart and a shape on it: |
| 222 |
loadFromFile(u"chart-zorder.docx"); |
| 223 |
|
| 224 |
// Then make sure the shape is on top of the chart: |
| 225 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 226 |
uno::Reference<container::XIndexAccess> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 227 |
uno::Reference<lang::XServiceInfo> xChart(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 228 |
// Without the accompanying fix in place, this test would have failed, as the chart was on top |
| 229 |
// of the shape. |
| 230 |
CPPUNIT_ASSERT(xChart->supportsService(u"com.sun.star.text.TextEmbeddedObject"_ustr)); |
| 231 |
} |
| 232 |
|
| 233 |
CPPUNIT_TEST_FIXTURE(Test, testPTab) |
| 234 |
{ |
| 235 |
// Given a document that has a <w:ptab> to render a linebreak: |
| 236 |
loadFromFile(u"ptab.docx"); |
| 237 |
|
| 238 |
// Then make sure that the Writer doc model contains that linebreak: |
| 239 |
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, |
| 240 |
uno::UNO_QUERY); |
| 241 |
uno::Reference<container::XNameAccess> xStyleFamilies |
| 242 |
= xStyleFamiliesSupplier->getStyleFamilies(); |
| 243 |
uno::Reference<container::XNameAccess> xStyleFamily( |
| 244 |
xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY); |
| 245 |
uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Standard"_ustr), |
| 246 |
uno::UNO_QUERY); |
| 247 |
auto xFooter |
| 248 |
= xStyle->getPropertyValue(u"FooterText"_ustr).get<uno::Reference<text::XTextRange>>(); |
| 249 |
// Without the accompanying fix in place, this test would have failed with: |
| 250 |
// - Expected: <space><newline>1\n |
| 251 |
// - Actual: <space><tab>1\n |
| 252 |
// i.e. the layout height of the footer text was incorrect, the page number field was not |
| 253 |
// visually inside the background shape. |
| 254 |
CPPUNIT_ASSERT_EQUAL(u" \n1" SAL_NEWLINE_STRING ""_ustr, xFooter->getString()); |
| 255 |
} |
| 256 |
|
| 257 |
CPPUNIT_TEST_FIXTURE(Test, testPasteOle) |
| 258 |
{ |
| 259 |
// Given an empty document: |
| 260 |
loadFromURL(u"private:factory/swriter"_ustr); |
| 261 |
|
| 262 |
// When pasting RTF into that document: |
| 263 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 264 |
uno::Reference<text::XText> xText = xTextDocument->getText(); |
| 265 |
uno::Reference<document::XDocumentInsertable> xCursor( |
| 266 |
xText->createTextCursorByRange(xText->getStart()), uno::UNO_QUERY); |
| 267 |
OUString aURL = createFileURL(u"paste-ole.rtf"); |
| 268 |
xCursor->insertDocumentFromURL(aURL, {}); |
| 269 |
|
| 270 |
// Then make sure that all the 3 paragraphs of the paste data (empty para, OLE obj, text) are |
| 271 |
// inserted to the document: |
| 272 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xText, uno::UNO_QUERY); |
| 273 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 274 |
xParaEnum->nextElement(); |
| 275 |
// Without the accompanying fix in place, this test would have failed, as the paste result was a |
| 276 |
// single paragraph, containing the OLE object, and the content after the OLE object was lost. |
| 277 |
CPPUNIT_ASSERT(xParaEnum->hasMoreElements()); |
| 278 |
xParaEnum->nextElement(); |
| 279 |
CPPUNIT_ASSERT(xParaEnum->hasMoreElements()); |
| 280 |
uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 281 |
CPPUNIT_ASSERT_EQUAL(u"hello"_ustr, xPara->getString()); |
| 282 |
} |
| 283 |
|
| 284 |
CPPUNIT_TEST_FIXTURE(Test, testClearingBreak) |
| 285 |
{ |
| 286 |
// Given a document with a clearing break: |
| 287 |
loadFromFile(u"clearing-break.docx"); |
| 288 |
|
| 289 |
// Then make sure that the clear property of the break is not ignored: |
| 290 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 291 |
uno::Reference<text::XText> xText = xTextDocument->getText(); |
| 292 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xText, uno::UNO_QUERY); |
| 293 |
uno::Reference<container::XEnumeration> xParagraphs = xParaEnumAccess->createEnumeration(); |
| 294 |
uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), |
| 295 |
uno::UNO_QUERY); |
| 296 |
uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); |
| 297 |
xPortions->nextElement(); |
| 298 |
xPortions->nextElement(); |
| 299 |
// Without the accompanying fix in place, this test would have failed with: |
| 300 |
// An uncaught exception of type com.sun.star.container.NoSuchElementException |
| 301 |
// i.e. the first para was just a fly + text portion, the clearing break was lost. |
| 302 |
uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); |
| 303 |
OUString aPortionType; |
| 304 |
xPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; |
| 305 |
CPPUNIT_ASSERT_EQUAL(u"LineBreak"_ustr, aPortionType); |
| 306 |
uno::Reference<text::XTextContent> xLineBreak; |
| 307 |
xPortion->getPropertyValue(u"LineBreak"_ustr) >>= xLineBreak; |
| 308 |
sal_Int16 eClear{}; |
| 309 |
uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, uno::UNO_QUERY); |
| 310 |
xLineBreakProps->getPropertyValue(u"Clear"_ustr) >>= eClear; |
| 311 |
// SwLineBreakClear::ALL |
| 312 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(3), eClear); |
| 313 |
} |
| 314 |
|
| 315 |
CPPUNIT_TEST_FIXTURE(Test, testContentControlDateDataBinding) |
| 316 |
{ |
| 317 |
// Given a document with date content control and data binding, data binding date is 2012, |
| 318 |
// in-document date is 2022: |
| 319 |
loadFromFile(u"content-control-date-data-binding.docx"); |
| 320 |
|
| 321 |
// Then make sure that the date is from the data binding, not from document.xml: |
| 322 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 323 |
uno::Reference<text::XText> xText = xTextDocument->getText(); |
| 324 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xText, uno::UNO_QUERY); |
| 325 |
uno::Reference<container::XEnumeration> xParagraphs = xParaEnumAccess->createEnumeration(); |
| 326 |
uno::Reference<text::XTextRange> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); |
| 327 |
// Without the accompanying fix in place, this test would have failed with: |
| 328 |
// - Expected: 4/26/2012 |
| 329 |
// - Actual : 4/26/2022 |
| 330 |
// i.e. the date was from document.xml, which is considered outdated. |
| 331 |
CPPUNIT_ASSERT_EQUAL(u"4/26/2012"_ustr, xParagraph->getString()); |
| 332 |
} |
| 333 |
|
| 334 |
CPPUNIT_TEST_FIXTURE(Test, testContentControlDataBindingColor) |
| 335 |
{ |
| 336 |
// Given a document with an inline content control with data binding, placeholder char color is |
| 337 |
// set to red, when loading that document: |
| 338 |
loadFromFile(u"content-control-data-binding-color.docx"); |
| 339 |
|
| 340 |
// Then make sure that the placeholder char color is not in the document, since data binding is |
| 341 |
// active: |
| 342 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 343 |
uno::Reference<text::XText> xText = xTextDocument->getText(); |
| 344 |
uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); |
| 345 |
xCursor->gotoEnd(/*bExpand=*/false); |
| 346 |
xCursor->goLeft(/*nCount=*/1, /*bExpand=*/false); |
| 347 |
uno::Reference<beans::XPropertySet> xCursorProps(xCursor, uno::UNO_QUERY); |
| 348 |
Color nColor; |
| 349 |
CPPUNIT_ASSERT(xCursorProps->getPropertyValue(u"CharColor"_ustr) >>= nColor); |
| 350 |
// Without the accompanying fix in place, this test would have failed with: |
| 351 |
// - Expected: rgba[ffffff00] |
| 352 |
// - Actual : rgba[ff0000ff] |
| 353 |
// i.e. the char color was red, not the default / automatic. |
| 354 |
CPPUNIT_ASSERT_EQUAL(COL_AUTO, nColor); |
| 355 |
} |
| 356 |
|
| 357 |
CPPUNIT_TEST_FIXTURE(Test, testFloatingTableSectionBreak) |
| 358 |
{ |
| 359 |
// Given a document with 2 floating tables and 2 pages, section break (next page) between the |
| 360 |
// two: |
| 361 |
loadFromFile(u"floating-table-section-break.docx"); |
| 362 |
|
| 363 |
// When going to the last page: |
| 364 |
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); |
| 365 |
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier( |
| 366 |
xModel->getCurrentController(), uno::UNO_QUERY); |
| 367 |
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), |
| 368 |
uno::UNO_QUERY); |
| 369 |
xCursor->jumpToLastPage(); |
| 370 |
|
| 371 |
// Then make sure that we're on page 2: |
| 372 |
// Without the accompanying fix in place, this test would have failed with: |
| 373 |
// - Expected: 2 |
| 374 |
// - Actual : 1 |
| 375 |
// i.e. the document was of 1 page, the section break was lost. |
| 376 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), xCursor->getPage()); |
| 377 |
} |
| 378 |
|
| 379 |
CPPUNIT_TEST_FIXTURE(Test, testFloattableSectend) |
| 380 |
{ |
| 381 |
// Given a document with 2 tables, table 1 on page 1, table 2 on page 2: |
| 382 |
loadFromFile(u"floattable-sectend.docx"); |
| 383 |
|
| 384 |
// When importing that document and listing the tables: |
| 385 |
uno::Reference<text::XTextTablesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 386 |
uno::Reference<container::XIndexAccess> xTables(xTextDocument->getTextTables(), uno::UNO_QUERY); |
| 387 |
|
| 388 |
// Then make sure that we have two tables: |
| 389 |
// Without the accompanying fix in place, this test would have failed with: |
| 390 |
// - Expected: 2 |
| 391 |
// - Actual : 1 |
| 392 |
// i.e. the first table was lost. |
| 393 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xTables->getCount()); |
| 394 |
} |
| 395 |
|
| 396 |
CPPUNIT_TEST_FIXTURE(Test, testRedlinedShapeThenSdt) |
| 397 |
{ |
| 398 |
// Given a file with a second paragraph where text is followed by a redline, then an SDT: |
| 399 |
// When importing that document: |
| 400 |
loadFromFile(u"redlined-shape-sdt.docx"); |
| 401 |
|
| 402 |
// Then make sure the content control doesn't start at para start: |
| 403 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 404 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 405 |
uno::UNO_QUERY); |
| 406 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 407 |
xParaEnum->nextElement(); |
| 408 |
uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(), |
| 409 |
uno::UNO_QUERY); |
| 410 |
uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration(); |
| 411 |
|
| 412 |
uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 413 |
// Without the accompanying fix in place, this test would have failed with: |
| 414 |
// - Expected: Text |
| 415 |
// - Actual : ContentControl |
| 416 |
// i.e. the content control started at para start. |
| 417 |
CPPUNIT_ASSERT_EQUAL(u"Text"_ustr, |
| 418 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 419 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 420 |
// Redline start+end pair, containing a pair of text portions with an anchored object in the |
| 421 |
// middle. |
| 422 |
CPPUNIT_ASSERT_EQUAL(u"Redline"_ustr, |
| 423 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 424 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 425 |
CPPUNIT_ASSERT_EQUAL(u"Text"_ustr, |
| 426 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 427 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 428 |
CPPUNIT_ASSERT_EQUAL(u"Frame"_ustr, |
| 429 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 430 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 431 |
CPPUNIT_ASSERT_EQUAL(u"Text"_ustr, |
| 432 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 433 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 434 |
CPPUNIT_ASSERT_EQUAL(u"Redline"_ustr, |
| 435 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 436 |
xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 437 |
CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, |
| 438 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 439 |
} |
| 440 |
|
| 441 |
CPPUNIT_TEST_FIXTURE(Test, testClearingBreakSectEnd) |
| 442 |
{ |
| 443 |
// Given a file with a single-paragraph section, ends with a clearing break: |
| 444 |
// When importing that document: |
| 445 |
loadFromFile(u"clearing-break-sect-end.docx"); |
| 446 |
|
| 447 |
// Then make sure the clearing break is not lost before a cont sect break: |
| 448 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 449 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 450 |
uno::UNO_QUERY); |
| 451 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 452 |
uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(), |
| 453 |
uno::UNO_QUERY); |
| 454 |
uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration(); |
| 455 |
uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); |
| 456 |
// Without the accompanying fix in place, this test would have failed with: |
| 457 |
// - Expected: LineBreak |
| 458 |
// - Actual : Text |
| 459 |
// i.e. the clearing break at sect end was lost, leading to text overlap. |
| 460 |
CPPUNIT_ASSERT_EQUAL(u"LineBreak"_ustr, |
| 461 |
xPortion->getPropertyValue(u"TextPortionType"_ustr).get<OUString>()); |
| 462 |
} |
| 463 |
|
| 464 |
CPPUNIT_TEST_FIXTURE(Test, testParaStyleLostNumbering) |
| 465 |
{ |
| 466 |
// Given a document with a first paragraph, its paragraph style has a numbering: |
| 467 |
// When loading the document: |
| 468 |
loadFromFile(u"para-style-lost-numbering.docx"); |
| 469 |
|
| 470 |
// Then make sure that the paragraph style name has no unexpected leading whitespace: |
| 471 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 472 |
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), |
| 473 |
uno::UNO_QUERY); |
| 474 |
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); |
| 475 |
uno::Reference<beans::XPropertySet> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); |
| 476 |
OUString aParaStyleName; |
| 477 |
xPara->getPropertyValue("ParaStyleName") >>= aParaStyleName; |
| 478 |
// Without the accompanying fix in place, this test would have failed with: |
| 479 |
// - Expected: Signature |
| 480 |
// - Actual : Signature |
| 481 |
// i.e. there was an unwanted space at the start. |
| 482 |
CPPUNIT_ASSERT_EQUAL(u"Signature"_ustr, aParaStyleName); |
| 483 |
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, |
| 484 |
uno::UNO_QUERY); |
| 485 |
// Also make sure the paragraph style has a numbering associated with it: |
| 486 |
uno::Reference<container::XNameAccess> xStyleFamilies |
| 487 |
= xStyleFamiliesSupplier->getStyleFamilies(); |
| 488 |
uno::Reference<container::XNameAccess> xStyleFamily( |
| 489 |
xStyleFamilies->getByName(u"ParagraphStyles"_ustr), uno::UNO_QUERY); |
| 490 |
uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Signature"_ustr), |
| 491 |
uno::UNO_QUERY); |
| 492 |
OUString aNumberingStyleName; |
| 493 |
// Without the accompanying fix in place, this test would have failed, the WWNum14 list was set |
| 494 |
// only as direct formatting, not at a style level. |
| 495 |
xStyle->getPropertyValue("NumberingStyleName") >>= aNumberingStyleName; |
| 496 |
CPPUNIT_ASSERT(!aNumberingStyleName.isEmpty()); |
| 497 |
} |
| 498 |
|
| 499 |
CPPUNIT_TEST_FIXTURE(Test, testIfField) |
| 500 |
{ |
| 501 |
// Without the accompanying fix in place, this test would have failed, the document failed to |
| 502 |
// load. |
| 503 |
loadFromFile(u"if-field.docx"); |
| 504 |
} |
| 505 |
|
| 506 |
CPPUNIT_TEST_FIXTURE(Test, testFieldCharHeightHeaderToC) |
| 507 |
{ |
| 508 |
// Given a document with a header that has a field with a custom font size, while the document |
| 509 |
// ends with a table of contents: |
| 510 |
// When importing that document: |
| 511 |
createSwDoc("field-char-height-header-toc.docx"); |
| 512 |
|
| 513 |
// Then make sure the custom font size is not lost: |
| 514 |
SwDocShell* pDocShell = getSwDocShell(); |
| 515 |
// Navigate to the start of the only table's B1 cell. |
| 516 |
SwDoc* pDoc = pDocShell->GetDoc(); |
| 517 |
sw::TableFrameFormats& rTableFormats = *pDoc->GetTableFrameFormats(); |
| 518 |
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rTableFormats.size()); |
| 519 |
SwTableFormat* pTableFormat = rTableFormats[0]; |
| 520 |
SwTable* pTable = SwTable::FindTable(pTableFormat); |
| 521 |
const SwTableBox* pCell = pTable->GetTableBox(u"B1"_ustr); |
| 522 |
// Get the font size there. |
| 523 |
const SwStartNode* pStartNode = pCell->GetSttNd(); |
| 524 |
SwNodeIndex aNodeIndex(*pStartNode); |
| 525 |
++aNodeIndex; |
| 526 |
const SwTextNode* pTextNode = aNodeIndex.GetNode().GetTextNode(); |
| 527 |
SwTextAttr* pAttr = pTextNode->GetTextAttrAt(0, RES_TXTATR_AUTOFMT); |
| 528 |
// Without the accompanying fix in place, this test would have failed, there was no direct |
| 529 |
// formatting, so we got 12pt from style instead of the wanted 24pt. |
| 530 |
CPPUNIT_ASSERT(pAttr); |
| 531 |
const SwFormatAutoFormat& rAutoFormat |
| 532 |
= static_txtattr_cast<SwTextAttrEnd*>(pAttr)->GetAutoFormat(); |
| 533 |
const SvxFontHeightItem& rFontHeightItem |
| 534 |
= rAutoFormat.GetStyleHandle()->Get(RES_CHRATR_FONTSIZE); |
| 535 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(480), rFontHeightItem.GetHeight()); |
| 536 |
} |
| 537 |
|
| 538 |
CPPUNIT_TEST_FIXTURE(Test, testAnnotationMarkRedline) |
| 539 |
{ |
| 540 |
// Given a document with a commented text range, inside a redline: |
| 541 |
// When importing that document: |
| 542 |
createSwDoc("redline-range-comment.docx"); |
| 543 |
|
| 544 |
// Then make sure the comment anchor is inside a redline: |
| 545 |
SwDocShell* pDocShell = getSwDocShell(); |
| 546 |
SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); |
| 547 |
pWrtShell->SttEndDoc(/*bStt=*/true); |
| 548 |
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 7, /*bBasicCall=*/false); |
| 549 |
SwPaM* pCursor = pWrtShell->GetCursor(); |
| 550 |
SwField* pField = SwCursorShell::GetFieldAtCursor(pCursor, true); |
| 551 |
CPPUNIT_ASSERT_EQUAL(SwFieldIds::Postit, pField->Which()); |
| 552 |
const IDocumentRedlineAccess& rIDRA = pDocShell->GetDoc()->getIDocumentRedlineAccess(); |
| 553 |
const SwRangeRedline* pRedline = rIDRA.GetRedline(*pCursor->Start(), nullptr); |
| 554 |
// Without the accompanying fix in place, this test would have failed, the anchor point was not |
| 555 |
// inside a redline. |
| 556 |
CPPUNIT_ASSERT(pRedline); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |