home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / tsdtfmsy.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.6 KB  |  160 lines

  1.  
  2. /*
  3. ********************************************************************
  4. * COPYRIGHT: 
  5. * (C) Copyright Taligent, Inc., 1997
  6. * (C) Copyright International Business Machines Corporation, 1997 - 1998
  7. * Licensed Material - Program-Property of IBM - All Rights Reserved. 
  8. * US Government Users Restricted Rights - Use, duplication, or disclosure 
  9. * restricted by GSA ADP Schedule Contract with IBM Corp. 
  10. *
  11. ********************************************************************
  12. */
  13.  
  14. #include "utypes.h"
  15. #include "tsdtfmsy.h"
  16.  
  17. #include "dtfmtsym.h"
  18.  
  19.  
  20. void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  21. {
  22.     if (exec) logln("TestSuite DateFormatSymbols");
  23.     switch (index) {
  24.         case 0: name = "DateFormatSymbols test"; 
  25.                 if (exec) {
  26.                     logln("DateFormatSymbols test---"); logln("");
  27.                     testSymbols(par);
  28.                 }
  29.                 break;
  30.  
  31.         case 1: name = "TestGetMonths"; 
  32.                 if (exec) {
  33.                     logln("TestGetMonths test---"); logln("");
  34.                     TestGetMonths();
  35.                 }
  36.                 break;
  37.  
  38.         default: name = ""; break;
  39.     }
  40. }
  41.  
  42. /**
  43.  * Test getMonths.
  44.  */
  45. void IntlTestDateFormatSymbols::TestGetMonths()
  46. {
  47.     UErrorCode  status = U_ZERO_ERROR;
  48.     int32_t cnt;
  49.     const UnicodeString* month;
  50.     DateFormatSymbols *symbol;
  51.  
  52.     symbol=new DateFormatSymbols(Locale::getDefault(), status);
  53.  
  54.     month=symbol->getMonths(cnt);
  55.  
  56.     logln((UnicodeString)"size = " + cnt);
  57.  
  58.     for (int32_t i=0; i<cnt; ++i)
  59.     {
  60.         logln(month[i]);
  61.     }
  62.  
  63.     delete symbol;
  64. }
  65.  
  66. /**
  67.  * Test the API of DateFormatSymbols; primarily a simple get/set set.
  68.  */
  69. void IntlTestDateFormatSymbols::testSymbols(char *par)
  70. {
  71.     UErrorCode status = U_ZERO_ERROR;
  72.  
  73.     DateFormatSymbols fr(Locale::FRENCH, status);
  74.     if(U_FAILURE(status)) {
  75.         errln("ERROR: Couldn't create French DateFormatSymbols");
  76.     }
  77.  
  78.     status = U_ZERO_ERROR;
  79.     DateFormatSymbols en(Locale::ENGLISH, status);
  80.     if(U_FAILURE(status)) {
  81.         errln("ERROR: Couldn't create English DateFormatSymbols");
  82.     }
  83.  
  84.     if(en == fr || ! (en != fr) ) {
  85.         errln("ERROR: English DateFormatSymbols equal to French");
  86.     }
  87.  
  88.     // just do some VERY basic tests to make sure that get/set work
  89.  
  90.     int32_t count = 0;
  91.     const UnicodeString *eras = en.getEras(count);
  92.     fr.setEras(eras, count);
  93.     if( *en.getEras(count) != *fr.getEras(count)) {
  94.         errln("ERROR: setEras() failed");
  95.     }
  96.  
  97.     const UnicodeString *months = en.getMonths(count);
  98.     fr.setMonths(months, count);
  99.     if( *en.getMonths(count) != *fr.getMonths(count)) {
  100.         errln("ERROR: setMonths() failed");
  101.     }
  102.  
  103.     const UnicodeString *shortMonths = en.getShortMonths(count);
  104.     fr.setShortMonths(shortMonths, count);
  105.     if( *en.getShortMonths(count) != *fr.getShortMonths(count)) {
  106.         errln("ERROR: setShortMonths() failed");
  107.     }
  108.  
  109.     const UnicodeString *weekdays = en.getWeekdays(count);
  110.     fr.setWeekdays(weekdays, count);
  111.     if( *en.getWeekdays(count) != *fr.getWeekdays(count)) {
  112.         errln("ERROR: setWeekdays() failed");
  113.     }
  114.  
  115.     const UnicodeString *shortWeekdays = en.getShortWeekdays(count);
  116.     fr.setShortWeekdays(shortWeekdays, count);
  117.     if( *en.getShortWeekdays(count) != *fr.getShortWeekdays(count)) {
  118.         errln("ERROR: setShortWeekdays() failed");
  119.     }
  120.  
  121.     const UnicodeString *ampms = en.getAmPmStrings(count);
  122.     fr.setAmPmStrings(ampms, count);
  123.     if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
  124.         errln("ERROR: setAmPmStrings() failed");
  125.     }
  126.  
  127.     int32_t rowCount = 0, columnCount = 0;
  128.     const UnicodeString **strings = en.getZoneStrings(rowCount, columnCount);
  129.     fr.setZoneStrings(strings, rowCount, columnCount);
  130.     const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount);
  131.     for(int32_t i = 0; i < rowCount; i++) {
  132.         for(int32_t j = 0; j < columnCount; j++) {
  133.             if( strings[i][j] != strings1[i][j] ) {
  134.                 errln("ERROR: setZoneStrings() failed");
  135.             }
  136.  
  137.         }
  138.     }
  139.  
  140.     const UnicodeString pattern = DateFormatSymbols::getPatternChars();
  141.     
  142.     UnicodeString localPattern, pat1, pat2;
  143.     localPattern = en.getLocalPatternChars(localPattern);
  144.     fr.setLocalPatternChars(localPattern);
  145.     if( en.getLocalPatternChars(pat1) != fr.getLocalPatternChars(pat2)) {
  146.         errln("ERROR: setLocalPatternChars() failed");
  147.     }
  148.  
  149.  
  150.     status = U_ZERO_ERROR;
  151.     DateFormatSymbols foo(status);
  152.     DateFormatSymbols bar(foo);
  153.  
  154.     en = fr;
  155.  
  156.     if(en != fr || foo != bar) {
  157.         errln("ERROR: Copy Constructor or Assignment failed");
  158.     }
  159. }
  160.