/* -*- 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/.
*/
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testRedlineFrameAtParaOneParagraph)
{ // test ALLFLYS flag: oddly enough it didn't fail as fodt but failed as odt...
testRedlineFrame("redline_fly_at_para_one_paragraph.odt");
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testRedlineFrameAtPara2ndParagraph)
{ // lost via the buggy increment in Copy
testRedlineFrame("redline_fly_duplication_at_para_2nd_paragraph.fodt");
}
//threaded reading only kicks in if there is sufficient buffer to make it worthwhile, so read //from a SvFileStream to ensure that bool bRes = TestImportFODT(aFileStream);
// all 4 shapes are on the 2nd paragraph
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr);
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr);
CPPUNIT_ASSERT_EQUAL(size_t(4), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size());
// one shape is anchored in the middle, others at the start/end/at-para
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr);
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr);
CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size());
// now try the same with redlining enabled - should be the same result
dispatchCommand(mxComponent, u".uno:ShowTrackedChanges"_ustr, {});
dispatchCommand(mxComponent, u".uno:TrackChanges"_ustr, {});
{
pWrtShell->Down(false);
pWrtShell->SttPara(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
dispatchCommand(mxComponent, u".uno:Cut"_ustr, {});
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr);
CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); // problem was that this deleted all at-char flys, even at the start/end
CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size());
CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
CPPUNIT_ASSERT_EQUAL(u"WithMargin"_ustr, getProperty<OUString>(getParagraph(1), u"PageDescName"_ustr));
CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetSections().size());
CPPUNIT_ASSERT_EQUAL(u"SourceSection"_ustr, pWrtShell->GetCurrSection()->GetSectionName().toString()); // the problem was that there was a page break now
CPPUNIT_ASSERT_EQUAL(1, getPages()); // page style WithMargin is used
CPPUNIT_ASSERT_EQUAL(tools::Long(5669), pWrtShell->GetLayout()->GetLower()->getFramePrintArea().Top());
pWrtShell->Undo();
CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
CPPUNIT_ASSERT_EQUAL(u"WithMargin"_ustr, getProperty<OUString>(getParagraph(1), u"PageDescName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"TargetSection"_ustr, pWrtShell->GetCurrSection()->GetSectionName().toString());
CPPUNIT_ASSERT_EQUAL(1, getPages()); // page style WithMargin is used
CPPUNIT_ASSERT_EQUAL(tools::Long(5669), pWrtShell->GetLayout()->GetLower()->getFramePrintArea().Top());
pWrtShell->Redo();
CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
CPPUNIT_ASSERT_EQUAL(u"WithMargin"_ustr, getProperty<OUString>(getParagraph(1), u"PageDescName"_ustr));
CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetSections().size());
CPPUNIT_ASSERT_EQUAL(u"SourceSection"_ustr, pWrtShell->GetCurrSection()->GetSectionName().toString());
CPPUNIT_ASSERT_EQUAL(1, getPages()); // page style WithMargin is used
CPPUNIT_ASSERT_EQUAL(tools::Long(5669), pWrtShell->GetLayout()->GetLower()->getFramePrintArea().Top());
pWrtShell->Undo();
CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
CPPUNIT_ASSERT_EQUAL(u"WithMargin"_ustr, getProperty<OUString>(getParagraph(1), u"PageDescName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"TargetSection"_ustr, pWrtShell->GetCurrSection()->GetSectionName().toString());
CPPUNIT_ASSERT_EQUAL(1, getPages()); // page style WithMargin is used
CPPUNIT_ASSERT_EQUAL(tools::Long(5669), pWrtShell->GetLayout()->GetLower()->getFramePrintArea().Top());
}
// check bookmark was copied to correct position
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), rIDMA.getBookmarksCount()); for (auto it(rIDMA.getBookmarksBegin()); it != rIDMA.getBookmarksEnd(); ++it)
{
OUString markText(SwPaM((*it)->GetMarkPos(), (*it)->GetOtherMarkPos()).GetText());
CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, markText);
}
// copy 2nd time, such that bCanMoveBack is false in CopyImpl
SwPaM aCopyPaM(*aPaM.GetMark(), *aPaM.GetPoint());
aPaM.SttEndDoc(true/*start*/);
rIDCO.SplitNode(*aPaM.GetPoint(), false);
aPaM.SttEndDoc(true/*start*/);
// check bookmark was copied to correct position
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rIDMA.getBookmarksCount()); for (auto it(rIDMA.getBookmarksBegin()); it != rIDMA.getBookmarksEnd(); ++it)
{
OUString markText(SwPaM((*it)->GetMarkPos(), (*it)->GetOtherMarkPos()).GetText());
CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, markText);
}
}
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"1000"_ustr, pField->GetFormula());
CPPUNIT_ASSERT_EQUAL(u"1.000"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->GoNextCell();
CPPUNIT_ASSERT_EQUAL(u"10000"_ustr, pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
pWrtShell->GoNextCell();
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"test"_ustr, pField->GetFormula());
CPPUNIT_ASSERT_EQUAL(u"1.000"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->GoNextCell(); // the problem was that this was 0
CPPUNIT_ASSERT_EQUAL(u"10000"_ustr, pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
pWrtShell->Down(false);
pWrtShell->SttPara(false);
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"1000*10%"_ustr, pField->GetFormula());
CPPUNIT_ASSERT_EQUAL(u"100"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->Down(false);
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"5.000*10%"_ustr, pField->GetFormula()); // the problem was that this was 0
CPPUNIT_ASSERT_EQUAL(u"500"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->Down(false);
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"5.000*10%"_ustr, pField->GetFormula()); // the problem was that this was
CPPUNIT_ASSERT_EQUAL(u"500"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->Down(false);
pField = pWrtShell->GetCurField();
CPPUNIT_ASSERT_EQUAL(u"5000*10%"_ustr, pField->GetFormula());
CPPUNIT_ASSERT_EQUAL(u"500"_ustr, pField->ExpandField(true, nullptr));
pWrtShell->Down(false);
CPPUNIT_ASSERT_EQUAL(u"-100,00 €"_ustr, pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
pWrtShell->GoNextCell(); // tdf#42518 the problem was that this was 1.900,00 €
CPPUNIT_ASSERT_EQUAL(u"** Expression is faulty **"_ustr, pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testInsertFileInInputFieldException)
{
createSwDoc();
uno::Reference<text::XTextDocument> const xTextDoc(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XText> const xBody(xTextDoc->getText());
uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextCursor> const xCursor(xBody->createTextCursor());
uno::Reference<document::XDocumentInsertable> const xInsertable(xCursor, uno::UNO_QUERY);
uno::Reference<text::XTextContent> const xContent(
xFactory->createInstance(u"com.sun.star.text.textfield.Input"_ustr), uno::UNO_QUERY);
xBody->insertTextContent(xCursor, xContent, false);
xCursor->goLeft(1, false); // try to insert some random file // inserting even asserts in debug builds - document model goes invalid with input field split across 2 nodes
CPPUNIT_ASSERT_THROW(xInsertable->insertDocumentFromURL(createFileURL(u"fdo75110.odt"), {}), uno::RuntimeException);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf67238)
{ //create a new writer document
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); //insert a 3X3 table in the newly created document
SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0); const SwTable& rTable = pWrtShell->InsertTable(TableOpt, 3, 3); //checking for the rows and columns
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getColumns()->getCount()); //selecting the table
pWrtShell->StartOfSection();
pWrtShell->SelTable(); //making the table protected
pWrtShell->ProtectCells(); //checking each cell's protection, it should be protected
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected()); //undo the changes, make cells [un]protected
rUndoManager.Undo(); //checking each cell's protection, it should be [un]protected
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected()); //redo the changes, make cells protected
rUndoManager.Redo(); //checking each cell's protection, it should be protected
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected()); //moving the cursor to the starting of the document
pWrtShell->StartOfSection(); //making the table [un]protected
pWrtShell->SelTable();
pWrtShell->UnProtectCells(); //checking each cell's protection, it should be [un]protected
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected()); //undo the changes, make cells protected
rUndoManager.Undo(); //checking each cell's protection, it should be protected
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected()); //redo the changes, make cells [un]protected
rUndoManager.Redo(); //checking each cell's protection, it should be [un]protected
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"A3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"B3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C1"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C2"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
CPPUNIT_ASSERT(!((rTable.GetTableBox(u"C3"_ustr))->GetFrameFormat()->GetProtect()).IsContentProtected());
}
// this did not remove the original text from the layout
pWrtShell->Replace(u"Él"_ustr, false);
// currently the deleted text is before the replacement text, not sure if // that is really required
CPPUNIT_ASSERT_EQUAL(u"élÉl"_ustr,
pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode()->GetText());
CPPUNIT_ASSERT_EQUAL(u"Él"_ustr, static_cast<SwTextFrame const*>(pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode()->getLayoutFrame(nullptr))->GetText());
pWrtShell->SelAll(); // The problem was that SwEditShell::DeleteSel() what this Delete() invokes took the wrong selection...
pWrtShell->Delete();
sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); // ... so this Undo() call resulted in a crash.
rUndoManager.Undo();
}
// Now check if the table has 3 lines.
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
SwTableNode* pTableNode = pShellCursor->Start()->GetNode().FindTableNode(); // This was 1, when doing the same using the UI, Writer even crashed.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pTableNode->GetTable().GetTabLines().size());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testReplaceBackward)
{ //Regression test of fdo#70143 //EDITING: undo search&replace corrupt text when searching backward
createSwDoc();
SwDoc* pDoc = getSwDoc();
pWrtShell->SelAll(); // A1 is empty -> selects the whole table.
pWrtShell->SelAll(); // Selects the whole document.
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
SwTextNode& rEnd = dynamic_cast<SwTextNode&>(pShellCursor->End()->GetNode()); // Selection did not include the para after table, this was "B1".
CPPUNIT_ASSERT_EQUAL(u"Para after table."_ustr, rEnd.GetText());
}
// just these styles are user defined styles if (styleName == "pagestyle1" || styleName == "pagestyle2")
expectedUserDefined = true;
// just these styles are used in the document if (styleName == "Right Page" || styleName == "pagestyle1" || styleName == "pagestyle2")
expectedUsedStyle = true;
//Amusingly eventually there was a commit id with "ccc" in it, and so the rtf contained //{\*\generator LibreOfficeDev/4.4.0.0.alpha0$Linux_X86_64 LibreOffice_project/f70664ccc6837f2cc21a29bb4f44e41e100efe6b} //so the test fell over. so strip the generator tag
sal_Int32 nGeneratorStart = aData.indexOf("{\\*\\generator ");
CPPUNIT_ASSERT(nGeneratorStart != -1);
sal_Int32 nGeneratorEnd = aData.indexOf('}', nGeneratorStart + 1);
CPPUNIT_ASSERT(nGeneratorEnd != -1);
aData = aData.replaceAt(nGeneratorStart, nGeneratorEnd-nGeneratorStart+1, "");
CPPUNIT_ASSERT(aData.startsWith("{\\rtf1"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aData.indexOf("aaa"));
CPPUNIT_ASSERT(aData.indexOf("bbb") != -1);
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aData.indexOf("ccc")); // Ensure there's no extra newline
CPPUNIT_ASSERT(aData.endsWith("bbb}" SAL_NEWLINE_STRING "}"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testDOCXAutoTextEmpty)
{ // file contains normal content but no AutoText
std::unique_ptr<SwTextBlocks> pGlossary = readDOCXAutotext(u"autotext-empty.dotx", true);
CPPUNIT_ASSERT(pGlossary != nullptr);
}
// first line
SwNode& rNode = aStart.GetNode();
CPPUNIT_ASSERT(rNode.IsTextNode());
SwTextNode& rTextNode = *rNode.GetTextNode();
CPPUNIT_ASSERT_EQUAL(u"Another "_ustr, rTextNode.GetText());
// Make sure that autotext does not set a custom page style, leading to an unexpected page break // on insertion. // Without the accompanying fix in place, this test would have failed: the text node had an // attribute set containing a page style item.
CPPUNIT_ASSERT(!rTextNode.HasSwAttrSet() || !rTextNode.GetSwAttrSet().HasItem(RES_PAGEDESC));
// last line
SwNodeIndex aLast(*aDocEnd.GetNode().EndOfSectionNode(), -1);
SwNode& rLastNode = aLast.GetNode();
CPPUNIT_ASSERT_EQUAL(u"complex"_ustr, rLastNode.GetTextNode()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testDOTMAutoText)
{ // this is dotm file difference is that in the dotm // there are no empty paragraphs at the end of each entry
std::unique_ptr<SwTextBlocks> pGlossary = readDOCXAutotext(u"autotext-dotm.dotm");
// check if content is correct
SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
SwNodeIndex aStart(*aDocEnd.GetNode().StartOfSectionNode(), 1);
SwNode& rNode = aStart.GetNode();
CPPUNIT_ASSERT_EQUAL(u"paragraph"_ustr, rNode.GetTextNode()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testDOCXAutoTextGallery)
{ // this file contains one AutoText entry and other // entries which are not AutoText (have different "gallery" value)
std::unique_ptr<SwTextBlocks> pGlossary = readDOCXAutotext(u"autotext-gallery.dotx");
// go to the begin of the paragraph and split this node
pWrtShell->Left(SwCursorSkipMode::Chars, false, 100, false);
pWrtShell->SplitNode();
{ // expect only the second paragraph to have hints
SwNodeIndex aIdx(SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1));
SwTextNode* pTextNode = aIdx.GetNode().GetTextNode();
CPPUNIT_ASSERT(pTextNode->HasHints());
--aIdx;
pTextNode = aIdx.GetNode().GetTextNode();
CPPUNIT_ASSERT(!pTextNode->HasHints());
}
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testShapeTextboxSelect)
{
createSwDoc("shape-textbox.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
SdrObject* pObject = pPage->GetObj(1);
SwContact* pTextBox = static_cast<SwContact*>(pObject->GetUserCall()); // First, make sure that pTextBox is a fly frame (textbox of a shape).
CPPUNIT_ASSERT_EQUAL(sal_uInt16(RES_FLYFRMFMT), pTextBox->GetFormat()->Which());
// Then select it.
pWrtShell->SelectObj(Point(), 0, pObject); const SdrMarkList& rMarkList = pWrtShell->GetDrawView()->GetMarkedObjectList();
SwDrawContact* pShape = static_cast<SwDrawContact*>(rMarkList.GetMark(0)->GetMarkedSdrObj()->GetUserCall()); // And finally make sure the shape got selected, not just the textbox itself.
CPPUNIT_ASSERT_EQUAL(sal_uInt16(RES_DRAWFRMFMT), pShape->GetFormat()->Which());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testShapeTextboxDelete)
{
createSwDoc("shape-textbox.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
SdrObject* pObject = pPage->GetObj(0);
pWrtShell->SelectObj(Point(), 0, pObject);
size_t nActual = pPage->GetObjCount(); // Two objects on the draw page: the shape and its textbox.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), nActual);
pWrtShell->DelSelectedObj();
nActual = pPage->GetObjCount(); // Both (not only the shape) should be removed by now (the textbox wasn't removed, so this was 1).
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), nActual);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testShapeTextboxAutosize)
{
createSwDoc("shape-textbox-autosize.odt");
SwDoc* pDoc = getSwDoc();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); // 0-1 is the first UI-visible shape+textbox.
SdrObject* pFirst = pPage->GetObj(0);
CPPUNIT_ASSERT_EQUAL(u"1st"_ustr, pFirst->GetName());
// 2-3 is the second UI-visible shape+textbox.
SdrObject* pSecond = pPage->GetObj(2);
CPPUNIT_ASSERT_EQUAL(u"2nd"_ustr, pSecond->GetName());
// Shape -> textbox synchronization was missing, the second shape had the // same height as the first, even though the first contained 1 paragraph // and the other 2 ones.
CPPUNIT_ASSERT(pFirst->GetSnapRect().getOpenHeight() < pSecond->GetSnapRect().getOpenHeight());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testFdo82191)
{
createSwDoc("fdo82191.odt");
SwDoc* pDoc = getSwDoc();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); // Make sure we have a single draw shape.
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), SwTextBoxHelper::getCount(pPage));
// This was one: the textbox of the shape wasn't copied.
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), SwTextBoxHelper::getCount(*pDoc));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testCommentedWord)
{ // This word is commented. <- string in document // 123456789 <- character positions
createSwDoc("commented-word.odt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); // Move the cursor into the second word.
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 5, /*bBasicCall=*/false); // Select the word.
pWrtShell->SelWrd();
// Make sure that not only the word, but its comment anchor is also selected.
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false); // This was 9, only "word", not "word<anchor character>" was selected.
CPPUNIT_ASSERT_EQUAL(sal_Int32(10), pShellCursor->End()->GetContentIndex());
// Test that getAnchor() points to "word", not to an empty string.
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
uno::Reference<text::XTextContent> xField(xFields->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"word"_ustr, xField->getAnchor()->getString());
}
// Then
SwTextNode* pTextNode = aPaM.GetPointNode().GetTextNode();
CPPUNIT_ASSERT_EQUAL(NON_CHINESE_CONTENT, pTextNode->GetText());
}
// Tests conversion of traditional Chinese characters to simplified Chinese
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testChineseConversionTraditionalToSimplified)
{
// Then
SwTextNode* pTextNode = aPaM.GetPointNode().GetTextNode();
CPPUNIT_ASSERT_EQUAL(OUString(CHINESE_SIMPLIFIED_CONTENT), pTextNode->GetText());
}
// Tests conversion of simplified Chinese characters to traditional Chinese
CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testChineseConversionSimplifiedToTraditional)
{
// accept all redlines while(pEditShell->GetRedlineCount())
pEditShell->AcceptRedline(0);
CPPUNIT_ASSERT_EQUAL(7, getParagraphs());
getParagraph(1, u"Para One: Two Three Four Five"_ustr);
getParagraph(2, u"Para Two: One Three Four Five"_ustr);
getParagraph(3, u"Para Three: One Two Four Five"_ustr);
getParagraph(4, u"Para Four: One Two Three Four Five"_ustr);
getParagraph(5, u"Para Six: One Three Four Five"_ustr);
getParagraph(6, u""_ustr);
getParagraph(7, u""_ustr);
}
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.