1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.i18n; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.i18n.CalendarDisplayIndex; 33*cdf0e10cSrcweir import com.sun.star.i18n.CalendarFieldIndex; 34*cdf0e10cSrcweir import com.sun.star.i18n.CalendarItem; 35*cdf0e10cSrcweir import com.sun.star.i18n.XCalendar; 36*cdf0e10cSrcweir import com.sun.star.i18n.XLocaleData; 37*cdf0e10cSrcweir import com.sun.star.lang.Locale; 38*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 39*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir /** 42*cdf0e10cSrcweir * Testing <code>com.sun.star.i18n.XCalendar</code> 43*cdf0e10cSrcweir * interface methods : 44*cdf0e10cSrcweir * <ul> 45*cdf0e10cSrcweir * <li><code> loadDefaultCalendar()</code></li> 46*cdf0e10cSrcweir * <li><code> loadCalendar()</code></li> 47*cdf0e10cSrcweir * <li><code> getLoadedCalendar()</code></li> 48*cdf0e10cSrcweir * <li><code> getAllCalendars()</code></li> 49*cdf0e10cSrcweir * <li><code> getUniqueID()</code></li> 50*cdf0e10cSrcweir * <li><code> setDateTime()</code></li> 51*cdf0e10cSrcweir * <li><code> getDateTime()</code></li> 52*cdf0e10cSrcweir * <li><code> setValue()</code></li> 53*cdf0e10cSrcweir * <li><code> getValue()</code></li> 54*cdf0e10cSrcweir * <li><code> isValid()</code></li> 55*cdf0e10cSrcweir * <li><code> addValue()</code></li> 56*cdf0e10cSrcweir * <li><code> getFirstDayOfWeek()</code></li> 57*cdf0e10cSrcweir * <li><code> setFirstDayOfWeek()</code></li> 58*cdf0e10cSrcweir * <li><code> setMinimumNumberOfDaysForFirstWeek()</code></li> 59*cdf0e10cSrcweir * <li><code> getMinimumNumberOfDaysForFirstWeek()</code></li> 60*cdf0e10cSrcweir * <li><code> getNumberOfMonthsInYear()</code></li> 61*cdf0e10cSrcweir * <li><code> getNumberOfDaysInWeek()</code></li> 62*cdf0e10cSrcweir * <li><code> getMonths()</code></li> 63*cdf0e10cSrcweir * <li><code> getDays()</code></li> 64*cdf0e10cSrcweir * <li><code> getDisplayName()</code></li> 65*cdf0e10cSrcweir * </ul> <p> 66*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 67*cdf0e10cSrcweir * @see com.sun.star.i18n.XCalendar 68*cdf0e10cSrcweir */ 69*cdf0e10cSrcweir public class _XCalendar extends MultiMethodTest { 70*cdf0e10cSrcweir private boolean debug = false; 71*cdf0e10cSrcweir public XCalendar oObj = null; 72*cdf0e10cSrcweir public String[][] calendars; 73*cdf0e10cSrcweir public int[] count; 74*cdf0e10cSrcweir public double newDTime = 1000.75; 75*cdf0e10cSrcweir public short newValue = 2; 76*cdf0e10cSrcweir public short firstDay = 2; 77*cdf0e10cSrcweir public short mdfw = 3; 78*cdf0e10cSrcweir double aOriginalDTime = 0; 79*cdf0e10cSrcweir Locale[] installed_locales; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir public void before() { 82*cdf0e10cSrcweir XLocaleData locData = null; 83*cdf0e10cSrcweir try { 84*cdf0e10cSrcweir locData = (XLocaleData) UnoRuntime.queryInterface( 85*cdf0e10cSrcweir XLocaleData.class, 86*cdf0e10cSrcweir ((XMultiServiceFactory)tParam.getMSF()).createInstance( 87*cdf0e10cSrcweir "com.sun.star.i18n.LocaleData")); 88*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir installed_locales = locData.getAllInstalledLocaleNames(); 92*cdf0e10cSrcweir calendars = new String[installed_locales.length][]; 93*cdf0e10cSrcweir count = new int[installed_locales.length]; 94*cdf0e10cSrcweir oObj.loadDefaultCalendar(installed_locales[0]); 95*cdf0e10cSrcweir aOriginalDTime = oObj.getDateTime(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir debug = tParam.getBool("DebugIsActive"); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * Restore the changed time during the test to the original value of the 102*cdf0e10cSrcweir * machine: has to be correct for the following interface tests. 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir public void after() { 105*cdf0e10cSrcweir oObj.loadDefaultCalendar(installed_locales[0]); 106*cdf0e10cSrcweir oObj.setDateTime(aOriginalDTime); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** 110*cdf0e10cSrcweir * Loads default calendar for different locales. <p> 111*cdf0e10cSrcweir * Has <b> OK </b> status if method loads calendar, that is 112*cdf0e10cSrcweir * default for a given locale. 113*cdf0e10cSrcweir */ 114*cdf0e10cSrcweir public void _loadDefaultCalendar() { 115*cdf0e10cSrcweir boolean res = true; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 118*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 119*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 120*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 121*cdf0e10cSrcweir oObj.loadDefaultCalendar(installed_locales[i]); 122*cdf0e10cSrcweir if (oObj.getLoadedCalendar().Default) { 123*cdf0e10cSrcweir //log.println(lang + " ... OK"); 124*cdf0e10cSrcweir } else { 125*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir res &= oObj.getLoadedCalendar().Default; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir tRes.tested("loadDefaultCalendar()", res); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /** 134*cdf0e10cSrcweir * Tries to obtain calendars for a number of locales. <p> 135*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns more than zero calendars for 136*cdf0e10cSrcweir * every locale. 137*cdf0e10cSrcweir */ 138*cdf0e10cSrcweir public void _getAllCalendars() { 139*cdf0e10cSrcweir boolean res = true; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 142*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 143*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 144*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 145*cdf0e10cSrcweir calendars[i] = oObj.getAllCalendars(installed_locales[i]); 146*cdf0e10cSrcweir count[i] = calendars[i].length-1; 147*cdf0e10cSrcweir if (calendars[i].length > 0) { 148*cdf0e10cSrcweir //log.println(lang + " ... OK"); 149*cdf0e10cSrcweir } else { 150*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir res &= (calendars[i].length > 0); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir tRes.tested("getAllCalendars()", res); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** 158*cdf0e10cSrcweir * Loads calendars for a number of locales. <p> 159*cdf0e10cSrcweir * Has <b> OK </b> status if loaded calendar names are equal to gotten 160*cdf0e10cSrcweir * calendar names after loading.<p> 161*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 162*cdf0e10cSrcweir * <ul> 163*cdf0e10cSrcweir * <li> <code> getAllCalendars() </code> : gets all calendars for a given 164*cdf0e10cSrcweir * locale </li> 165*cdf0e10cSrcweir * </ul> 166*cdf0e10cSrcweir */ 167*cdf0e10cSrcweir public void _loadCalendar() { 168*cdf0e10cSrcweir boolean res = true; 169*cdf0e10cSrcweir requiredMethod("getAllCalendars()"); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 172*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 173*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 174*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 175*cdf0e10cSrcweir oObj.loadCalendar(calendars[i][0], installed_locales[i]); 176*cdf0e10cSrcweir if (calendars[i][0].equals(oObj.getLoadedCalendar().Name)) { 177*cdf0e10cSrcweir //log.println(lang + " ... OK"); 178*cdf0e10cSrcweir } else { 179*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir res &= calendars[i][0].equals(oObj.getLoadedCalendar().Name); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir tRes.tested("loadCalendar()", res); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir /** 188*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 189*cdf0e10cSrcweir * Has <b> OK </b> status if loaded calendar names are equal to gotten 190*cdf0e10cSrcweir * calendar names after loading.<p> 191*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 192*cdf0e10cSrcweir * <ul> 193*cdf0e10cSrcweir * <li> <code> loadCalendar() </code> : loads calendar using a given name 194*cdf0e10cSrcweir * and locale </li> 195*cdf0e10cSrcweir * </ul> 196*cdf0e10cSrcweir */ 197*cdf0e10cSrcweir public void _getLoadedCalendar() { 198*cdf0e10cSrcweir boolean res = true; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir requiredMethod("loadCalendar()"); 201*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 202*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 203*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 204*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 205*cdf0e10cSrcweir oObj.loadCalendar(calendars[i][0], installed_locales[i]); 206*cdf0e10cSrcweir if (calendars[i][0].equals(oObj.getLoadedCalendar().Name)) { 207*cdf0e10cSrcweir //log.println(lang + " ... OK"); 208*cdf0e10cSrcweir } else { 209*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir res &= calendars[i][0].equals(oObj.getLoadedCalendar().Name); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir tRes.tested("getLoadedCalendar()", res); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir /** 217*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 218*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value that's equal to a 219*cdf0e10cSrcweir * calendar name. <p> 220*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 221*cdf0e10cSrcweir * <ul> 222*cdf0e10cSrcweir * <li> <code> loadCalendar() </code> : loads calendar using a given name 223*cdf0e10cSrcweir * and locale </li> 224*cdf0e10cSrcweir * </ul> 225*cdf0e10cSrcweir */ 226*cdf0e10cSrcweir public void _getUniqueID() { 227*cdf0e10cSrcweir boolean res = true; 228*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 229*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 230*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 231*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 232*cdf0e10cSrcweir oObj.loadCalendar(calendars[i][0], installed_locales[i]); 233*cdf0e10cSrcweir String uID = oObj.getUniqueID(); 234*cdf0e10cSrcweir if (uID.equals(calendars[i][0])) { 235*cdf0e10cSrcweir //log.println(lang + " ... OK"); 236*cdf0e10cSrcweir } else { 237*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir res &= uID.equals(calendars[i][0]); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir tRes.tested("getUniqueID()",res); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir /** 246*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 247*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value, that's equal to 248*cdf0e10cSrcweir * value set before. <p> 249*cdf0e10cSrcweir */ 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir public void _setDateTime() { 252*cdf0e10cSrcweir boolean res = true; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 255*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 256*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 257*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 258*cdf0e10cSrcweir oObj.setDateTime(newDTime); 259*cdf0e10cSrcweir double aDTime = oObj.getDateTime(); 260*cdf0e10cSrcweir if (aDTime == newDTime) { 261*cdf0e10cSrcweir //log.println(lang + " ... OK"); 262*cdf0e10cSrcweir } else { 263*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir res &= (aDTime == newDTime); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir tRes.tested("setDateTime()", res); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir /** 272*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 273*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value, that's equal to 274*cdf0e10cSrcweir * value set before. <p> 275*cdf0e10cSrcweir */ 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir public void _getDateTime() { 278*cdf0e10cSrcweir boolean res = true; 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 281*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 282*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 283*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Country; 284*cdf0e10cSrcweir oObj.setDateTime(newDTime); 285*cdf0e10cSrcweir double aDTime = oObj.getDateTime(); 286*cdf0e10cSrcweir if (aDTime == newDTime) { 287*cdf0e10cSrcweir //log.println(lang + " ... OK"); 288*cdf0e10cSrcweir } else { 289*cdf0e10cSrcweir log.println(lang + " ... FAILED"); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir res &= (aDTime == newDTime); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir tRes.tested("getDateTime()", res); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir /** 297*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 298*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value, that's equal to 299*cdf0e10cSrcweir * value set before. <p> 300*cdf0e10cSrcweir */ 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir public void _setValue() { 303*cdf0e10cSrcweir boolean res = true; 304*cdf0e10cSrcweir for (int i=0; i<installed_locales.length; i++) { 305*cdf0e10cSrcweir String error = ""; 306*cdf0e10cSrcweir String lang = "Language: "+installed_locales[i].Language + 307*cdf0e10cSrcweir ", Country: "+ installed_locales[i].Country + 308*cdf0e10cSrcweir ", Variant: "+ installed_locales[i].Variant + 309*cdf0e10cSrcweir ", Name: "+calendars[i][count[i]]; 310*cdf0e10cSrcweir String[] names = new String[]{"DAY_OF_MONTH", 311*cdf0e10cSrcweir "HOUR","MINUTE","SECOND","MILLISECOND", 312*cdf0e10cSrcweir "YEAR","MONTH"}; 313*cdf0e10cSrcweir oObj.loadCalendar(calendars[i][count[i]],installed_locales[i]); 314*cdf0e10cSrcweir short[] fields = new short[]{CalendarFieldIndex.DAY_OF_MONTH, 315*cdf0e10cSrcweir CalendarFieldIndex.HOUR, 316*cdf0e10cSrcweir CalendarFieldIndex.MINUTE, 317*cdf0e10cSrcweir CalendarFieldIndex.SECOND, 318*cdf0e10cSrcweir CalendarFieldIndex.MILLISECOND, 319*cdf0e10cSrcweir CalendarFieldIndex.YEAR, 320*cdf0e10cSrcweir CalendarFieldIndex.MONTH 321*cdf0e10cSrcweir }; 322*cdf0e10cSrcweir for (int k=0; k<fields.length;k++) { 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir oObj.setDateTime(0.0); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir // save the current values for debug purposes 327*cdf0e10cSrcweir short[] oldValues = new short[fields.length]; 328*cdf0e10cSrcweir for (int n=0; n < oldValues.length; n++){ 329*cdf0e10cSrcweir oldValues[n] = oObj.getValue(fields[n]); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir short set = oObj.getValue(fields[k]); 333*cdf0e10cSrcweir if (fields[k] == CalendarFieldIndex.MONTH) set = newValue; 334*cdf0e10cSrcweir oObj.setValue(fields[k],set); 335*cdf0e10cSrcweir short get = oObj.getValue(fields[k]); 336*cdf0e10cSrcweir if (get != set) { 337*cdf0e10cSrcweir if (debug) 338*cdf0e10cSrcweir log.println("ERROR occure: tried to set " + names[k] + " to value " + set); 339*cdf0e10cSrcweir log.println("list of values BEFORE set " + names[k] + " to value " + set + ":"); 340*cdf0e10cSrcweir for (int n=0; n < oldValues.length; n++){ 341*cdf0e10cSrcweir log.println(names[n] + ":" + oldValues[n]); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir log.println("list of values AFTER set " + names[k] + " to value " + set + ":"); 344*cdf0e10cSrcweir for (int n=0; n < fields.length;n++){ 345*cdf0e10cSrcweir log.println(names[n] + ":" + oObj.getValue(fields[n])); 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir error += "failed for "+names[k]+" expected "+ 349*cdf0e10cSrcweir set+" gained "+get+" ; \n"; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir if (error.equals("")) { 353*cdf0e10cSrcweir log.println(lang + " ... OK"); 354*cdf0e10cSrcweir } else { 355*cdf0e10cSrcweir log.println("*** "+lang + " ... FAILED ***"); 356*cdf0e10cSrcweir log.println(error); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir res &= (error.equals("")); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir tRes.tested("setValue()", res); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir /** 365*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 366*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value, that's equal to 367*cdf0e10cSrcweir * value set before. <p> 368*cdf0e10cSrcweir */ 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir public void _getValue() { 371*cdf0e10cSrcweir boolean res = true; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir requiredMethod("setValue()"); 374*cdf0e10cSrcweir short aValue = oObj.getValue(CalendarFieldIndex.MONTH); 375*cdf0e10cSrcweir res &= (aValue == newValue); 376*cdf0e10cSrcweir if (!res){ 377*cdf0e10cSrcweir log.println("the returned value is not the expected value:"); 378*cdf0e10cSrcweir log.println("expexted: " + newValue + " returned value: " + aValue); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir tRes.tested("getValue()", res); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir /** 384*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 385*cdf0e10cSrcweir * Has <b> OK </b> status if value, added by the method is greater than 386*cdf0e10cSrcweir * previously defined "newValue". 387*cdf0e10cSrcweir * <p> 388*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 389*cdf0e10cSrcweir * <ul> 390*cdf0e10cSrcweir * <li> <code> getValue() </code> : gets the value of a field </li> 391*cdf0e10cSrcweir * </ul> 392*cdf0e10cSrcweir */ 393*cdf0e10cSrcweir public void _addValue() { 394*cdf0e10cSrcweir boolean res = true; 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir requiredMethod("getValue()"); 397*cdf0e10cSrcweir oObj.addValue(CalendarFieldIndex.MONTH, 1); 398*cdf0e10cSrcweir short aValue = oObj.getValue(CalendarFieldIndex.MONTH); 399*cdf0e10cSrcweir res &= (aValue > newValue); 400*cdf0e10cSrcweir if (!res){ 401*cdf0e10cSrcweir log.println("the returned value is not the expected value:"); 402*cdf0e10cSrcweir log.println("expexted: " + newValue + " returned value: " + aValue); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir tRes.tested("addValue()", res); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir /** 408*cdf0e10cSrcweir * Test calls the method. <p> 409*cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 410*cdf0e10cSrcweir * and no exceptions were thrown. 411*cdf0e10cSrcweir */ 412*cdf0e10cSrcweir public void _setFirstDayOfWeek() { 413*cdf0e10cSrcweir boolean res = true; 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir oObj.setFirstDayOfWeek(firstDay); 416*cdf0e10cSrcweir res &= true; 417*cdf0e10cSrcweir tRes.tested("setFirstDayOfWeek()", res); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir /** 421*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 422*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value that is equal to 423*cdf0e10cSrcweir * value set before. <p> 424*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 425*cdf0e10cSrcweir * <ul> 426*cdf0e10cSrcweir * <li> <code> setFirstDayOfWeek() </code> : set the first day of a 427*cdf0e10cSrcweir * week</li> 428*cdf0e10cSrcweir * </ul> 429*cdf0e10cSrcweir */ 430*cdf0e10cSrcweir public void _getFirstDayOfWeek() { 431*cdf0e10cSrcweir boolean res = true; 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir requiredMethod("setFirstDayOfWeek()"); 434*cdf0e10cSrcweir short aFirstDayOfWeek = oObj.getFirstDayOfWeek(); 435*cdf0e10cSrcweir res &= (aFirstDayOfWeek == firstDay); 436*cdf0e10cSrcweir tRes.tested("getFirstDayOfWeek()", res); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir /** 440*cdf0e10cSrcweir * Test calls the method. <p> 441*cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 442*cdf0e10cSrcweir * and no exceptions were thrown. 443*cdf0e10cSrcweir */ 444*cdf0e10cSrcweir public void _setMinimumNumberOfDaysForFirstWeek() { 445*cdf0e10cSrcweir boolean res = true; 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir oObj.setMinimumNumberOfDaysForFirstWeek(mdfw); 448*cdf0e10cSrcweir res &= true; 449*cdf0e10cSrcweir tRes.tested("setMinimumNumberOfDaysForFirstWeek()", res); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir /** 453*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 454*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns value that is equal to 455*cdf0e10cSrcweir * value set before. <p> 456*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 457*cdf0e10cSrcweir * <ul> 458*cdf0e10cSrcweir * <li> <code> setMinimumNumberOfDaysForFirstWeek() </code> : sets how 459*cdf0e10cSrcweir * many days of a week must reside in the first week of a year</li> 460*cdf0e10cSrcweir * </ul> 461*cdf0e10cSrcweir */ 462*cdf0e10cSrcweir public void _getMinimumNumberOfDaysForFirstWeek() { 463*cdf0e10cSrcweir boolean res = true; 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir requiredMethod("setMinimumNumberOfDaysForFirstWeek()"); 466*cdf0e10cSrcweir short aShort = oObj.getMinimumNumberOfDaysForFirstWeek(); 467*cdf0e10cSrcweir res &= (aShort == mdfw); 468*cdf0e10cSrcweir tRes.tested("getMinimumNumberOfDaysForFirstWeek()", res); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir /** 472*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 473*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns 12. 474*cdf0e10cSrcweir */ 475*cdf0e10cSrcweir public void _getNumberOfMonthsInYear() { 476*cdf0e10cSrcweir boolean res = true; 477*cdf0e10cSrcweir short aShort = oObj.getNumberOfMonthsInYear(); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir res &= (aShort == (short) 12); 480*cdf0e10cSrcweir tRes.tested("getNumberOfMonthsInYear()", res); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir /** 484*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 485*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns 7. 486*cdf0e10cSrcweir */ 487*cdf0e10cSrcweir public void _getNumberOfDaysInWeek() { 488*cdf0e10cSrcweir boolean res = true; 489*cdf0e10cSrcweir short aShort = oObj.getNumberOfDaysInWeek(); 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir res &= (aShort == (short) 7); 492*cdf0e10cSrcweir tRes.tested("getNumberOfDaysInWeek()", res); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir /** 496*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 497*cdf0e10cSrcweir * Has <b> OK </b> status if length of array, returned by the method is 12. 498*cdf0e10cSrcweir */ 499*cdf0e10cSrcweir public void _getMonths() { 500*cdf0e10cSrcweir boolean res = true; 501*cdf0e10cSrcweir CalendarItem[] months = oObj.getMonths(); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir res &= (months.length == 12); 504*cdf0e10cSrcweir tRes.tested("getMonths()", res); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir /** 508*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 509*cdf0e10cSrcweir * Has <b> OK </b> status if length of array, returned by the method is 7. 510*cdf0e10cSrcweir */ 511*cdf0e10cSrcweir public void _getDays() { 512*cdf0e10cSrcweir boolean res = true; 513*cdf0e10cSrcweir CalendarItem[] Days = oObj.getDays(); 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir res &= (Days.length == 7); 516*cdf0e10cSrcweir tRes.tested("getDays()", res); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir /** 520*cdf0e10cSrcweir * After loading calendar, test calls the method, then result is checked.<p> 521*cdf0e10cSrcweir * Has <b> OK </b> status if length of string, returned by the method is 3. 522*cdf0e10cSrcweir */ 523*cdf0e10cSrcweir public void _getDisplayName() { 524*cdf0e10cSrcweir boolean res = true; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir oObj.loadCalendar(calendars[0][0],installed_locales[0]); 527*cdf0e10cSrcweir String DisplayName = oObj.getDisplayName(CalendarDisplayIndex.MONTH, 528*cdf0e10cSrcweir newValue, (short) 0); 529*cdf0e10cSrcweir res &= (DisplayName.length() == 3); 530*cdf0e10cSrcweir tRes.tested("getDisplayName()", res); 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir /** 535*cdf0e10cSrcweir * The test sets obviously wrong value, then calls a method. After that the 536*cdf0e10cSrcweir * test sets correct value, and again calls a method. <p> 537*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns true when valid month is 538*cdf0e10cSrcweir * set, and if the method returns false when set month is not valid. 539*cdf0e10cSrcweir */ 540*cdf0e10cSrcweir public void _isValid() { 541*cdf0e10cSrcweir boolean res = true; 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir oObj.loadDefaultCalendar(installed_locales[0]); 544*cdf0e10cSrcweir oObj.setValue(CalendarFieldIndex.MONTH, (short) 37); 545*cdf0e10cSrcweir res &= !oObj.isValid(); 546*cdf0e10cSrcweir oObj.setValue(CalendarFieldIndex.MONTH, (short) 10); 547*cdf0e10cSrcweir res &= oObj.isValid(); 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir tRes.tested("isValid()", res); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir /** 553*cdf0e10cSrcweir * Method returns locale for a given language and country. 554*cdf0e10cSrcweir * @param localeIndex index of needed locale. 555*cdf0e10cSrcweir */ 556*cdf0e10cSrcweir /* public Locale getLocale(int localeIndex) { 557*cdf0e10cSrcweir return new Locale(languages[localeIndex], countries[localeIndex], ""); 558*cdf0e10cSrcweir }*/ 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562