1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ******************************************************************************* 6 * Copyright (C) 2008, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 package android.icu.dev.test.lang; 11 12 import java.util.LinkedList; 13 import java.util.List; 14 import java.util.ListIterator; 15 16 import org.junit.Test; 17 import org.junit.runner.RunWith; 18 import org.junit.runners.JUnit4; 19 20 import android.icu.dev.test.TestFmwk; 21 import android.icu.lang.UCharacter; 22 import android.icu.testsharding.MainTestShard; 23 24 /** 25 * @author aheninger 26 * 27 */ 28 @MainTestShard 29 @RunWith(JUnit4.class) 30 public class UCharacterThreadTest extends TestFmwk { 31 // constructor ----------------------------------------------------------- 32 33 /** 34 * Private constructor to prevent initialisation 35 */ 36 public UCharacterThreadTest() 37 { 38 } 39 40 // public methods -------------------------------------------------------- 41 42 // 43 // Test multi-threaded parallel calls to UCharacter.getName(codePoint) 44 // Regression test for ticket 6264. 45 // 46 @Test 47 public void TestUCharactersGetName() throws InterruptedException { 48 List threads = new LinkedList(); 49 for(int t=0; t<20; t++) { 50 int codePoint = 47 + t; 51 String correctName = UCharacter.getName(codePoint); 52 GetNameThread thread = new GetNameThread(codePoint, correctName); 53 thread.start(); 54 threads.add(thread); 55 } 56 ListIterator i = threads.listIterator(); 57 while (i.hasNext()) { 58 GetNameThread thread = (GetNameThread)i.next(); 59 thread.join(); 60 if (!thread.correctName.equals(thread.actualName)) { 61 errln("FAIL, expected \"" + thread.correctName + "\", got \"" + thread.actualName + "\""); 62 } 63 } 64 } 65 66 private static class GetNameThread extends Thread { 67 private final int codePoint; 68 private final String correctName; 69 private String actualName; 70 71 GetNameThread(int codePoint, String correctName) { 72 this.codePoint = codePoint; 73 this.correctName = correctName; 74 } 75 76 @Override 77 public void run() { 78 for(int i=0; i<10000; i++) { 79 actualName = UCharacter.getName(codePoint); 80 if (!correctName.equals(actualName)) { 81 break; 82 } 83 } 84 } 85 } 86 } 87