Kaydet (Commit) e1835944 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Björn Michaelsen

[API CHANGE] SwXTextField: no more SwModify/SwClient

- fix unittest assuming the double-insertion of annotation
  throwing an IllegalArgumentException was intentional
- remove SwModify/SwClient in SwXTextField
- also: add basic C++ api test

Change-Id: Ia4657dc65dfadc3e975bdf409bd5e43413ea1f5a
Reviewed-on: https://gerrit.libreoffice.org/71452
Tested-by: Jenkins
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst 74ac2881
......@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \
sw/qa/api/SwXDocumentIndex \
sw/qa/api/SwXDocumentSettings \
sw/qa/api/SwXTextField \
sw/qa/api/SwXTextTable \
))
......
......@@ -36,7 +36,7 @@ namespace com { namespace sun { namespace star { namespace text { class XTextFie
// ATT_FLD
class SW_DLLPUBLIC SwFormatField
: public SfxPoolItem
, public SwModify
, public sw::BroadcastingModify
, public SfxBroadcaster
{
friend void InitCore();
......
/* -*- 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/.
*/
#include <test/bootstrapfixture.hxx>
#include <test/lang/xcomponent.hxx>
#include <unotest/macros_test.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/text/XDependentTextField.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
#include <comphelper/processfactory.hxx>
using namespace css;
using namespace css::uno;
using namespace css::beans;
namespace
{
/**
* Initial tests for SwXTextField.
*/
struct SwXTextField final : public test::BootstrapFixture,
public unotest::MacrosTest,
public apitest::XComponent
{
virtual void setUp() override;
Reference<XInterface> init() override;
void triggerDesktopTerminate() override;
CPPUNIT_TEST_SUITE(SwXTextField);
CPPUNIT_TEST(testAddEventListener);
CPPUNIT_TEST(testRemoveEventListener);
//CPPUNIT_TEST(testDisposedByDesktopTerminate);
CPPUNIT_TEST_SUITE_END();
};
void SwXTextField::setUp()
{
test::BootstrapFixture::setUp();
mxDesktop.set(
frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
}
void SwXTextField::triggerDesktopTerminate() { mxDesktop->terminate(); }
Reference<XInterface> SwXTextField::init()
{
auto xComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
CPPUNIT_ASSERT(xComponent.is());
Reference<text::XTextDocument> xTextDocument(xComponent, UNO_QUERY_THROW);
Reference<lang::XMultiServiceFactory> xMSF(xComponent, UNO_QUERY_THROW);
Reference<XPropertySet> xFieldMaster(
xMSF->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW);
xFieldMaster->setPropertyValue("DataBaseName", makeAny(OUString("Address Book File")));
xFieldMaster->setPropertyValue("DataTableName", makeAny(OUString("address")));
xFieldMaster->setPropertyValue("DataColumnName", makeAny(OUString("FIRSTNAME")));
Reference<text::XDependentTextField> xField(
xMSF->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW);
xField->attachTextFieldMaster(xFieldMaster);
Reference<text::XText> xText = xTextDocument->getText();
Reference<text::XTextCursor> xCursor = xText->createTextCursor();
Reference<text::XTextContent> xFieldAsContent(xField, UNO_QUERY_THROW);
xText->insertTextContent(xCursor, xFieldAsContent, false);
return Reference<XInterface>(xField, UNO_QUERY_THROW);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextField);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -37,9 +37,11 @@ class TestXText(unittest.TestCase):
# And the same once again, actually not inserted
x_text.insertTextContent(x_cursor, x_annotation, False)
# Exception if we try to replace object by itself
with self.assertRaises(IllegalArgumentException):
x_text.insertTextContent(x_cursor, x_annotation, True)
# no exception if we try to replace object by itself:
# this did throw in the past, but only because the inserted
# UNO annotation had a core object assigned, but no document
# which insertTextContent then didnt like on another call.
x_text.insertTextContent(x_cursor, x_annotation, True)
# We expect just one annotation actually
self.check_annotations(["John Doe"])
......
......@@ -47,7 +47,6 @@
// constructor for default item in attribute-pool
SwFormatField::SwFormatField( sal_uInt16 nWhich )
: SfxPoolItem( nWhich )
, SwModify(nullptr)
, SfxBroadcaster()
, mpTextField( nullptr )
{
......@@ -55,11 +54,11 @@ SwFormatField::SwFormatField( sal_uInt16 nWhich )
SwFormatField::SwFormatField( const SwField &rField )
: SfxPoolItem( RES_TXTATR_FIELD )
, SwModify( rField.GetTyp() )
, SfxBroadcaster()
, mpField( rField.CopyField() )
, mpTextField( nullptr )
{
rField.GetTyp()->Add(this);
if ( mpField->GetTyp()->Which() == SwFieldIds::Input )
{
// input field in-place editing
......@@ -93,7 +92,6 @@ SwFormatField::SwFormatField( const SwField &rField )
// corrected
SwFormatField::SwFormatField( const SwFormatField& rAttr )
: SfxPoolItem( rAttr )
, SwModify(nullptr)
, SfxBroadcaster()
, mpTextField( nullptr )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment