home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / tsnmfmt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  2.5 KB  |  109 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. #ifndef _INTLTESTNUMBERFORMAT
  15. #define _INTLTESTNUMBERFORMAT
  16.  
  17.  
  18. #include "utypes.h"
  19. #include "intltest.h"
  20.  
  21. #include "fmtable.h"
  22.  
  23. class NumberFormat;
  24.  
  25. /**
  26.  * This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
  27.  * NumberFormat.
  28.  */
  29. class IntlTestNumberFormat: public IntlTest {
  30.     void runIndexedTest( int32_t index, bool_t exec, char* &name, char* par = NULL );  
  31.  
  32. private:
  33.  
  34.     /**
  35.      *  call tryIt with many variations, called by testLocale
  36.      **/
  37.     void testFormat(char *par);
  38.     /**
  39.      *  perform tests using aNumber and fFormat, called in many variations
  40.      **/
  41.     void tryIt(double aNumber);
  42.     /**
  43.      *  perform tests using aNumber and fFormat, called in many variations
  44.      **/
  45.     void tryIt(int32_t aNumber);
  46.     /**
  47.      *  test NumberFormat::getAvailableLocales
  48.      **/
  49.     void testAvailableLocales(char *par);
  50.     /**
  51.      *  call testLocale for all locales
  52.      **/
  53.     void monsterTest(char *par);
  54.     /**
  55.      *  call testFormat for currency, percent and plain number instances
  56.      **/
  57.     void testLocale(char *par, const Locale& locale, const UnicodeString& localeName);
  58.  
  59.     NumberFormat*   fFormat;
  60.     UErrorCode       fStatus;
  61.  
  62. public:
  63.  
  64. /*
  65.  * Return a random double
  66.  **/
  67. static double randDouble()
  68. {
  69.     // Assume 8-bit (or larger) rand values.  Also assume
  70.     // that the system rand() function is very poor, which it always is.
  71.     double d;
  72.     int32_t i;
  73.     for (i=0; i < sizeof(double); ++i)
  74.     {
  75.         char* poke = (char*)&d;
  76.         poke[i] = (rand() & 0xFF);
  77.     }
  78.     return d;
  79. }
  80.  
  81. /*
  82.  * Return a random uint32_t
  83.  **/
  84. static uint32_t randLong()
  85. {
  86.     // Assume 8-bit (or larger) rand values.  Also assume
  87.     // that the system rand() function is very poor, which it always is.
  88.     uint32_t d;
  89.     int32_t i;
  90.     for (i=0; i < sizeof(uint32_t); ++i)
  91.     {
  92.         char* poke = (char*)&d;
  93.         poke[i] = (rand() & 0xFF);
  94.     }
  95.     return d;
  96. }
  97.  
  98. /**
  99.  * Return a random double 0 <= x < 1.0
  100.  **/
  101. static double randFraction()
  102. {
  103.     return (double)randLong() / (double)0xFFFFFFFF;
  104. }
  105.  
  106. };
  107.  
  108. #endif
  109.