namespace
{ /// Covers sw/source/uibase/shells/textsh1.cxx fixes. class Test : public SwModelTestBase
{ public:
Test()
: SwModelTestBase("/sw/qa/uibase/shells/data/")
{
}
};
CPPUNIT_TEST_FIXTURE(Test, testDeleteRichTextContentControl)
{ // Given an empty document
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// When inserting a content control:
pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
// Then verify that the content control has been inserted
SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode();
CPPUNIT_ASSERT(pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL));
// And verify that there is text in the document
size_t nTextNodeLength = pTextNode->GetText().getLength();
CPPUNIT_ASSERT(nTextNodeLength > 0);
// And the content control manager has one content control
SwContentControlManager& rManager = pDoc->GetContentControlManager();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
// When deleting the content control
dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
// Then verify that there are no content controls
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL));
CPPUNIT_ASSERT_EQUAL(nTextNodeLength, static_cast<size_t>(pTextNode->GetText().getLength()));
}
CPPUNIT_TEST_FIXTURE(Test, testDeleteCheckboxContentControl)
{ // Given an empty document
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); // The default Liberation Serif doesn't have a checkmark glyph, avoid font fallback.
SwView& rView = pWrtShell->GetView();
SfxItemSetFixed<RES_CHRATR_BEGIN, RES_CHRATR_END> aSet(rView.GetPool());
SvxFontItem aFont(FAMILY_DONTKNOW, u"DejaVu Sans"_ustr, OUString(), PITCH_DONTKNOW,
RTL_TEXTENCODING_DONTKNOW, RES_CHRATR_FONT);
aSet.Put(aFont);
SwTextFormatColl* pStyle
= pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD);
pStyle->SetFormatAttr(aSet);
// When inserting a content control:
pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX);
// Then verify that a checkbox content control exists in the document
SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode();
SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); auto& rFormatContentControl
= static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr());
std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl();
CPPUNIT_ASSERT(pContentControl->GetCheckbox());
// And the content control manager has one content control
SwContentControlManager& rManager = pDoc->GetContentControlManager();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
// When deleting the content control
dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
// Then verify that there are no content controls
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL));
// And verify that text remains in the document
size_t nTextNodeLength = pTextNode->GetText().getLength();
CPPUNIT_ASSERT(nTextNodeLength > 0);
}
CPPUNIT_TEST_FIXTURE(Test, testDeleteDropdownContentControl)
{ // Create a document with a dropdown content control
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
// Then verify that the content control manager has one content control
SwContentControlManager& rManager = pDoc->GetContentControlManager();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
// When deleting the content control
dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
// Then verify that there are no content controls
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode();
CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL));
// And verify that text remains in the document
size_t nTextNodeLength = pTextNode->GetText().getLength();
CPPUNIT_ASSERT(nTextNodeLength > 0);
}
CPPUNIT_TEST_FIXTURE(Test, testDeleteDateContentControl)
{ // Create a document with a date content control
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->InsertContentControl(SwContentControlType::DATE);
// Then verify that the content control manager has one content control
SwContentControlManager& rManager = pDoc->GetContentControlManager();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
// When deleting the content control
dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
// Then verify that there are no content controls
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode();
CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL));
// And verify that text remains in the document
size_t nTextNodeLength = pTextNode->GetText().getLength();
CPPUNIT_ASSERT(nTextNodeLength > 0);
}
}
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.