home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / dtfmtrtts.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-07  |  2.3 KB  |  97 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. #ifndef _DATEFORMATROUNDTRIPTEST_
  13. #define _DATEFORMATROUNDTRIPTEST_
  14.  
  15. #include "utypes.h"
  16. #include "intltest.h"
  17. #include "locale.h"
  18. #include "unistr.h"
  19.  
  20. class DateFormat;
  21. class SimpleDateFormat;
  22. class Calendar;
  23.  
  24. /** 
  25.  * Performs round-trip tests for DateFormat
  26.  **/
  27. class DateFormatRoundTripTest : public IntlTest {    
  28.     
  29.     // IntlTest override
  30.     void runIndexedTest( int32_t index, bool_t exec, char* &name, char* par );
  31.  
  32. public:
  33.     void TestDateFormatRoundTrip(void);
  34.     void test(const Locale& loc);
  35.     void test(DateFormat *fmt, bool_t timeOnly = FALSE );
  36.     int32_t getField(UDate d, int32_t f);
  37.     UnicodeString& escape(const UnicodeString& src, UnicodeString& dst);
  38.     UDate generateDate(void); 
  39.  
  40.  
  41. //============================================================
  42. // statics
  43. //============================================================
  44.  
  45. /**
  46.  * Return a random uint32_t
  47.  **/
  48. static uint32_t randLong()
  49. {
  50.     // Assume 8-bit (or larger) rand values.  Also assume
  51.     // that the system rand() function is very poor, which it always is.
  52.     uint32_t d;
  53.     int32_t i;
  54.     for (i=0; i < sizeof(uint32_t); ++i)
  55.     {
  56.         char* poke = (char*)&d;
  57.         poke[i] = (rand() & 0xFF);
  58.     }
  59.     return d;
  60. }
  61.  
  62. /**
  63.  * Return a random double 0 <= x < 1.0
  64.  **/
  65. static double randFraction()
  66. {
  67.     return (double)randLong() / (double)0xFFFFFFFF;
  68. }
  69.  
  70. /**
  71.  * Return a random value from -range..+range.
  72.  **/
  73. static double randDouble(double range)
  74. {
  75.     double a = randFraction();
  76.     //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
  77.     //    a = randFraction();
  78.     return (2.0 * range * a) - range;
  79. }
  80.  
  81. protected:
  82.     bool_t failure(UErrorCode status, const char* msg);
  83.  
  84. private:
  85.  
  86.     static bool_t INFINITE;
  87.     static int32_t SPARSENESS;
  88.     static int32_t TRIALS;
  89.     static int32_t DEPTH;
  90.  
  91.     SimpleDateFormat *dateFormat;
  92.     Calendar *getFieldCal;
  93. };
  94.  
  95. #endif // _DATEFORMATROUNDTRIPTEST_
  96. //eof
  97.