/* -*- 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 #include #include #include #include #include #include #include #include #include #include using namespace css; using namespace css::uno; namespace { /** * Initial tests for SwXFieldEnumeration. */ class SwXFieldEnumeration final : public UnoApiTest, public apitest::XEnumeration { public: SwXFieldEnumeration() : UnoApiTest("") { } virtual void setUp() override { UnoApiTest::setUp(); mxDesktop.set(frame::Desktop::create(mxComponentContext)); mxComponent = loadFromDesktop("private:factory/swriter"); CPPUNIT_ASSERT(mxComponent.is()); } Reference init() override { Reference xTextDocument(mxComponent, UNO_QUERY_THROW); Reference xMSF(mxComponent, UNO_QUERY_THROW); Reference xFieldMaster; Reference xTF; try { xFieldMaster = Reference( xMSF->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW); xTF = Reference( xMSF->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW); } catch (Exception&) { } try { xFieldMaster->setPropertyValue("DataBaseName", Any(OUString("Bibliography"))); xFieldMaster->setPropertyValue("DataTableName", Any(OUString("biblio"))); xFieldMaster->setPropertyValue("DataColumnName", Any(OUString("Address"))); } catch (lang::WrappedTargetException&) { } catch (lang::IllegalArgumentException&) { } catch (beans::UnknownPropertyException&) { } catch (beans::PropertyVetoException&) { } Reference xText = xTextDocument->getText(); Reference xCursor = xText->createTextCursor(); Reference xTextContent(xTF, UNO_QUERY_THROW); xTF->attachTextFieldMaster(xFieldMaster); xText->insertTextContent(xCursor, xTextContent, false); Reference xTFS(xTextDocument, UNO_QUERY_THROW); Reference xEnumerationAccess = xTFS->getTextFields(); return Reference(xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW); } CPPUNIT_TEST_SUITE(SwXFieldEnumeration); CPPUNIT_TEST(testHasMoreElements); CPPUNIT_TEST(testNextElement); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(SwXFieldEnumeration); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */