home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / tsdcfmsy.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.0 KB  |  142 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 "tsdcfmsy.h"
  16.  
  17. #include "dcfmtsym.h"
  18.  
  19.  
  20. void IntlTestDecimalFormatSymbols::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  21. {
  22.     if (exec) logln("TestSuite DecimalFormatSymbols");
  23.     switch (index) {
  24.         case 0: name = "DecimalFormatSymbols test"; 
  25.                 if (exec) {
  26.                     logln("DecimalFormatSymbols test---"); logln("");
  27.                     testSymbols(par);
  28.                 }
  29.                 break;
  30.  
  31.         default: name = ""; break;
  32.     }
  33. }
  34.  
  35. /**
  36.  * Test the API of DecimalFormatSymbols; primarily a simple get/set set.
  37.  */
  38. void IntlTestDecimalFormatSymbols::testSymbols(char *par)
  39. {
  40.     UErrorCode status = U_ZERO_ERROR;
  41.  
  42.     DecimalFormatSymbols fr(Locale::FRENCH, status);
  43.     if(U_FAILURE(status)) {
  44.         errln("ERROR: Couldn't create French DecimalFormatSymbols");
  45.     }
  46.  
  47.     status = U_ZERO_ERROR;
  48.     DecimalFormatSymbols en(Locale::ENGLISH, status);
  49.     if(U_FAILURE(status)) {
  50.         errln("ERROR: Couldn't create English DecimalFormatSymbols");
  51.     }
  52.  
  53.     if(en == fr || ! (en != fr) ) {
  54.         errln("ERROR: English DecimalFormatSymbols equal to French");
  55.     }
  56.  
  57.     // just do some VERY basic tests to make sure that get/set work
  58.  
  59.     UChar zero = en.getZeroDigit();
  60.     fr.setZeroDigit(zero);
  61.     if(fr.getZeroDigit() != en.getZeroDigit()) {
  62.         errln("ERROR: get/set ZeroDigit failed");
  63.     }
  64.  
  65.     UChar group = en.getGroupingSeparator();
  66.     fr.setGroupingSeparator(group);
  67.     if(fr.getGroupingSeparator() != en.getGroupingSeparator()) {
  68.         errln("ERROR: get/set GroupingSeparator failed");
  69.     }
  70.  
  71.     UChar decimal = en.getDecimalSeparator();
  72.     fr.setDecimalSeparator(decimal);
  73.     if(fr.getDecimalSeparator() != en.getDecimalSeparator()) {
  74.         errln("ERROR: get/set DecimalSeparator failed");
  75.     }
  76.  
  77.     UChar perMill = en.getPerMill();
  78.     fr.setPerMill(perMill);
  79.     if(fr.getPerMill() != en.getPerMill()) {
  80.         errln("ERROR: get/set PerMill failed");
  81.     }
  82.  
  83.     UChar percent = en.getPercent();
  84.     fr.setPercent(percent);
  85.     if(fr.getPercent() != en.getPercent()) {
  86.         errln("ERROR: get/set Percent failed");
  87.     }
  88.  
  89.     UChar digit = en.getDigit();
  90.     fr.setDigit(digit);
  91.     if(fr.getPercent() != en.getPercent()) {
  92.         errln("ERROR: get/set Percent failed");
  93.     }
  94.  
  95.     UChar patternSeparator = en.getPatternSeparator();
  96.     fr.setPatternSeparator(patternSeparator);
  97.     if(fr.getPatternSeparator() != en.getPatternSeparator()) {
  98.         errln("ERROR: get/set PatternSeparator failed");
  99.     }
  100.  
  101.     UnicodeString infinity;
  102.     infinity = en.getInfinity(infinity);
  103.     fr.setInfinity(infinity);
  104.     UnicodeString infinity2;
  105.     infinity2 = fr.getInfinity(infinity2);
  106.     if(infinity != infinity2) {
  107.         errln("ERROR: get/set Infinity failed");
  108.     }
  109.  
  110.     UnicodeString nan;
  111.     nan = en.getNaN(infinity);
  112.     fr.setNaN(nan);
  113.     UnicodeString nan2;
  114.     nan2 = fr.getNaN(nan2);
  115.     if(nan != nan2) {
  116.         errln("ERROR: get/set NaN failed");
  117.     }
  118.  
  119.     UChar minusSign = en.getMinusSign();
  120.     fr.setMinusSign(minusSign);
  121.     if(fr.getMinusSign() != en.getMinusSign()) {
  122.         errln("ERROR: get/set MinusSign failed");
  123.     }
  124.  
  125.     UChar exponential = en.getExponentialSymbol();
  126.     fr.setExponentialSymbol(exponential);
  127.     if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
  128.         errln("ERROR: get/set Exponential failed");
  129.     }
  130.  
  131.     status = U_ZERO_ERROR;
  132.     DecimalFormatSymbols foo(status);
  133.     
  134.     DecimalFormatSymbols bar(foo);
  135.  
  136.     en = fr;
  137.  
  138.     if(en != fr || foo != bar) {
  139.         errln("ERROR: Copy Constructor or Assignment failed");
  140.     }
  141. }
  142.