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'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.text.XSimpleText
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim oCursor As Object
44    Dim oPosCursor As Variant
45    Dim cIfcShortName As String
46    Dim bOK As Boolean
47    Dim oldString, newString As String
48
49    cIfcShortName = "XSimpleText"
50
51    Test.StartMethod("createTextCursor()")
52    bOK = true
53    oCursor = oObj.createTextCursor()
54    bOK = bOK AND NOT (isNull(oCursor))
55    bOK = bOK AND hasUnoInterfaces(oCursor, "com.sun.star.text.XTextCursor")
56    Test.MethodTested("createTextCursor()", bOK)
57
58    Test.StartMethod("createTextCursorByRange()")
59    bOK = true
60    oPosCursor = oObj.createTextCursorbyRange(oCursor)
61    bOK = bOK AND NOT isNull(oPosCursor)
62    bOK = bOK AND hasUnoInterfaces(oPosCursor, "com.sun.star.text.XTextCursor")
63    Test.MethodTested("createTextCursorByRange()", bOK)
64
65    Test.StartMethod("insertString()")
66    bOK = true
67    oldString = oObj.String
68    Out.Log("String before inserting:'" + oldString + "'")
69    oCursor.gotoStart(false)
70    oObj.insertString(oCursor, cIfcShortName, false)
71    Dim newStr As String
72    newStr = oObj.String
73    Out.Log("String content after inserting:'" + newStr + "'")
74    Dim expectedStr As String
75    expectedStr = cIfcShortName + oldString
76    Out.Log("Expected string:'" + expectedStr + "'")
77    bOK = bOK AND (expectedStr = newStr)
78    oObj.setString(oldString)
79    Test.MethodTested("insertString()", bOK)
80
81    ' some cursor navigation to verify if controlcharacters have benn inserted:)
82    Test.StartMethod("insertControlCharacter()")
83    bOK = true
84    oldString = oObj.getString()
85    newString = "XSimpleText"
86    Out.Log("Set string to '" + newString + "'")
87    oObj.setString(newString)
88    Out.Log("Current string content of object: '" + oObj.getString() + "'")
89    oCursor.gotoStart(false)
90    Out.Log("Insert control characters...")
91'    oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false)
92    oObj.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, false)
93    Out.Log("Now string content of object: '" + oObj.getString() + "'")
94    Dim breakPos As Integer
95    breakPos = inStr(oObj.getString(), chr(10))
96    Out.Log("Line break found at " + breakPos)
97    bOK = bOK AND breakPos > 0
98    oObj.String = oldString
99    Out.Log("Return string to old state:'" + oObj.getString() + "'" )
100    Test.MethodTested("insertControlCharacter()", bOK)
101
102Exit Sub
103ErrHndl:
104    Test.Exception()
105    bOK = false
106    resume next
107End Sub
108</script:module>
109