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="chart_XChartDataArray" 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 nTableH As Integer
39'      Global nTableW As Integer
40
41'*************************************************************************
42
43
44
45
46
47Sub RunTest()
48
49'*************************************************************************
50' INTERFACE:
51' com.sun.star.chart.XChartDataArray
52'*************************************************************************
53On Error Goto ErrHndl
54
55    Dim bOK As Boolean
56    Dim i As Integer, j As Integer
57    Dim objRowDsc As Variant, objColDsc As Variant
58    Dim objEl As Variant, newEl As Variant
59    Dim chData As Variant
60
61    Out.Log("Object is '" + cObjectName + "'")
62    if (cObjectName = "sw.SwXTextTable") then
63        Out.Log("Object is 'SwXTextTable'. First, remove labels.")
64        oObj.setPropertyValue("ChartRowAsLabel", false)
65        oObj.setPropertyValue("ChartColumnAsLabel", false)
66    end if
67
68    Test.StartMethod("getData()")
69    bOK = true
70
71    Dim oData As Object
72    oData = oObj.getData()
73    bOK = bOK AND NOT isNULL(oData)
74    Test.MethodTested("getData()", bOK)
75
76    Test.StartMethod("setData()")
77    bOK = true
78
79    Dim newData(nTableH - 1) As Variant
80    Dim a(nTableW - 1) As Double
81
82    for i = 0 to nTableH - 1
83        ReDim a(nTableW - 1) As Double
84        for j = 0 to nTableW - 1
85            a(j) = ((nTableW * 4) / (i + 2) + j * 2) + 16
86        next j
87        newData(i) = a()
88    next i
89
90    oObj.setData(newData())
91    chData = oObj.getData()
92
93    bOK = bOK AND ubound(oObj.getRowDescriptions()) = nTableH - 1
94    bOK = bOK AND ubound(oObj.getColumnDescriptions()) = nTableW - 1
95
96    for i = 0 to nTableH - 1
97        objEl = chData(i)
98        newEl = newData(i)
99        for j = 0 to nTableW - 1
100            bOK = bOK AND objEl(j) = newEl(j)
101        next j
102    next i
103
104    Test.MethodTested("setData()", bOK)
105
106    if (cObjectName = "sw.SwXTextTable") then
107        Out.Log("Object is 'SwXTextTable'. Initialize labels.")
108        oObj.setPropertyValue("ChartRowAsLabel", true)
109        oObj.setPropertyValue("ChartColumnAsLabel", true)
110    end if
111
112    Test.StartMethod("getRowDescriptions()")
113    bOK = true
114
115    Dim oRowDsc() As String
116    oRowDsc = oObj.getRowDescriptions()
117    bOK = bOK AND NOT isNULL(oRowDsc)
118    Test.MethodTested("getRowDescriptions()", bOK)
119
120    Test.StartMethod("setRowDescriptions()")
121    bOK = true
122
123    Dim newRowDsc(nTableH - 2) As String
124    for i = 0 to nTableH - 2 ' -1 for 0-index and -1 for columns labels
125        newRowDsc(i) = "RowDsc " + i
126    next i
127
128    oObj.setRowDescriptions(newRowDsc())
129
130    objRowDsc = oObj.getRowDescriptions()
131
132    for i = 0 to nTableH - 2
133        bOK = bOK AND newRowDsc(i) = objRowDsc(i)
134    next i
135
136    Test.MethodTested("setRowDescriptions()", bOK)
137
138    Test.StartMethod("getColumnDescriptions()")
139    bOK = true
140    bOK = bOK AND NOT isNULL(oObj.getColumnDescriptions())
141    Test.MethodTested("getColumnDescriptions()", bOK)
142
143    Test.StartMethod("setColumnDescriptions()")
144    bOK = true
145
146    Dim newColDsc(nTableW - 2) As String
147    for i = 0 to nTableW - 2
148        newColDsc(i) = "ColDsc " + i
149    next i
150
151    oObj.setColumnDescriptions(newColDsc())
152
153    objColDsc = oObj.getColumnDescriptions()
154
155    for i = 0 to nTableW - 2
156        bOK = bOK AND newColDsc(i) = objColDsc(i)
157    next i
158
159    if (cObjectName = "sw.SwXTextTable") then
160        Out.Log("Object is 'SwXTextTable'. Remove labels finally.")
161        oObj.setPropertyValue("ChartRowAsLabel", false)
162        oObj.setPropertyValue("ChartColumnAsLabel", false)
163    end if
164
165    Test.MethodTested("setColumnDescriptions()", bOK)
166
167
168Exit Sub
169ErrHndl:
170    Test.Exception()
171    bOK = false
172    resume next
173End Sub
174</script:module>
175