]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterThreadTest.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / lang / UCharacterThreadTest.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test.lang;
8
9 import java.util.LinkedList;
10 import java.util.List;
11 import java.util.ListIterator;
12
13 import com.ibm.icu.dev.test.TestFmwk;
14 import com.ibm.icu.lang.UCharacter;
15
16 /**
17  * @author aheninger
18  *
19  */
20 public class UCharacterThreadTest extends TestFmwk {
21   // constructor -----------------------------------------------------------
22     
23     /**
24     * Private constructor to prevent initialisation
25     */
26     public UCharacterThreadTest()
27     {
28     }
29     
30       // public methods --------------------------------------------------------
31       
32     public static void main(String[] arg)  
33     {
34         try
35         {
36             UCharacterThreadTest test = new UCharacterThreadTest();
37             test.run(arg);
38         }
39         catch (Exception e)
40         {
41               e.printStackTrace();
42         }
43     }
44     
45     
46     //
47     //  Test multi-threaded parallel calls to UCharacter.getName(codePoint)
48     //  Regression test for ticket 6264.
49     //
50     public void TestUCharactersGetName() throws InterruptedException {
51         List threads = new LinkedList();
52         for(int t=0; t<20; t++) {
53           int codePoint = 47 + t;
54           String correctName = UCharacter.getName(codePoint);
55           GetNameThread thread = new GetNameThread(codePoint, correctName);
56           thread.start();
57           threads.add(thread);
58         }
59         ListIterator i = threads.listIterator();
60         while (i.hasNext()) {
61             GetNameThread thread = (GetNameThread)i.next();
62             thread.join();
63             if (!thread.correctName.equals(thread.actualName)) {
64                 errln("FAIL, expected \"" + thread.correctName + "\", got \"" + thread.actualName + "\"");
65             }
66         }
67       }
68
69       private static class GetNameThread extends Thread {
70         private final int codePoint;
71         private final String correctName;
72         private String actualName;
73
74         GetNameThread(int codePoint, String correctName) {
75            this.codePoint = codePoint;
76            this.correctName = correctName;
77         }
78
79         public void run() {
80           for(int i=0; i<10000; i++) {
81             actualName = UCharacter.getName(codePoint);
82             if (!correctName.equals(actualName)) {
83               break;
84             }
85           }
86         }
87       }
88 }