/* -*- 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/.
*/
/// Covers sw/source/uibase/uiview/ fixes. class SwUibaseUiviewTest : public SwModelTestBase
{ public:
SwUibaseUiviewTest()
: SwModelTestBase(u"/sw/qa/uibase/uiview/data/"_ustr)
{
}
};
CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements)
{ // Make a temporary copy of the test document
createTempCopy(u"updateall-objectreplacements.odt");
// Check the contents of the updated copy and verify that ObjectReplacements are there
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(xFactory),
maTempFile.GetURL());
CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
{ // Load a copy of the document in hidden mode.
OUString aSourceURL = createFileURL(u"update-replacement-nosetting.odt");
CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, maTempFile.GetURL()));
loadWithParams(maTempFile.GetURL(), { comphelper::makePropertyValue(u"Hidden"_ustr, true) });
// Update "everything" (including object replacements) and save it.
dispatchCommand(mxComponent, u".uno:UpdateAll"_ustr, {});
uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
xStorable->storeSelf({});
// Check the contents of the updated copy.
uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(xContext, maTempFile.GetURL());
// Without the accompanying fix in place, this test would have failed, because the embedded // object replacement image was not generated.
CPPUNIT_ASSERT(xNameAccess->hasByName(u"ObjectReplacements/Components"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testKeepRatio)
{ // Given a document with a custom KeepRatio:
createSwDoc("keep-ratio.fodt");
// Then make sure we read the custom value:
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); const SwViewOption* pViewOption = pWrtShell->GetViewOptions();
comphelper::ScopeGuard g([pWrtShell, pViewOption] {
SwViewOption aViewOption(*pViewOption);
aViewOption.SetKeepRatio(false);
SwModule::get()->ApplyUsrPref(aViewOption, &pWrtShell->GetView());
}); // Without the accompanying fix in place, this test would have failed, because KeepRatio was not // mapped to settings.xml
CPPUNIT_ASSERT(pViewOption->IsKeepRatio());
// Then export as well:
save(u"writer8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"settings.xml"_ustr);
assertXPathContent(pXmlDoc, "//config:config-item[@config:name='KeepRatio']", u"true");
}
namespace
{ /// Interception implementation that disables .uno:Zoom on Image1, but not on Image2. struct ImageInterceptor : public cppu::WeakImplHelper<frame::XDispatchProviderInterceptor>
{
uno::Reference<view::XSelectionSupplier> m_xSelectionSupplier;
uno::Reference<frame::XDispatchProvider> m_xMaster;
uno::Reference<frame::XDispatchProvider> m_xSlave; int m_nEnabled = 0; int m_nDisabled = 0;
uno::Reference<frame::XDispatch> ImageInterceptor::queryDispatch(const util::URL& rURL, const OUString& rTargetFrameName,
sal_Int32 nSearchFlags)
{ // Disable the UNO command based on the currently selected image, i.e. this can't be cached when // a different image is selected. Originally this was .uno:SetBorderStyle, but let's pick a // command which is active when running cppunit tests: if (rURL.Complete == ".uno:Zoom")
{
uno::Reference<container::XNamed> xImage;
m_xSelectionSupplier->getSelection() >>= xImage; if (xImage.is() && xImage->getName() == "Image1")
{
++m_nDisabled; return {};
}
// When selecting the first image:
selectShape(1);
// Then make sure the UNO command is disabled:
CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled);
CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled);
// Given a clean state:
pInterceptor->m_nEnabled = 0;
pInterceptor->m_nDisabled = 0;
// When selecting the second image:
selectShape(2);
// Then make sure the UNO command is enabled:
CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nEnabled);
CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nDisabled);
// Given a clean state:
pInterceptor->m_nEnabled = 0;
pInterceptor->m_nDisabled = 0;
// When selecting the first image, again (this time not changing the selection type):
selectShape(1);
// Then make sure the UNO command is disabled:
CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled); // Without the accompanying fix in place, this test would have failed with: // - Expected greater or equal than: 1 // - Actual : 0 // i.e. selecting the first image didn't result in a disabled UNO command.
CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled);
}
CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testPrintPreview)
{ // Given a normal Writer view, in half-destroyed state, similar to what // SfxViewFrame::SwitchToViewShell_Impl() does in practice:
createSwDoc();
SwDocShell* pDocShell = getSwDocShell();
SwView* pView = pDocShell->GetView();
FmFormShell* pFormShell = pView->GetFormShell();
pView->SetFormShell(reinterpret_cast<FmFormShell*>(-1));
pView->SetDying();
// When selecting a shell, similar to what happens the doc size changes: // Then make sure we don't crash:
pView->SelectShell();
// Restore the state and shut down.
pView->SetFormShell(pFormShell);
}
// move the cursor to the non-editable section
xSelSupplier->select(css::uno::Any(xParaCursor));
bool bShow;
bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be hidden
// move the cursor to the editable section
xParaCursor->gotoNextParagraph(false);
xSelSupplier->select(css::uno::Any(xParaCursor));
bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
CPPUNIT_ASSERT_EQUAL(true, bShow); // the formatting toolbar should be shown
// move the cursor to the non-editable section
xParaCursor->gotoPreviousParagraph(false);
xSelSupplier->select(css::uno::Any(xParaCursor));
bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be hidden
}
CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testReinstateTrackedChangeState)
{ // Given a document with a deletion:
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->Insert("abcd");
RedlineFlags nMode = pWrtShell->GetRedlineFlags();
pWrtShell->SetRedlineFlags(nMode | RedlineFlags::On);
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 2, /*bBasicCall=*/false);
pWrtShell->DelRight();
// When the cursor is inside a redline:
pWrtShell->SttPara(/*bSelect=*/false);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false);
// Then make sure that reinstate is enabled:
SwView* pView = getSwDocShell()->GetView();
std::unique_ptr<SfxPoolItem> pItem;
SfxItemState eState
= pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, pItem);
CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
// When the cursor is outside a redline:
pWrtShell->SttPara(/*bSelect=*/false);
// Then make sure that reinstate is disabled:
eState = pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, pItem); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 (DISABLED) // - Actual : 32 (DEFAULT) // i.e. reinstate was always enabled.
CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, eState);
}
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.