1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="text_XSimpleText" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36' Be sure that all variables are dimensioned: 37option explicit 38 39 40 41Sub RunTest() 42 43'************************************************************************* 44' INTERFACE: 45' com.sun.star.text.XSimpleText 46'************************************************************************* 47On Error Goto ErrHndl 48 Dim oCursor As Object 49 Dim oPosCursor As Variant 50 Dim cIfcShortName As String 51 Dim bOK As Boolean 52 Dim oldString, newString As String 53 54 cIfcShortName = "XSimpleText" 55 56 Test.StartMethod("createTextCursor()") 57 bOK = true 58 oCursor = oObj.createTextCursor() 59 bOK = bOK AND NOT (isNull(oCursor)) 60 bOK = bOK AND hasUnoInterfaces(oCursor, "com.sun.star.text.XTextCursor") 61 Test.MethodTested("createTextCursor()", bOK) 62 63 Test.StartMethod("createTextCursorByRange()") 64 bOK = true 65 oPosCursor = oObj.createTextCursorbyRange(oCursor) 66 bOK = bOK AND NOT isNull(oPosCursor) 67 bOK = bOK AND hasUnoInterfaces(oPosCursor, "com.sun.star.text.XTextCursor") 68 Test.MethodTested("createTextCursorByRange()", bOK) 69 70 Test.StartMethod("insertString()") 71 bOK = true 72 oldString = oObj.String 73 Out.Log("String before inserting:'" + oldString + "'") 74 oCursor.gotoStart(false) 75 oObj.insertString(oCursor, cIfcShortName, false) 76 Dim newStr As String 77 newStr = oObj.String 78 Out.Log("String content after inserting:'" + newStr + "'") 79 Dim expectedStr As String 80 expectedStr = cIfcShortName + oldString 81 Out.Log("Expected string:'" + expectedStr + "'") 82 bOK = bOK AND (expectedStr = newStr) 83 oObj.setString(oldString) 84 Test.MethodTested("insertString()", bOK) 85 86 ' some cursor navigation to verify if controlcharacters have benn inserted:) 87 Test.StartMethod("insertControlCharacter()") 88 bOK = true 89 oldString = oObj.getString() 90 newString = "XSimpleText" 91 Out.Log("Set string to '" + newString + "'") 92 oObj.setString(newString) 93 Out.Log("Current string content of object: '" + oObj.getString() + "'") 94 oCursor.gotoStart(false) 95 Out.Log("Insert control characters...") 96' oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false) 97 oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, false) 98 Out.Log("Now string content of object: '" + oObj.getString() + "'") 99 Dim breakPos As Integer 100 breakPos = inStr(oObj.getString(), chr(10)) 101 Out.Log("Line break found at " + breakPos) 102 bOK = bOK AND breakPos > 0 103 oObj.String = oldString 104 Out.Log("Return string to old state:'" + oObj.getString() + "'" ) 105 Test.MethodTested("insertControlCharacter()", bOK) 106 107Exit Sub 108ErrHndl: 109 Test.Exception() 110 bOK = false 111 resume next 112End Sub 113</script:module> 114