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_XTextTable" 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' This Interface/Service test depends on the following GLOBAL variables, 36' which must be specified in the object creation: 37 38' - Global nTableW As Integer 39' - Global nTableH As Integer 40 41'************************************************************************* 42 43 44 45 46 47Sub RunTest() 48 49'************************************************************************* 50' INTERFACE: 51' com.sun.star.text.XTextTable 52'************************************************************************* 53On Error Goto ErrHndl 54 Dim bOK As Boolean 55 Dim i As Integer, j As Integer 56 Dim oRows As Object, oColumns As Object 57 Dim oCursor As Object, oCell As Object 58 Dim aNames As Variant 59 Dim nDscColumns As Integer, nDscRows As Integer 60 61 Test.StartMethod("initialize()") 62 bOK = true 63 ' Object is already was initialized, when it was created... So, assume that this is OK. 64 65 For i = 0 to nTableW - 1 66 For j = 0 to nTableH - 1 67 oObj.getCellByPosition(i, j).Value = i + j * nTableW 68 Next j 69 Next i 70 71 nDscColumns = ubound(oObj.getColumnDescriptions()) + 1 72 nDscRows = ubound(oObj.getRowDescriptions()) + 1 73 74 bOK = bOK AND nDscRows = nTableH AND nDscColumns = nTableW 75 if NOT bOK then 76 Out.Log("The table must have size (" + nTableW + "," + nTableH + _ 77 "), but descriptions returned for size (" + nDscColumns + "," + nDscRows + ")") 78 endif 79 Test.MethodTested("initialize()", bOK) 80 81 Test.StartMethod("getRows()") 82 bOK = true 83 84 oRows = oObj.getRows() 85 86 bOK = bOK AND hasUnoInterfaces(oRows, "com.sun.star.table.XTableRows") 87 bOK = bOK AND oRows.getCount() = nTableH 88 Test.MethodTested("getRows()", bOK) 89 90 Test.StartMethod("getColumns()") 91 bOK = true 92 93 oColumns = oObj.getColumns() 94 95 bOK = bOK AND hasUnoInterfaces(oColumns, "com.sun.star.table.XTableColumns") 96 bOK = bOK AND oColumns.getCount() = nTableW 97 Test.MethodTested("getColumns()", bOK) 98 99 100 Test.StartMethod("createCursorByCellName()") 101 bOK = true 102 oCursor = oObj.createCursorByCellName("B2") 103 bOK = bOK AND hasUnoInterfaces(oCursor, "com.sun.star.text.XTextTableCursor") 104 bOK = bOK AND oCursor.getRangeName() = "B2" 105 Test.MethodTested("createCursorByCellName()", bOK) 106 107 oCursor.splitRange(1, true) 108 oCursor.splitRange(1, false) 109 110 Test.StartMethod("getCellNames()") 111 bOK = true 112 aNames = oObj.getCellNames() 113 bOK = bOK AND ubound(aNames) = nTableW * nTableH + 1 ' = nTableW * nTableH - 1 + 2(after splitting) 114 Test.MethodTested("getCellNames()", bOK) 115 116 Test.StartMethod("getCellByName()") 117 bOK = true 118 oCell = oObj.getCellByPosition(0,0) 119 oCell.String = "A1" 120 oCell = oObj.getCellByName("A1") 121 bOK = bOK AND oCell.String = "A1" 122 123 oCell = oObj.getCellByName("B2.2.1") 124 bOK = bOK AND hasUnoInterfaces(oCell, "com.sun.star.table.XCell") 125 126 Test.MethodTested("getCellByName()", bOK) 127 128 ReCreateObj() 129Exit Sub 130ErrHndl: 131 Test.Exception() 132 bOK = false 133 resume next 134End Sub 135</script:module> 136