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