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/.
This file incorporates work covered by the following license notice:
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file to you under the Apache
License, Version 2.0 (the "License"); you may not use this file exceptin compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 . ''' import unittest from com.sun.star.text.ReferenceFieldPart import (NUMBER, NUMBER_NO_CONTEXT, NUMBER_FULL_CONTEXT, TEXT) from com.sun.star.text.ReferenceFieldSource import BOOKMARK from org.libreoffice.unotest import UnoInProcess
@classmethod def tearDownClass(cls):
cls._uno.tearDown() # HACK in case cls.document holds a UNO proxy to an SwXTextDocument (whose dtor calls # Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be # garbage-collected after VCL has already been deinitialized:
cls.document = None
def getNextField(self): whileTrue: while self.xPortionEnum isNone: if (not(self.xParaEnum.hasMoreElements())):
self.fail("Cannot retrieve next field.")
def checkField(self, xField, xProps, nFormat, aExpectedFieldResult): # set requested format
xProps.setPropertyValue("ReferenceFieldPart", int(nFormat))
# refresh fields in order to get new format applied
self.xFieldsRefresh.refresh()
aFieldResult = xField.getPresentation(False)
self.assertEqual(aExpectedFieldResult, aFieldResult, "set reference field format doesn't result in correct field result")
# insert a certain cross-reference bookmark and a reference field to this bookmark # restart paragraph enumeration
xParaEnumAccess = self.__class__.document.getText()
self.xParaEnum = xParaEnumAccess.createEnumeration()
# iterate on the paragraphs to find certain paragraph to insert the bookmark for xParaTextRange in self.xParaEnum:
if xParaTextRange.getString() == "J": break else:
xParaTextRange = None
self.assertTrue(xParaTextRange, "Cannot find paragraph to insert cross-reference bookmark")
# check inserted reference field
xField = xNewField
self.assertEqual("J", xField.getPresentation(False), "inserted reference field doesn't has correct field result")
xParaTextRange.getStart().setString("Hallo new bookmark: ")
self.xFieldsRefresh.refresh()
self.assertEqual("Hallo new bookmark: J", xField.getPresentation(False), "inserted reference field doesn't has correct field result")
if __name__ == "__main__":
unittest.main()
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
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 ist noch experimentell.