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="sheet_XNamedRanges" 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.sheet.XNamedRanges
46'*************************************************************************
47On Error Goto ErrHndl
48    Dim bOK As Boolean
49    Dim count As Integer
50    Dim outRange As New com.sun.star.table.CellAddress
51    Dim range As New com.sun.star.table.CellRangeAddress
52    Dim i As Integer
53
54    Test.StartMethod("addNewByName()")
55    bOK = true
56    outRange.Sheet = 0
57    outRange.Row = 1
58    outRange.Column = 1
59    count = oObj.Count
60    oObj.addNewByName(cIfcShortName, "T4:Y7", outRange, 0)
61    bOK = bOK AND oObj.count = count + 1
62    bOK = bOK AND oObj.hasByName(cIfcShortName)
63    Test.MethodTested("addNewByName()", bOK)
64
65    Test.StartMethod("addNewFromTitles()")
66    bOK = true
67    count = oObj.count
68
69    range.Sheet = 0
70    range.StartRow = 1
71    range.StartColumn = 2
72    range.EndRow = 3
73    range.EndColumn = 4
74
75    for i = 1 to 5
76        oDoc.Sheets(0).getCellByPosition(i, 1).String = "Col" &amp; i
77    next i
78
79    oObj.addNewFromTitles(range, com.sun.star.sheet.Border.TOP)
80
81    bOK = bOK AND (oObj.count = count + 3)
82
83    bOK = bOK AND NOT oObj.hasByName("Col1")
84    bOK = bOK AND oObj.hasByName("Col2")
85    bOK = bOK AND oObj.hasByName("Col3")
86    bOK = bOK AND oObj.hasByName("Col4")
87    bOK = bOK AND NOT oObj.hasByName("Col5")
88    Test.MethodTested("addNewFromTitles()", bOK)
89
90    Test.StartMethod("removeByName()")
91    bOK = true
92    count = oObj.Count
93    oObj.removeByName(cIfcShortName)
94    bOK = bOK AND (count = oObj.count + 1)
95    bOK = bOK AND NOT oObj.hasByName(cIfcShortName)
96    Test.MethodTested("removeByName()", bOK)
97
98    Test.StartMethod("outputList()")
99    bOK = true
100    outRange.Sheet = 0
101    outRange.Row = 5
102    outRange.Column = 5
103
104    count = oObj.count
105    for i = 4 to 5 + count
106        oDoc.Sheets(0).getCellByPosition(5, i).String = "a"
107        oDoc.Sheets(0).getCellByPosition(6, i).String = "b"
108    next i
109
110    oObj.outputList(outRange)
111
112    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 4).String = "a"
113    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 4).String = "b"
114    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 5 + count).String = "a"
115    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 5 + count).String = "b"
116
117    for i = 5 to 4 + count
118        bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, i).String &lt;&gt; "a"
119        bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, i).String &lt;&gt; "b"
120        bOK = bOK AND oObj.hasByName(oDoc.Sheets(0).getCellByPosition(5, i).String)
121    next i
122
123    Test.MethodTested("outputList()", bOK)
124
125Exit Sub
126ErrHndl:
127    Test.Exception()
128    bOK = false
129    resume next
130End Sub
131</script:module>
132