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

  1. /*
  2. ********************************************************************
  3. * COPYRIGHT: 
  4. * (C) Copyright International Business Machines Corporation, 1998
  5. * Licensed Material - Program-Property of IBM - All Rights Reserved. 
  6. * US Government Users Restricted Rights - Use, duplication, or disclosure 
  7. * restricted by GSA ADP Schedule Contract with IBM Corp. 
  8. *
  9. ********************************************************************
  10. */
  11.  
  12. #include "miscdtfm.h"
  13.  
  14. #include "format.h"
  15. #include "decimfmt.h"
  16. #include "datefmt.h"
  17. #include "smpdtfmt.h"
  18. #include "dtfmtsym.h"
  19. #include "locid.h"
  20. #include "msgfmt.h"
  21. #include "numfmt.h"
  22. #include "choicfmt.h"
  23. #include "gregocal.h"
  24.  
  25. // *****************************************************************************
  26. // class DateFormatMiscTests
  27. // *****************************************************************************
  28.  
  29. #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
  30.  
  31. void 
  32. DateFormatMiscTests::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  33. {
  34.     // if (exec) logln((UnicodeString)"TestSuite DateFormatMiscTests");
  35.     switch (index) {
  36.         CASE(0, test4097450)
  37.         CASE(1, test4099975)
  38.         CASE(2, test4117335)
  39.  
  40.         default: name = ""; break;
  41.     }
  42. }
  43.  
  44. bool_t 
  45. DateFormatMiscTests::failure(UErrorCode status, const char* msg)
  46. {
  47.     if(U_FAILURE(status)) {
  48.         errln(UnicodeString("FAIL: ") + msg + " failed, error " + errorName(status));
  49.         return TRUE;
  50.     }
  51.  
  52.     return FALSE;
  53. }
  54.  
  55. /*
  56.  * @test @(#)$RCSfile: miscdtfm.cpp,v $ $Revision: 1.4 $ $Date: 1999/10/18 22:48:31 $
  57.  *
  58.  * @bug 4097450
  59.  */
  60. void
  61. DateFormatMiscTests::test4097450()
  62. {
  63.     //
  64.     // Date parse requiring 4 digit year.
  65.     //
  66.     UnicodeString  dstring [] = {
  67.         UnicodeString("97"),
  68.         UnicodeString("1997"),  
  69.         UnicodeString("97"),
  70.         UnicodeString("1997"),
  71.         UnicodeString("01"),
  72.         UnicodeString("2001"),  
  73.         UnicodeString("01"),
  74.         UnicodeString("2001"),  
  75.         UnicodeString("1"),
  76.         UnicodeString("1"),
  77.         UnicodeString("11"),  
  78.         UnicodeString("11"),
  79.         UnicodeString("111"), 
  80.         UnicodeString("111")
  81.     };
  82.     
  83.     UnicodeString dformat [] = {
  84.         UnicodeString("yy"),  
  85.         UnicodeString("yy"),
  86.         UnicodeString("yyyy"),
  87.         UnicodeString("yyyy"),
  88.         UnicodeString("yy"),  
  89.         UnicodeString("yy"),
  90.         UnicodeString("yyyy"),
  91.         UnicodeString("yyyy"),
  92.         UnicodeString("yy"),
  93.         UnicodeString("yyyy"),
  94.         UnicodeString("yy"),
  95.         UnicodeString("yyyy"), 
  96.         UnicodeString("yy"),
  97.         UnicodeString("yyyy")
  98.     };
  99.     
  100.     bool_t dresult [] = {
  101.         TRUE, 
  102.         FALSE, 
  103.         FALSE,  
  104.         TRUE,
  105.         TRUE, 
  106.         FALSE, 
  107.         FALSE,  
  108.         TRUE,
  109.         FALSE,
  110.         FALSE,
  111.         TRUE, 
  112.         FALSE,
  113.         FALSE, 
  114.         FALSE
  115.     };
  116.  
  117.     UErrorCode status = U_ZERO_ERROR;
  118.     SimpleDateFormat *formatter;
  119.     SimpleDateFormat *resultFormatter = new SimpleDateFormat("yyyy", status);
  120.     failure(status, "new SimpleDateFormat");
  121.  
  122.     logln("Format\tSource\tResult");
  123.     logln("-------\t-------\t-------");
  124.     for (int i = 0; i < 14/*dstring.length*/; i++)
  125.     {
  126.         log(dformat[i] + "\t" + dstring[i] + "\t");
  127.         formatter = new SimpleDateFormat(dformat[i], status);
  128.         failure(status, "new SimpleDateFormat");
  129.         //try {
  130.         UnicodeString str;
  131.         FieldPosition pos(FieldPosition::DONT_CARE);
  132.         logln(resultFormatter->format(formatter->parse(dstring[i], status), str, pos));
  133.         failure(status, "resultFormatter->format");
  134.             //if ( !dresult[i] ) System.out.print("   <-- error!");
  135.         /*}
  136.         catch (ParseException exception) {
  137.             //if ( dresult[i] ) System.out.print("   <-- error!");
  138.             System.out.print("exception --> " + exception);
  139.         }*/
  140.         delete formatter;
  141.         logln();
  142.     }
  143.  
  144.     delete resultFormatter;
  145. }
  146.  
  147. /*
  148.  * @test @(#)$RCSfile: miscdtfm.cpp,v $ $Revision: 1.4 $ $Date: 1999/10/18 22:48:31 $
  149.  *
  150.  * @bug 4099975
  151.  */
  152.  
  153. void
  154. DateFormatMiscTests::test4099975()
  155. {
  156.     UErrorCode status = U_ZERO_ERROR;
  157.     DateFormatSymbols *symbols = new DateFormatSymbols(status);
  158.     failure(status, "new DateFormatSymbols");
  159.     SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("E hh:mm"), symbols, status);
  160.     failure(status, "new SimpleDateFormat");
  161.     UnicodeString res;
  162.     logln(df->toLocalizedPattern(res, status));
  163.     failure(status, "df->toLocalizedPattern");
  164.     symbols->setLocalPatternChars(UnicodeString("abcdefghijklmonpqr")); // change value of field
  165.     logln(df->toLocalizedPattern(res, status));
  166.     failure(status, "df->toLocalizedPattern");
  167.  
  168.     delete df;
  169. }
  170.  
  171. /*
  172.  * @test @(#)bug4117335.java    1.1 3/5/98
  173.  *
  174.  * @bug 4117335
  175.  */
  176. void
  177. DateFormatMiscTests::test4117335()
  178. {
  179.     //UnicodeString bc = "\u7d00\u5143\u524d";
  180.     UChar bcC [] = {
  181.         0x7D00,
  182.         0x5143,
  183.         0x524D
  184.     };
  185.     UnicodeString bc(bcC, 3, 3);
  186.  
  187.     //UnicodeString ad = "\u897f\u66a6";
  188.     UChar adC [] = {
  189.         0x897F,
  190.         0x66A6
  191.     };
  192.     UnicodeString ad(adC, 2, 2);
  193.     
  194.     //UnicodeString jstLong = "\u65e5\u672c\u6a19\u6e96\u6642";
  195.     UChar jstLongC [] = {
  196.         0x65e5,
  197.         0x672c,
  198.         0x6a19,
  199.         0x6e96,
  200.         0x6642
  201.     };
  202.     UnicodeString jstLong(jstLongC, 5, 5);
  203.  
  204.     UnicodeString jstShort = "JST";
  205.  
  206.     
  207.     UErrorCode status = U_ZERO_ERROR;
  208.     DateFormatSymbols *symbols = new DateFormatSymbols(Locale::JAPAN, status);
  209.     failure(status, "new DateFormatSymbols");
  210.     int32_t eraCount = 0;
  211.     const UnicodeString *eras = symbols->getEras(eraCount);
  212.     
  213.     logln(UnicodeString("BC = ") + eras[0]);
  214.     if (eras[0] != bc) {
  215.         errln("*** Should have been " + bc);
  216.         //throw new Exception("Error in BC");
  217.     }
  218.  
  219.     logln(UnicodeString("AD = ") + eras[1]);
  220.     if (eras[1] != ad) {
  221.         errln("*** Should have been " + ad);
  222.         //throw new Exception("Error in AD");
  223.     }
  224.  
  225.     int32_t rowCount, colCount;
  226.     const UnicodeString **zones = symbols->getZoneStrings(rowCount, colCount);
  227.     logln(UnicodeString("Long zone name = ") + zones[0][1]);
  228.     if (zones[0][1] != jstLong) {
  229.         errln("*** Should have been " + jstLong);
  230.         //throw new Exception("Error in long TZ name");
  231.     }
  232.     logln(UnicodeString("Short zone name = ") + zones[0][2]);
  233.     if (zones[0][2] != jstShort) {
  234.         errln("*** Should have been " + jstShort);
  235.         //throw new Exception("Error in short TZ name");
  236.     }
  237.     logln(UnicodeString("Long zone name = ") + zones[0][3]);
  238.     if (zones[0][3] != jstLong) {
  239.         errln("*** Should have been " + jstLong);
  240.         //throw new Exception("Error in long TZ name");
  241.     }
  242.     logln(UnicodeString("SHORT zone name = ") + zones[0][4]);
  243.     if (zones[0][4] != jstShort) {
  244.         errln("*** Should have been " + jstShort);
  245.         //throw new Exception("Error in short TZ name");
  246.     }
  247.  
  248. }
  249.