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 37' Be sure that all variables are dimensioned: 38option explicit 39 40 41 42Sub RunTest() 43 44'************************************************************************* 45' INTERFACE: 46' com.sun.star.text.XSimpleText 47'************************************************************************* 48On Error Goto ErrHndl 49 Dim oCursor As Object 50 Dim oPosCursor As Variant 51 Dim cIfcShortName As String 52 Dim bOK As Boolean 53 Dim oldString, newString As String 54 55 cIfcShortName = "XSimpleText" 56 57 Test.StartMethod("createTextCursor()") 58 bOK = true 59 oCursor = oObj.createTextCursor() 60 bOK = bOK AND NOT (isNull(oCursor)) 61 bOK = bOK AND hasUnoInterfaces(oCursor, "com.sun.star.text.XTextCursor") 62 Test.MethodTested("createTextCursor()", bOK) 63 64 Test.StartMethod("createTextCursorByRange()") 65 bOK = true 66 oPosCursor = oObj.createTextCursorbyRange(oCursor) 67 bOK = bOK AND NOT isNull(oPosCursor) 68 bOK = bOK AND hasUnoInterfaces(oPosCursor, "com.sun.star.text.XTextCursor") 69 Test.MethodTested("createTextCursorByRange()", bOK) 70 71 Test.StartMethod("insertString()") 72 bOK = true 73 oldString = oObj.String 74 Out.Log("String before inserting:'" + oldString + "'") 75 oCursor.gotoStart(false) 76 oObj.insertString(oCursor, cIfcShortName, false) 77 Dim newStr As String 78 newStr = oObj.String 79 Out.Log("String content after inserting:'" + newStr + "'") 80 Dim expectedStr As String 81 expectedStr = cIfcShortName + oldString 82 Out.Log("Expected string:'" + expectedStr + "'") 83 bOK = bOK AND (expectedStr = newStr) 84 oObj.setString(oldString) 85 Test.MethodTested("insertString()", bOK) 86 87 ' some cursor navigation to verify if controlcharacters have benn inserted:) 88 Test.StartMethod("insertControlCharacter()") 89 bOK = true 90 oldString = oObj.getString() 91 newString = "XSimpleText" 92 Out.Log("Set string to '" + newString + "'") 93 oObj.setString(newString) 94 Out.Log("Current string content of object: '" + oObj.getString() + "'") 95 oCursor.gotoStart(false) 96 Out.Log("Insert control characters...") 97' oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false) 98 oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, false) 99 Out.Log("Now string content of object: '" + oObj.getString() + "'") 100 Dim breakPos As Integer 101 breakPos = inStr(oObj.getString(), chr(10)) 102 Out.Log("Line break found at " + breakPos) 103 bOK = bOK AND breakPos > 0 104 oObj.String = oldString 105 Out.Log("Return string to old state:'" + oObj.getString() + "'" ) 106 Test.MethodTested("insertControlCharacter()", bOK) 107 108Exit Sub 109ErrHndl: 110 Test.Exception() 111 bOK = false 112 resume next 113End Sub 114</script:module> 115