/* -*- 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/.
*/
void SwMacrosTest::testBookmarkDeleteAndJoin()
{
rtl::Reference<SwDoc> const pDoc(new SwDoc);
pDoc->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
SwPaM aPaM(aIdx);
IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations());
rIDCO.AppendTextNode(*aPaM.GetPoint());
rIDCO.InsertString(aPaM, u"A"_ustr);
rIDCO.AppendTextNode(*aPaM.GetPoint());
rIDCO.InsertString(aPaM, u"A"_ustr);
rIDCO.AppendTextNode(*aPaM.GetPoint());
aPaM.Move(fnMoveBackward, GoInNode);
aPaM.Move(fnMoveBackward, GoInNode);
aPaM.Move(fnMoveBackward, GoInContent);
aPaM.SetMark();
aPaM.Move(fnMoveForward, GoInDoc);
IDocumentMarkAccess & rIDMA = *pDoc->getIDocumentMarkAccess();
sw::mark::MarkBase *pMark =
rIDMA.makeMark(aPaM, SwMarkName(u"test"_ustr), IDocumentMarkAccess::MarkType::BOOKMARK,
::sw::mark::InsertMode::New);
CPPUNIT_ASSERT(pMark); // select so pMark start position is on a node that is fully deleted
aPaM.Move(fnMoveBackward, GoInNode); // must leave un-selected content in last node to get the bJoinPrev flag!
aPaM.Move(fnMoveBackward, GoInContent);
aPaM.Exchange();
aPaM.Move(fnMoveBackward, GoInDoc); // delete
rIDCO.DeleteAndJoin(aPaM);
for (auto i = rIDMA.getAllMarksBegin(); i != rIDMA.getAllMarksEnd(); ++i)
{ // problem was that the nContent was pointing at deleted node
CPPUNIT_ASSERT_EQUAL((*i)->GetMarkStart().GetContentNode(), static_cast<const SwContentNode*>((*i)->GetMarkStart().GetNode().GetContentNode()));
}
}
void SwMacrosTest::testBookmarkDeleteTdf90816()
{
rtl::Reference<SwDoc> const pDoc(new SwDoc);
pDoc->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
SwPaM aPaM(aIdx);
// delete the same selection as the bookmark
rIDCO.DeleteAndJoin(aPaM);
// bookmark still there? auto iter = rIDMA.getAllMarksBegin();
CPPUNIT_ASSERT_MESSAGE("the bookmark was deleted",
iter != rIDMA.getAllMarksEnd());
CPPUNIT_ASSERT_EQUAL((*iter)->GetMarkPos(), *aPaM.Start());
CPPUNIT_ASSERT_EQUAL((*iter)->GetOtherMarkPos(), *aPaM.End());
}
// Without the fix in place, this test would have failed with // Property or method not found: createDiagramByDataSource.
executeMacro(u"vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document"_ustr);
void SwMacrosTest::testFdo55289()
{
SwDoc* const pDoc = new SwDoc;
SwDocShellRef pDocShell = new SwDocShell(*pDoc, SfxObjectCreateMode::EMBEDDED); // this needs to run with no layout to tickle the bugs in the special // cases in SwXShape re-anchoring
assert(!pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
{ // check that password-protected library survived store and re-load
Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected(u"BarLibrary"_ustr));
CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword(u"BarLibrary"_ustr, u"foo"_ustr));
xBasLib->loadLibrary(u"BarLibrary"_ustr);
CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(u"BarLibrary"_ustr));
Reference<container::XNameContainer> xLibrary(xBasLib->getByName(u"BarLibrary"_ustr), UNO_QUERY);
Any module(xLibrary->getByName(u"BarModule"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Sub Main\nEnd Sub\n"_ustr, module.get<OUString>());
// add a second module now - tdf#87530 happened here
Reference<container::XNameContainer> xFooLib(xBasLib->createLibrary(u"FooLibrary"_ustr));
xFooLib->insertByName(u"FooModule"_ustr,
uno::Any(u"Sub Main\nEnd Sub\n"_ustr));
xBasLibPwd->changeLibraryPassword(u"FooLibrary"_ustr, u""_ustr, u"foo"_ustr);
}
saveAndReload(u"writer8"_ustr);
// check that password-protected library survived store and re-load
Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected(u"FooLibrary"_ustr));
CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword(u"FooLibrary"_ustr, u"foo"_ustr));
xBasLib->loadLibrary(u"FooLibrary"_ustr);
CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(u"FooLibrary"_ustr));
Reference<container::XNameContainer> xLibrary(xBasLib->getByName(u"FooLibrary"_ustr), UNO_QUERY);
Any module(xLibrary->getByName(u"FooModule"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Sub Main\nEnd Sub\n"_ustr, module.get<OUString>());
}
void SwMacrosTest::testFindReplace()
{ // we need a full document with view and layout etc. because ::GetNode()
loadFromURL(u"private:factory/swriter"_ustr);
SwXTextDocument *const pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc *const pDoc = pTextDoc->GetDocShell()->GetDoc();
SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1); // use a UnoCursor so it will be corrected when deleting nodes auto pPaM(pDoc->CreateUnoCursor(SwPosition(aIdx)));
// now do another Find, inside the selection from the first Find // opts.searchFlags = 71680;
bFound = pPaM->Find_Text(
opts, false, SwDocPositions::Curr, SwDocPositions::End, bCancel, FindRanges::InSel);
CPPUNIT_ASSERT(bFound);
CPPUNIT_ASSERT(pPaM->HasMark());
CPPUNIT_ASSERT(pPaM->GetPoint()->GetNode() != pPaM->GetMark()->GetNode());
CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_NEWLINE)), pPaM->GetText());
// problem was that after the 2nd Find, the wrong newline was selected
CPPUNIT_ASSERT_EQUAL(u"foo bar"_ustr,
pPaM->Start()->GetNode().GetTextNode()->GetText());
pPaM->Move(fnMoveForward, GoInNode);
CPPUNIT_ASSERT_EQUAL(u"baz"_ustr,
pPaM->End()->GetNode().GetTextNode()->GetText());
}
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.