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="i18n_XCalendar" 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.i18n.XCalendar 46'************************************************************************* 47On Error Goto ErrHndl 48 Dim bOK As Boolean 49 Dim oLocaleData As Object 50 Dim oLocale As Object 51 Dim allLocales As Variant 52 Dim allCalendars As Variant 53 Dim uniqueID As String 54 Dim oCalendar As Object 55 Dim dDateTime As Double 56 Dim aValue As Variant 57 Dim oldValue As Variant 58 Dim newValue As Variant 59 Dim i As Integer 60 61 oLocaleData = createUnoService("com.sun.star.i18n.LocaleData") 62 allLocales = oLocaleData.getAllInstalledLocaleNames() 63 Out.Log("Found " + ubound(allLocales) + " Loacales registered in the system") 64 Randomize 65 oLocale = allLocales(rnd * ubound(allLocales)) 66 Out.Log("Choose for testing : " + oLocale.Country) 67 68 Test.StartMethod("getAllCalendars()") 69 bOK = true 70 allCalendars = oObj.getAllCalendars(oLocale) 71 Out.Log("There are " + ubound(allCalendars) + 1 + " calendars for this locale.") 72 bOK = bOK AND NOT isNULL(allCalendars) 73 Test.MethodTested("getAllCalendars()", bOK) 74 75 Test.StartMethod("loadDefaultCalendar()") 76 bOK = true 77 oObj.loadDefaultCalendar(oLocale) 78 bOK = bOK AND oObj.getLoadedCalendar().Default 79 Test.MethodTested("loadDefaultCalendar()", bOK) 80 81 Test.StartMethod("getUniqueID()") 82 bOK = true 83 uniqueID = oObj.getUniqueID() 84 Out.Log("UniqueID for loaded calendar is " + uniqueID) 85 bOK = bOK AND (uniqueID = allCalendars(0)) 86 Test.MethodTested("getUniqueID()", bOK) 87 88 Test.StartMethod("loadCalendar()") 89 bOK = true 90 oObj.loadCalendar(allCalendars(0), oLocale) 91 bOK = bOK AND NOT isNULL(oObj.getLoadedCalendar()) 92 Test.MethodTested("loadCalendar()", bOK) 93 94 Test.StartMethod("getLoadedCalendar()") 95 bOK = true 96 oCalendar = oObj.getLoadedCalendar() 97 Out.Log("Loaded calendar's name is '" + oCalendar.Name + "'") 98 bOK = bOK AND NOT isNULL(oCalendar) 99 Test.MethodTested("getLoadedCalendar()", bOK) 100 101 Test.StartMethod("setDateTime()") 102 Test.StartMethod("getDateTime()") 103 bOK = true 104 oObj.setDateTime(12345.25) 105 dDateTime = oObj.getDateTime() 106 bOK = bOK AND dDateTime = 12345.25 107 Out.Log("Expected: 12345,25; Actual: " + dDateTime) 108 Test.MethodTested("setDateTime()", bOK) 109 Test.MethodTested("getDateTime()", bOK) 110 111 Test.StartMethod("getFirstDayOfWeek()") 112 Test.StartMethod("setFirstDayOfWeek()") 113 bOK = true 114 oObj.setFirstDayOfWeek(com.sun.star.i18n.Weekdays.SATURDAY) 115 Out.Log("Expected: " + com.sun.star.i18n.Weekdays.SATURDAY + ", Actual: " + oObj.getFirstDayOfWeek()) 116 bOK = bOK AND oObj.getFirstDayOfWeek() = com.sun.star.i18n.Weekdays.SATURDAY 117 oObj.setFirstDayOfWeek(com.sun.star.i18n.Weekdays.SUNDAY) 118 Out.Log("Expected: " + com.sun.star.i18n.Weekdays.SUNDAY + ", Actual: " + oObj.getFirstDayOfWeek()) 119 bOK = bOK AND oObj.getFirstDayOfWeek() = com.sun.star.i18n.Weekdays.SUNDAY 120 121 Test.MethodTested("getFirstDayOfWeek()", bOK) 122 Test.MethodTested("setFirstDayOfWeek()", bOK) 123 124 Test.StartMethod("setValue()") 125 Test.StartMethod("getValue()") 126 bOK = true 127 bOK = bOK AND TestValue(1, com.sun.star.i18n.Months.JANUARY, 2001, com.sun.star.i18n.WeekDays.MONDAY, 1, 1) 128 '1.01.2001 - Monday, 1-st week of month, 1-st week of year 129 bOK = bOK AND TestValue(12, com.sun.star.i18n.Months.JULY, 2001, com.sun.star.i18n.WeekDays.THURSDAY, 2, 28) 130 '12.07.2001 - Thursday, 2-nd week of month, 28-st week of year 131 132 Test.MethodTested("setValue()", bOK) 133 Test.MethodTested("getValue()", bOK) 134 135 Test.StartMethod("addValue()") 136 bOK = true 137 138 bOK = bOK AND TestAddValue("DST_OFFSET", com.sun.star.i18n.CalendarFieldIndex.DST_OFFSET, 1, 0) 139 bOK = bOK AND TestAddValue("DAY_OF_MONTH", com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 1, 0) 140 bOK = bOK AND TestAddValue("MONTH", com.sun.star.i18n.CalendarFieldIndex.MONTH, 3, 12) 141 bOK = bOK AND TestAddValue("YEAR", com.sun.star.i18n.CalendarFieldIndex.YEAR, -1, 0) 142 bOK = bOK AND TestAddValue("HOUR", com.sun.star.i18n.CalendarFieldIndex.HOUR, 7, 24) 143 bOK = bOK AND TestAddValue("MINUTE", com.sun.star.i18n.CalendarFieldIndex.MINUTE, 31, 60) 144 bOK = bOK AND TestAddValue("SECOND", com.sun.star.i18n.CalendarFieldIndex.SECOND, 13, 60) 145 bOK = bOK AND TestAddValue("MILLISECOND", com.sun.star.i18n.CalendarFieldIndex.MILLISECOND, 67, 1000) 146 bOK = bOK AND TestAddValue("ERA", com.sun.star.i18n.CalendarFieldIndex.ERA, -1, 0) 147 148 Test.MethodTested("addValue()", bOK) 149 150 Test.StartMethod("getNumberOfMonthsInYear()") 151 bOK = true 152 aValue = oObj.getNumberOfMonthsInYear() 153 Out.Log("There are " + aValue + " months in year") 154 bOK = bOK AND aValue = 12 155 Test.MethodTested("getNumberOfMonthsInYear()", bOK) 156 157 Test.StartMethod("getNumberOfDaysInWeek()") 158 bOK = true 159 aValue = oObj.getNumberOfDaysInWeek() 160 Out.Log("There are " + aValue + " days in week") 161 bOK = bOK AND aValue = 7 162 Test.MethodTested("getNumberOfDaysInWeek()", bOK) 163 164 Test.StartMethod("getMinimumNumberOfDaysForFirstWeek()") 165 bOK = true 166 aValue = oObj.getMinimumNumberOfDaysForFirstWeek() 167 Out.Log("MinimumNumberOfDaysForFirstWeek = " + aValue) 168 bOK = bOK AND aValue > 0 AND aValue < 8 169 Test.MethodTested("getMinimumNumberOfDaysForFirstWeek()", bOK) 170 171 Test.StartMethod("setMinimumNumberOfDaysForFirstWeek()") 172 bOK = true 173 oObj.setMinimumNumberOfDaysForFirstWeek(211) 174 aValue = oObj.getMinimumNumberOfDaysForFirstWeek() 175 Out.Log("MinimumNumberOfDaysForFirstWeek = " + aValue) 176 bOK = bOK AND aValue > 0 AND aValue < 8 177 Test.MethodTested("setMinimumNumberOfDaysForFirstWeek()", bOK) 178 179 Test.StartMethod("getMonths()") 180 bOK = true 181 Dim allMonths As Variant 182 Dim cAllMonths As String 183 allMonths = oObj.getMonths() 184 Out.Log("Returned " + ubound(allMonths) + 1 + " months.") 185 bOK = bOK AND ubound(allMonths) + 1= oObj.getNumberOfMonthsInYear() 186 if (bOK) then 187 cAllMonths = "" 188 for i = 0 to ubound(allMonths) 189 cAllMonths = cAllMonths + allMonths(i).FullName + ", " 190 next i 191 Out.Log("Months: " + cAllMonths) 192 end if 193 194 Test.MethodTested("getMonths()", bOK) 195 196 Test.StartMethod("getDays()") 197 bOK = true 198 Dim allDays As Variant 199 Dim cAllDays As String 200 allDays = oObj.getDays() 201 Out.Log("Returned " + ubound(allMonths) + 1 + " days.") 202 bOK = bOK AND ubound(allDays) + 1= oObj.getNumberOfDaysInWeek() 203 if (bOK) then 204 cAllDays = "" 205 for i = 0 to ubound(allDays) 206 cAllDays = cAllDays + allDays(i).FullName + ", " 207 next i 208 Out.Log("Days: " + cAllDays) 209 end if 210 Test.MethodTested("getDays()", bOK) 211 212 Test.StartMethod("getDisplayName()") 213 bOK = true 214 Dim cDisplayName As String 215 cDisplayName = oObj.getDisplayName(com.sun.star.i18n.CalendarDisplayIndex.MONTH, com.sun.star.i18n.Months.JANUARY, 1) 216 Out.Log("Full name for JANUARY is: " + cDisplayName) 217 bOK = bOK AND cDisplayName <> "" 218 Test.MethodTested("getDisplayName()", bOK) 219 220 Test.StartMethod("isValid()") 221 bOK = true 222 223 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 30) 224 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, com.sun.star.i18n.Months.FEBURARY) 225 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, 2001) 226 Out.Log("isValid() = " + oObj.isValid()) 227 bOK = bOK AND NOT oObj.isValid() 228 229 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, 27) 230 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, com.sun.star.i18n.Months.FEBURARY) 231 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, 2001) 232 Out.Log("isValid() = " + oObj.isValid()) 233 bOK = bOK AND oObj.isValid() 234 235 Test.MethodTested("isValid()", bOK) 236 237Exit Sub 238ErrHndl: 239 Test.Exception() 240 bOK = false 241 resume next 242End Sub 243 244Function TestValue(_Day As Integer, _Month As Integer, _Year As Integer, _ 245 _Day_of_week As Integer, _Week_of_month As Integer, _Week_of_year As Integer) As Boolean 246 247 Dim bOK As Boolean 248 Dim aDay As Integer, aMonth As Integer, aYear As Integer 249 Dim aDay_of_week As Integer, aWeek_of_Month As Integer, aWeek_of_year As Integer 250 251 bOK = true 252 253 Out.Log("Set date to " + _Day + "." + _Month + "." + _Year + ";") 254 255 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH, _Day) 256 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.MONTH, _Month) 257 oObj.setValue(com.sun.star.i18n.CalendarFieldIndex.YEAR, _Year) 258 259 aDay = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_MONTH) 260 aMonth = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.MONTH) 261 aYear = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.YEAR) 262 263 Out.Log("Now date is " + aDay + "." + aMonth + "." + aYear + ";") 264 265 bOK = (aDay = _Day) AND (aMonth = _Month) AND (aYear = _Year) 266 267 if (bOK) then 268 aDay_of_week = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.DAY_OF_WEEK) 269 aWeek_of_month = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.WEEK_OF_MONTH) 270 aWeek_of_year = oObj.getValue(com.sun.star.i18n.CalendarFieldIndex.WEEK_OF_YEAR) 271 Out.Log("aDay_of_week: Expected: " + _Day_of_week + ", Actual: " + aDay_of_week) 272 Out.Log("aWeek_of_month: Expected: " + _Week_of_month + ", Actual: " + aWeek_of_month) 273 Out.Log("aWeek_of_year: Expected: " + _Week_of_year + ", Actual: " + aWeek_of_year) 274 bOK = (aDay_of_week = _Day_of_week) AND (aWeek_of_month = _Week_of_month) AND (aWeek_of_year = _Week_of_year) 275 end if 276 277 TestValue() = bOK 278 279Exit Function 280ErrHndl: 281 Test.Exception() 282 TestValue() = false 283End Function 284 285Function TestAddValue(valname As String, Idx As Integer, incValue As Integer, valModule As Integer) As Boolean 286 Dim aValue As Integer 287 Dim newValue As Integer 288 Dim bOK As Boolean 289 290 aValue = oObj.getValue(idx) 291 oObj.addValue(idx, incValue) 292 newValue = oObj.getValue(idx) 293 if (valModule = 0) then 294 bOK = (newValue = (aValue + incValue)) 295 Out.Log(valname + ": Expected: " + (aValue + incValue) + ", Actual: " + newValue) 296 else 297 bOK = (newValue = (aValue + incValue) mod valModule) 298 Out.Log(valname + ": Expected: " + (aValue + incValue) mod valModule + ", Actual: " + newValue) 299 end if 300 TestAddValue() = bOK 301Exit Function 302ErrHndl: 303 Test.Exception() 304 TestAddValue() = false 305End Function 306</script:module> 307