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

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright International Business Machines Corporation,  1998                    *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  9. *                                                                                       *
  10. *****************************************************************************************
  11. */
  12.  
  13. // define NO_THREADED_INTL to not test ICU in a threaded way.
  14.  
  15.  
  16. // Note: A LOT OF THE FUNCTIONS IN THIS FILE SHOULD LIVE ELSEWHERE!!!!!
  17. // Note: A LOT OF THE FUNCTIONS IN THIS FILE SHOULD LIVE ELSEWHERE!!!!!
  18. //   -srl
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <ctype.h>    // tolower, toupper
  23.  
  24. #include "putil.h"
  25. #include "tsmthred.h"
  26.  
  27. /* for mthreadtest*/
  28. #include "numfmt.h"
  29. #include "choicfmt.h"
  30. #include "msgfmt.h"
  31. #include "locid.h"
  32.  
  33. /* HPUX */
  34. #ifdef sleep
  35. #undef sleep
  36. #endif
  37.  
  38. #ifdef WIN32
  39. #define HAVE_IMP
  40.  
  41. #include <windows.h>
  42.  
  43. struct Win32ThreadImplementation
  44. {
  45.     HANDLE fHandle;
  46.     DWORD fThreadID;
  47. };
  48.  
  49. extern "C" unsigned long _stdcall SimpleThreadProc(void *arg)
  50. {
  51.     ((SimpleThread*)arg)->run();
  52.     return 0;
  53. }
  54.  
  55. SimpleThread::SimpleThread()
  56. :fImplementation(0)
  57. {
  58.     Win32ThreadImplementation *imp = new Win32ThreadImplementation;
  59.     imp->fHandle = 0;
  60.     imp->fThreadID = 0;
  61.  
  62.     fImplementation = imp;
  63. }
  64.  
  65. SimpleThread::~SimpleThread()
  66. {
  67.     delete (Win32ThreadImplementation*)fImplementation;
  68. }
  69.  
  70. void SimpleThread::start()
  71. {
  72.     Win32ThreadImplementation *imp = (Win32ThreadImplementation*)fImplementation;
  73.  
  74.     if(imp->fHandle != NULL)
  75.         return;
  76.  
  77.     imp->fHandle = CreateThread(NULL,0,SimpleThreadProc,(void*)this,0,&imp->fThreadID);
  78. }
  79.  
  80. void SimpleThread::sleep(int32_t millis)
  81. {
  82.     ::Sleep(millis);
  83. }
  84.  
  85. #elif defined XP_MAC
  86.  
  87. // since the Mac has no preemptive threading (at least on MacOS 8), only
  88. // cooperative threading, threads are a no-op.  We have no yield() calls
  89. // anywhere in the ICU, so we are guaranteed to be thread-safe.
  90.  
  91. #define HAVE_IMP
  92.  
  93. SimpleThread::SimpleThread()
  94. {}
  95.  
  96. SimpleThread::~SimpleThread()
  97. {}
  98.  
  99. void 
  100. SimpleThread::start()
  101. {}
  102.  
  103. void 
  104. SimpleThread::run()
  105. {}
  106.  
  107. void 
  108. SimpleThread::sleep(int32_t millis)
  109. {}
  110.  
  111. #else
  112.   #define POSIX 1
  113. #endif
  114.  
  115. #if defined(POSIX)||defined(SOLARIS)||defined(AIX)||defined(HPUX)
  116. #define HAVE_IMP
  117.  
  118. #include <pthread.h>
  119. #include <unistd.h>
  120. #include <signal.h>
  121.  
  122. /* HPUX */
  123. #ifdef sleep
  124. #undef sleep
  125. #endif
  126.  
  127. struct PosixThreadImplementation
  128. {
  129.     pthread_t fThread;
  130. };
  131.  
  132. extern "C" void* SimpleThreadProc(void *arg)
  133. {
  134.     ((SimpleThread*)arg)->run();
  135.     return 0;
  136. }
  137.  
  138. SimpleThread::SimpleThread() :fImplementation(0)
  139. {
  140.     PosixThreadImplementation *imp = new PosixThreadImplementation;
  141.     fImplementation = imp;
  142. }
  143.  
  144. SimpleThread::~SimpleThread()
  145. {
  146.     delete (PosixThreadImplementation*)fImplementation;
  147. }
  148.  
  149. void SimpleThread::start()
  150. {
  151.     PosixThreadImplementation *imp = (PosixThreadImplementation*)fImplementation;
  152.  
  153.     int32_t rc;
  154.  
  155.     pthread_attr_t attr;
  156.  
  157. #ifdef HPUX
  158.     rc = pthread_attr_create(&attr);
  159.     rc = pthread_create(&(imp->fThread),attr,&SimpleThreadProc,(void*)this);
  160.     pthread_attr_delete(&attr);
  161. #else
  162.     rc = pthread_attr_init(&attr);
  163.     rc = pthread_create(&(imp->fThread),&attr,&SimpleThreadProc,(void*)this);
  164.     pthread_attr_destroy(&attr);
  165. #endif
  166.  
  167. }
  168.  
  169. void SimpleThread::sleep(int32_t millis)
  170. {
  171. #ifdef SOLARIS
  172.    sigignore(SIGALRM);
  173. #endif
  174.  
  175. #ifdef HPUX
  176.    cma_sleep(millis/100);
  177. #else
  178.    usleep(millis * 1000); 
  179. #endif
  180. }
  181.  
  182. #endif
  183. // end POSIX
  184.  
  185.  
  186. #ifndef HAVE_IMP
  187. #error  No implementation for threads! Cannot test.
  188. 0 = 216; //die
  189. #endif
  190.  
  191.  
  192. // *************** end fluff ******************
  193.  
  194. /* now begins the real test. */
  195. MultithreadTest::MultithreadTest()
  196. {
  197. }
  198.  
  199. MultithreadTest::~MultithreadTest()
  200. {
  201. }
  202.  
  203. void MultithreadTest::runIndexedTest( int32_t index, bool_t exec, 
  204.                 char* &name, char* par ) {
  205.   if (exec) logln("TestSuite MultithreadTest: ");
  206.   switch (index) {
  207.   case 0: name = "TestThreads"; if (exec) TestThreads(); break;
  208.   case 1: name = "TestMutex"; if (exec) TestMutex(); break;
  209.   case 2: name = "TestThreadedIntl"; if (exec) TestThreadedIntl(); break;
  210.     
  211.   default: name = ""; break; //needed to end loop
  212.   }
  213. }
  214.  
  215.  
  216. /* 
  217.    TestThreads -- see if threads really work at all.
  218.  
  219.    Set up N threads pointing at N chars. When they are started, they will
  220.    each sleep 2 seconds and then set their chars. At the end we make sure they
  221.    are all set.
  222.  */
  223.  
  224. #define THREADTEST_NRTHREADS 8
  225.  
  226. class TestThreadsThread : public SimpleThread
  227. {
  228. public:
  229.     TestThreadsThread(char* whatToChange) { fWhatToChange = whatToChange; }
  230.     virtual void run() { SimpleThread::sleep(2000); *fWhatToChange = '*'; }
  231. private:
  232.     char *fWhatToChange;
  233. };
  234.  
  235. void MultithreadTest::TestThreads()
  236. {
  237.     char threadTestChars[THREADTEST_NRTHREADS + 1];
  238.     SimpleThread *threads[THREADTEST_NRTHREADS];
  239.  
  240.     int32_t i;
  241.     for(i=0;i<THREADTEST_NRTHREADS;i++)
  242.     {
  243.         threadTestChars[i] = ' ';
  244.         threads[i] = new TestThreadsThread(&threadTestChars[i]);
  245.     }
  246.     threadTestChars[THREADTEST_NRTHREADS] = '\0';
  247.  
  248.     logln("->" + UnicodeString(threadTestChars) + "<- Firing off threads.. ");
  249.     for(i=0;i<THREADTEST_NRTHREADS;i++)
  250.     {
  251.         threads[i]->start();
  252.         SimpleThread::sleep(200);
  253.         logln(" Subthread started.");
  254.     }
  255.  
  256.     logln("Waiting for threads to be set..");
  257.  
  258.     int32_t patience = 40; // seconds to wait
  259.  
  260.     while(patience--)
  261.     {
  262.         int32_t count = 0;
  263.         for(i=0;i<THREADTEST_NRTHREADS;i++)
  264.         {
  265.             if(threadTestChars[i] == '*')
  266.             {
  267.                 count++;
  268.             }
  269.         }
  270.         
  271.         if(count == THREADTEST_NRTHREADS)
  272.         {
  273.             logln("->" + UnicodeString(threadTestChars) + "<- Got all threads! cya");
  274.             return;
  275.         }
  276.  
  277.         logln("->" + UnicodeString(threadTestChars) + "<- Waiting..");
  278.         SimpleThread::sleep(500);
  279.     }
  280.  
  281.     errln("->" + UnicodeString(threadTestChars) + "<- PATIENCE EXCEEDED!! Still missing some.");
  282. }
  283.  
  284.  
  285. class TestMutexThread1 : public SimpleThread
  286. {
  287. public:
  288.     TestMutexThread1() : fDone(FALSE) {}
  289.     virtual void run()
  290.     {
  291.         Mutex m;                        // grab the lock first thing
  292.         SimpleThread::sleep(2000);      // then wait
  293.         fDone = TRUE;                   // finally, set our flag
  294.     }
  295. public:
  296.     bool_t fDone;
  297. };
  298.  
  299. class TestMutexThread2 : public SimpleThread
  300. {
  301. public:
  302.     TestMutexThread2(TestMutexThread1& r) : fOtherThread(r), fDone(FALSE), fErr(FALSE) {}
  303.     virtual void run()
  304.     {
  305.         SimpleThread::sleep(1000);          // wait, make sure they aquire the lock
  306.         fElapsed = icu_getUTCtime();
  307.         {
  308.             Mutex m;                        // wait here
  309.  
  310.             fElapsed = icu_getUTCtime() - fElapsed;
  311.  
  312.             if(fOtherThread.fDone == FALSE) 
  313.                 fErr = TRUE;                // they didnt get to it yet
  314.  
  315.             fDone = TRUE;               // we're done.
  316.         }
  317.     }
  318. public:
  319.     TestMutexThread1 & fOtherThread;
  320.     bool_t fDone, fErr;
  321.     int32_t fElapsed;
  322. };
  323.  
  324. void MultithreadTest::TestMutex()
  325. {
  326.   /* this test uses printf so that we don't hang by calling UnicodeString inside of a mutex. */
  327.   //logln("Bye.");
  328.   //  printf("Warning: MultiThreadTest::Testmutex() disabled.\n");
  329.   //  return; 
  330.   
  331.   if(verbose)
  332.     printf("Before mutex.");
  333.   {
  334.     Mutex m;
  335.     if(verbose)
  336.       printf(" Exitted 2nd mutex");
  337.   }
  338.   if(verbose)
  339.     printf("exitted 1st mutex. Now testing with threads:");
  340.   
  341.   TestMutexThread1  thread1;
  342.   TestMutexThread2  thread2(thread1);
  343.   thread2.start();
  344.   thread1.start();
  345.   
  346.   for(int32_t patience = 12; patience > 0;patience--)
  347.     {
  348.       if(thread1.fDone && verbose)
  349.     printf("Thread1 done");
  350.       
  351.       if(thread1.fDone && thread2.fDone)
  352.         {
  353.       char tmp[999];
  354.       sprintf(tmp,"%lu",thread2.fElapsed);
  355.       if(thread2.fErr)
  356.         errln("Thread 2 says: thread1 didn't run before I aquired the mutex.");
  357.       logln("took " + UnicodeString(tmp) + " seconds for thread2 to aquire the mutex.");
  358.       return;
  359.         }
  360.       SimpleThread::sleep(1000);
  361.     }
  362.   if(verbose)
  363.     printf("patience exceeded. [WARNING mutex may still be acquired.] ");
  364. }
  365.  
  366. // ***********
  367. // ***********   TestMultithreadedIntl.  Test the ICU in a multithreaded way. 
  368.  
  369.  
  370.  
  371. #ifdef NO_THREADED_INTL
  372. void MultithreadTest::TestThreadedIntl()
  373. {
  374.     logln("TestThreadedIntl - test DISABLED.  see tsutil/tsmthred.cpp, look for NO_THREADED_INTL. ");
  375. }
  376.  
  377. #else
  378.  
  379. // ** First, some utility classes.
  380.  
  381. //
  382. ///* Here is an idea which needs more work
  383. //   TestATest simply runs another Intltest subset against itself.
  384. //    The correct subset of intltest that should be run in this way should be identified.
  385. // */
  386. //
  387. //class TestATest : public SimpleThread
  388. //{
  389. //public:
  390. //    TestATest(IntlTest &t) : fTest(t), fDone(FALSE) {}
  391. //    virtual void run()
  392. //    {
  393. //       fTest.runTest(NULL,"TestNumberSpelloutFormat");
  394. //       fErrs = fTest.getErrors();
  395. //       fDone = TRUE;
  396. //    }
  397. //public:
  398. //    IntlTest &fTest;
  399. //    bool_t    fDone;
  400. //    int32_t   fErrs;
  401. //};
  402. //
  403. //
  404. //#include "itutil.h"
  405. ////#include "tscoll.h"
  406. ////#include "ittxtbd.h"
  407. //#include "itformat.h"
  408. ////#include "itcwrap.h"
  409. //
  410. ///* main code was:
  411. //    IntlTestFormat formatTest;
  412. ////    IntlTestCollator collatorTest;
  413. //
  414. //  #define NUMTESTS 2
  415. //    TestATest tests[NUMTESTS] = { TestATest(formatTest), TestATest(formatTest) };
  416. //    char testName[NUMTESTS][20] = { "formatTest", "formatTest2" };
  417. //*/
  418.  
  419.  
  420. #include <string.h>
  421.  
  422. // [HSYS] Just to make it easier to use with UChar array.
  423. // ripped off from ittxtbd.cpp::CharsToUnicodeString
  424. UnicodeString UEscapeString(const char* chars)
  425. {
  426.     int len = strlen(chars);
  427.     int i;
  428.     UnicodeString buffer;
  429.     for (i = 0; i < len;) {
  430.         if ((chars[i] == '\\') && (i+1 < len) && (chars[i+1] == 'u')) {
  431.             int unicode;
  432.             sscanf(&(chars[i+2]), "%4X", &unicode);
  433.             buffer += (UChar)unicode;
  434.             i += 6;
  435.         } else {
  436.             buffer += (UChar)chars[i++];
  437.         }
  438.     }
  439.     return buffer;
  440. }
  441.  
  442. // * Show exactly where the string's differences lie.
  443. UnicodeString showDifference(const UnicodeString& expected, const UnicodeString& result)
  444. {
  445.     UnicodeString res;
  446.     res = expected + "<Expected\n";
  447.     if(expected.size() != result.size())
  448.         res += " [ Different lengths ] \n";
  449.     else
  450.     {
  451.         for(int32_t i=0;i<expected.size();i++)
  452.         {
  453.             if(expected[i] == result[i])
  454.             {
  455.                 res += " ";
  456.             }
  457.             else
  458.             {
  459.                 res += "|";
  460.             }
  461.         }
  462.         res += "<Differences";
  463.         res += "\n";
  464.     }
  465.     res += result + "<Result\n";
  466.  
  467.     return res;
  468. }
  469.  
  470.  
  471. // ** ThreadWithStatus - a thread that we can check the status and error condition of
  472.  
  473.  
  474. class ThreadWithStatus : public SimpleThread
  475. {
  476. public:
  477.     bool_t  getDone() { return fDone; }
  478.     bool_t  getError() { return (fErrors > 0); } 
  479.     bool_t  getError(UnicodeString& fillinError) { fillinError = fErrorString; return (fErrors > 0); } 
  480.     virtual ~ThreadWithStatus(){}
  481. protected:
  482.     ThreadWithStatus() : fDone(FALSE), fErrors(0) {}
  483.     void done() { fDone = TRUE; }
  484.     void error(const UnicodeString &error) { fErrors++; fErrorString = error; done(); }
  485.     void error() { error("An error occured."); }
  486. private:
  487.     bool_t fDone;
  488.     int32_t fErrors;
  489.     UnicodeString fErrorString;
  490. };
  491.  
  492. // ** FormatThreadTest - a thread that tests performing a number of numberformats.
  493.  
  494.  
  495. #define kFormatThreadIterations 20  // # of iterations per thread
  496. #define kFormatThreadThreads    10  // # of threads to spawn
  497. #define kFormatThreadPatience   60  // time in seconds to wait for all threads
  498. struct FormatThreadTestData
  499. {
  500.     double number;
  501.     UnicodeString string;
  502.     FormatThreadTestData(double a, const UnicodeString& b) : number(a),string(b) {}
  503. } ;
  504.  
  505. // 
  506. FormatThreadTestData kNumberFormatTestData[] = 
  507. {
  508.    FormatThreadTestData((double)5., UnicodeString("5")),
  509.    FormatThreadTestData( 6., "6" ),
  510.    FormatThreadTestData( 20., "20" ),
  511.    FormatThreadTestData( 8., "8" ),
  512.    FormatThreadTestData( 8.3, "8.3" ),
  513.    FormatThreadTestData( 12345, "12,345" ),
  514.    FormatThreadTestData( 81890.23, "81,890.23" ),
  515. };
  516. int32_t kNumberFormatTestDataLength = sizeof(kNumberFormatTestData) / sizeof(kNumberFormatTestData[0]);
  517.  
  518. // 
  519. FormatThreadTestData kPercentFormatTestData[] = 
  520. {
  521.    FormatThreadTestData((double)5., UnicodeString("500%")),
  522.    FormatThreadTestData( 1, "100%" ),
  523.    FormatThreadTestData( 0.26, "26%" ),
  524.    FormatThreadTestData( 16384.99, UEscapeString("1\\u00a0638\\u00a0499%") ), // U+00a0 = NBSP
  525.    FormatThreadTestData( 81890.23, UEscapeString("8\\u00a0189\\u00a0023%" )),
  526. };
  527. int32_t kPercentFormatTestDataLength = sizeof(kPercentFormatTestData) / sizeof(kPercentFormatTestData[0]);
  528.  
  529.  
  530. void errorToString(UErrorCode theStatus, UnicodeString &string)
  531. {
  532.     string=errorName(theStatus);
  533. }
  534.  
  535. // "Someone from {2} is receiving a #{0} error - {1}. Their telephone call is costing {3 number,currency}."
  536.  
  537. void formatErrorMessage(UErrorCode &realStatus, const UnicodeString& pattern, const Locale& theLocale,
  538.                      UErrorCode inStatus0, /* statusString 1 */ const Locale &inCountry2, double currency3, // these numbers are the message arguments.
  539.                      UnicodeString &result)
  540. {
  541.     if(U_FAILURE(realStatus))
  542.         return; // you messed up
  543.  
  544.     UnicodeString errString1;
  545.     errorToString(inStatus0, errString1);
  546.  
  547.     UnicodeString countryName2;
  548.     inCountry2.getDisplayCountry(theLocale,countryName2);
  549.  
  550.     Formattable myArgs[] = {
  551.         Formattable((int32_t)inStatus0),   // inStatus0      {0}
  552.         Formattable(errString1), // statusString1 {1}
  553.         Formattable(countryName2),  // inCountry2 {2}
  554.         Formattable(currency3)// currency3  {3,number,currency}
  555.     };
  556.  
  557.     MessageFormat *fmt = new MessageFormat("MessageFormat's API is broken!!!!!!!!!!!",realStatus);
  558.     fmt->setLocale(theLocale);
  559.     fmt->applyPattern(pattern, realStatus);
  560.     
  561.     if (U_FAILURE(realStatus)) {
  562.         delete fmt;
  563.         return;
  564.     }
  565.  
  566.     FieldPosition ignore = 0;                      
  567.     fmt->format(myArgs,4,result,ignore,realStatus);
  568.  
  569.     delete fmt;
  570. };
  571.  
  572.  
  573. class FormatThreadTest : public ThreadWithStatus
  574. {
  575. public:
  576.     FormatThreadTest() // constructor is NOT multithread safe.
  577.         // the locale to use
  578.     {
  579.         static int32_t fgOffset = 0;
  580.         fOffset = fgOffset += 3;
  581.     }
  582.  
  583.     virtual void run()
  584.     {
  585.         int32_t iteration;
  586.  
  587.         UErrorCode status = U_ZERO_ERROR;
  588.         NumberFormat *formatter = NumberFormat::createInstance(Locale::ENGLISH,status);
  589.  
  590.         if(U_FAILURE(status))
  591.         {
  592.             error("Error on NumberFormat::createInstance()");
  593.             return;
  594.         }
  595.  
  596.         NumberFormat *percentFormatter = NumberFormat::createPercentInstance(Locale::FRENCH,status);
  597.  
  598.         if(U_FAILURE(status))
  599.         {
  600.             error("Error on NumberFormat::createPercentInstance()");
  601.             delete formatter;
  602.             return;
  603.         }
  604.  
  605.         for(iteration = 0;!getError() && iteration<kFormatThreadIterations;iteration++)
  606.         {
  607.             int32_t whichLine = (iteration + fOffset)%kNumberFormatTestDataLength;
  608.  
  609.             UnicodeString  output;
  610.  
  611.             formatter->format(kNumberFormatTestData[whichLine].number, output);
  612.  
  613.             if(0 != output.compare(kNumberFormatTestData[whichLine].string))
  614.             {
  615.                 error("format().. expected " + kNumberFormatTestData[whichLine].string + " got " + output);
  616.                 continue; // will break
  617.             }
  618.  
  619.             // Now check percent.
  620.             output.remove();
  621.             whichLine = (iteration + fOffset)%kPercentFormatTestDataLength;
  622.  
  623.             percentFormatter->format(kPercentFormatTestData[whichLine].number, output);
  624.  
  625.             if(0 != output.compare(kPercentFormatTestData[whichLine].string))
  626.             {
  627.                 error("percent format().. \n" + showDifference(kPercentFormatTestData[whichLine].string,output));
  628.                 continue;
  629.             }
  630.  
  631.             // Test message error 
  632. #define kNumberOfMessageTests 3
  633.             UErrorCode       statusToCheck;
  634.             UnicodeString   patternToCheck;
  635.             Locale          messageLocale;
  636.             Locale          countryToCheck;
  637.             double          currencyToCheck;
  638.  
  639.             UnicodeString   expected;
  640.  
  641.             // load the cases.
  642.             switch((iteration+fOffset) % kNumberOfMessageTests)
  643.             {
  644.             default:
  645.             case 0:
  646.                 statusToCheck=                      U_FILE_ACCESS_ERROR;
  647.                 patternToCheck=                     "0:Someone from {2} is receiving a #{0} error - {1}. Their telephone call is costing {3,number,currency}."; // number,currency
  648.                 messageLocale=                      Locale("en","US");
  649.                 countryToCheck=                     Locale("","HR");
  650.                 currencyToCheck=                    8192.77;
  651.                 expected=                           "0:Someone from Croatia is receiving a #4 error - U_FILE_ACCESS_ERROR. Their telephone call is costing $8,192.77.";
  652.                 break;
  653.             case 1:
  654.                 statusToCheck=                      U_INDEX_OUTOFBOUNDS_ERROR;
  655.                 patternToCheck=                     "1:A customer in {2} is receiving a #{0} error - {1}. Their telephone call is costing {3,number,currency}."; // number,currency
  656.                 messageLocale=                      Locale("de","DE");
  657.                 countryToCheck=                     Locale("","BF");
  658.                 currencyToCheck=                    2.32;
  659.                 expected=                           "1:A customer in Burkina Faso is receiving a #8 error - U_INDEX_OUTOFBOUNDS_ERROR. Their telephone call is costing $2.32.";
  660.             case 2:
  661.                 statusToCheck=                      U_MEMORY_ALLOCATION_ERROR;
  662.                 patternToCheck=                     "2:user in {2} is receiving a #{0} error - {1}. They insist they just spent {3,number,currency} on memory."; // number,currency
  663.                 messageLocale=                      Locale("de","AT"); // Austrian German
  664.                 countryToCheck=                     Locale("","US"); // hmm
  665.                 currencyToCheck=                    40193.12;
  666.                 expected=                           UEscapeString("2:user in Vereinigte Staaten is receiving a #7 error - U_MEMORY_ALLOCATION_ERROR. They insist they just spent \\u00f6S 40.193,12 on memory.");
  667.                 break;
  668.             }
  669.  
  670.             UnicodeString result;
  671.             UErrorCode status = U_ZERO_ERROR;
  672.             formatErrorMessage(status,patternToCheck,messageLocale,statusToCheck,countryToCheck,currencyToCheck,result);
  673.             if(U_FAILURE(status))
  674.             {
  675.                UnicodeString tmp;
  676.                errorToString(status,tmp);
  677.                error("Failure on message format, pattern=" + patternToCheck +", error = " + tmp);
  678.                continue;
  679.             }
  680.  
  681.             if(result != expected)
  682.             {
  683.                 error("PatternFormat: \n" + showDifference(expected,result));
  684.                 continue;
  685.             }
  686.         }
  687.  
  688.         delete formatter;
  689.         delete percentFormatter;
  690.         done();
  691.     }
  692.  
  693. private:
  694.     int32_t fOffset; // where we are testing from.
  695. };
  696.  
  697. // ** The actual test function.
  698.  
  699. void MultithreadTest::TestThreadedIntl()
  700. {
  701.  
  702.     FormatThreadTest tests[kFormatThreadThreads];
  703.  
  704.     logln(UnicodeString("Spawning: ") + kFormatThreadThreads + " threads * " + kFormatThreadIterations + " iterations each.");
  705.     for(int32_t j = 0; j < kFormatThreadThreads; j++)
  706.         tests[j].start();
  707.  
  708.     for(int32_t patience = kFormatThreadPatience;patience > 0; patience --)
  709.     {
  710.         logln("Waiting...");
  711.  
  712.         int32_t i;
  713.         int32_t terrs = 0;
  714.         int32_t completed =0;
  715.  
  716.         for(i=0;i<kFormatThreadThreads;i++)
  717.         {
  718.             if(tests[i].getDone())
  719.             {
  720.                 completed++;
  721.  
  722.                 logln(UnicodeString("Test #") + i + " is complete.. ");
  723.  
  724.                 UnicodeString theErr;
  725.                 if(tests[i].getError(theErr))
  726.                 {
  727.                     terrs++;
  728.                     errln(UnicodeString("#") + i + ": " + theErr);
  729.                 }
  730.                 // print out the error, too, if any.
  731.             }
  732.         }
  733.  
  734.         if(completed == kFormatThreadThreads)
  735.         {
  736.             logln("Done!");
  737.  
  738.             if(terrs)
  739.             {
  740.                 errln("There were errors.");
  741.             }
  742.  
  743.             return;
  744.         }
  745.  
  746.         SimpleThread::sleep(1000);
  747.     }
  748.     errln("patience exceeded. ");
  749. }
  750.  
  751. #endif // NO_THREADED_INTL
  752.