1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XCalendar" script:language="StarBasic">
'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org. If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************
' Be sure that all variables are dimensioned:
option explicit
Sub RunTest()
'*************************************************************************
' INTERFACE:
' com.sun.star.i18n.XCalendar
'*************************************************************************
On Error Goto ErrHndl
Dim bOK As Boolean
Dim oLocaleData As Object
Dim oLocale As Object
Dim allLocales As Variant
Dim allCalendars As Variant
Dim uniqueID As String
Dim oCalendar As Object
Dim dDateTime As Double
Dim aValue As Variant
Dim oldValue As Variant
Dim newValue As Variant
Dim i As Integer
oLocaleData = createUnoService("com.sun.star.i18n.LocaleData")
allLocales = oLocaleData.getAllInstalledLocaleNames()
Out.Log("Found " + ubound(allLocales) + " Loacales registered in the system")
Randomize
oLocale = allLocales(rnd * ubound(allLocales))
Out.Log("Choose for testing : " + oLocale.Country)
Test.StartMethod("getAllCalendars()")
bOK = true
allCalendars = oObj.getAllCalendars(oLocale)
Out.Log("There are " + ubound(allCalendars) + 1 + " calendars for this locale.")
bOK = bOK AND NOT isNULL(allCalendars)
Test.MethodTested("getAllCalendars()", bOK)
Test.StartMethod("loadDefaultCalendar()")
bOK = true
oObj.loadDefaultCalendar(oLocale)
bOK = bOK AND oObj.getLoadedCalendar().Default
Test.MethodTested("loadDefaultCalendar()", bOK)
Test.StartMethod("getUniqueID()")
bOK = true
uniqueID = oObj.getUniqueID()
Out.Log("UniqueID for loaded calendar is " + uniqueID)
bOK = bOK AND (uniqueID = allCalendars(0))
Test.MethodTested("getUniqueID()", bOK)
Test.StartMethod("loadCalendar()")
bOK = true
oObj.loadCalendar(allCalendars(0), oLocale)
bOK = bOK AND NOT isNULL(oObj.getLoadedCalendar())
Test.MethodTested("loadCalendar()", bOK)
Test.StartMethod("getLoadedCalendar()")
bOK = true
oCalendar = oObj.getLoadedCalendar()
Out.Log("Loaded calendar's name is '" + oCalendar.Name + "'")
bOK = bOK AND NOT isNULL(oCalendar)
Test.MethodTested("getLoadedCalendar()", bOK)
Test.StartMethod("setDateTime()")
Test.StartMethod("getDateTime()")
bOK = true
oObj.setDateTime(12345.25)
dDateTime = oObj.getDateTime()
bOK = bOK AND dDateTime = 12345.25
Out.Log("Expected: 12345,25; Actual: " + dDateTime)
Test.MethodTested("setDateTime()", bOK)
Test.MethodTested("getDateTime()", bOK)
Test.StartMethod("getFirstDayOfWeek()")
Test.StartMethod("setFirstDayOfWeek()")
bOK = true
oObj.setFirstDayOfWeek(com.sun.star.i18n.Weekdays.SATURDAY)
Out.Log("Expected: " + com.sun.star.i18n.Weekdays.SATURDAY + ", Actual: " + oObj.getFirstDayOfWeek())
bOK = bOK AND oObj.getFirstDayOfWeek() = com.sun.star.i18n.Weekdays.SATURDAY
oObj.setFirstDayOfWeek(com.sun.star.i18n.Weekdays.SUNDAY)
Out.Log("Expected: " + com.sun.star.i18n.Weekdays.SUNDAY + ", Actual: " + oObj.getFirstDayOfWeek())
bOK = bOK AND oObj.getFirstDayOfWeek() = com.sun.star.i18n.Weekdays.SUNDAY
Test.MethodTested("getFirstDayOfWeek()", bOK)
Test.MethodTested("setFirstDayOfWeek()", bOK)
Test.StartMethod("setValue()")
Test.StartMethod("getValue()")
bOK = true
bOK = bOK AND TestValue(1, com.sun.star.i18n.Months.JANUARY, 2001, com.sun.star.i18n.WeekDays.MONDAY, 1, 1)
'1.01.2001 - Monday, 1-st week of month, 1-st week of year
bOK = bOK AND TestValue(12, com.sun.star.i18n.Months.JULY, 2001, com.sun.star.i18n.WeekDays.THURSDAY, 2, 28)
'12.07.2001 - Thursday, 2-nd week of month, 28-st week of year
Test.MethodTested("setValue()", bOK)
Test.MethodTested("getValue()", bOK)
Test.StartMethod("addValue()")
bOK = true
bOK = bOK AND TestAddValue("DST_OFFSET", com.sun.star.i18n.CalendarFieldIndex.DST_OFFSET, 1, 0)
bOK = bOK AND TestAddValue("DAY_OF_MONTH", com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 1, 0)
bOK = bOK AND TestAddValue("MONTH", com.sun.star.i18n.CalendarFieldIndex.MONTH, 3, 12)
bOK = bOK AND TestAddValue("YEAR", com.sun.star.i18n.CalendarFieldIndex.YEAR, -1, 0)
bOK = bOK AND TestAddValue("HOUR", com.sun.star.i18n.CalendarFieldIndex.HOUR, 7, 24)
bOK = bOK AND TestAddValue("MINUTE", com.sun.star.i18n.CalendarFieldIndex.MINUTE, 31, 60)
bOK = bOK AND TestAddValue("SECOND", com.sun.star.i18n.CalendarFieldIndex.SECOND, 13, 60)
bOK = bOK AND TestAddValue("MILLISECOND", com.sun.star.i18n.CalendarFieldIndex.MILLISECOND, 67, 1000)
bOK = bOK AND TestAddValue("ERA", com.sun.star.i18n.CalendarFieldIndex.ERA, -1, 0)
Test.MethodTested("addValue()", bOK)
Test.StartMethod("getNumberOfMonthsInYear()")
bOK = true
aValue = oObj.getNumberOfMonthsInYear()
Out.Log("There are " + aValue + " months in year")
bOK = bOK AND aValue = 12
Test.MethodTested("getNumberOfMonthsInYear()", bOK)
Test.StartMethod("getNumberOfDaysInWeek()")
bOK = true
aValue = oObj.getNumberOfDaysInWeek()
Out.Log("There are " + aValue + " days in week")
bOK = bOK AND aValue = 7
Test.MethodTested("getNumberOfDaysInWeek()", bOK)
Test.StartMethod("getMinimumNumberOfDaysForFirstWeek()")
bOK = true
aValue = oObj.getMinimumNumberOfDaysForFirstWeek()
Out.Log("MinimumNumberOfDaysForFirstWeek = " + aValue)
bOK = bOK AND aValue > 0 AND aValue < 8
Test.MethodTested("getMinimumNumberOfDaysForFirstWeek()", bOK)
Test.StartMethod("setMinimumNumberOfDaysForFirstWeek()")
bOK = true
oObj.setMinimumNumberOfDaysForFirstWeek(211)
aValue = oObj.getMinimumNumberOfDaysForFirstWeek()
Out.Log("MinimumNumberOfDaysForFirstWeek = " + aValue)
bOK = bOK AND aValue > 0 AND aValue < 8
Test.MethodTested("setMinimumNumberOfDaysForFirstWeek()", bOK)
Test.StartMethod("getMonths()")
bOK = true
Dim allMonths As Variant
Dim cAllMonths As String
allMonths = oObj.getMonths()
Out.Log("Returned " + ubound(allMonths) + 1 + " months.")
bOK = bOK AND ubound(allMonths) + 1= oObj.getNumberOfMonthsInYear()
if (bOK) then
cAllMonths = ""
for i = 0 to ubound(allMonths)
cAllMonths = cAllMonths + allMonths(i).FullName + ", "
next i
Out.Log("Months: " + cAllMonths)
end if
Test.MethodTested("getMonths()", bOK)
Test.StartMethod("getDays()")
bOK = true
Dim allDays As Variant
Dim cAllDays As String
allDays = oObj.getDays()
Out.Log("Returned " + ubound(allMonths) + 1 + " days.")
bOK = bOK AND ubound(allDays) + 1= oObj.getNumberOfDaysInWeek()
if (bOK) then
cAllDays = ""
for i = 0 to ubound(allDays)
cAllDays = cAllDays + allDays(i).FullName + ", "
next i
Out.Log("Days: " + cAllDays)
end if
Test.MethodTested("getDays()", bOK)
Test.StartMethod("getDisplayName()")
bOK = true
Dim cDisplayName As String
cDisplayName = oObj.getDisplayName(com.sun.star.i18n.CalendarDisplayIndex.MONTH, com.sun.star.i18n.Months.JANUARY, 1)
Out.Log("Full name for JANUARY is: " + cDisplayName)
bOK = bOK AND cDisplayName <> ""
Test.MethodTested("getDisplayName()", bOK)
Test.StartMethod("isValid()")
bOK = true
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 30)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, com.sun.star.i18n.Months.FEBURARY)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, 2001)
Out.Log("isValid() = " + oObj.isValid())
bOK = bOK AND NOT oObj.isValid()
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 27)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, com.sun.star.i18n.Months.FEBURARY)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, 2001)
Out.Log("isValid() = " + oObj.isValid())
bOK = bOK AND oObj.isValid()
Test.MethodTested("isValid()", bOK)
Exit Sub
ErrHndl:
Test.Exception()
bOK = false
resume next
End Sub
Function TestValue(_Day As Integer, _Month As Integer, _Year As Integer, _
_Day_of_week As Integer, _Week_of_month As Integer, _Week_of_year As Integer) As Boolean
Dim bOK As Boolean
Dim aDay As Integer, aMonth As Integer, aYear As Integer
Dim aDay_of_week As Integer, aWeek_of_Month As Integer, aWeek_of_year As Integer
bOK = true
Out.Log("Set date to " + _Day + "." + _Month + "." + _Year + ";")
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, _Day)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, _Month)
oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, _Year)
aDay = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH)
aMonth = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.MONTH)
aYear = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.YEAR)
Out.Log("Now date is " + aDay + "." + aMonth + "." + aYear + ";")
bOK = (aDay = _Day) AND (aMonth = _Month) AND (aYear = _Year)
if (bOK) then
aDay_of_week = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_WEEK)
aWeek_of_month = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.WEEK_OF_MONTH)
aWeek_of_year = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.WEEK_OF_YEAR)
Out.Log("aDay_of_week: Expected: " + _Day_of_week + ", Actual: " + aDay_of_week)
Out.Log("aWeek_of_month: Expected: " + _Week_of_month + ", Actual: " + aWeek_of_month)
Out.Log("aWeek_of_year: Expected: " + _Week_of_year + ", Actual: " + aWeek_of_year)
bOK = (aDay_of_week = _Day_of_week) AND (aWeek_of_month = _Week_of_month) AND (aWeek_of_year = _Week_of_year)
end if
TestValue() = bOK
Exit Function
ErrHndl:
Test.Exception()
TestValue() = false
End Function
Function TestAddValue(valname As String, Idx As Integer, incValue As Integer, valModule As Integer) As Boolean
Dim aValue As Integer
Dim newValue As Integer
Dim bOK As Boolean
aValue = oObj.getValue(idx)
oObj.addValue(idx, incValue)
newValue = oObj.getValue(idx)
if (valModule = 0) then
bOK = (newValue = (aValue + incValue))
Out.Log(valname + ": Expected: " + (aValue + incValue) + ", Actual: " + newValue)
else
bOK = (newValue = (aValue + incValue) mod valModule)
Out.Log(valname + ": Expected: " + (aValue + incValue) mod valModule + ", Actual: " + newValue)
end if
TestAddValue() = bOK
Exit Function
ErrHndl:
Test.Exception()
TestAddValue() = false
End Function
</script:module>
|