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