ICU-12603 Annotates ICU4J unit test classes which use JUnit with @RunWith(JUnit4.class).
X-SVN-Rev: 40375
This commit is contained in:
parent
ef72d0734e
commit
a782748606
File diff suppressed because it is too large
Load Diff
@ -9,13 +9,13 @@
|
||||
|
||||
/**
|
||||
* Test for CharsetSelector
|
||||
*
|
||||
*
|
||||
* This is a port of ucnvseltst.c from ICU4C
|
||||
*
|
||||
*
|
||||
* Tests related to serialization are not ported in this version. In addition,
|
||||
* the TestConversionUTF8 method is not going to be ported, as UTF8 is seldom used
|
||||
* in Java.
|
||||
*
|
||||
*
|
||||
* @author Shaopeng Jia
|
||||
*/
|
||||
|
||||
@ -27,6 +27,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.charset.CharsetICU;
|
||||
import com.ibm.icu.charset.CharsetProviderICU;
|
||||
@ -35,6 +37,7 @@ import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class TestSelection extends TestFmwk {
|
||||
@Test
|
||||
public void TestConversionUTF16() {
|
||||
@ -141,7 +144,7 @@ public class TestSelection extends TestFmwk {
|
||||
logln("IllegalArgumentException was thrown by CharsetSelector with a bogus mappingType.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String[] texts = {
|
||||
"Cos\'\u00E8 Unicode?\n\nUnicode assegna un numero univoco a ogni carattere,\nindipendentemente dalla piattaforma," +
|
||||
"\nindipendentemente dall\'applicazione,\nindipendentemente dalla lingua.\n\nI computer, in buona sostanza," +
|
||||
@ -170,7 +173,7 @@ public class TestSelection extends TestFmwk {
|
||||
"o di un sito web siano fruibili con piattaforme, lingue e paesi diversi, evitando la necessit\u00E0 di " +
|
||||
"reingenierizzare il prodotto per ogni situazione specifica. Permette, inoltre, il trasporto del testo " +
|
||||
"fra sistemi diversi senza che abbia luogo alcuna corruzione dei dati.\n",
|
||||
|
||||
|
||||
"\u0427\u0442\u043E \u0442\u0430\u043A\u043E\u0435 Unicode? Unicode - \u044D\u0442\u043E" +
|
||||
" \u0443\u043D\u0438\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u043A\u043E\u0434" +
|
||||
" \u0434\u043B\u044F \u043B\u044E\u0431\u043E\u0433\u043E \u0441\u0438\u043C\u0432\u043E\u043B\u0430," +
|
||||
@ -332,7 +335,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u0440\u0430\u0437\u043B\u0438\u0447\u043D\u044B\u043C\u0438 \u0441\u0438\u0441\u0442\u0435\u043C\u0430\u043C\u0438 " +
|
||||
"\u043F\u0440\u0435\u0434\u043E\u0445\u0440\u0430\u043D\u044F\u0435\u0442 \u044D\u0442\u0438 " +
|
||||
"\u0434\u0430\u043D\u043D\u044B\u0435 \u043E\u0442 \u043F\u043E\u0432\u0440\u0435\u0436\u0434\u0435",
|
||||
|
||||
|
||||
"\u0645\u0627 \u0647\u064A \u0627\u0644\u0634\u0641\u0631\u0629 \u0627\u0644\u0645\u0648\u062D\u062F\u0629 " +
|
||||
"\"\u064A\u0648\u0646\u0650\u0643\u0648\u062F\" \u061F\n\n\u0623\u0633\u0627\u0633\u064B\u0627\u060C " +
|
||||
"\u062A\u062A\u0639\u0627\u0645\u0644 \u0627\u0644\u062D\u0648\u0627\u0633\u064A\u0628 \u0641\u0642\u0637 \u0645\u0639 " +
|
||||
@ -431,7 +434,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u0643\u062A\u0627\u0628\u0629 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062C \u0645\u0631\u0629 " +
|
||||
"\u0648\u0627\u062D\u062F\u0629\u060C \u0648\u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647 \u0639\u0644\u0649 " +
|
||||
"\u0623\u064A \u0646\u0648\u0639 \u0645\u0646 \u0627\u0644\u0623\u062C\u0647\u0632\u0629",
|
||||
|
||||
|
||||
"\u4EC0\u9EBD\u662FUnicode(\u7D71\u4E00\u78BC/\u6A19\u6E96\u842C\u570B\u78BC)?\n\n" +
|
||||
"Unicode\u7D66\u6BCF\u500B\u5B57\u5143\u63D0\u4F9B\u4E86\u4E00\u500B\u552F\u4E00\u7684\u6578\u4F4D\uFF0C\n" +
|
||||
"\u4E0D\u8AD6\u662F\u4EC0\u9EBD\u5E73\u81FA\uFF0C\n\u4E0D\u8AD6\u662F\u4EC0\u9EBD\u7A0B\u5F0F\uFF0C\n" +
|
||||
@ -470,7 +473,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u570B\u5BB6\uFF0C\u800C\u4E0D\u9700\u8981\u91CD\u5EFA\u3002\u5B83\u53EF\u5C07\u8CC7\u6599\u50B3\u8F38" +
|
||||
"\u5230\u8A31\u591A\u4E0D\u540C\u7684\u7CFB\u7D71\uFF0C\u800C\u7121\u640D\u58DE\u3002\n\u95DC\u65BCUnicode" +
|
||||
"\u5B78\u8853\u5B78\u6703\n\nUnicode\u5B78\u8853\u5B78\u6703",
|
||||
|
||||
|
||||
"\u00C7\'\u00EBsht\u00EB UNICODE?\n\nUnicode siguron nj\u00EB num\u00EBr t\u00EB vet\u00EBm p\u00EBr \u00E7do " +
|
||||
"g\u00EBrm\u00EB,\np\u00EBr cil\u00EBndo platform\u00EB,\np\u00EBr cilindo program,\np\u00EBr cil\u00EBndo " +
|
||||
"gjuh\u00EB.\n\nN\u00EB themel, kompjuterat veprojn\u00EB me an\u00EBn e numrave. Ata ruajn\u00EB g\u00EBrmat " +
|
||||
@ -502,7 +505,7 @@ public class TestSelection extends TestFmwk {
|
||||
"softuer ose nj\u00EB faqe interneti t\u00EB p\u00EBrdoret p\u00EBr shum\u00EB platforma, gjuh\u00EB dhe vende " +
|
||||
"pa re-inxhinierim. Ai lejon t\u00EB dh\u00EBnat t\u00EB kalohen p\u00EBrmes shum\u00EB sistemeve t\u00EB ndryshme " +
|
||||
"pa korruptim.",
|
||||
|
||||
|
||||
"\u092F\u0942\u0928\u093F\u0915\u094B\u0921 \u0915\u094D\u092F\u093E \u0939\u0948?\n\n\u092F\u0942\u0928\u093F\u0915" +
|
||||
"\u094B\u0921 \u092A\u094D\u0930\u0924\u094D\u092F\u0947\u0915 \u0905\u0915\u094D\u0937\u0930 \u0915\u0947 " +
|
||||
"\u0932\u093F\u090F \u090F\u0915 \u0935\u093F\u0936\u0947\u0937 \u0928\u092E\u094D\u092C\u0930 \u092A\u094D" +
|
||||
@ -611,7 +614,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u0940 \u092C\u093E\u0927\u093E \u0915\u0947 \u0935\u093F\u092D\u093F\u0928\u094D\u0928 \u092A\u094D" +
|
||||
"\u0930\u0923\u093E\u0932\u093F\u092F\u094B\u0902 \u0938\u0947 \u0939\u094B\u0915\u0930 \u0932\u0947 " +
|
||||
"\u091C\u093E\u092F\u093E \u091C\u093E \u0938\u0915\u0924\u093E \u0939\u0948\u0964\n",
|
||||
|
||||
|
||||
"\u0E1A\u0E40\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E02\u0E2D\u0E07\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02. \u0E04" +
|
||||
"\u0E2D\u0E21\u0E1E\u0E34\u0E27\u0E40\u0E15\u0E2D\u0E23\u0E4C\u0E08\u0E31\u0E14\u0E40\u0E01\u0E47\u0E1A" +
|
||||
"\u0E15\u0E31\u0E27\u0E2D\u0E31\u0E01\u0E29\u0E23\u0E41\u0E25\u0E30\u0E2D\u0E31\u0E01\u0E02\u0E23\u0E30" +
|
||||
@ -683,7 +686,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u0E48\u0E07\u0E43\u0E19\u0E41\u0E19\u0E27\u0E42\u0E19\u0E49\u0E21\u0E17\u0E32\u0E07\u0E40\u0E17\u0E04\u0E42" +
|
||||
"\u0E19\u0E42\u0E25\u0E22\u0E35\u0E0B\u0E2D\u0E1F\u0E15\u0E4C\u0E41\u0E27\u0E23\u0E4C\u0E23\u0E30\u0E14\u0E31" +
|
||||
"\u0E1A\u0E42\u0E25\u0E01\u0E17\u0E35\u0E48\u0E21\u0E35\u0E04\u0E27\u0E32\u0E21\u0E2A\u0E33\u0E04\n",
|
||||
|
||||
|
||||
"\u4EC0\u4E48\u662FUnicode(\u7EDF\u4E00\u7801)?\n\nUnicode\u7ED9\u6BCF\u4E2A\u5B57\u7B26\u63D0\u4F9B\u4E86" +
|
||||
"\u4E00\u4E2A\u552F\u4E00\u7684\u6570\u5B57\uFF0C\n\u4E0D\u8BBA\u662F\u4EC0\u4E48\u5E73\u53F0\uFF0C\n\u4E0D" +
|
||||
"\u8BBA\u662F\u4EC0\u4E48\u7A0B\u5E8F\uFF0C\n\u4E0D\u8BBA\u662F\u4EC0\u4E48\u8BED\u8A00\u3002\n\n\u57FA\u672C" +
|
||||
@ -727,7 +730,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u8D44\u91D1\u3002Unicode\u5B66\u672F\u5B66\u4F1A\u7684\u4F1A\u5458\u8D44\u683C\u5F00\u653E\u7ED9\u4E16\u754C" +
|
||||
"\u4E0A\u4EFB\u4F55\u652F\u6301Unicode\u6807\u51C6\u548C\u5E0C\u671B\u534F\u52A9\u5176\u6269\u5C55\u548C\u6267" +
|
||||
"\u884C\u7684\u7EC4\u7EC7\u53CA\u4E2A\u4EBA\u3002\n",
|
||||
|
||||
|
||||
"Mik\u00E4 Unicode on?\n\nUnicode m\u00E4\u00E4ritt\u00E4\u00E4 jokaiselle merkille yksil\u00F6llisen arvon." +
|
||||
"\nRiippumatta k\u00E4ytt\u00F6j\u00E4rjestelm\u00E4st\u00E4\nRiippumatta ohjelmistosta\nRiippumatta kielest" +
|
||||
"\u00E4\n\nTietokoneiden toiminta perustuu numeroiden k\u00E4sittelylle. My\u00F6s kirjaimet ja muut merkit " +
|
||||
@ -754,7 +757,7 @@ public class TestSelection extends TestFmwk {
|
||||
"\u00E4inen sovellus tai sivusto voidaan tarjota useille eri k\u00E4ytt\u00F6j\u00E4rjestelmille ja monilla " +
|
||||
"eri kielill\u00E4 maailmanlaajuisesti, ilman uudelleenohjelmoinnin tarvetta. Tieto kulkee j\u00E4rjestelmien " +
|
||||
"v\u00E4lill\u00E4 vailla tuhoutumisen tai v\u00E4\u00E4ristymisen vaaraa.\nUnicode-konsortio",
|
||||
|
||||
|
||||
"Co je Unicode?\n\nUnicode p\u0159i\u0159azuje ka\u017Ed\u00E9mu znaku jedine\u010Dn\u00E9 \u010D\u00EDslo,\nnez" +
|
||||
"\u00E1visle na platform\u011B,\nnez\u00E1visle na programu,\nnez\u00E1visle na jazyce.\n\nPo\u010D\u00EDta\u010De," +
|
||||
" ze sv\u00E9 podstaty, pracuj\u00ED pouze s \u010D\u00EDsly. P\u00EDsmena a dal\u0161\u00ED znaky ukl\u00E1daj\u00ED" +
|
||||
@ -785,7 +788,7 @@ public class TestSelection extends TestFmwk {
|
||||
"softwarov\u00FD produkt nebo jedin\u00E1 webov\u00E1 str\u00E1nka byla zam\u011B\u0159ena na mnoho platforem, " +
|
||||
"jazyk\u016F a zem\u00ED beze zm\u011Bn n\u00E1vrhu. To dovoluje p\u0159en\u00E1\u0161et data p\u0159es mnoho " +
|
||||
"r\u016Fzn\u00FDch syst\u00E9m\u016F bez poru\u0161en\u00ED.",
|
||||
|
||||
|
||||
"?\n\n\u05D9\u05D5\u05E0\u05D9\u05E7\u05D5\u05D3 \u05DE\u05E7\u05E6\u05D4 \u05DE\u05E1\u05E4\u05E8 \u05D9\u05D9" +
|
||||
"\u05D7\u05D5\u05D3\u05D9 \u05DC\u05DB\u05DC \u05EA\u05D5,\n\u05DC\u05D0 \u05DE\u05E9\u05E0\u05D4 \u05E2\u05DC " +
|
||||
"\u05D0\u05D9\u05D6\u05D5 \u05E4\u05DC\u05D8\u05E4\u05D5\u05E8\u05DE\u05D4,\n\u05DC\u05D0 \u05DE\u05E9\u05E0\u05D4" +
|
||||
|
@ -18,6 +18,8 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.util.CollectionUtilities;
|
||||
@ -43,6 +45,7 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* @author Mark Davis
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class AlphabeticIndexTest extends TestFmwk {
|
||||
/**
|
||||
*
|
||||
|
@ -23,6 +23,8 @@ import java.util.MissingResourceException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
@ -38,6 +40,7 @@ import com.ibm.icu.text.UnicodeSet;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationAPITest extends TestFmwk {
|
||||
/**
|
||||
* This tests the collation key related APIs.
|
||||
|
@ -7,30 +7,33 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationTurkishTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/trcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationChineseTest extends TestFmwk{
|
||||
public CollationChineseTest()
|
||||
public CollationChineseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPinYin()
|
||||
public void TestPinYin()
|
||||
{
|
||||
String seq[]
|
||||
String seq[]
|
||||
= {"\u963f", "\u554a", "\u54ce", "\u6371", "\u7231", "\u9f98",
|
||||
"\u4e5c", "\u8baa", "\u4e42", "\u53c8"};
|
||||
RuleBasedCollator collator = null;
|
||||
@ -45,4 +48,4 @@ public class CollationChineseTest extends TestFmwk{
|
||||
CollationTest.doTest(this, collator, seq[i], seq[i + 1], -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,15 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
@ -21,20 +23,21 @@ import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* CollationCreationMethodTest checks to ensure that the collators act the same whether they are created by choosing a
|
||||
*
|
||||
* CollationCreationMethodTest checks to ensure that the collators act the same whether they are created by choosing a
|
||||
* locale and loading the data from file, or by using rules.
|
||||
*
|
||||
*
|
||||
* @author Brian Rower - IBM - August 2008
|
||||
*
|
||||
*/
|
||||
public class CollationCreationMethodTest extends TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationCreationMethodTest extends TestFmwk
|
||||
{
|
||||
@Test
|
||||
public void TestRuleVsLocaleCreationMonkey()
|
||||
{
|
||||
//create a RBC from a collator reader by reading in a locale collation file
|
||||
//also create one simply from a rules string (which should be
|
||||
//also create one simply from a rules string (which should be
|
||||
//pulled from the locale collation file)
|
||||
//and then do crazy monkey testing on it to make sure they are the same.
|
||||
int x,y,z;
|
||||
@ -60,8 +63,8 @@ public class CollationCreationMethodTest extends TestFmwk
|
||||
localeCollator = (RuleBasedCollator)Collator.getInstance(locale);
|
||||
logln("Rules for " + locale + " are: " + localeCollator.getRules());
|
||||
ruleCollator = new RuleBasedCollator(localeCollator.getRules());
|
||||
}
|
||||
catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
warnln("ERROR: in creation of collator of locale " + locale.getDisplayName() + ": " + e);
|
||||
return;
|
||||
@ -76,7 +79,7 @@ public class CollationCreationMethodTest extends TestFmwk
|
||||
|
||||
key1 = localeCollator.getCollationKey(randString1);
|
||||
key2 = ruleCollator.getCollationKey(randString1);
|
||||
|
||||
|
||||
report(locale.getDisplayName(), randString1, key1, key2);
|
||||
}
|
||||
}
|
||||
@ -108,9 +111,9 @@ public class CollationCreationMethodTest extends TestFmwk
|
||||
return s;
|
||||
}
|
||||
|
||||
private void report(String localeName, String string1, CollationKey k1, CollationKey k2)
|
||||
private void report(String localeName, String string1, CollationKey k1, CollationKey k2)
|
||||
{
|
||||
if (!k1.equals(k2))
|
||||
if (!k1.equals(k2))
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("With ").append(localeName).append(" collator\n and input string: ").append(string1).append('\n');
|
||||
|
@ -7,22 +7,25 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationCurrencyTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/currcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationCurrencyTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestCurrency() {
|
||||
@ -59,16 +62,16 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
{ 0x20AE }, /*20AE; L; [14 62, 03, 03] # [0841.0020.0002] # TUGRIK SIGN*/
|
||||
{ 0x20AF } /*20AF; L; [14 64, 03, 03] # [0842.0020.0002] # DRACHMA SIGN*/
|
||||
};
|
||||
|
||||
|
||||
int i, j;
|
||||
int expectedResult = 0;
|
||||
RuleBasedCollator c = (RuleBasedCollator)Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
||||
// Compare each currency symbol against all the
|
||||
// currency symbols, including itself
|
||||
String source;
|
||||
String target;
|
||||
|
||||
|
||||
for (i = 0; i < currency.length; i += 1) {
|
||||
for (j = 0; j < currency.length; j += 1) {
|
||||
source = new String(currency[i]);
|
||||
@ -84,14 +87,14 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
|
||||
int compareResult = c.compare(source, target);
|
||||
CollationKey sourceKey = null;
|
||||
|
||||
|
||||
sourceKey = c.getCollationKey(source);
|
||||
|
||||
if (sourceKey == null) {
|
||||
errln("Couldn't get collationKey for source");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
CollationKey targetKey = null;
|
||||
targetKey = c.getCollationKey(target);
|
||||
if (targetKey == null) {
|
||||
@ -105,7 +108,7 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -118,13 +121,13 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -134,7 +137,7 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -147,7 +150,7 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -158,7 +161,7 @@ public class CollationCurrencyTest extends TestFmwk {
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,18 +7,20 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationDummyTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/allcoll.cpp
|
||||
* $ICU4CRoot/source/test/cintltst/callcoll.c
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationElementIterator;
|
||||
@ -26,7 +28,8 @@ import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationDummyTest extends TestFmwk {
|
||||
//testSourceCases[][] and testTargetCases[][], testCases[][] are ported from the file callcoll.c in icu4c
|
||||
private static char[][] testSourceCases = {
|
||||
@ -39,34 +42,34 @@ public class CollationDummyTest extends TestFmwk {
|
||||
{0x66, 0x69, 0x76, 0x65},
|
||||
{0x31},
|
||||
{0x31},
|
||||
{0x31}, // 10
|
||||
{0x31}, // 10
|
||||
{0x32},
|
||||
{0x32},
|
||||
{0x48, 0x65, 0x6c, 0x6c, 0x6f},
|
||||
{0x61, 0x3c, 0x62},
|
||||
{0x61, 0x3c, 0x62},
|
||||
{0x61, 0x63, 0x63},
|
||||
{0x61, 0x63, 0x48, 0x63}, // simple test
|
||||
{0x61, 0x63, 0x48, 0x63}, // simple test
|
||||
{0x70, 0x00EA, 0x63, 0x68, 0x65},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x62, 0x63}, // 20
|
||||
{0x61, 0x62, 0x63}, // 20
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x00E6, 0x63},
|
||||
{0x61, 0x63, 0x48, 0x63}, // primary test
|
||||
{0x61, 0x63, 0x48, 0x63}, // primary test
|
||||
{0x62, 0x6c, 0x61, 0x63, 0x6b},
|
||||
{0x66, 0x6f, 0x75, 0x72},
|
||||
{0x66, 0x69, 0x76, 0x65},
|
||||
{0x31},
|
||||
{0x61, 0x62, 0x63}, // 30
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x62, 0x63}, // 30
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x62, 0x63, 0x48},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x63, 0x48, 0x63}, // 34
|
||||
{0x61, 0x63, 0x48, 0x63}, // 34
|
||||
{0x61, 0x63, 0x65, 0x30},
|
||||
{0x31, 0x30},
|
||||
{0x70, 0x00EA,0x30} // 37
|
||||
{0x70, 0x00EA,0x30} // 37
|
||||
};
|
||||
|
||||
private static char[][] testTargetCases = {
|
||||
@ -79,36 +82,36 @@ public class CollationDummyTest extends TestFmwk {
|
||||
{0x35},
|
||||
{0x6f, 0x6e, 0x65},
|
||||
{0x6e, 0x6e, 0x65},
|
||||
{0x70, 0x6e, 0x65}, // 10
|
||||
{0x70, 0x6e, 0x65}, // 10
|
||||
{0x74, 0x77, 0x6f},
|
||||
{0x75, 0x77, 0x6f},
|
||||
{0x68, 0x65, 0x6c, 0x6c, 0x4f},
|
||||
{0x61, 0x3c, 0x3d, 0x62},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x43, 0x48, 0x63},
|
||||
{0x61, 0x43, 0x48, 0x63}, // simple test
|
||||
{0x61, 0x43, 0x48, 0x63}, // simple test
|
||||
{0x70, 0x00E9, 0x63, 0x68, 0x00E9},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x42, 0x43}, // 20
|
||||
{0x61, 0x42, 0x43}, // 20
|
||||
{0x61, 0x62, 0x63, 0x68},
|
||||
{0x61, 0x62, 0x64},
|
||||
{0x00E4, 0x62, 0x63},
|
||||
{0x61, 0x00C6, 0x63},
|
||||
{0x61, 0x43, 0x48, 0x63}, // primary test
|
||||
{0x61, 0x43, 0x48, 0x63}, // primary test
|
||||
{0x62, 0x6c, 0x61, 0x63, 0x6b, 0x2d, 0x62, 0x69, 0x72, 0x64},
|
||||
{0x34},
|
||||
{0x35},
|
||||
{0x6f, 0x6e, 0x65},
|
||||
{0x61, 0x62, 0x63},
|
||||
{0x61, 0x42, 0x63}, // 30
|
||||
{0x61, 0x42, 0x63}, // 30
|
||||
{0x61, 0x62, 0x63, 0x68},
|
||||
{0x61, 0x62, 0x64},
|
||||
{0x61, 0x43, 0x48, 0x63}, // 34
|
||||
{0x61, 0x43, 0x48, 0x63}, // 34
|
||||
{0x61, 0x63, 0x65, 0x30},
|
||||
{0x31, 0x30},
|
||||
{0x70, 0x00EB,0x30} // 37
|
||||
{0x70, 0x00EB,0x30} // 37
|
||||
};
|
||||
|
||||
|
||||
private static char[][] testCases = {
|
||||
{0x61},
|
||||
{0x41},
|
||||
@ -124,7 +127,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
{0x63},
|
||||
{0x7a}
|
||||
};
|
||||
|
||||
|
||||
int[] results = {
|
||||
-1,
|
||||
-1, //Collator::GREATER,
|
||||
@ -135,7 +138,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
-1,
|
||||
1,
|
||||
1,
|
||||
-1, // 10
|
||||
-1, // 10
|
||||
1,
|
||||
-1,
|
||||
1,
|
||||
@ -143,44 +146,44 @@ public class CollationDummyTest extends TestFmwk {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
// test primary > 17
|
||||
// test primary > 17
|
||||
0,
|
||||
0,
|
||||
0, // 20
|
||||
0, // 20
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
// test secondary > 26
|
||||
// test secondary > 26
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, // 30
|
||||
0, // 30
|
||||
0,
|
||||
-1,
|
||||
0, // 34
|
||||
0, // 34
|
||||
0,
|
||||
0,
|
||||
-1
|
||||
-1
|
||||
};
|
||||
|
||||
|
||||
final int MAX_TOKEN_LEN = 16;
|
||||
|
||||
|
||||
private RuleBasedCollator myCollation;
|
||||
|
||||
|
||||
public CollationDummyTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String ruleset = "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
|
||||
// String ruleset = "& Four, 4";
|
||||
myCollation = new RuleBasedCollator(ruleset);
|
||||
}
|
||||
|
||||
|
||||
// perform test with strength tertiary
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
@ -194,7 +197,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
// perform test with strength PRIMARY
|
||||
@Test
|
||||
public void TestPrimary() {
|
||||
// problem in strcollinc for unfinshed contractions
|
||||
// problem in strcollinc for unfinshed contractions
|
||||
myCollation.setStrength(Collator.PRIMARY);
|
||||
for (int i = 17; i < 26 ; i++) {
|
||||
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
|
||||
@ -250,17 +253,17 @@ public class CollationDummyTest extends TestFmwk {
|
||||
errln("Comparing two strings with only secondary differences in C failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// To compare them with just primary differences
|
||||
|
||||
// To compare them with just primary differences
|
||||
coll.setStrength(Collator.PRIMARY);
|
||||
result = coll.compare(source, target);
|
||||
// result is 0
|
||||
// result is 0
|
||||
if (result != 0) {
|
||||
errln("Comparing two strings with no differences in C failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, do the same comparison with keys
|
||||
}
|
||||
|
||||
// Now, do the same comparison with keys
|
||||
CollationKey sourceKeyOut, targetKeyOut;
|
||||
sourceKeyOut = coll.getCollationKey(source);
|
||||
targetKeyOut = coll.getCollationKey(target);
|
||||
@ -270,38 +273,38 @@ public class CollationDummyTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TestSurrogates() is ported from cintltst/callcoll.c
|
||||
|
||||
|
||||
/**
|
||||
* Tests surrogate support.
|
||||
*/
|
||||
@Test
|
||||
public void TestSurrogates()
|
||||
public void TestSurrogates()
|
||||
{
|
||||
String rules = "&z<'\ud800\udc00'<'\ud800\udc0a\u0308'<A";
|
||||
String source[] = {"z",
|
||||
"\uD800\uDC00",
|
||||
"\ud800\udc0a\u0308",
|
||||
"\ud800\udc02"
|
||||
"\ud800\udc02"
|
||||
};
|
||||
|
||||
|
||||
String target[] = {"\uD800\uDC00",
|
||||
"\ud800\udc0a\u0308",
|
||||
"A",
|
||||
"\ud800\udc03"
|
||||
"\ud800\udc03"
|
||||
};
|
||||
|
||||
// this test is to verify the supplementary sort key order in the english
|
||||
|
||||
// this test is to verify the supplementary sort key order in the english
|
||||
// collator
|
||||
Collator enCollation;
|
||||
try {
|
||||
enCollation = Collator.getInstance(Locale.ENGLISH);
|
||||
} catch (Exception e) {
|
||||
errln("ERROR: Failed to create the collator for ENGLISH");
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
myCollation.setStrength(Collator.TERTIARY);
|
||||
int count = 0;
|
||||
// logln("start of english collation supplementary characters test\n");
|
||||
@ -310,7 +313,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
count ++;
|
||||
}
|
||||
doTest(enCollation, source[count], target[count], 1);
|
||||
|
||||
|
||||
// logln("start of tailored collation supplementary characters test\n");
|
||||
count = 0;
|
||||
Collator newCollation;
|
||||
@ -318,16 +321,16 @@ public class CollationDummyTest extends TestFmwk {
|
||||
newCollation = new RuleBasedCollator(rules);
|
||||
} catch (Exception e) {
|
||||
errln("ERROR: Failed to create the collator for rules");
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// tests getting collation elements for surrogates for tailored rules
|
||||
|
||||
// tests getting collation elements for surrogates for tailored rules
|
||||
while (count < 4) {
|
||||
doTest(newCollation, source[count], target[count], -1);
|
||||
count ++;
|
||||
}
|
||||
|
||||
// tests that \uD801\uDC01 still has the same value, not changed
|
||||
|
||||
// tests that \uD801\uDC01 still has the same value, not changed
|
||||
CollationKey enKey = enCollation.getCollationKey(source[3]);
|
||||
CollationKey newKey = newCollation.getCollationKey(source[3]);
|
||||
int keyResult = enKey.compareTo(newKey);
|
||||
@ -358,68 +361,68 @@ public class CollationDummyTest extends TestFmwk {
|
||||
char[] source = new char[1];
|
||||
char ch;
|
||||
int expected[] = {0};
|
||||
|
||||
|
||||
try {
|
||||
enColl = Collator.getInstance(Locale.ENGLISH);
|
||||
} catch (Exception e) {
|
||||
errln("ERROR: Failed to create the collator for ENGLISH");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
myColl = new RuleBasedCollator(rule);
|
||||
} catch(Exception e){
|
||||
errln("Fail to create RuleBasedCollator with rules:" + rule);
|
||||
return;
|
||||
}
|
||||
}
|
||||
enColl.setStrength(Collator.PRIMARY);
|
||||
myColl.setStrength(Collator.PRIMARY);
|
||||
|
||||
|
||||
((RuleBasedCollator)enColl).setAlternateHandlingShifted(true);
|
||||
((RuleBasedCollator)myColl).setAlternateHandlingShifted(true);
|
||||
|
||||
|
||||
if(((RuleBasedCollator)enColl).isAlternateHandlingShifted() != true) {
|
||||
errln("ERROR: ALTERNATE_HANDLING value can not be set to SHIFTED\n");
|
||||
}
|
||||
|
||||
// space is supposed to be a variable
|
||||
CollationKey key = enColl.getCollationKey(" ");
|
||||
byte[] result = key.toByteArray();
|
||||
|
||||
|
||||
// space is supposed to be a variable
|
||||
CollationKey key = enColl.getCollationKey(" ");
|
||||
byte[] result = key.toByteArray();
|
||||
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
if(result[i]!= expected[i]) {
|
||||
errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
|
||||
break;
|
||||
errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ch = 'a';
|
||||
while (ch < 'z') {
|
||||
source[0] = ch;
|
||||
key = myColl.getCollationKey(new String(source));
|
||||
result = key.toByteArray();
|
||||
|
||||
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
if(result[i]!= expected[i]) {
|
||||
errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
|
||||
break;
|
||||
errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
ch ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestJB1401() {
|
||||
Collator myCollator = null;
|
||||
char[] NFD_UnsafeStartChars = {
|
||||
0x0f73, // Tibetan Vowel Sign II
|
||||
0x0f75, // Tibetan Vowel Sign UU
|
||||
0x0f81, // Tibetan Vowel Sign Reversed II
|
||||
0x0f73, // Tibetan Vowel Sign II
|
||||
0x0f75, // Tibetan Vowel Sign UU
|
||||
0x0f81, // Tibetan Vowel Sign Reversed II
|
||||
0
|
||||
};
|
||||
int i;
|
||||
|
||||
|
||||
try{
|
||||
myCollator = Collator.getInstance(Locale.ENGLISH);
|
||||
} catch(Exception e) {
|
||||
@ -433,11 +436,11 @@ public class CollationDummyTest extends TestFmwk {
|
||||
// in original form, NFD, and then NFC form.
|
||||
char c = NFD_UnsafeStartChars[i];
|
||||
if (c==0) {break;}
|
||||
|
||||
|
||||
String x = "\u00C0" + c; // \u00C0 is A Grave
|
||||
String y;
|
||||
String z;
|
||||
|
||||
|
||||
try{
|
||||
y = Normalizer.decompose(x, false);
|
||||
z = Normalizer.decompose(y, true);
|
||||
@ -445,15 +448,15 @@ public class CollationDummyTest extends TestFmwk {
|
||||
errln("ERROR: Failed to normalize test of character" + c);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Collation test. All three strings should be equal.
|
||||
// doTest does both strcoll and sort keys, with params in both orders.
|
||||
doTest(myCollator, x, y, 0);
|
||||
doTest(myCollator, x, z, 0);
|
||||
doTest(myCollator, y, z, 0);
|
||||
|
||||
doTest(myCollator, y, z, 0);
|
||||
|
||||
// Run collation element iterators over the three strings. Results should be same for each.
|
||||
|
||||
|
||||
{
|
||||
CollationElementIterator ceiX, ceiY, ceiZ;
|
||||
int ceX, ceY, ceZ;
|
||||
@ -466,7 +469,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
errln("ERROR: getCollationElementIterator failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (j=0;; j++) {
|
||||
try{
|
||||
ceX = ceiX.next();
|
||||
@ -476,7 +479,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
errln("ERROR: CollationElementIterator.next failed for iteration " + j);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (ceX != ceY || ceY != ceZ) {
|
||||
errln("ERROR: ucol_next failed for iteration " + j);
|
||||
break;
|
||||
@ -488,10 +491,10 @@ public class CollationDummyTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test method called with different strengths,
|
||||
// tests comparison of custum collation with different strengths
|
||||
|
||||
|
||||
private void doTest(Collator collation, char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
String t = new String(target);
|
||||
@ -504,10 +507,10 @@ public class CollationDummyTest extends TestFmwk {
|
||||
doTestVariant(collation, t, s, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test method called with different strengths,
|
||||
// tests comparison of custum collation with different strengths
|
||||
|
||||
|
||||
private void doTest(Collator collation,String s, String t, int result) {
|
||||
doTestVariant(collation, s, t, result);
|
||||
if(result == -1) {
|
||||
@ -518,7 +521,7 @@ public class CollationDummyTest extends TestFmwk {
|
||||
doTestVariant(collation, t, s, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void doTestVariant(Collator collation, String source, String target, int result) {
|
||||
int compareResult = collation.compare(source, target);
|
||||
CollationKey srckey , tgtkey;
|
||||
@ -532,4 +535,4 @@ public class CollationDummyTest extends TestFmwk {
|
||||
errln("Collation key comparison failed in variant test\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,22 +7,25 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationEnglishTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/encoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationEnglishTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */},
|
||||
@ -30,12 +33,12 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0020 /* ' ' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x002D /* '-' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0048 /* 'H' */, 0x0065 /* 'e' */, 0x006C /* 'l' */, 0x006C /* 'l' */, 0x006F /* 'o' */},
|
||||
{0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
|
||||
{0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x002D /* '-' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x002D /* '-' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x0065 /* 'e' */},
|
||||
{0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x0065 /* 'e' */},
|
||||
{0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x00E9},
|
||||
{0x00C4, 0x0042 /* 'B' */, 0x0308, 0x0043 /* 'C' */, 0x0308},
|
||||
{0x0061 /* 'a' */, 0x0308, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
@ -44,9 +47,9 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0041 /* 'A' */},
|
||||
{0x0041 /* 'A' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */},
|
||||
{0x0074 /* 't' */, 0x0063 /* 'c' */, 0x006F /* 'o' */, 0x006D /* 'm' */, 0x0070 /* 'p' */, 0x0061 /* 'a' */, 0x0072 /* 'r' */, 0x0065 /* 'e' */, 0x0070 /* 'p' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0069 /* 'i' */, 0x006E /* 'n' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */},
|
||||
{0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0062 /* 'b' */},
|
||||
{0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0062 /* 'b' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
@ -54,7 +57,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00E6, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
@ -64,7 +67,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0061 /* 'a' */, 0x0308, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0074 /* 't' */, 0x0068 /* 'h' */, 0x0069 /* 'i' */, 0x0302, 0x0073 /* 's' */},
|
||||
{0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x0065 /* 'e' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x00E6, 0x0063 /* 'c' */},
|
||||
@ -72,10 +75,10 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x00E6, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x00E9} // 49
|
||||
};
|
||||
|
||||
|
||||
private static char[][] testTargetCases = {
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
@ -86,7 +89,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */, 0x0073 /* 's' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */, 0x0073 /* 's' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x006B /* 'k' */, 0x0062 /* 'b' */, 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
|
||||
{0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x00E9},
|
||||
{0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x0065 /* 'e' */, 0x0072 /* 'r' */},
|
||||
{0x00C4, 0x0042 /* 'B' */, 0x0308, 0x0043 /* 'C' */, 0x0308},
|
||||
@ -96,7 +99,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x0041 /* 'A' */, 0x00E1, 0x0063 /* 'c' */, 0x0064 /* 'd' */},
|
||||
{0x0041 /* 'A' */, 0x00E1, 0x0063 /* 'c' */, 0x0064 /* 'd' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0054 /* 'T' */, 0x0043 /* 'C' */, 0x006F /* 'o' */, 0x006D /* 'm' */, 0x0070 /* 'p' */, 0x0061 /* 'a' */, 0x0072 /* 'r' */, 0x0065 /* 'e' */, 0x0050 /* 'P' */, 0x006C /* 'l' */, 0x0061 /* 'a' */, 0x0069 /* 'i' */, 0x006E /* 'n' */},
|
||||
{0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0042 /* 'B' */},
|
||||
@ -106,7 +109,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */, 0x0064 /* 'd' */, 0x0061 /* 'a' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0023 /* '#' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x003D /* '=' */, 0x0063 /* 'c' */},
|
||||
@ -116,7 +119,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0074 /* 't' */, 0x0068 /* 'h' */, 0x00EE, 0x0073 /* 's' */},
|
||||
{0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x00E9},
|
||||
{0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
|
||||
{0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
|
||||
{0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0064 /* 'd' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x00C6, 0x0063 /* 'c' */},
|
||||
@ -124,13 +127,13 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x00C6, 0x0063 /* 'c' */},
|
||||
{0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0064 /* 'd' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
|
||||
{0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */, 0x0068 /* 'h' */, 0x0065 /* 'e' */}
|
||||
}; // 49
|
||||
|
||||
private static int[] results = {
|
||||
//-1:LESS; 0:EQUAL; 1:GREATER
|
||||
-1,
|
||||
-1,
|
||||
-1, /*Collator::GREATER,*/
|
||||
-1,
|
||||
1,
|
||||
@ -181,7 +184,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
-1,
|
||||
0,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1 // 49
|
||||
};
|
||||
|
||||
@ -238,17 +241,17 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
{ 0x0152},
|
||||
{0x006F /* 'o' */, 0x0066 /* 'f' */},
|
||||
};
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationEnglishTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception {
|
||||
myCollation = Collator.getInstance(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
|
||||
//performs test with strength PRIMARY
|
||||
@Test
|
||||
public void TestPrimary() {
|
||||
@ -256,9 +259,9 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
myCollation.setStrength(Collator.PRIMARY);
|
||||
for (i = 38; i < 43 ; i++) {
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//perform test with strength SECONDARY
|
||||
@Test
|
||||
public void TestSecondary() {
|
||||
@ -284,7 +287,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//perform test with strength TERTIARY
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
@ -294,7 +297,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
for (i = 0; i < 38 ; i++)
|
||||
{
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (i = 0; i < 10; i++)
|
||||
@ -321,10 +324,10 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test routine, tests rules defined by the "en" locale
|
||||
private void doTest(char[] source, char[] target, int result){
|
||||
|
||||
|
||||
String s = new String(source);
|
||||
String t = new String(target);
|
||||
int compareResult = myCollation.compare(s, t);
|
||||
@ -333,9 +336,9 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ){
|
||||
if (expectedResult < -1 || expectedResult > 1)
|
||||
@ -349,13 +352,13 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()){
|
||||
return;
|
||||
return;
|
||||
}else{
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -365,7 +368,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -378,7 +381,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -389,7 +392,7 @@ public class CollationEnglishTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,21 +7,24 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationFinnishTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/ficoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationFinnishTest extends TestFmwk {
|
||||
private static char[][] testSourceCases = {
|
||||
{0x77, 0x61, 0x74},
|
||||
@ -49,26 +52,26 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
};
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationFinnishTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception{
|
||||
myCollation = Collator.getInstance(new ULocale("fi_FI@collation=standard"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// perform tests with strength PRIMARY
|
||||
@Test
|
||||
public void TestPrimary() {
|
||||
int i = 0;
|
||||
myCollation.setStrength(Collator.PRIMARY);
|
||||
for(i = 4; i < 5; i++) {
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform test with strength TERTIARY
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
@ -76,9 +79,9 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
myCollation.setStrength(Collator.TERTIARY);
|
||||
for(i = 0; i < 4; i++ ) {
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test routine, tests rules specific to the finish locale
|
||||
private void doTest(char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
@ -90,7 +93,7 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -103,13 +106,13 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -119,7 +122,7 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -132,7 +135,7 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -143,7 +146,7 @@ public class CollationFinnishTest extends TestFmwk {
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,23 +7,26 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationFrenchTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/frcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationFrenchTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/},
|
||||
@ -78,7 +81,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
/*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/},
|
||||
/*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/},
|
||||
/*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/},
|
||||
/*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301},
|
||||
/*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301},
|
||||
/*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301},
|
||||
/*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301},
|
||||
/*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301},
|
||||
@ -112,29 +115,29 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
{0x0065/*'e'*/, 0x0061/*'a'*/},
|
||||
{0x0078/*'x'*/}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationFrenchTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception {
|
||||
myCollation = Collator.getInstance(Locale.CANADA_FRENCH);
|
||||
}
|
||||
|
||||
|
||||
// perform tests with strength TERTIARY
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
int i = 0;
|
||||
myCollation.setStrength(Collator.TERTIARY);
|
||||
|
||||
|
||||
for (i = 0; i < 12 ; i++) {
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform tests with strength SECONDARY
|
||||
@Test
|
||||
public void TestSecondary() {
|
||||
@ -144,7 +147,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
int expected;
|
||||
|
||||
myCollation.setStrength(Collator.SECONDARY);
|
||||
|
||||
|
||||
for (i = 0; i < testAcute.length; i++) {
|
||||
for (j = 0; j < testAcute.length; j++) {
|
||||
if (i < j) {
|
||||
@ -170,7 +173,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestContinuationReordering()
|
||||
{
|
||||
@ -178,7 +181,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
try {
|
||||
RuleBasedCollator collator = new RuleBasedCollator(rule);
|
||||
collator.setFrenchCollation(true);
|
||||
CollationKey key1
|
||||
CollationKey key1
|
||||
= collator.getCollationKey("a\u0325\u2f00\u2f01b\u0325");
|
||||
CollationKey key2
|
||||
= collator.getCollationKey("a\u0325\u2f01\u2f01b\u0325");
|
||||
@ -189,7 +192,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
errln(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test routine, test rules specific to the french locale
|
||||
private void doTest(char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
@ -199,9 +202,9 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
sortKey1 = myCollation.getCollationKey(s);
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -214,13 +217,13 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -230,7 +233,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -243,7 +246,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -254,7 +257,7 @@ public class CollationFrenchTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : collate/CollationMonkeyTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/mnkytst.cpp
|
||||
**/
|
||||
@ -18,6 +18,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
@ -25,16 +27,17 @@ import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
/**
|
||||
* CollationFrozenMonkeyTest is a third level test class. This tests the random
|
||||
* substrings of the default test strings to verify if the compare and
|
||||
* CollationFrozenMonkeyTest is a third level test class. This tests the random
|
||||
* substrings of the default test strings to verify if the compare and
|
||||
* sort key algorithm works correctly on frozen collators. For example, any string is always
|
||||
* less than the string itself appended with any character.
|
||||
*/
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
|
||||
|
||||
private String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCollationKey() {
|
||||
if(source.length() == 0) {
|
||||
@ -47,15 +50,15 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
try {
|
||||
Collator myCollator = Collator.getInstance(new Locale("en", "CA"));
|
||||
myCollator.freeze();
|
||||
|
||||
|
||||
myPrimaryCollator = myCollator.cloneAsThawed();
|
||||
myPrimaryCollator.setStrength(Collator.PRIMARY);
|
||||
myPrimaryCollator.freeze();
|
||||
|
||||
|
||||
mySecondaryCollator = myPrimaryCollator.cloneAsThawed();
|
||||
mySecondaryCollator.setStrength(Collator.SECONDARY);
|
||||
mySecondaryCollator.freeze();
|
||||
|
||||
|
||||
myTertiaryCollator = mySecondaryCollator.cloneAsThawed();
|
||||
myTertiaryCollator.setStrength(Collator.TERTIARY);
|
||||
myTertiaryCollator.freeze();
|
||||
@ -63,7 +66,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
warnln("ERROR: in creation of collator of ENGLISH locale");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Random rand = createRandom(); // use test framework's random seed
|
||||
int s = rand.nextInt(0x7fff) % source.length();
|
||||
int t = rand.nextInt(0x7fff) % source.length();
|
||||
@ -71,30 +74,30 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
|
||||
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
|
||||
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
|
||||
|
||||
|
||||
CollationKey collationKey1, collationKey2;
|
||||
|
||||
|
||||
collationKey1 = myTertiaryCollator.getCollationKey(subs);
|
||||
collationKey2 = myTertiaryCollator.getCollationKey(subt);
|
||||
int result = collationKey1.compareTo(collationKey2); // Tertiary
|
||||
int revResult = collationKey2.compareTo(collationKey1); // Tertiary
|
||||
report( subs, subt, result, revResult);
|
||||
|
||||
|
||||
collationKey1 = mySecondaryCollator.getCollationKey(subs);
|
||||
collationKey2 = mySecondaryCollator.getCollationKey(subt);
|
||||
result = collationKey1.compareTo(collationKey2); // Secondary
|
||||
revResult = collationKey2.compareTo(collationKey1); // Secondary
|
||||
report( subs, subt, result, revResult);
|
||||
|
||||
|
||||
collationKey1 = myPrimaryCollator.getCollationKey(subs);
|
||||
collationKey2 = myPrimaryCollator.getCollationKey(subt);
|
||||
result = collationKey1.compareTo(collationKey2); // Primary
|
||||
revResult = collationKey2.compareTo(collationKey1); // Primary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
String msg = "";
|
||||
String addOne = subs + String.valueOf(0xE000);
|
||||
|
||||
|
||||
collationKey1 = myPrimaryCollator.getCollationKey(subs);
|
||||
collationKey2 = myPrimaryCollator.getCollationKey(addOne);
|
||||
result = collationKey1.compareTo(collationKey2);
|
||||
@ -106,7 +109,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
msg += ") Failed.";
|
||||
errln(msg);
|
||||
}
|
||||
|
||||
|
||||
msg = "";
|
||||
result = collationKey2.compareTo(collationKey1);
|
||||
if (result != 1) {
|
||||
@ -118,7 +121,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform monkey tests using Collator.compare
|
||||
@Test
|
||||
public void TestCompare() {
|
||||
@ -126,22 +129,22 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
errln("CollationMonkeyTest.TestCompare(): source is empty - ICU_DATA not set or data missing?");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Collator myPrimaryCollator;
|
||||
Collator mySecondaryCollator;
|
||||
Collator myTertiaryCollator;
|
||||
try {
|
||||
Collator myCollator = Collator.getInstance(new Locale("en", "CA"));
|
||||
myCollator.freeze();
|
||||
|
||||
|
||||
myPrimaryCollator = myCollator.cloneAsThawed();
|
||||
myPrimaryCollator.setStrength(Collator.PRIMARY);
|
||||
myPrimaryCollator.freeze();
|
||||
|
||||
|
||||
mySecondaryCollator = myPrimaryCollator.cloneAsThawed();
|
||||
mySecondaryCollator.setStrength(Collator.SECONDARY);
|
||||
mySecondaryCollator.freeze();
|
||||
|
||||
|
||||
myTertiaryCollator = mySecondaryCollator.cloneAsThawed();
|
||||
myTertiaryCollator.setStrength(Collator.TERTIARY);
|
||||
myTertiaryCollator.freeze();
|
||||
@ -149,12 +152,12 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
warnln("ERROR: in creation of collator of ENGLISH locale");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Seed the random-number generator with current time so that
|
||||
* the numbers will be different every time we run.
|
||||
*/
|
||||
|
||||
|
||||
Random rand = createRandom(); // use test framework's random seed
|
||||
int s = rand.nextInt(0x7fff) % source.length();
|
||||
int t = rand.nextInt(0x7fff) % source.length();
|
||||
@ -162,22 +165,22 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
|
||||
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
|
||||
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
|
||||
|
||||
|
||||
int result = myTertiaryCollator.compare(subs, subt); // Tertiary
|
||||
int revResult = myTertiaryCollator.compare(subt, subs); // Tertiary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
result = mySecondaryCollator.compare(subs, subt); // Secondary
|
||||
revResult = mySecondaryCollator.compare(subt, subs); // Secondary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
result = myPrimaryCollator.compare(subs, subt); // Primary
|
||||
revResult = myPrimaryCollator.compare(subt, subs); // Primary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
String msg = "";
|
||||
String addOne = subs + String.valueOf(0xE000);
|
||||
|
||||
|
||||
result = myPrimaryCollator.compare(subs, addOne);
|
||||
if (result != -1) {
|
||||
msg += "Test : ";
|
||||
@ -187,7 +190,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
msg += " Failed.";
|
||||
errln(msg);
|
||||
}
|
||||
|
||||
|
||||
msg = "";
|
||||
result = myPrimaryCollator.compare(addOne, subs);
|
||||
if (result != 1) {
|
||||
@ -199,31 +202,31 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void report(String s, String t, int result, int revResult) {
|
||||
if (revResult != -result) {
|
||||
String msg = "";
|
||||
msg += s;
|
||||
msg += s;
|
||||
msg += " and ";
|
||||
msg += t;
|
||||
msg += " round trip comparison failed";
|
||||
msg += " (result " + result + ", reverse Result " + revResult + ")";
|
||||
msg += " (result " + result + ", reverse Result " + revResult + ")";
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestRules() {
|
||||
String testSourceCases[] = {
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
};
|
||||
|
||||
|
||||
String testTargetCases[] = {
|
||||
"\u0061\u0062\u00e4",
|
||||
"\u0061\u0062\u0061\u0308",
|
||||
};
|
||||
|
||||
|
||||
int i=0;
|
||||
logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
|
||||
Collator col = Collator.getInstance(new Locale("en", "US"));
|
||||
@ -237,7 +240,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
warnln( "Demo Test 1 Table Collation object creation failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(i=0; i<2; i++){
|
||||
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
|
||||
}
|
||||
@ -254,11 +257,11 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doTest(RuleBasedCollator myCollation, String mysource, String target, int result) {
|
||||
int compareResult = myCollation.compare(source, target);
|
||||
CollationKey sortKey1, sortKey2;
|
||||
|
||||
|
||||
try {
|
||||
sortKey1 = myCollation.getCollationKey(source);
|
||||
sortKey2 = myCollation.getCollationKey(target);
|
||||
@ -269,7 +272,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult( mysource, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
|
||||
}
|
||||
|
||||
|
||||
public void reportCResult(String src, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -280,7 +283,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
boolean ok2 = (keyResult == expectedResult);
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
@ -315,7 +318,7 @@ public class CollationFrozenMonkeyTest extends TestFmwk {
|
||||
logln(msg1 + src + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + src + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,23 +7,26 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationGermanTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/decoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
public class CollationGermanTest extends TestFmwk{
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationGermanTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0x47, 0x72, 0x00F6, 0x00DF, 0x65},
|
||||
{0x61, 0x62, 0x63},
|
||||
@ -70,12 +73,12 @@ import com.ibm.icu.text.Collator;
|
||||
{ -1, -1 },
|
||||
{ 0, 1 }
|
||||
};
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationGermanTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
myCollation = Collator.getInstance(Locale.GERMAN);
|
||||
@ -100,13 +103,13 @@ import com.ibm.icu.text.Collator;
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform test with strength SECONDARY
|
||||
//This method in icu4c has no implementation.
|
||||
@Test
|
||||
public void TestSecondary(){
|
||||
}
|
||||
|
||||
|
||||
// perform test with strength PRIMARY
|
||||
@Test
|
||||
public void TestPrimary(){
|
||||
@ -122,8 +125,8 @@ import com.ibm.icu.text.Collator;
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i][0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//main test routine, tests rules specific to germa locale
|
||||
private void doTest(char[] source, char[] target, int result){
|
||||
String s = new String(source);
|
||||
@ -134,9 +137,9 @@ import com.ibm.icu.text.Collator;
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ){
|
||||
if (expectedResult < -1 || expectedResult > 1)
|
||||
@ -150,13 +153,13 @@ import com.ibm.icu.text.Collator;
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()){
|
||||
return;
|
||||
return;
|
||||
}else{
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -166,7 +169,7 @@ import com.ibm.icu.text.Collator;
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -179,7 +182,7 @@ import com.ibm.icu.text.Collator;
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -190,7 +193,7 @@ import com.ibm.icu.text.Collator;
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : collate/CollationIteratorTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/itercoll.cpp
|
||||
**/
|
||||
@ -20,6 +20,8 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
@ -29,11 +31,12 @@ import com.ibm.icu.text.RuleBasedCollator;
|
||||
import com.ibm.icu.text.UCharacterIterator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationIteratorTest extends TestFmwk {
|
||||
|
||||
|
||||
String test1 = "What subset of all possible test cases?";
|
||||
String test2 = "has the highest probability of detecting";
|
||||
|
||||
|
||||
/*
|
||||
* @bug 4157299
|
||||
*/
|
||||
@ -46,7 +49,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
warnln("Couldn't create a RuleBasedCollator.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String source = "abcd";
|
||||
CollationElementIterator i = c.getCollationElementIterator(source);
|
||||
int e0 = 0;
|
||||
@ -56,27 +59,27 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("call to i.next() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
i.setOffset(3); // go to the expanding character
|
||||
} catch (Exception e) {
|
||||
errln("call to i.setOffset(3) failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
i.next(); // but only use up half of it
|
||||
} catch (Exception e) {
|
||||
errln("call to i.next() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
i.setOffset(0); // go back to the beginning
|
||||
} catch (Exception e) {
|
||||
errln("call to i.setOffset(0) failed. ");
|
||||
}
|
||||
|
||||
|
||||
int e = 0;
|
||||
try {
|
||||
e = i.next(); // and get this one again
|
||||
@ -84,12 +87,12 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("call to i.next() failed. ");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (e != e0) {
|
||||
errln("got 0x" + Integer.toHexString(e) + ", expected 0x" + Integer.toHexString(e0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @bug 4108762
|
||||
* Test for getMaxExpansion()
|
||||
*/
|
||||
@ -106,37 +109,37 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
char ch = 0;
|
||||
String str = String.valueOf(ch);
|
||||
|
||||
|
||||
CollationElementIterator iter = coll.getCollationElementIterator(str);
|
||||
|
||||
|
||||
while (ch < 0xFFFF) {
|
||||
int count = 1;
|
||||
ch ++;
|
||||
str = String.valueOf(ch);
|
||||
iter.setText(str);
|
||||
int order = iter.previous();
|
||||
|
||||
// thai management
|
||||
|
||||
// thai management
|
||||
if (order == 0) {
|
||||
order = iter.previous();
|
||||
}
|
||||
|
||||
|
||||
while (iter.previous() != CollationElementIterator.NULLORDER) {
|
||||
count ++;
|
||||
count ++;
|
||||
}
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(order) < count) {
|
||||
errln("Failure at codepoint " + ch + ", maximum expansion count < " + count);
|
||||
}
|
||||
}
|
||||
|
||||
// testing for exact max expansion
|
||||
|
||||
// testing for exact max expansion
|
||||
ch = 0;
|
||||
while (ch < 0x61) {
|
||||
str = String.valueOf(ch);
|
||||
iter.setText(str);
|
||||
int order = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(order) != 1) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count == 1");
|
||||
@ -148,7 +151,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
str = String.valueOf(ch);
|
||||
iter.setText(str);
|
||||
int temporder = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(temporder) != 3) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count == 3");
|
||||
@ -158,7 +161,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
str = String.valueOf(ch);
|
||||
iter.setText(str);
|
||||
temporder = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(temporder) != 1) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count == 1");
|
||||
@ -167,7 +170,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
str = UCharacter.toString(unassigned);
|
||||
iter.setText(str);
|
||||
temporder = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(temporder) != 2) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count == 2");
|
||||
@ -179,7 +182,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
str = String.valueOf(ch);
|
||||
iter.setText(str);
|
||||
temporder = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(temporder) > 3) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count < 3");
|
||||
@ -195,15 +198,15 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
iter = coll.getCollationElementIterator(str);
|
||||
|
||||
|
||||
temporder = iter.previous();
|
||||
|
||||
|
||||
if (iter.getMaxExpansion(temporder) != 6) {
|
||||
errln("Failure at codepoint 0x" + Integer.toHexString(ch)
|
||||
+ " maximum expansion count == 6");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for getOffset() and setOffset()
|
||||
*/
|
||||
@ -211,7 +214,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
public void TestOffset(/* char* par */) {
|
||||
RuleBasedCollator en_us;
|
||||
try {
|
||||
en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
|
||||
en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
|
||||
} catch (Exception e) {
|
||||
warnln("ERROR: in creation of collator of ENGLISH locale");
|
||||
return;
|
||||
@ -226,32 +229,32 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
iter.setOffset(test1.length());
|
||||
if (iter.next() != CollationElementIterator.NULLORDER) {
|
||||
errln("Error: After setting offset to the end of the string, we "
|
||||
errln("Error: After setting offset to the end of the string, we "
|
||||
+ "should be at the end of the forwards iteration");
|
||||
}
|
||||
|
||||
|
||||
// Run all the way through the iterator, then get the offset
|
||||
int[] orders = CollationTest.getOrders(iter);
|
||||
logln("orders.length = " + orders.length);
|
||||
|
||||
|
||||
int offset = iter.getOffset();
|
||||
|
||||
|
||||
if (offset != test1.length()) {
|
||||
String msg1 = "offset at end != length: ";
|
||||
String msg2 = " vs ";
|
||||
errln(msg1 + offset + msg2 + test1.length());
|
||||
}
|
||||
|
||||
|
||||
// Now set the offset back to the beginning and see if it works
|
||||
CollationElementIterator pristine = en_us.getCollationElementIterator(test1);
|
||||
|
||||
|
||||
try {
|
||||
iter.setOffset(0);
|
||||
} catch(Exception e) {
|
||||
errln("setOffset failed.");
|
||||
}
|
||||
assertEqual(iter, pristine);
|
||||
|
||||
|
||||
// setting offset in the middle of a contraction
|
||||
String contraction = "change";
|
||||
RuleBasedCollator tailored = null;
|
||||
@ -297,8 +300,8 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
// TODO: try iterating halfway through a messy string.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void assertEqual(CollationElementIterator i1, CollationElementIterator i2) {
|
||||
int c1, c2, count = 0;
|
||||
@ -306,7 +309,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
c1 = i1.next();
|
||||
c2 = i2.next();
|
||||
if (c1 != c2) {
|
||||
errln(" " + count + ": strength(0x" +
|
||||
errln(" " + count + ": strength(0x" +
|
||||
Integer.toHexString(c1) + ") != strength(0x" + Integer.toHexString(c2) + ")");
|
||||
break;
|
||||
}
|
||||
@ -315,21 +318,21 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
CollationTest.backAndForth(this, i1);
|
||||
CollationTest.backAndForth(this, i2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for CollationElementIterator.previous()
|
||||
*
|
||||
* @bug 4108758 - Make sure it works with contracting characters
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void TestPrevious(/* char* par */) {
|
||||
RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
|
||||
CollationElementIterator iter = en_us.getCollationElementIterator(test1);
|
||||
|
||||
|
||||
// A basic test to see if it's working at all
|
||||
CollationTest.backAndForth(this, iter);
|
||||
|
||||
|
||||
// Test with a contracting character sequence
|
||||
String source;
|
||||
RuleBasedCollator c1 = null;
|
||||
@ -339,11 +342,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("Couldn't create a RuleBasedCollator with a contracting sequence.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
source = "abchdcba";
|
||||
iter = c1.getCollationElementIterator(source);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
|
||||
|
||||
// Test with an expanding character sequence
|
||||
RuleBasedCollator c2 = null;
|
||||
try {
|
||||
@ -352,11 +355,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("Couldn't create a RuleBasedCollator with an expanding sequence.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
source = "abcd";
|
||||
iter = c2.getCollationElementIterator(source);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
|
||||
|
||||
// Now try both
|
||||
RuleBasedCollator c3 = null;
|
||||
try {
|
||||
@ -365,11 +368,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("Couldn't create a RuleBasedCollator with both an expanding and a contracting sequence.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
source = "abcdbchdc";
|
||||
iter = c3.getCollationElementIterator(source);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
|
||||
|
||||
source= "\u0e41\u0e02\u0e41\u0e02\u0e27abc";
|
||||
Collator c4 = null;
|
||||
try {
|
||||
@ -378,10 +381,10 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
errln("Couldn't create a collator");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
iter = ((RuleBasedCollator)c4).getCollationElementIterator(source);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
|
||||
|
||||
source= "\u0061\u30CF\u3099\u30FC";
|
||||
Collator c5 = null;
|
||||
try {
|
||||
@ -391,12 +394,12 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
iter = ((RuleBasedCollator)c5).getCollationElementIterator(source);
|
||||
|
||||
|
||||
CollationTest.backAndForth(this, iter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test for setText()
|
||||
*/
|
||||
@ -405,11 +408,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
|
||||
CollationElementIterator iter1 = en_us.getCollationElementIterator(test1);
|
||||
CollationElementIterator iter2 = en_us.getCollationElementIterator(test2);
|
||||
|
||||
|
||||
// Run through the second iterator just to exercise it
|
||||
int c = iter2.next();
|
||||
int i = 0;
|
||||
|
||||
|
||||
while ( ++i < 10 && c != CollationElementIterator.NULLORDER) {
|
||||
try {
|
||||
c = iter2.next();
|
||||
@ -418,7 +421,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now set it to point to the same string as the first iterator
|
||||
try {
|
||||
iter2.setText(test1);
|
||||
@ -427,7 +430,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
assertEqual(iter1, iter2);
|
||||
|
||||
|
||||
iter1.reset();
|
||||
//now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
|
||||
CharacterIterator chariter = new StringCharacterIterator(test1);
|
||||
@ -438,7 +441,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
assertEqual(iter1, iter2);
|
||||
|
||||
|
||||
iter1.reset();
|
||||
//now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
|
||||
UCharacterIterator uchariter = UCharacterIterator.getInstance(test1);
|
||||
@ -464,7 +467,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
source.append("\u0e4d\u0e4e\u0e4f");
|
||||
// source.append("\u04e8\u04e9");
|
||||
iter = en_us.getCollationElementIterator(source.toString());
|
||||
// A basic test to see if it's working at all
|
||||
// A basic test to see if it's working at all
|
||||
CollationTest.backAndForth(this, iter);
|
||||
for (codepoint = 1; codepoint < 0xFFFE;) {
|
||||
source.delete(0, source.length());
|
||||
@ -474,11 +477,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
codepoint ++;
|
||||
}
|
||||
|
||||
|
||||
if (UCharacter.isDefined(codepoint)) {
|
||||
source.append(codepoint);
|
||||
}
|
||||
|
||||
|
||||
if (codepoint != 0xFFFF) {
|
||||
codepoint ++;
|
||||
}
|
||||
@ -486,18 +489,18 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
System.out.println("codepoint " + Integer.toHexString(codepoint));
|
||||
String str = source.substring(230, 232);
|
||||
System.out.println(com.ibm.icu.impl.Utility.escape(str));
|
||||
System.out.println("codepoint " + Integer.toHexString(codepoint)
|
||||
System.out.println("codepoint " + Integer.toHexString(codepoint)
|
||||
+ "length " + str.length());
|
||||
iter = en_us.getCollationElementIterator(str);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
}
|
||||
*/
|
||||
iter = en_us.getCollationElementIterator(source.toString());
|
||||
// A basic test to see if it's working at all
|
||||
// A basic test to see if it's working at all
|
||||
CollationTest.backAndForth(this, iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for CollationElementIterator previous and next for the whole set of
|
||||
* unicode characters with normalization on.
|
||||
@ -516,7 +519,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
StringBuffer source = new StringBuffer();
|
||||
source.append('\uFDFA');
|
||||
CollationElementIterator iter
|
||||
CollationElementIterator iter
|
||||
= th_th.getCollationElementIterator(source.toString());
|
||||
CollationTest.backAndForth(this, iter);
|
||||
for (char codepoint = 0x1; codepoint < 0xfffe;) {
|
||||
@ -527,35 +530,35 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
}
|
||||
codepoint ++;
|
||||
}
|
||||
|
||||
|
||||
if (UCharacter.isDefined(codepoint)) {
|
||||
source.append(codepoint);
|
||||
}
|
||||
|
||||
|
||||
if (codepoint != 0xFFFF) {
|
||||
codepoint ++;
|
||||
}
|
||||
|
||||
|
||||
/*if (((int)codepoint) >= 0xfe00) {
|
||||
String str = source.substring(185, 190);
|
||||
System.out.println(com.ibm.icu.impl.Utility.escape(str));
|
||||
System.out.println("codepoint "
|
||||
+ Integer.toHexString(codepoint)
|
||||
System.out.println("codepoint "
|
||||
+ Integer.toHexString(codepoint)
|
||||
+ "length " + str.length());
|
||||
iter = th_th.getCollationElementIterator(str);
|
||||
CollationTest.backAndForth(this, iter);
|
||||
*/
|
||||
iter = th_th.getCollationElementIterator(source.toString());
|
||||
// A basic test to see if it's working at all
|
||||
// A basic test to see if it's working at all
|
||||
CollationTest.backAndForth(this, iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Testing the discontiguous contractions
|
||||
*/
|
||||
@Test
|
||||
public void TestDiscontiguous()
|
||||
public void TestDiscontiguous()
|
||||
{
|
||||
String rulestr ="&z < AB < X\u0300 < ABC < X\u0300\u0315";
|
||||
String src[] = {"ADB", "ADBC", "A\u0315B", "A\u0315BC",
|
||||
@ -566,11 +569,11 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
// blocking combining character
|
||||
"X\u0314\u0300", "X\u0314\u0300\u0315",
|
||||
// contraction prefix
|
||||
"ABDC", "AB\u0315C","X\u0300D\u0315",
|
||||
"ABDC", "AB\u0315C","X\u0300D\u0315",
|
||||
"X\u0300\u0319\u0315", "X\u0300\u031A\u0315",
|
||||
// ends not with a contraction character
|
||||
"X\u0319\u0300D", "X\u0319\u0300\u0315D",
|
||||
"X\u0300D\u0315D", "X\u0300\u0319\u0315D",
|
||||
"X\u0319\u0300D", "X\u0319\u0300\u0315D",
|
||||
"X\u0300D\u0315D", "X\u0300\u0319\u0315D",
|
||||
"X\u0300\u031A\u0315D"
|
||||
};
|
||||
String tgt[] = {// non blocking combining character
|
||||
@ -582,20 +585,20 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
// blocking combining character
|
||||
"X \u0314 \u0300", "X \u0314 \u0300\u0315",
|
||||
// contraction prefix
|
||||
"AB DC", "AB \u0315 C","X\u0300 D \u0315",
|
||||
"AB DC", "AB \u0315 C","X\u0300 D \u0315",
|
||||
"X\u0300\u0315 \u0319", "X\u0300 \u031A \u0315",
|
||||
// ends not with a contraction character
|
||||
"X\u0300 \u0319D", "X\u0300\u0315 \u0319D",
|
||||
"X\u0300 D\u0315D", "X\u0300\u0315 \u0319D",
|
||||
"X\u0300 \u0319D", "X\u0300\u0315 \u0319D",
|
||||
"X\u0300 D\u0315D", "X\u0300\u0315 \u0319D",
|
||||
"X\u0300 \u031A\u0315D"
|
||||
};
|
||||
int count = 0;
|
||||
try {
|
||||
RuleBasedCollator coll = new RuleBasedCollator(rulestr);
|
||||
CollationElementIterator iter
|
||||
CollationElementIterator iter
|
||||
= coll.getCollationElementIterator("");
|
||||
CollationElementIterator resultiter
|
||||
= coll.getCollationElementIterator("");
|
||||
CollationElementIterator resultiter
|
||||
= coll.getCollationElementIterator("");
|
||||
while (count < src.length) {
|
||||
iter.setText(src[count]);
|
||||
int s = 0;
|
||||
@ -609,7 +612,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
int ce = resultiter.next();
|
||||
while (ce != CollationElementIterator.NULLORDER) {
|
||||
if (ce != iter.next()) {
|
||||
errln("Discontiguos contraction test mismatch at"
|
||||
errln("Discontiguos contraction test mismatch at"
|
||||
+ count);
|
||||
return;
|
||||
}
|
||||
@ -649,7 +652,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
warnln("ERROR: in creation of collator using rules " + rules);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CollationElementIterator iter = coll.getCollationElementIterator("testing");
|
||||
for (int count = 0; count < testdata.length; count ++) {
|
||||
iter.setText(testdata[count]);
|
||||
@ -683,7 +686,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
" \u00E6" + // small letter ae, expands
|
||||
" \u1E4D" + // small letter o with tilde and acute, decomposes
|
||||
" ";
|
||||
|
||||
|
||||
int[] rootStandardOffsets = {
|
||||
0, 1,2,
|
||||
2, 3,4,4,
|
||||
@ -698,7 +701,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
28,
|
||||
29
|
||||
};
|
||||
|
||||
|
||||
int[] rootSearchOffsets = {
|
||||
0, 1,2,
|
||||
2, 3,4,4,
|
||||
@ -724,7 +727,7 @@ public class CollationIteratorTest extends TestFmwk {
|
||||
public String getLocaleString() { return localeString; }
|
||||
public int[] getOffsets() { return offsets; }
|
||||
}
|
||||
final TSCEItem[] tsceItems = {
|
||||
final TSCEItem[] tsceItems = {
|
||||
new TSCEItem( "root", rootStandardOffsets ),
|
||||
new TSCEItem( "root@collation=search", rootSearchOffsets ),
|
||||
};
|
||||
|
@ -7,24 +7,27 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationKanaTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/jacoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationKanaTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0xff9E},
|
||||
@ -91,16 +94,16 @@ public class CollationKanaTest extends TestFmwk{
|
||||
/*4*/ {0x30AD, 0x30A4, 0x3042},
|
||||
/*5*/ {0x30AD, 0x30A4, 0x30A2}
|
||||
};
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationKanaTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception {
|
||||
public void init()throws Exception {
|
||||
if(myCollation==null){
|
||||
myCollation = Collator.getInstance(Locale.JAPANESE);
|
||||
myCollation = Collator.getInstance(Locale.JAPANESE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +112,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
public void TestTertiary() {
|
||||
int i = 0;
|
||||
myCollation.setStrength(Collator.TERTIARY);
|
||||
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
@ -135,7 +138,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Test Small, Large letters
|
||||
*/
|
||||
@Test
|
||||
@ -171,7 +174,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
doTest(testChooonKigooCases[i], testChooonKigooCases[i + 1], -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test common Hiragana and Katakana characters (e.g. 0x3099) (ticket:6140)
|
||||
*/
|
||||
@ -186,20 +189,20 @@ public class CollationKanaTest extends TestFmwk{
|
||||
RuleBasedCollator rb = (RuleBasedCollator)Collator.getInstance(ULocale.JAPANESE);
|
||||
rb.setStrength(Collator.QUATERNARY);
|
||||
rb.setAlternateHandlingShifted(false);
|
||||
|
||||
|
||||
result = rb.compare(string1, string2);
|
||||
|
||||
|
||||
key1 = rb.getCollationKey(string1);
|
||||
key2 = rb.getCollationKey(string2);
|
||||
|
||||
|
||||
if ( result != 0 || !key1.equals(key2)) {
|
||||
errln("Failed Hiragana and Katakana common characters test. Expected results to be equal.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// main test routine, tests rules specific to "Kana" locale
|
||||
private void doTest(char[] source, char[] target, int result){
|
||||
|
||||
|
||||
String s = new String(source);
|
||||
String t = new String(target);
|
||||
int compareResult = myCollation.compare(s, t);
|
||||
@ -208,9 +211,9 @@ public class CollationKanaTest extends TestFmwk{
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ){
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -223,13 +226,13 @@ public class CollationKanaTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()){
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -239,7 +242,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -252,7 +255,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -263,7 +266,7 @@ public class CollationKanaTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
@ -40,6 +42,7 @@ import com.ibm.icu.text.UnicodeSetIterator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationMiscTest extends TestFmwk {
|
||||
//private static final int NORM_BUFFER_TEST_LEN_ = 32;
|
||||
private static final class Tester
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : collate/CollationMonkeyTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/mnkytst.cpp
|
||||
**/
|
||||
@ -18,6 +18,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
@ -25,16 +27,17 @@ import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
/**
|
||||
* CollationMonkeyTest is a third level test class. This tests the random
|
||||
* substrings of the default test strings to verify if the compare and
|
||||
* CollationMonkeyTest is a third level test class. This tests the random
|
||||
* substrings of the default test strings to verify if the compare and
|
||||
* sort key algorithm works correctly. For example, any string is always
|
||||
* less than the string itself appended with any character.
|
||||
*/
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationMonkeyTest extends TestFmwk {
|
||||
|
||||
|
||||
private String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCollationKey() {
|
||||
if(source.length() == 0) {
|
||||
@ -48,7 +51,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
warnln("ERROR: in creation of collator of ENGLISH locale");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Random rand = createRandom(); // use test framework's random seed
|
||||
int s = rand.nextInt(0x7fff) % source.length();
|
||||
int t = rand.nextInt(0x7fff) % source.length();
|
||||
@ -56,33 +59,33 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
|
||||
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
|
||||
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
|
||||
|
||||
|
||||
CollationKey collationKey1, collationKey2;
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.TERTIARY);
|
||||
collationKey1 = myCollator.getCollationKey(subs);
|
||||
collationKey2 = myCollator.getCollationKey(subt);
|
||||
int result = collationKey1.compareTo(collationKey2); // Tertiary
|
||||
int revResult = collationKey2.compareTo(collationKey1); // Tertiary
|
||||
report( subs, subt, result, revResult);
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.SECONDARY);
|
||||
collationKey1 = myCollator.getCollationKey(subs);
|
||||
collationKey2 = myCollator.getCollationKey(subt);
|
||||
result = collationKey1.compareTo(collationKey2); // Secondary
|
||||
revResult = collationKey2.compareTo(collationKey1); // Secondary
|
||||
report( subs, subt, result, revResult);
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.PRIMARY);
|
||||
collationKey1 = myCollator.getCollationKey(subs);
|
||||
collationKey2 = myCollator.getCollationKey(subt);
|
||||
result = collationKey1.compareTo(collationKey2); // Primary
|
||||
revResult = collationKey2.compareTo(collationKey1); // Primary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
String msg = "";
|
||||
String addOne = subs + String.valueOf(0xE000);
|
||||
|
||||
|
||||
collationKey1 = myCollator.getCollationKey(subs);
|
||||
collationKey2 = myCollator.getCollationKey(addOne);
|
||||
result = collationKey1.compareTo(collationKey2);
|
||||
@ -94,7 +97,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
msg += ") Failed.";
|
||||
errln(msg);
|
||||
}
|
||||
|
||||
|
||||
msg = "";
|
||||
result = collationKey2.compareTo(collationKey1);
|
||||
if (result != 1) {
|
||||
@ -106,7 +109,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform monkey tests using Collator.compare
|
||||
@Test
|
||||
public void TestCompare() {
|
||||
@ -114,7 +117,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
errln("CollationMonkeyTest.TestCompare(): source is empty - ICU_DATA not set or data missing?");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Collator myCollator;
|
||||
try {
|
||||
myCollator = Collator.getInstance(new Locale("en", "US"));
|
||||
@ -122,11 +125,11 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
warnln("ERROR: in creation of collator of ENGLISH locale");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Seed the random-number generator with current time so that
|
||||
* the numbers will be different every time we run.
|
||||
*/
|
||||
|
||||
|
||||
Random rand = createRandom(); // use test framework's random seed
|
||||
int s = rand.nextInt(0x7fff) % source.length();
|
||||
int t = rand.nextInt(0x7fff) % source.length();
|
||||
@ -134,25 +137,25 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
|
||||
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
|
||||
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.TERTIARY);
|
||||
int result = myCollator.compare(subs, subt); // Tertiary
|
||||
int revResult = myCollator.compare(subt, subs); // Tertiary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.SECONDARY);
|
||||
result = myCollator.compare(subs, subt); // Secondary
|
||||
revResult = myCollator.compare(subt, subs); // Secondary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
myCollator.setStrength(Collator.PRIMARY);
|
||||
result = myCollator.compare(subs, subt); // Primary
|
||||
revResult = myCollator.compare(subt, subs); // Primary
|
||||
report(subs, subt, result, revResult);
|
||||
|
||||
|
||||
String msg = "";
|
||||
String addOne = subs + String.valueOf(0xE000);
|
||||
|
||||
|
||||
result = myCollator.compare(subs, addOne);
|
||||
if (result != -1) {
|
||||
msg += "Test : ";
|
||||
@ -162,7 +165,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
msg += " Failed.";
|
||||
errln(msg);
|
||||
}
|
||||
|
||||
|
||||
msg = "";
|
||||
result = myCollator.compare(addOne, subs);
|
||||
if (result != 1) {
|
||||
@ -174,31 +177,31 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void report(String s, String t, int result, int revResult) {
|
||||
if (revResult != -result) {
|
||||
String msg = "";
|
||||
msg += s;
|
||||
msg += s;
|
||||
msg += " and ";
|
||||
msg += t;
|
||||
msg += " round trip comparison failed";
|
||||
msg += " (result " + result + ", reverse Result " + revResult + ")";
|
||||
msg += " (result " + result + ", reverse Result " + revResult + ")";
|
||||
errln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestRules() {
|
||||
String testSourceCases[] = {
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
"\u0061\u0062\u007a",
|
||||
};
|
||||
|
||||
|
||||
String testTargetCases[] = {
|
||||
"\u0061\u0062\u00e4",
|
||||
"\u0061\u0062\u0061\u0308",
|
||||
};
|
||||
|
||||
|
||||
int i=0;
|
||||
logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
|
||||
Collator col = Collator.getInstance(new Locale("en", "US"));
|
||||
@ -212,7 +215,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
warnln( "Demo Test 1 Table Collation object creation failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(i=0; i<2; i++){
|
||||
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
|
||||
}
|
||||
@ -229,11 +232,11 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doTest(RuleBasedCollator myCollation, String mysource, String target, int result) {
|
||||
int compareResult = myCollation.compare(source, target);
|
||||
CollationKey sortKey1, sortKey2;
|
||||
|
||||
|
||||
try {
|
||||
sortKey1 = myCollation.getCollationKey(source);
|
||||
sortKey2 = myCollation.getCollationKey(target);
|
||||
@ -244,7 +247,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult( mysource, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
|
||||
}
|
||||
|
||||
|
||||
public void reportCResult(String src, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -255,7 +258,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
boolean ok2 = (keyResult == expectedResult);
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
@ -290,7 +293,7 @@ public class CollationMonkeyTest extends TestFmwk {
|
||||
logln(msg1 + src + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + src + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : collate/CollationRegressionTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/regcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
import java.text.ParseException;
|
||||
@ -20,6 +20,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationElementIterator;
|
||||
@ -27,6 +29,7 @@ import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationRegressionTest extends TestFmwk {
|
||||
// @bug 4048446
|
||||
//
|
||||
@ -39,31 +42,31 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
RuleBasedCollator en_us = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
CollationElementIterator i1 = en_us.getCollationElementIterator(test1);
|
||||
CollationElementIterator i2 = en_us.getCollationElementIterator(test1);
|
||||
|
||||
|
||||
if (i1 == null || i2 == null) {
|
||||
errln("Could not create CollationElementIterator's");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while (i1.next() != CollationElementIterator.NULLORDER) {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
i1.reset();
|
||||
assertEqual(i1, i2);
|
||||
}
|
||||
|
||||
|
||||
void assertEqual(CollationElementIterator i1, CollationElementIterator i2) {
|
||||
int c1, c2, count = 0;
|
||||
|
||||
|
||||
do {
|
||||
c1 = i1.next();
|
||||
c2 = i2.next();
|
||||
|
||||
|
||||
if (c1 != c2) {
|
||||
String msg = "";
|
||||
String msg1 = " ";
|
||||
|
||||
|
||||
msg += msg1 + count;
|
||||
msg += ": strength(0x" + Integer.toHexString(c1);
|
||||
msg += ") != strength(0x" + Integer.toHexString(c2);
|
||||
@ -74,7 +77,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
count += 1;
|
||||
} while (c1 != CollationElementIterator.NULLORDER);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4051866
|
||||
//
|
||||
// Collator -> rules -> Collator round-trip broken for expanding characters
|
||||
@ -85,14 +88,14 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
|
||||
// Build a collator containing expanding characters
|
||||
RuleBasedCollator c1 = null;
|
||||
|
||||
|
||||
try {
|
||||
c1 = new RuleBasedCollator(rules);
|
||||
} catch (Exception e) {
|
||||
errln("Fail to create RuleBasedCollator with rules:" + rules);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Build another using the rules from the first
|
||||
RuleBasedCollator c2 = null;
|
||||
try {
|
||||
@ -101,14 +104,14 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Fail to create RuleBasedCollator with rules:" + rules);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Make sure they're the same
|
||||
if (!(c1.getRules().equals(c2.getRules())))
|
||||
{
|
||||
errln("Rules are not equal");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4053636
|
||||
//
|
||||
// Collator thinks "black-bird" == "black"
|
||||
@ -120,7 +123,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("black-bird == black");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4054238
|
||||
//
|
||||
// CollationElementIterator will not work correctly if the associated
|
||||
@ -131,45 +134,45 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
final char[] chars3 = {0x61, 0x00FC, 0x62, 0x65, 0x63, 0x6b, 0x20, 0x47, 0x72, 0x00F6, 0x00DF, 0x65, 0x20, 0x4c, 0x00FC, 0x62, 0x63, 0x6b, 0};
|
||||
final String test3 = new String(chars3);
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
|
||||
|
||||
// NOTE: The Java code uses en_us to create the CollationElementIterators
|
||||
// but I'm pretty sure that's wrong, so I've changed this to use c.
|
||||
c.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
CollationElementIterator i1 = c.getCollationElementIterator(test3);
|
||||
logln("Offset:" + i1.getOffset());
|
||||
}
|
||||
|
||||
|
||||
// @bug 4054734
|
||||
//
|
||||
// Collator::IDENTICAL documented but not implemented
|
||||
//
|
||||
@Test
|
||||
public void Test4054734(/* char* par */) {
|
||||
|
||||
|
||||
//Here's the original Java:
|
||||
|
||||
|
||||
String[] decomp = {
|
||||
"\u0001", "<", "\u0002",
|
||||
"\u0001", "=", "\u0001",
|
||||
"A\u0001", ">", "~\u0002", // Ensure A and ~ are not compared bitwise
|
||||
"\u00C0", "=", "A\u0300", // Decomp should make these equal
|
||||
};
|
||||
|
||||
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c.setStrength(Collator.IDENTICAL);
|
||||
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
|
||||
compareArray(c, decomp);
|
||||
}
|
||||
|
||||
|
||||
void compareArray(Collator c, String[] tests) {
|
||||
|
||||
|
||||
int expectedResult = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < tests.length; i += 3) {
|
||||
String source = tests[i];
|
||||
String comparison = tests[i + 1];
|
||||
String target = tests[i + 2];
|
||||
|
||||
|
||||
if (comparison.equals("<")) {
|
||||
expectedResult = -1;
|
||||
} else if (comparison.equals(">")) {
|
||||
@ -179,9 +182,9 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
} else {
|
||||
errln("Bogus comparison string \"" + comparison + "\"");
|
||||
}
|
||||
|
||||
|
||||
int compareResult = 0;
|
||||
|
||||
|
||||
logln("i = " + i);
|
||||
logln(source);
|
||||
logln(target);
|
||||
@ -190,7 +193,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
} catch (Exception e) {
|
||||
errln(e.toString());
|
||||
}
|
||||
|
||||
|
||||
CollationKey sourceKey = null, targetKey = null;
|
||||
try {
|
||||
sourceKey = c.getCollationKey(source);
|
||||
@ -198,19 +201,19 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Couldn't get collationKey for source");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
targetKey = c.getCollationKey(target);
|
||||
} catch (Exception e) {
|
||||
errln("Couldn't get collationKey for target");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int keyResult = sourceKey.compareTo(targetKey);
|
||||
reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ){
|
||||
if (expectedResult < -1 || expectedResult > 1)
|
||||
@ -224,13 +227,13 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()){
|
||||
return;
|
||||
return;
|
||||
}else{
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -240,7 +243,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -253,7 +256,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -264,7 +267,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,45 +278,45 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
@Test
|
||||
public void Test4054736(/* char* par */) {
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
|
||||
|
||||
c.setStrength(Collator.SECONDARY);
|
||||
c.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
|
||||
|
||||
final String[] tests = { "\uFB4F", "\u003d", "\u05D0\u05DC" }; // Alef-Lamed vs. Alef, Lamed
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4058613
|
||||
//
|
||||
// Collator::createInstance() causes an ArrayIndexOutofBoundsException for Korean
|
||||
// Collator::createInstance() causes an ArrayIndexOutofBoundsException for Korean
|
||||
//
|
||||
@Test
|
||||
public void Test4058613(/* char* par */) {
|
||||
// Creating a default collator doesn't work when Korean is the default
|
||||
// locale
|
||||
|
||||
|
||||
Locale oldDefault = Locale.getDefault();
|
||||
Locale.setDefault(new Locale("ko", ""));
|
||||
|
||||
|
||||
Collator c = null;
|
||||
|
||||
|
||||
c = Collator.getInstance(new Locale("en", "US"));
|
||||
|
||||
|
||||
if (c == null) {
|
||||
errln("Could not create a Korean collator");
|
||||
Locale.setDefault(oldDefault);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Since the fix to this bug was to turn off decomposition for Korean collators,
|
||||
// ensure that's what we got
|
||||
if (c.getDecomposition() != Collator.NO_DECOMPOSITION) {
|
||||
errln("Decomposition is not set to NO_DECOMPOSITION for Korean collator");
|
||||
}
|
||||
|
||||
|
||||
Locale.setDefault(oldDefault);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4059820
|
||||
//
|
||||
// RuleBasedCollator.getRules does not return the exact pattern as input
|
||||
@ -329,13 +332,13 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Failure building a collator.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( c.getRules().indexOf("c/a") == -1)
|
||||
{
|
||||
errln("returned rules do not contain 'c/a'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4060154
|
||||
//
|
||||
// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"
|
||||
@ -343,7 +346,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
@Test
|
||||
public void Test4060154(/* char* par */) {
|
||||
String rules ="&f < g, G < h, H < i, I < j, J & H < \u0131, \u0130, i, I";
|
||||
|
||||
|
||||
RuleBasedCollator c = null;
|
||||
try {
|
||||
c = new RuleBasedCollator(rules);
|
||||
@ -352,9 +355,9 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("failure building collator:" + e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
c.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
|
||||
|
||||
String[] tertiary = {
|
||||
"A", "<", "B",
|
||||
"H", "<", "\u0131",
|
||||
@ -363,19 +366,19 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
"\u0130", "<", "i",
|
||||
"\u0130", ">", "H",
|
||||
};
|
||||
|
||||
|
||||
c.setStrength(Collator.TERTIARY);
|
||||
compareArray(c, tertiary);
|
||||
|
||||
|
||||
String[] secondary = {
|
||||
"H", "<", "I",
|
||||
"\u0131", "=", "\u0130",
|
||||
};
|
||||
|
||||
|
||||
c.setStrength(Collator.PRIMARY);
|
||||
compareArray(c, secondary);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4062418
|
||||
//
|
||||
// Secondary/Tertiary comparison incorrect in French Secondary
|
||||
@ -390,14 +393,14 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
c.setStrength(Collator.SECONDARY);
|
||||
|
||||
|
||||
String[] tests = {
|
||||
"p\u00eache", "<", "p\u00e9ch\u00e9", // Comparing accents from end, p\u00e9ch\u00e9 is greater
|
||||
};
|
||||
|
||||
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4065540
|
||||
//
|
||||
// Collator::compare() method broken if either string contains spaces
|
||||
@ -409,7 +412,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("'abcd e' == 'abcd f'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4066189
|
||||
//
|
||||
// Unicode characters need to be recursively decomposed to get the
|
||||
@ -420,21 +423,21 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
public void Test4066189(/* char* par */) {
|
||||
final String test1 = "\u1EB1";
|
||||
final String test2 = "\u0061\u0306\u0300";
|
||||
|
||||
|
||||
// NOTE: The java code used en_us to create the
|
||||
// CollationElementIterator's. I'm pretty sure that
|
||||
// was wrong, so I've change the code to use c1 and c2
|
||||
RuleBasedCollator c1 = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
|
||||
CollationElementIterator i1 = c1.getCollationElementIterator(test1);
|
||||
|
||||
|
||||
RuleBasedCollator c2 = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c2.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
CollationElementIterator i2 = c2.getCollationElementIterator(test2);
|
||||
|
||||
|
||||
assertEqual(i1, i2);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4066696
|
||||
//
|
||||
// French secondary collation checking at the end of compare iteration fails
|
||||
@ -449,13 +452,13 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
c.setStrength(Collator.SECONDARY);
|
||||
|
||||
|
||||
String[] tests = {
|
||||
"\u00e0", ">", "\u01fa", // a-grave < A-ring-acute
|
||||
};
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4076676
|
||||
//
|
||||
// Bad canonicalization of same-class combining characters
|
||||
@ -466,10 +469,10 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
// be reordered, and they should compare as unequal.
|
||||
final String s1 = "\u0041\u0301\u0302\u0300";
|
||||
final String s2 = "\u0041\u0302\u0300\u0301";
|
||||
|
||||
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c.setStrength(Collator.TERTIARY);
|
||||
|
||||
|
||||
if (c.compare(s1,s2) == 0) {
|
||||
errln("Same-class combining chars were reordered");
|
||||
}
|
||||
@ -488,20 +491,20 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Failed to create RuleBasedCollator.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int result = rbc.compare("a","bb");
|
||||
|
||||
|
||||
if (result >= 0) {
|
||||
errln("Compare(a,bb) returned " + result + "; expected -1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4079231
|
||||
//
|
||||
// RuleBasedCollator::operator==(NULL) throws NullPointerException
|
||||
//
|
||||
@Test
|
||||
public void Test4079231(/* char* par */) {
|
||||
public void Test4079231(/* char* par */) {
|
||||
RuleBasedCollator en_us = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
try {
|
||||
if (en_us.equals(null)) {
|
||||
@ -511,7 +514,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("en_us.equals(null) threw " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4081866
|
||||
//
|
||||
// Combining characters in different classes not reordered properly.
|
||||
@ -522,10 +525,10 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
// so they should be reordered and the strings should compare as equal.
|
||||
String s1 = "\u0041\u0300\u0316\u0327\u0315";
|
||||
String s2 = "\u0041\u0327\u0316\u0315\u0300";
|
||||
|
||||
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c.setStrength(Collator.TERTIARY);
|
||||
|
||||
|
||||
// Now that the default collators are set to NO_DECOMPOSITION
|
||||
// (as a result of fixing bug 4114077), we must set it explicitly
|
||||
// when we're testing reordering behavior. -- lwerner, 5/5/98
|
||||
@ -534,7 +537,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Combining chars were not reordered");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4087241
|
||||
//
|
||||
// string comparison errors in Scandinavian collators
|
||||
@ -557,7 +560,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4087243
|
||||
//
|
||||
// CollationKey takes ignorable strings into account when it shouldn't
|
||||
@ -571,7 +574,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4092260
|
||||
//
|
||||
// Mu/micro conflict
|
||||
@ -594,7 +597,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4095316
|
||||
//
|
||||
@Test
|
||||
@ -616,7 +619,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4101940
|
||||
//
|
||||
@Test
|
||||
@ -636,7 +639,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("next did not return NULLORDER");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4103436
|
||||
//
|
||||
// Collator::compare not handling spaces properly
|
||||
@ -651,7 +654,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
};
|
||||
compareArray(c, tests);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4114076
|
||||
//
|
||||
// Collation not Unicode conformant with Hangul syllables
|
||||
@ -660,7 +663,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
public void Test4114076(/* char* par */) {
|
||||
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
c.setStrength(Collator.TERTIARY);
|
||||
|
||||
|
||||
//
|
||||
// With Canonical decomposition, Hangul syllables should get decomposed
|
||||
// into Jamo, but Jamo characters should not be decomposed into
|
||||
@ -669,16 +672,16 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
String test1[] = {
|
||||
"\ud4db", "\u003d", "\u1111\u1171\u11b6"
|
||||
};
|
||||
|
||||
|
||||
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
|
||||
compareArray(c, test1);
|
||||
|
||||
|
||||
// From UTR #15:
|
||||
// *In earlier versions of Unicode, jamo characters like ksf
|
||||
// had compatibility mappings to kf + sf. These mappings were
|
||||
// had compatibility mappings to kf + sf. These mappings were
|
||||
// removed in Unicode 2.1.9 to ensure that Hangul syllables are maintained.)
|
||||
// That is, the following test is obsolete as of 2.1.9
|
||||
|
||||
|
||||
//obsolete- // With Full decomposition, it should go all the way down to
|
||||
//obsolete- // conjoining Jamo characters.
|
||||
//obsolete- //
|
||||
@ -693,7 +696,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
|
||||
// @bug 4114077
|
||||
//
|
||||
// Collation with decomposition off doesn't work for Europe
|
||||
// Collation with decomposition off doesn't work for Europe
|
||||
//
|
||||
@Test
|
||||
public void Test4114077(/* char* par */) {
|
||||
@ -709,18 +712,18 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
// -> a, ring, acute
|
||||
"\u0041\u0300\u0316", "\u003c", "\u0041\u0316\u0300" // No reordering --> unequal
|
||||
};
|
||||
|
||||
|
||||
c.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
compareArray(c, test1);
|
||||
|
||||
|
||||
String test2[] = {
|
||||
"\u0041\u0300\u0316", "\u003d", "\u0041\u0316\u0300" // Reordering --> equal
|
||||
};
|
||||
|
||||
|
||||
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
|
||||
compareArray(c, test2);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4124632
|
||||
//
|
||||
// Collator::getCollationKey was hanging on certain character sequences
|
||||
@ -743,7 +746,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("CollationKey creation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4132736
|
||||
//
|
||||
// sort order of french words with multiple accents has errors
|
||||
@ -757,14 +760,14 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
} catch (Exception e) {
|
||||
errln("Failed to create a collator for Locale.CANADA_FRENCH");
|
||||
}
|
||||
|
||||
|
||||
String test1[] = {
|
||||
"\u0065\u0300\u0065\u0301", "\u003c", "\u0065\u0301\u0065\u0300",
|
||||
"\u0065\u0300\u0301", "\u003c", "\u0065\u0301\u0300",
|
||||
};
|
||||
compareArray(c, test1);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4133509
|
||||
//
|
||||
// The sorting using java.text.CollationKey is not in the exact order
|
||||
@ -777,13 +780,13 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
"\u0047\u0072\u0061\u0070\u0068\u0069\u0063\u0073", "\u003c", "\u0047\u0072\u0061\u0070\u0068\u0069\u0063\u0073\u0045\u006e\u0076\u0069\u0072\u006f\u006e\u006d\u0065\u006e\u0074",
|
||||
"\u0053\u0074\u0072\u0069\u006e\u0067", "\u003c", "\u0053\u0074\u0072\u0069\u006e\u0067\u0042\u0075\u0066\u0066\u0065\u0072",
|
||||
};
|
||||
|
||||
|
||||
compareArray(en_us, test1);
|
||||
}
|
||||
|
||||
|
||||
// @bug 4139572
|
||||
//
|
||||
// getCollationKey throws exception for spanish text
|
||||
// getCollationKey throws exception for spanish text
|
||||
// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6
|
||||
//
|
||||
@Test
|
||||
@ -810,10 +813,10 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Error creating CollationKey for \"Nombre De Ojbeto\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @bug 4141640
|
||||
//
|
||||
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
|
||||
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
|
||||
//
|
||||
@Test
|
||||
public void Test4141640(/* char* par */) {
|
||||
@ -823,7 +826,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
// in order to prevent this sort of bug from cropping up in the future
|
||||
//
|
||||
Locale locales[] = Collator.getAvailableLocales();
|
||||
|
||||
|
||||
for (int i = 0; i < locales.length; i += 1)
|
||||
{
|
||||
Collator c = null;
|
||||
@ -838,7 +841,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkListOrder(String[] sortedList, Collator c) {
|
||||
// this function uses the specified Collator to make sure the
|
||||
// passed-in list is already sorted into ascending order
|
||||
@ -1042,7 +1045,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
}
|
||||
|
||||
RuleBasedCollator collator = new RuleBasedCollator("&a<\u00e0=a\u0300");
|
||||
//commented by Kevin 2003/10/21
|
||||
//commented by Kevin 2003/10/21
|
||||
//for "FULL_DECOMPOSITION is not supported here." in ICU4J DOC
|
||||
//collator.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
collator.setStrength(Collator.IDENTICAL);
|
||||
@ -1125,51 +1128,51 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(Locale.US);
|
||||
java.text.StringCharacterIterator stringIter = new java.text.StringCharacterIterator("fox");
|
||||
CollationElementIterator iter = collator.getCollationElementIterator(stringIter);
|
||||
|
||||
|
||||
int[] elements_next = new int[3];
|
||||
logln("calling next:");
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
logln("[" + i + "] " + (elements_next[i] = iter.next()));
|
||||
}
|
||||
|
||||
|
||||
int[] elements_fwd = new int[3];
|
||||
logln("calling set/next:");
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
iter.setOffset(i);
|
||||
logln("[" + i + "] " + (elements_fwd[i] = iter.next()));
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (elements_next[i] != elements_fwd[i]) {
|
||||
errln("mismatch at position " + i +
|
||||
": " + elements_next[i] +
|
||||
errln("mismatch at position " + i +
|
||||
": " + elements_next[i] +
|
||||
" != " + elements_fwd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fixing the infinite loop for surrogates
|
||||
@Test
|
||||
public void Test8484()
|
||||
{
|
||||
String s = "\u9FE1\uCEF3\u2798\uAAB6\uDA7C";
|
||||
Collator coll = Collator.getInstance();
|
||||
CollationKey collKey = coll.getCollationKey(s);
|
||||
CollationKey collKey = coll.getCollationKey(s);
|
||||
logln("Pass: " + collKey.toString() + " generated OK.");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBengaliSortKey() throws Exception {
|
||||
char rules[] = { 0x26, 0x9fa, 0x3c, 0x98c, 0x3c, 0x9e1, 0x3c, 0x98f, 0x3c, 0x990, 0x3c, 0x993,
|
||||
0x3c, 0x994, 0x3c, 0x9bc, 0x3c, 0x982, 0x3c, 0x983, 0x3c, 0x981, 0x3c, 0x9b0, 0x3c,
|
||||
0x9b8, 0x3c, 0x9b9, 0x3c, 0x9bd, 0x3c, 0x9be, 0x3c, 0x9bf, 0x3c, 0x9c8, 0x3c, 0x9cb,
|
||||
char rules[] = { 0x26, 0x9fa, 0x3c, 0x98c, 0x3c, 0x9e1, 0x3c, 0x98f, 0x3c, 0x990, 0x3c, 0x993,
|
||||
0x3c, 0x994, 0x3c, 0x9bc, 0x3c, 0x982, 0x3c, 0x983, 0x3c, 0x981, 0x3c, 0x9b0, 0x3c,
|
||||
0x9b8, 0x3c, 0x9b9, 0x3c, 0x9bd, 0x3c, 0x9be, 0x3c, 0x9bf, 0x3c, 0x9c8, 0x3c, 0x9cb,
|
||||
0x3d, 0x9cb };
|
||||
|
||||
|
||||
Collator col = new RuleBasedCollator(String.copyValueOf(rules));
|
||||
|
||||
|
||||
String str1 = "\u09be";
|
||||
String str2 = "\u0b70";
|
||||
|
||||
|
||||
int result = col.compare(str1, str2);
|
||||
System.out.flush();
|
||||
|
||||
@ -1191,7 +1194,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
}
|
||||
System.out.print(": ");
|
||||
for(int i=0;i<bytes.length;i++) {
|
||||
sb.append(" 0x"+Integer.toHexString(((int)bytes[i])&0xff));
|
||||
sb.append(" 0x"+Integer.toHexString((bytes[i])&0xff));
|
||||
}
|
||||
sb.append("\n");
|
||||
return sb;
|
||||
@ -1290,7 +1293,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
//
|
||||
// Use a custom collator class whose createCollationElementIterator
|
||||
// methods increment a count....
|
||||
//
|
||||
//
|
||||
RuleBasedCollator en_us = (RuleBasedCollator) Collator.getInstance(Locale.US);
|
||||
My4146160Collator.count = 0;
|
||||
My4146160Collator mc = null;
|
||||
@ -1300,7 +1303,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Failed to create a My4146160Collator.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CollationKey key = null;
|
||||
try {
|
||||
key = mc.getCollationKey("1");
|
||||
@ -1308,14 +1311,14 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
errln("Failure to get a CollationKey from a My4146160Collator.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (My4146160Collator.count < 1) {
|
||||
errln("My4146160Collator.getCollationElementIterator not called for getCollationKey");
|
||||
}
|
||||
|
||||
|
||||
My4146160Collator.count = 0;
|
||||
mc.compare("1", "2");
|
||||
|
||||
|
||||
if (My4146160Collator.count < 1) {
|
||||
errln("My4146160Collator.getCollationElementIterator not called for compare");
|
||||
}
|
||||
@ -1334,7 +1337,7 @@ public class CollationRegressionTest extends TestFmwk {
|
||||
count += 1;
|
||||
return super.getCollationElementIterator(text);
|
||||
}
|
||||
|
||||
|
||||
public CollationElementIterator getCollationElementIterator(java.text.CharacterIterator text) {
|
||||
count += 1;
|
||||
return super.getCollationElementIterator(text);
|
||||
|
@ -20,19 +20,22 @@ import java.util.MissingResourceException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.Collator.CollatorFactory;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationServiceTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestRegister() {
|
||||
// register a singleton
|
||||
Collator frcol = Collator.getInstance(ULocale.FRANCE);
|
||||
Collator uscol = Collator.getInstance(ULocale.US);
|
||||
|
||||
|
||||
{ // try override en_US collator
|
||||
Object key = Collator.registerInstance(frcol, ULocale.US);
|
||||
Collator ncol = Collator.getInstance(ULocale.US);
|
||||
@ -64,7 +67,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
if (!frcol.equals(ncol)) {
|
||||
errln("register of fr collator for fu_FU failed");
|
||||
}
|
||||
|
||||
|
||||
ULocale[] locales = Collator.getAvailableULocales();
|
||||
boolean found = false;
|
||||
for (int i = 0; i < locales.length; ++i) {
|
||||
@ -83,7 +86,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
errln("found " + name + " for fu_FU");
|
||||
}
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Could not load locale data.");
|
||||
warnln("Could not load locale data.");
|
||||
}
|
||||
try{
|
||||
String name = Collator.getDisplayName(fu_FU, fu_FU);
|
||||
@ -92,7 +95,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
errln("found " + name + " for fu_FU");
|
||||
}
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Could not load locale data.");
|
||||
warnln("Could not load locale data.");
|
||||
}
|
||||
|
||||
if (!Collator.unregister(key)) {
|
||||
@ -105,9 +108,9 @@ public class CollationServiceTest extends TestFmwk {
|
||||
}
|
||||
|
||||
{
|
||||
// coverage after return to default
|
||||
// coverage after return to default
|
||||
ULocale[] locales = Collator.getAvailableULocales();
|
||||
|
||||
|
||||
for (int i = 0; i < locales.length; ++i) {
|
||||
if (locales[i].equals(fu_FU)) {
|
||||
errln("new locale fu_FU not reported as supported locale");
|
||||
@ -151,7 +154,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
class TestFactory extends CollatorFactory {
|
||||
private Map map;
|
||||
private Set ids;
|
||||
|
||||
|
||||
TestFactory(CollatorInfo[] info) {
|
||||
map = new HashMap();
|
||||
for (int i = 0; i < info.length; ++i) {
|
||||
@ -160,6 +163,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collator createCollator(ULocale loc) {
|
||||
CollatorInfo ci = (CollatorInfo)map.get(loc);
|
||||
if (ci != null) {
|
||||
@ -168,6 +172,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(ULocale objectLocale, ULocale displayLocale) {
|
||||
CollatorInfo ci = (CollatorInfo)map.get(objectLocale);
|
||||
if (ci != null) {
|
||||
@ -176,6 +181,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set getSupportedLocaleIDs() {
|
||||
if (ids == null) {
|
||||
HashSet set = new HashSet();
|
||||
@ -190,20 +196,22 @@ public class CollationServiceTest extends TestFmwk {
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestFactoryWrapper extends CollatorFactory {
|
||||
CollatorFactory delegate;
|
||||
|
||||
|
||||
TestFactoryWrapper(CollatorFactory delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collator createCollator(ULocale loc) {
|
||||
return delegate.createCollator(loc);
|
||||
}
|
||||
|
||||
|
||||
// use CollatorFactory getDisplayName(ULocale, ULocale) for coverage
|
||||
|
||||
|
||||
@Override
|
||||
public Set getSupportedLocaleIDs() {
|
||||
return delegate.getSupportedLocaleIDs();
|
||||
}
|
||||
@ -222,7 +230,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
Collator gecol = Collator.getInstance(ULocale.GERMANY);
|
||||
Collator jpcol = Collator.getInstance(ULocale.JAPAN);
|
||||
Collator fucol = Collator.getInstance(fu_FU);
|
||||
|
||||
|
||||
CollatorInfo[] info = {
|
||||
new CollatorInfo(ULocale.US, frcol, null),
|
||||
new CollatorInfo(ULocale.FRANCE, gecol, null),
|
||||
@ -232,7 +240,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
try{
|
||||
factory = new TestFactory(info);
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Could not load locale data.");
|
||||
warnln("Could not load locale data.");
|
||||
}
|
||||
// coverage
|
||||
{
|
||||
@ -242,11 +250,11 @@ public class CollationServiceTest extends TestFmwk {
|
||||
try{
|
||||
name = Collator.getDisplayName(fu_FU, fu_FU_FOO);
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Could not load locale data.");
|
||||
warnln("Could not load locale data.");
|
||||
}
|
||||
logln("*** default name: " + name);
|
||||
Collator.unregister(key);
|
||||
|
||||
|
||||
ULocale bar_BAR = new ULocale("bar_BAR");
|
||||
Collator col = Collator.getInstance(bar_BAR);
|
||||
ULocale valid = col.getLocale(ULocale.VALID_LOCALE);
|
||||
@ -257,12 +265,12 @@ public class CollationServiceTest extends TestFmwk {
|
||||
}
|
||||
|
||||
int n1 = checkAvailable("before registerFactory");
|
||||
|
||||
|
||||
{
|
||||
Object key = Collator.registerFactory(factory);
|
||||
|
||||
|
||||
int n2 = checkAvailable("after registerFactory");
|
||||
|
||||
|
||||
Collator ncol = Collator.getInstance(ULocale.US);
|
||||
if (!frcol.equals(ncol)) {
|
||||
errln("frcoll for en_US failed");
|
||||
@ -272,7 +280,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
if (!jpcol.equals(ncol)) {
|
||||
errln("jpcol for fu_FU_FOO failed, got: " + ncol);
|
||||
}
|
||||
|
||||
|
||||
ULocale[] locales = Collator.getAvailableULocales();
|
||||
boolean found = false;
|
||||
for (int i = 0; i < locales.length; ++i) {
|
||||
@ -284,7 +292,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
if (!found) {
|
||||
errln("new locale fu_FU not reported as supported locale");
|
||||
}
|
||||
|
||||
|
||||
String name = Collator.getDisplayName(fu_FU);
|
||||
if (!"little bunny Foo Foo".equals(name)) {
|
||||
errln("found " + name + " for fu_FU");
|
||||
@ -302,7 +310,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
int n3 = checkAvailable("after unregister");
|
||||
assertTrue("register increases count", n2>n1);
|
||||
assertTrue("unregister restores count", n3==n1);
|
||||
|
||||
|
||||
ncol = Collator.getInstance(fu_FU);
|
||||
if (!fucol.equals(ncol)) {
|
||||
errln("collator after unregister does not match original fu_FU");
|
||||
@ -321,12 +329,12 @@ public class CollationServiceTest extends TestFmwk {
|
||||
ULocale ulocs[] = Collator.getAvailableULocales();
|
||||
if (!assertTrue("getAvailableULocales != null", ulocs!=null)) return -1;
|
||||
checkArray(msg, ulocs, null);
|
||||
// This is not true because since ULocale objects with script code cannot be
|
||||
// This is not true because since ULocale objects with script code cannot be
|
||||
// converted to Locale objects
|
||||
//assertTrue("getAvailableLocales().length == getAvailableULocales().length", locs.length == ulocs.length);
|
||||
return locs.length;
|
||||
}
|
||||
|
||||
|
||||
private static final String KW[] = {
|
||||
"collation"
|
||||
};
|
||||
@ -341,7 +349,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
String kw[] = Collator.getKeywords();
|
||||
if (!assertTrue("getKeywords != null", kw!=null)) return;
|
||||
checkArray("getKeywords", kw, KW);
|
||||
|
||||
|
||||
String kwval[] = Collator.getKeywordValues(KW[0]);
|
||||
if (!assertTrue("getKeywordValues != null", kwval!=null)) return;
|
||||
checkArray("getKeywordValues", kwval, KWVAL);
|
||||
@ -355,7 +363,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
}
|
||||
assertTrue("getFunctionalEquivalent(de).isAvailable==true",
|
||||
isAvailable[0] == true);
|
||||
|
||||
|
||||
equiv = Collator.getFunctionalEquivalent(KW[0],
|
||||
new ULocale("de_DE"),
|
||||
isAvailable);
|
||||
@ -370,11 +378,11 @@ public class CollationServiceTest extends TestFmwk {
|
||||
assertEquals("getFunctionalEquivalent(zh_Hans)", "zh", equiv.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestGetFunctionalEquivalent() {
|
||||
String kw[] = Collator.getKeywords();
|
||||
final String DATA[] = {
|
||||
final String DATA[] = {
|
||||
"sv", "sv", "t",
|
||||
"sv@collation=direct", "sv", "t",
|
||||
"sv@collation=traditional", "sv", "t",
|
||||
@ -406,7 +414,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
"en_US_VALLEYGIRL","root","f"
|
||||
};
|
||||
final int DATA_COUNT=(DATA.length/3);
|
||||
|
||||
|
||||
for(int i=0;i<DATA_COUNT;i++) {
|
||||
boolean isAvailable[] = new boolean[1];
|
||||
ULocale input = new ULocale(DATA[(i*3)+0]);
|
||||
@ -440,8 +448,8 @@ public class CollationServiceTest extends TestFmwk {
|
||||
// for (int i = 0; i < Collator.getKeywords().length; ++i) {
|
||||
// ULocale base = Collator.getFunctionalEquivalent(keywords[i],locales[k]);
|
||||
// String[] values = Collator.getKeywordValues(keywords[i]);
|
||||
// for (int j = 0; j < Collator.getKeywordValues(keywords[i]).length;++j) {
|
||||
// ULocale other = Collator.getFunctionalEquivalent(keywords[i],
|
||||
// for (int j = 0; j < Collator.getKeywordValues(keywords[i]).length;++j) {
|
||||
// ULocale other = Collator.getFunctionalEquivalent(keywords[i],
|
||||
// new ULocale(locales[k] + "@" + keywords[i] + "=" + values[j]),
|
||||
// isAvailable);
|
||||
// if (isAvailable[0] && !other.equals(base)) {
|
||||
@ -492,7 +500,7 @@ public class CollationServiceTest extends TestFmwk {
|
||||
errln("Keyword value " + expected[j] + " missing for locale: " + locale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Collator.getKeywordValues return the same contents for both commonlyUsed
|
||||
// true and false.
|
||||
String[] all = Collator.getKeywordValuesForLocale("collation", loc, false);
|
||||
|
@ -7,23 +7,26 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationSpanishTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/escoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
public class CollationSpanishTest extends TestFmwk {
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationSpanishTest extends TestFmwk {
|
||||
private static char[][] testSourceCases = {
|
||||
{0x61, 0x6c, 0x69, 0x61, 0x73},
|
||||
{0x45, 0x6c, 0x6c, 0x69, 0x6f, 0x74},
|
||||
@ -60,19 +63,19 @@ import com.ibm.icu.text.Collator;
|
||||
-1,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
//static public Collator myCollation = Collator.getInstance(new Locale("es", "ES"));
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationSpanishTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
myCollation = Collator.getInstance(new Locale("es", "ES"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestTertiary(){
|
||||
int i = 0;
|
||||
@ -81,7 +84,7 @@ import com.ibm.icu.text.Collator;
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPrimary(){
|
||||
int i;
|
||||
@ -90,7 +93,7 @@ import com.ibm.icu.text.Collator;
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// amin test routine, tests rules specific to the spanish locale
|
||||
private void doTest(char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
@ -102,7 +105,7 @@ import com.ibm.icu.text.Collator;
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -115,13 +118,13 @@ import com.ibm.icu.text.Collator;
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -131,7 +134,7 @@ import com.ibm.icu.text.Collator;
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -144,7 +147,7 @@ import com.ibm.icu.text.Collator;
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -155,7 +158,7 @@ import com.ibm.icu.text.Collator;
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -50,6 +52,7 @@ import com.ibm.icu.util.IllformedLocaleException;
|
||||
import com.ibm.icu.util.Output;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationTest extends TestFmwk {
|
||||
public CollationTest() {
|
||||
}
|
||||
@ -62,14 +65,14 @@ public class CollationTest extends TestFmwk {
|
||||
String fileTestName;
|
||||
|
||||
// package private methods ----------------------------------------------
|
||||
|
||||
static void doTest(TestFmwk test, RuleBasedCollator col, String source,
|
||||
|
||||
static void doTest(TestFmwk test, RuleBasedCollator col, String source,
|
||||
String target, int result)
|
||||
{
|
||||
doTestVariant(test, col, source, target, result);
|
||||
if (result == -1) {
|
||||
doTestVariant(test, col, target, source, 1);
|
||||
}
|
||||
}
|
||||
else if (result == 1) {
|
||||
doTestVariant(test, col, target, source, -1);
|
||||
}
|
||||
@ -82,17 +85,17 @@ public class CollationTest extends TestFmwk {
|
||||
iter.setText(target);
|
||||
backAndForth(test, iter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an integer array containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
*/
|
||||
static int[] getOrders(CollationElementIterator iter)
|
||||
static int[] getOrders(CollationElementIterator iter)
|
||||
{
|
||||
int maxSize = 100;
|
||||
int size = 0;
|
||||
int[] orders = new int[maxSize];
|
||||
|
||||
|
||||
int order;
|
||||
while ((order = iter.next()) != CollationElementIterator.NULLORDER) {
|
||||
if (size == maxSize) {
|
||||
@ -103,7 +106,7 @@ public class CollationTest extends TestFmwk {
|
||||
}
|
||||
orders[size++] = order;
|
||||
}
|
||||
|
||||
|
||||
if (maxSize > size) {
|
||||
int[] temp = new int[size];
|
||||
System.arraycopy(orders, 0, temp, 0, size);
|
||||
@ -111,20 +114,20 @@ public class CollationTest extends TestFmwk {
|
||||
}
|
||||
return orders;
|
||||
}
|
||||
|
||||
static void backAndForth(TestFmwk test, CollationElementIterator iter)
|
||||
|
||||
static void backAndForth(TestFmwk test, CollationElementIterator iter)
|
||||
{
|
||||
// Run through the iterator forwards and stick it into an array
|
||||
iter.reset();
|
||||
int[] orders = getOrders(iter);
|
||||
|
||||
|
||||
// Now go through it backwards and make sure we get the same values
|
||||
int index = orders.length;
|
||||
int o;
|
||||
|
||||
|
||||
// reset the iterator
|
||||
iter.reset();
|
||||
|
||||
|
||||
while ((o = iter.previous()) != CollationElementIterator.NULLORDER) {
|
||||
if (o != orders[--index]) {
|
||||
if (o == 0) {
|
||||
@ -132,24 +135,24 @@ public class CollationTest extends TestFmwk {
|
||||
} else {
|
||||
while (index > 0 && orders[index] == 0) {
|
||||
index --;
|
||||
}
|
||||
}
|
||||
if (o != orders[index]) {
|
||||
TestFmwk.errln("Mismatch at index " + index + ": 0x"
|
||||
TestFmwk.errln("Mismatch at index " + index + ": 0x"
|
||||
+ Utility.hex(orders[index]) + " vs 0x" + Utility.hex(o));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while (index != 0 && orders[index - 1] == 0) {
|
||||
index --;
|
||||
}
|
||||
|
||||
|
||||
if (index != 0) {
|
||||
String msg = "Didn't get back to beginning - index is ";
|
||||
TestFmwk.errln(msg + index);
|
||||
|
||||
|
||||
iter.reset();
|
||||
TestFmwk.err("next: ");
|
||||
while ((o = iter.next()) != CollationElementIterator.NULLORDER) {
|
||||
@ -165,7 +168,7 @@ public class CollationTest extends TestFmwk {
|
||||
TestFmwk.errln("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final String appendCompareResult(int result, String target){
|
||||
if (result == -1) {
|
||||
target += "LESS";
|
||||
@ -191,7 +194,7 @@ public class CollationTest extends TestFmwk {
|
||||
|
||||
static final String prettify(byte[] skBytes, int length) {
|
||||
StringBuilder target = new StringBuilder(length * 3 + 2).append('[');
|
||||
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
String numStr = Integer.toHexString(skBytes[i] & 0xff);
|
||||
if (numStr.length() < 2) {
|
||||
@ -203,17 +206,17 @@ public class CollationTest extends TestFmwk {
|
||||
return target.toString();
|
||||
}
|
||||
|
||||
private static void doTestVariant(TestFmwk test,
|
||||
private static void doTestVariant(TestFmwk test,
|
||||
RuleBasedCollator myCollation,
|
||||
String source, String target, int result)
|
||||
{
|
||||
int compareResult = myCollation.compare(source, target);
|
||||
if (compareResult != result) {
|
||||
|
||||
|
||||
// !!! if not mod build, error, else nothing.
|
||||
// warnln if not build, error, else always print warning.
|
||||
// do we need a 'quiet warning?' (err or log). Hmmm,
|
||||
// would it work to have the 'verbose' flag let you
|
||||
// would it work to have the 'verbose' flag let you
|
||||
// suppress warnings? Are there ever some warnings you
|
||||
// want to suppress, and others you don't?
|
||||
TestFmwk.errln("Comparing \"" + Utility.hex(source) + "\" with \""
|
||||
@ -224,9 +227,9 @@ public class CollationTest extends TestFmwk {
|
||||
CollationKey tsk = myCollation.getCollationKey(target);
|
||||
compareResult = ssk.compareTo(tsk);
|
||||
if (compareResult != result) {
|
||||
TestFmwk.errln("Comparing CollationKeys of \"" + Utility.hex(source)
|
||||
+ "\" with \"" + Utility.hex(target)
|
||||
+ "\" expected " + result + " but got "
|
||||
TestFmwk.errln("Comparing CollationKeys of \"" + Utility.hex(source)
|
||||
+ "\" with \"" + Utility.hex(target)
|
||||
+ "\" expected " + result + " but got "
|
||||
+ compareResult);
|
||||
}
|
||||
RawCollationKey srsk = new RawCollationKey();
|
||||
@ -235,10 +238,10 @@ public class CollationTest extends TestFmwk {
|
||||
myCollation.getRawCollationKey(target, trsk);
|
||||
compareResult = ssk.compareTo(tsk);
|
||||
if (compareResult != result) {
|
||||
TestFmwk.errln("Comparing RawCollationKeys of \""
|
||||
+ Utility.hex(source)
|
||||
+ "\" with \"" + Utility.hex(target)
|
||||
+ "\" expected " + result + " but got "
|
||||
TestFmwk.errln("Comparing RawCollationKeys of \""
|
||||
+ Utility.hex(source)
|
||||
+ "\" with \"" + Utility.hex(target)
|
||||
+ "\" expected " + result + " but got "
|
||||
+ compareResult);
|
||||
}
|
||||
}
|
||||
@ -250,7 +253,7 @@ public class CollationTest extends TestFmwk {
|
||||
|
||||
final String s = "\uFFFE\uFFFF";
|
||||
long[] ces;
|
||||
|
||||
|
||||
ces = rbc.internalGetCEs(s);
|
||||
if (ces.length != 2) {
|
||||
errln("expected 2 CEs for <FFFE, FFFF>, got " + ces.length);
|
||||
@ -355,7 +358,7 @@ public class CollationTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ICU4C: TestIllegalUTF8 / not applicable to ICU4J
|
||||
|
||||
|
||||
@ -1475,7 +1478,7 @@ public class CollationTest extends TestFmwk {
|
||||
if (b != bytes[i]) {
|
||||
break;
|
||||
}
|
||||
if ((int)b == Collation.LEVEL_SEPARATOR_BYTE) {
|
||||
if (b == Collation.LEVEL_SEPARATOR_BYTE) {
|
||||
++level;
|
||||
if (level == Collation.CASE_LEVEL && !collHasCaseLevel) {
|
||||
++level;
|
||||
|
@ -7,11 +7,11 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : collate/CollationRegressionTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/regcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -21,6 +21,8 @@ import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -29,10 +31,11 @@ import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationThaiTest extends TestFmwk {
|
||||
|
||||
|
||||
final int MAX_FAILURES_TO_SHOW = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Odd corner conditions taken from "How to Sort Thai Without Rewriting Sort",
|
||||
* by Doug Cooper, http://seasrc.th.net/paper/thaisort.zip
|
||||
@ -42,41 +45,41 @@ public class CollationThaiTest extends TestFmwk {
|
||||
String TESTS[] = {
|
||||
// Shorter words precede longer
|
||||
"\u0e01", "<", "\u0e01\u0e01",
|
||||
|
||||
|
||||
// Tone marks are considered after letters (i.e. are primary ignorable)
|
||||
"\u0e01\u0e32", "<", "\u0e01\u0e49\u0e32",
|
||||
|
||||
|
||||
// ditto for other over-marks
|
||||
"\u0e01\u0e32", "<", "\u0e01\u0e32\u0e4c",
|
||||
|
||||
|
||||
// commonly used mark-in-context order.
|
||||
// In effect, marks are sorted after each syllable.
|
||||
"\u0e01\u0e32\u0e01\u0e49\u0e32", "<", "\u0e01\u0e48\u0e32\u0e01\u0e49\u0e32",
|
||||
|
||||
|
||||
// Hyphens and other punctuation follow whitespace but come before letters
|
||||
"\u0e01\u0e32", "=", "\u0e01\u0e32-",
|
||||
"\u0e01\u0e32-", "<", "\u0e01\u0e32\u0e01\u0e32",
|
||||
|
||||
|
||||
// Doubler follows an indentical word without the doubler
|
||||
"\u0e01\u0e32", "=", "\u0e01\u0e32\u0e46",
|
||||
"\u0e01\u0e32\u0e46", "<", "\u0e01\u0e32\u0e01\u0e32",
|
||||
|
||||
|
||||
// \u0e45 after either \u0e24 or \u0e26 is treated as a single
|
||||
// combining character, similar to "c < ch" in traditional spanish.
|
||||
// TODO: beef up this case
|
||||
"\u0e24\u0e29\u0e35", "<", "\u0e24\u0e45\u0e29\u0e35",
|
||||
"\u0e26\u0e29\u0e35", "<", "\u0e26\u0e45\u0e29\u0e35",
|
||||
|
||||
|
||||
// Vowels reorder, should compare \u0e2d and \u0e34
|
||||
"\u0e40\u0e01\u0e2d", "<", "\u0e40\u0e01\u0e34",
|
||||
|
||||
|
||||
// Tones are compared after the rest of the word (e.g. primary ignorable)
|
||||
"\u0e01\u0e32\u0e01\u0e48\u0e32", "<", "\u0e01\u0e49\u0e32\u0e01\u0e32",
|
||||
|
||||
|
||||
// Periods are ignored entirely
|
||||
"\u0e01.\u0e01.", "<", "\u0e01\u0e32",
|
||||
};
|
||||
|
||||
|
||||
RuleBasedCollator coll = null;
|
||||
try {
|
||||
coll = getThaiCollator();
|
||||
@ -84,9 +87,9 @@ public class CollationThaiTest extends TestFmwk {
|
||||
warnln("could not construct Thai collator");
|
||||
return;
|
||||
}
|
||||
compareArray(coll, TESTS);
|
||||
compareArray(coll, TESTS);
|
||||
}
|
||||
|
||||
|
||||
void compareArray(RuleBasedCollator c, String[] tests) {
|
||||
for (int i = 0; i < tests.length; i += 3) {
|
||||
int expect = 0;
|
||||
@ -106,13 +109,13 @@ public class CollationThaiTest extends TestFmwk {
|
||||
CollationTest.doTest(this, c, s1, s2, expect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int sign(int i ) {
|
||||
if (i < 0) return -1;
|
||||
if (i > 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the external dictionary file, which is already in proper
|
||||
* sorted order, and confirm that the collator compares each line as
|
||||
@ -204,12 +207,12 @@ public class CollationThaiTest extends TestFmwk {
|
||||
errln("Summary: " + failed + " of " + (line - 1) +
|
||||
" comparisons failed");
|
||||
}
|
||||
|
||||
|
||||
logln("Words checked: " + wordCount);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestInvalidThai()
|
||||
public void TestInvalidThai()
|
||||
{
|
||||
String tests[] = { "\u0E44\u0E01\u0E44\u0E01",
|
||||
"\u0E44\u0E01\u0E01\u0E44",
|
||||
@ -218,7 +221,7 @@ public class CollationThaiTest extends TestFmwk {
|
||||
"\u0E44\u0E44\u0E01\u0E01",
|
||||
"\u0E01\u0E44\u0E44\u0E01",
|
||||
};
|
||||
|
||||
|
||||
RuleBasedCollator collator;
|
||||
StrCmp comparator;
|
||||
try {
|
||||
@ -228,26 +231,26 @@ public class CollationThaiTest extends TestFmwk {
|
||||
warnln("could not construct Thai collator");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Arrays.sort(tests, comparator);
|
||||
|
||||
|
||||
for (int i = 0; i < tests.length; i ++)
|
||||
{
|
||||
for (int j = i + 1; j < tests.length; j ++) {
|
||||
if (collator.compare(tests[i], tests[j]) > 0) {
|
||||
// inconsistency ordering found!
|
||||
errln("Inconsistent ordering between strings " + i
|
||||
errln("Inconsistent ordering between strings " + i
|
||||
+ " and " + j);
|
||||
}
|
||||
}
|
||||
CollationElementIterator iterator
|
||||
CollationElementIterator iterator
|
||||
= collator.getCollationElementIterator(tests[i]);
|
||||
CollationTest.backAndForth(this, iterator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestReordering()
|
||||
public void TestReordering()
|
||||
{
|
||||
String tests[] = {
|
||||
"\u0E41c\u0301", "=", "\u0E41\u0107", // composition
|
||||
@ -281,13 +284,13 @@ public class CollationThaiTest extends TestFmwk {
|
||||
|
||||
RuleBasedCollator collator;
|
||||
try {
|
||||
collator = (RuleBasedCollator)getThaiCollator();
|
||||
collator = getThaiCollator();
|
||||
} catch (Exception e) {
|
||||
warnln("could not construct Thai collator");
|
||||
return;
|
||||
}
|
||||
compareArray(collator, tests);
|
||||
|
||||
|
||||
String rule = "& c < ab";
|
||||
String testcontraction[] = { "\u0E41ab", ">", "\u0E41c"};
|
||||
try {
|
||||
@ -300,28 +303,29 @@ public class CollationThaiTest extends TestFmwk {
|
||||
}
|
||||
|
||||
// private inner class -------------------------------------------------
|
||||
|
||||
private static final class StrCmp implements Comparator<String>
|
||||
|
||||
private static final class StrCmp implements Comparator<String>
|
||||
{
|
||||
public int compare(String string1, String string2)
|
||||
@Override
|
||||
public int compare(String string1, String string2)
|
||||
{
|
||||
return collator.compare(string1, string2);
|
||||
}
|
||||
|
||||
|
||||
StrCmp() throws Exception
|
||||
{
|
||||
collator = getThaiCollator();
|
||||
}
|
||||
|
||||
|
||||
Collator collator;
|
||||
}
|
||||
|
||||
|
||||
// private data members ------------------------------------------------
|
||||
|
||||
|
||||
private static RuleBasedCollator m_collator_;
|
||||
|
||||
|
||||
// private methods -----------------------------------------------------
|
||||
|
||||
|
||||
private static RuleBasedCollator getThaiCollator() throws Exception
|
||||
{
|
||||
if (m_collator_ == null) {
|
||||
|
@ -13,9 +13,13 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationThreadTest extends TestFmwk {
|
||||
private static final String[] threadTestData;
|
||||
static {
|
||||
@ -195,6 +199,7 @@ public class CollationThreadTest extends TestFmwk {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
synchronized (control) {
|
||||
|
@ -7,22 +7,25 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/CollationTurkishTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/trcoll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CollationTurkishTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0x73, 0x0327},
|
||||
@ -66,18 +69,18 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
-1,
|
||||
1
|
||||
};
|
||||
|
||||
|
||||
private Collator myCollation = null;
|
||||
|
||||
|
||||
public CollationTurkishTest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception{
|
||||
myCollation = Collator.getInstance(new Locale("tr", ""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
int i = 0;
|
||||
@ -86,7 +89,7 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPrimary() {
|
||||
int i;
|
||||
@ -95,8 +98,8 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// main test routine, tests rules specific to turkish locale
|
||||
private void doTest(char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
@ -107,9 +110,9 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ) {
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -122,13 +125,13 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -138,7 +141,7 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -151,7 +154,7 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -162,7 +165,7 @@ public class CollationTurkishTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,26 +7,29 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/G7CollationTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/g7coll.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class G7CollationTest extends TestFmwk{
|
||||
private static String[] testCases = {
|
||||
"blackbirds", "Pat", "p\u00E9ch\u00E9", "p\u00EAche", "p\u00E9cher",
|
||||
"p\u00EAcher", "Tod", "T\u00F6ne", "Tofu", "blackbird", "Ton",
|
||||
"blackbirds", "Pat", "p\u00E9ch\u00E9", "p\u00EAche", "p\u00E9cher",
|
||||
"p\u00EAcher", "Tod", "T\u00F6ne", "Tofu", "blackbird", "Ton",
|
||||
"PAT", "black-bird", "black-birds", "pat", // 14
|
||||
// Additional tests
|
||||
"czar", "churo", "cat", "darn", "?", /* 19 */
|
||||
@ -44,7 +47,7 @@ public class G7CollationTest extends TestFmwk{
|
||||
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* it_IT */
|
||||
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* ja_JP */
|
||||
/* new table collation with rules "& Z < p, P" loop to FIXEDTESTSET */
|
||||
{ 12, 13, 9, 0, 6, 8, 10, 7, 14, 1, 11, 2, 3, 4, 5, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 },
|
||||
{ 12, 13, 9, 0, 6, 8, 10, 7, 14, 1, 11, 2, 3, 4, 5, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 },
|
||||
/* new table collation with rules "& C < ch , cH, Ch, CH " loop to TOTALTESTSET */
|
||||
{ 19, 22, 21, 23, 24, 25, 12, 13, 9, 0, 17, 26, 28, 27, 15, 16, 18, 14, 1, 11, 2, 3, 4, 5, 20, 6, 8, 10, 7, 29 },
|
||||
/* new table collation with rules "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&' " loop to TOTALTESTSET */
|
||||
@ -52,31 +55,31 @@ public class G7CollationTest extends TestFmwk{
|
||||
/* analogous to Japanese rules " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- " */ /* loop to TOTALTESTSET */
|
||||
{ 19, 22, 21, 24, 23, 25, 12, 13, 9, 0, 17, 16, 28, 26, 27, 15, 18, 14, 1, 11, 2, 3, 4, 5, 20, 6, 8, 10, 7, 29 }
|
||||
};
|
||||
|
||||
|
||||
//private static final int MAX_TOKEN_LEN = 16;
|
||||
//private static final int TESTLOCALES = 12;
|
||||
private static final int FIXEDTESTSET = 15;
|
||||
private static final int TOTALTESTSET = 30;
|
||||
|
||||
|
||||
// perform test with added rules " & Z < p, P"
|
||||
@Test
|
||||
public void TestDemo1() {
|
||||
logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\"");
|
||||
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
||||
String baseRules = ((RuleBasedCollator)col).getRules();
|
||||
String newRules = " & Z < p, P";
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
try {
|
||||
myCollation = new RuleBasedCollator(newRules);
|
||||
} catch(Exception e) {
|
||||
errln("Fail to create RuleBasedCollator with rules:" + newRules);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int j, n;
|
||||
for (j = 0; j < FIXEDTESTSET; j++) {
|
||||
for (n = j+1; n < FIXEDTESTSET; n++) {
|
||||
@ -84,25 +87,25 @@ public class G7CollationTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// perorm test with added rules "& C < ch , cH, Ch, CH"
|
||||
@Test
|
||||
public void TestDemo2() {
|
||||
logln("Demo Test 2 : Create a new table collation with rules \"& C < ch , cH, Ch, CH\"");
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
||||
String baseRules = ((RuleBasedCollator)col).getRules();
|
||||
String newRules = "& C < ch , cH, Ch, CH";
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
try {
|
||||
myCollation = new RuleBasedCollator(newRules);
|
||||
}catch(Exception e){
|
||||
errln("Fail to create RuleBasedCollator with rules:" + newRules);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int j, n;
|
||||
for (j = 0; j < TOTALTESTSET; j++) {
|
||||
@ -111,26 +114,26 @@ public class G7CollationTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform test with added rules
|
||||
|
||||
// perform test with added rules
|
||||
// "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"
|
||||
@Test
|
||||
public void TestDemo3() {
|
||||
// logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\"");
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
||||
|
||||
String baseRules = ((RuleBasedCollator)col).getRules();
|
||||
String newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
RuleBasedCollator myCollation = null;
|
||||
try {
|
||||
myCollation = new RuleBasedCollator(newRules);
|
||||
}catch(Exception e){
|
||||
errln("Fail to create RuleBasedCollator with rules:" + newRules);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int j, n;
|
||||
for (j = 0; j < TOTALTESTSET; j++) {
|
||||
@ -139,25 +142,25 @@ public class G7CollationTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// perform test with added rules
|
||||
|
||||
// perform test with added rules
|
||||
// " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "
|
||||
@Test
|
||||
public void TestDemo4() {
|
||||
logln("Demo Test 4 : Create a new table collation with rules \" & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' \"");
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
Collator col = Collator.getInstance(Locale.ENGLISH);
|
||||
|
||||
String baseRules = ((RuleBasedCollator)col).getRules();
|
||||
String newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
|
||||
newRules = baseRules + newRules;
|
||||
RuleBasedCollator myCollation = null;
|
||||
RuleBasedCollator myCollation = null;
|
||||
try {
|
||||
myCollation = new RuleBasedCollator(newRules);
|
||||
}catch(Exception e){
|
||||
errln("Fail to create RuleBasedCollator with rules:" + newRules);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int j, n;
|
||||
for (j = 0; j < TOTALTESTSET; j++) {
|
||||
@ -166,7 +169,7 @@ public class G7CollationTest extends TestFmwk{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestG7Data() {
|
||||
Locale locales[] = {
|
||||
@ -199,21 +202,21 @@ public class G7CollationTest extends TestFmwk{
|
||||
myCollation = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// main test routine, tests comparisons for a set of strings against sets of expected results
|
||||
private void doTest(Collator myCollation, String source, String target,
|
||||
private void doTest(Collator myCollation, String source, String target,
|
||||
int result){
|
||||
|
||||
|
||||
int compareResult = myCollation.compare(source, target);
|
||||
CollationKey sortKey1, sortKey2;
|
||||
sortKey1 = myCollation.getCollationKey(source);
|
||||
sortKey2 = myCollation.getCollationKey(target);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult(source, target, sortKey1, sortKey2, compareResult,
|
||||
reportCResult(source, target, sortKey1, sortKey2, compareResult,
|
||||
keyResult, compareResult, result);
|
||||
}
|
||||
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
int compareResult, int keyResult, int incResult, int expectedResult ){
|
||||
if (expectedResult < -1 || expectedResult > 1) {
|
||||
@ -226,13 +229,13 @@ public class G7CollationTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()){
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -242,7 +245,7 @@ public class G7CollationTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -255,7 +258,7 @@ public class G7CollationTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -266,7 +269,7 @@ public class G7CollationTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,46 +7,49 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v2.1 : Collate/LotusCollationKoreanTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/lcukocol.cpp
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class LotusCollationKoreanTest extends TestFmwk{
|
||||
private static char[][] testSourceCases = {
|
||||
{0xac00}
|
||||
};
|
||||
|
||||
|
||||
private static char[][] testTargetCases = {
|
||||
{0xac01}
|
||||
};
|
||||
|
||||
|
||||
private static int[] results = {
|
||||
-1
|
||||
};
|
||||
|
||||
|
||||
private Collator myCollation;
|
||||
|
||||
|
||||
public LotusCollationKoreanTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception {
|
||||
myCollation = Collator.getInstance(Locale.KOREAN);
|
||||
myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
|
||||
}
|
||||
|
||||
|
||||
// performs test with strength TERIARY
|
||||
@Test
|
||||
public void TestTertiary() {
|
||||
@ -56,7 +59,7 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main test routine, tests rules specific to "Korean" locale
|
||||
private void doTest( char[] source, char[] target, int result) {
|
||||
String s = new String(source);
|
||||
@ -66,7 +69,7 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
sortKey1 = myCollation.getCollationKey(s);
|
||||
sortKey2 = myCollation.getCollationKey(t);
|
||||
int keyResult = sortKey1.compareTo(sortKey2);
|
||||
reportCResult( s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
|
||||
reportCResult( s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
|
||||
}
|
||||
|
||||
private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
|
||||
@ -81,13 +84,13 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
boolean ok3 = (incResult == expectedResult);
|
||||
|
||||
if (ok1 && ok2 && ok3 && !isVerbose()) {
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
|
||||
String msg2 = "\", \"";
|
||||
String msg3 = "\") returned ";
|
||||
String msg4 = "; expected ";
|
||||
|
||||
|
||||
String sExpect = new String("");
|
||||
String sResult = new String("");
|
||||
sResult = CollationTest.appendCompareResult(compareResult, sResult);
|
||||
@ -97,7 +100,7 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
|
||||
msg2 = "\").compareTo(key(\"";
|
||||
msg3 = "\")) returned ";
|
||||
@ -110,7 +113,7 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
msg2 = " vs. ";
|
||||
errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
|
||||
}
|
||||
|
||||
|
||||
msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
|
||||
msg2 = "\", \"";
|
||||
msg3 = "\") returned ";
|
||||
@ -121,7 +124,7 @@ public class LotusCollationKoreanTest extends TestFmwk{
|
||||
logln(msg1 + source + msg2 + target + msg3 + sResult);
|
||||
} else {
|
||||
errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -29,6 +31,7 @@ import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class UCAConformanceTest extends TestFmwk {
|
||||
|
||||
public UCAConformanceTest() {
|
||||
|
@ -15,6 +15,8 @@ import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.BreakIterator;
|
||||
@ -32,8 +34,7 @@ import com.ibm.icu.util.JapaneseCalendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestDefault() {
|
||||
@ -46,7 +47,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
// If not, some test cases will fail...
|
||||
errln("FAIL: The default locale of the test environment must be en_US");
|
||||
}
|
||||
|
||||
|
||||
logln("Default locale: " + defLocale.toString());
|
||||
|
||||
// First locale is en_US
|
||||
@ -68,7 +69,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
if (gpLocale2 != null) {
|
||||
errln("FAIL: Number of locales must be 2");
|
||||
}
|
||||
|
||||
|
||||
// Calendar locale
|
||||
Calendar cal = gp.getCalendar();
|
||||
ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
|
||||
@ -118,7 +119,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
GlobalizationPreferences gp = new GlobalizationPreferences();
|
||||
if (gp.isFrozen()) {
|
||||
errln("FAIL: This object is not yet frozen");
|
||||
}
|
||||
}
|
||||
|
||||
logln("Call reset()");
|
||||
boolean bSet = true;
|
||||
@ -199,7 +200,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
if (bSet) {
|
||||
errln("FAIL: setLocale(ULocale) must be blocked after frozen");
|
||||
}
|
||||
|
||||
|
||||
// setTerritory(String)
|
||||
logln("Call setTerritory(String) after frozen");
|
||||
bSet = true;
|
||||
@ -214,11 +215,11 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Modifiable clone
|
||||
logln("Create a modifiable clone");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
|
||||
if (gp1.isFrozen()) {
|
||||
errln("FAIL: The object returned by cloneAsThawed() must not be frozen yet");
|
||||
}
|
||||
}
|
||||
|
||||
// setLocale(ULocale)
|
||||
logln("Call setLocale(ULocale) of the modifiable clone");
|
||||
@ -230,7 +231,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
}
|
||||
if (!bSet) {
|
||||
errln("FAIL: setLocales(ULocale) must not throw an exception before frozen");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String[][] INPUT_LOCALEIDS = {
|
||||
@ -283,7 +284,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
sb.append(localeStrings[j]);
|
||||
}
|
||||
logln("Input locales: " + sb.toString());
|
||||
|
||||
|
||||
gp.reset();
|
||||
gp.setLocales(locales);
|
||||
|
||||
@ -292,7 +293,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i].length);
|
||||
} else {
|
||||
|
||||
|
||||
for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
|
||||
ULocale loc = gp.getLocale(j);
|
||||
logln("Locale[" + j + "]: " + loc.toString());
|
||||
@ -300,10 +301,10 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// setLocales(ULocale[])
|
||||
for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
|
||||
String[] localeStrings = INPUT_LOCALEIDS[i];
|
||||
@ -317,7 +318,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
sb.append(localeStrings[j]);
|
||||
}
|
||||
logln("Input locales: " + sb.toString());
|
||||
|
||||
|
||||
gp.reset();
|
||||
gp.setLocales(localeArray);
|
||||
|
||||
@ -326,7 +327,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i].length);
|
||||
} else {
|
||||
|
||||
|
||||
for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
|
||||
ULocale loc = gp.getLocale(j);
|
||||
logln("Locale[" + j + "]: " + loc.toString());
|
||||
@ -334,7 +335,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,7 +343,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
for (int i = 0; i < ACCEPT_LANGUAGES.length; i++) {
|
||||
String acceptLanguage = ACCEPT_LANGUAGES[i];
|
||||
logln("Accept language: " + acceptLanguage);
|
||||
|
||||
|
||||
gp.reset();
|
||||
gp.setLocales(acceptLanguage);
|
||||
|
||||
@ -351,7 +352,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i].length);
|
||||
} else {
|
||||
|
||||
|
||||
for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
|
||||
ULocale loc = gp.getLocale(j);
|
||||
logln("Locale[" + j + "]: " + loc.toString());
|
||||
@ -359,7 +360,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
|
||||
+ " Expected:" + RESULTS_LOCALEIDS[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,7 +371,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
if (!gp.getLocale(0).toString().equals("de_AT")) {
|
||||
errln("FAIL: getLocale(0) returns " + gp.getLocale(0).toString() + " Expected: de_AT");
|
||||
}
|
||||
|
||||
|
||||
// Invalid accept-language
|
||||
logln("Set locale - ko_KR");
|
||||
gp.setLocale(new ULocale("ko_KR"));
|
||||
@ -395,7 +396,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
String baseName = "com.ibm.icu.dev.data.resources.TestDataElements";
|
||||
ResourceBundle rb;
|
||||
|
||||
logln("Get a resource bundle " + baseName +
|
||||
logln("Get a resource bundle " + baseName +
|
||||
" using GlobalizationPreferences initialized by locales - en_GB, en_US");
|
||||
GlobalizationPreferences gp = new GlobalizationPreferences();
|
||||
ULocale[] locales = new ULocale[2];
|
||||
@ -415,14 +416,14 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
gp.reset();
|
||||
|
||||
logln("Get a resource bundle " + baseName +
|
||||
logln("Get a resource bundle " + baseName +
|
||||
" using GlobalizationPreferences initialized by locales - ja, en_US_California");
|
||||
|
||||
locales = new ULocale[2];
|
||||
locales[0] = new ULocale("ja");
|
||||
locales[1] = new ULocale("en_US_California");
|
||||
gp.setLocales(locales);
|
||||
|
||||
|
||||
try {
|
||||
rb = gp.getResourceBundle(baseName, Thread.currentThread().getContextClassLoader());
|
||||
String str = rb.getString("from_en_US");
|
||||
@ -478,7 +479,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
// Freeze
|
||||
logln("Freeze this object");
|
||||
gp.freeze();
|
||||
|
||||
|
||||
boolean bFrozen = false;
|
||||
try {
|
||||
gp.setTerritory("FR");
|
||||
@ -495,7 +496,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
}
|
||||
|
||||
// Safe clone
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
territory = gp1.getTerritory();
|
||||
if (!territory.equals("CA")) {
|
||||
errln("FAIL: Territory is " + territory + " - Expected: CA");
|
||||
@ -505,7 +506,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
ULocale[] locales = new ULocale[2];
|
||||
locales[0] = new ULocale("ja");
|
||||
locales[1] = new ULocale("zh_Hant_TW");
|
||||
|
||||
|
||||
logln("Set locales - ja, zh_Hant_TW");
|
||||
gp1.setLocales(locales);
|
||||
|
||||
@ -594,7 +595,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Safe clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
cur = gp.getCurrency();
|
||||
code = cur.getCurrencyCode();
|
||||
if (!code.equals("BRL")) {
|
||||
@ -674,7 +675,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Safe clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
cal = gp.getCalendar();
|
||||
calType = cal.getType();
|
||||
if (!calType.equals("japanese")) {
|
||||
@ -694,7 +695,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
public void TestTimeZone() {
|
||||
GlobalizationPreferences gp = new GlobalizationPreferences();
|
||||
|
||||
// Set locale - zh_CN
|
||||
// Set locale - zh_CN
|
||||
logln("Set locale - zh_CN");
|
||||
gp.setLocale(new ULocale("zh_CN"));
|
||||
TimeZone tz = gp.getTimeZone();
|
||||
@ -757,7 +758,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Modifiable clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
tz = gp1.getTimeZone();
|
||||
tzid = tz.getID();
|
||||
if (!tzid.equals(customJstId)) {
|
||||
@ -770,7 +771,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
tzid = tz.getID();
|
||||
if (!tzid.equals(cst.getID())) {
|
||||
errln("FAIL: Time zone ID is " + tzid + " Expected: " + cst.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -840,7 +841,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Modifiable clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
coll = gp1.getCollator();
|
||||
locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
|
||||
if (!locStr.equals("it")) {
|
||||
@ -939,7 +940,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Modifiable clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
brk = gp1.getBreakIterator(GlobalizationPreferences.BI_WORD);
|
||||
/* TODO: JB#5383
|
||||
locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
|
||||
@ -1207,7 +1208,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
// Set locale - en_GB
|
||||
logln("Set locale - en_GB");
|
||||
gp.setLocale(new ULocale("en_GB"));
|
||||
|
||||
|
||||
// Date - full
|
||||
df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
|
||||
pattern = ((SimpleDateFormat)df).toPattern();
|
||||
@ -1354,9 +1355,9 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
|
||||
// Modifiable clone
|
||||
logln("cloneAsThawed");
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
gp1.setDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE, customLD);
|
||||
|
||||
|
||||
df = gp1.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_SHORT);
|
||||
dfCal = df.getCalendar();
|
||||
if (!(dfCal instanceof JapaneseCalendar)) {
|
||||
@ -1397,7 +1398,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
if (!numStr.equals("\u20a9\u00a0123,457")) {
|
||||
errln("FAIL: Number string is " + numStr + " Expected: \u20a9\u00a0123,457");
|
||||
}
|
||||
|
||||
|
||||
// Set locale - de_DE
|
||||
logln("Set locale - de_DE");
|
||||
gp.setLocale(new ULocale("de_DE"));
|
||||
@ -1464,7 +1465,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
if (!illegalArg) {
|
||||
errln("FAIL: getNumberFormat must throw IllegalArgumentException for type -1");
|
||||
}
|
||||
|
||||
|
||||
// Set explicit territory
|
||||
logln("Set territory - US");
|
||||
gp.setTerritory("US");
|
||||
@ -1496,7 +1497,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
NumberFormat customInt = NumberFormat.getIntegerInstance(new ULocale("pt_PT"));
|
||||
gp.setNumberFormat(GlobalizationPreferences.NF_INTEGER, customInt);
|
||||
|
||||
|
||||
|
||||
nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
|
||||
if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("he_IL")) {
|
||||
errln("FAIL: The NumberFormat instance must use locale he_IL");
|
||||
@ -1535,7 +1536,7 @@ public class GlobalizationPreferencesTest extends TestFmwk {
|
||||
}
|
||||
|
||||
// Create a modifiable clone
|
||||
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
|
||||
GlobalizationPreferences gp1 = gp.cloneAsThawed();
|
||||
|
||||
// Number type format's locale is still he_IL
|
||||
nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
|
||||
|
@ -14,6 +14,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.text.RbnfScannerProviderImpl;
|
||||
@ -21,6 +23,7 @@ import com.ibm.icu.text.RbnfLenientScannerProvider;
|
||||
import com.ibm.icu.text.RuleBasedNumberFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class RbnfLenientScannerTest extends TestFmwk {
|
||||
private static final RbnfLenientScannerProvider provider = new RbnfScannerProviderImpl();
|
||||
|
||||
@ -160,7 +163,7 @@ public class RbnfLenientScannerTest extends TestFmwk {
|
||||
if (r == null) {
|
||||
r = createRandom();
|
||||
}
|
||||
n = ((int)(r.nextInt(10000) - 3000)) / 16d;
|
||||
n = (r.nextInt(10000) - 3000) / 16d;
|
||||
}
|
||||
|
||||
String s = fmt.format(n);
|
||||
|
@ -29,6 +29,8 @@ import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.BreakIterator;
|
||||
@ -39,6 +41,7 @@ import com.ibm.icu.text.SearchIterator.ElementComparisonType;
|
||||
import com.ibm.icu.text.StringSearch;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class SearchTest extends TestFmwk {
|
||||
|
||||
//inner class
|
||||
|
@ -11,6 +11,8 @@ package com.ibm.icu.dev.test.util;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
@ -19,7 +21,7 @@ import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public final class ICUResourceBundleCollationTest extends TestFmwk {
|
||||
private static final String COLLATION_RESNAME = "collations";
|
||||
private static final String COLLATION_KEYWORD = "collation";
|
||||
@ -146,7 +148,7 @@ public final class ICUResourceBundleCollationTest extends TestFmwk {
|
||||
|
||||
@Test
|
||||
public void TestOpen(){
|
||||
UResourceBundle bundle = (UResourceBundle)UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
|
||||
UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
|
||||
if(bundle==null){
|
||||
errln("could not load the stream");
|
||||
}
|
||||
|
@ -13,10 +13,13 @@ import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class LocaleAliasCollationTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
private static final ULocale[][] _LOCALES = {
|
||||
{new ULocale("en", "RH"), new ULocale("en", "ZW")},
|
||||
|
@ -23,6 +23,8 @@ import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.Collator;
|
||||
@ -33,17 +35,21 @@ import com.ibm.icu.text.LocaleDisplayNames.UiListItem;
|
||||
import com.ibm.icu.util.IllformedLocaleException;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ULocaleCollationTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestCollator() {
|
||||
checkService("ja_JP_YOKOHAMA", new ServiceFacade() {
|
||||
@Override
|
||||
public Object create(ULocale req) {
|
||||
return Collator.getInstance(req);
|
||||
}
|
||||
}, null, new Registrar() {
|
||||
@Override
|
||||
public Object register(ULocale loc, Object prototype) {
|
||||
return Collator.registerInstance((Collator) prototype, loc);
|
||||
}
|
||||
@Override
|
||||
public boolean unregister(Object key) {
|
||||
return Collator.unregister(key);
|
||||
}
|
||||
@ -233,99 +239,99 @@ public class ULocaleCollationTest extends TestFmwk {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestNameList() {
|
||||
String[][][] tests = {
|
||||
public void TestNameList() {
|
||||
String[][][] tests = {
|
||||
/* name in French, name in self, minimized, modified */
|
||||
{{"fr-Cyrl-BE", "fr-Cyrl-CA"},
|
||||
{"Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE"},
|
||||
{"Français (cyrillique, Canada)", "Français (cyrillique, Canada)", "fr_Cyrl_CA", "fr_Cyrl_CA"},
|
||||
},
|
||||
{{"en", "de", "fr", "zh"},
|
||||
{"Allemand", "Deutsch", "de", "de"},
|
||||
{"Anglais", "English", "en", "en"},
|
||||
{"Chinois", "中文", "zh", "zh"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
{{"fr-Cyrl-BE", "fr-Cyrl-CA"},
|
||||
{"Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE"},
|
||||
{"Français (cyrillique, Canada)", "Français (cyrillique, Canada)", "fr_Cyrl_CA", "fr_Cyrl_CA"},
|
||||
},
|
||||
{{"en", "de", "fr", "zh"},
|
||||
{"Allemand", "Deutsch", "de", "de"},
|
||||
{"Anglais", "English", "en", "en"},
|
||||
{"Chinois", "中文", "zh", "zh"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
// some non-canonical names
|
||||
{{"iw", "iw-US", "no", "no-Cyrl", "in", "in-YU"},
|
||||
{"Hébreu (États-Unis)", "עברית (ארצות הברית)", "iw_US", "iw_US"},
|
||||
{"Hébreu (Israël)", "עברית (ישראל)", "iw", "iw_IL"},
|
||||
{"Indonésien (Indonésie)", "Indonesia (Indonesia)", "in", "in_ID"},
|
||||
{"Indonésien (Serbie)", "Indonesia (Serbia)", "in_YU", "in_YU"},
|
||||
{"Norvégien (cyrillique)", "Norsk (kyrillisk)", "no_Cyrl", "no_Cyrl"},
|
||||
{"Norvégien (latin)", "Norsk (latinsk)", "no", "no_Latn"},
|
||||
},
|
||||
{{"zh-Hant-TW", "en", "en-gb", "fr", "zh-Hant", "de", "de-CH", "zh-TW"},
|
||||
{"Allemand (Allemagne)", "Deutsch (Deutschland)", "de", "de_DE"},
|
||||
{"Allemand (Suisse)", "Deutsch (Schweiz)", "de_CH", "de_CH"},
|
||||
{"Anglais (États-Unis)", "English (United States)", "en", "en_US"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois (traditionnel)", "中文(繁體)", "zh_Hant", "zh_Hant"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
{{"zh", "en-gb", "en-CA", "fr-Latn-FR"},
|
||||
{"Anglais (Canada)", "English (Canada)", "en_CA", "en_CA"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois", "中文", "zh", "zh"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
{{"en-gb", "fr", "zh-Hant", "zh-SG", "sr", "sr-Latn"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois (simplifié, Singapour)", "中文(简体,新加坡)", "zh_SG", "zh_Hans_SG"},
|
||||
{"Chinois (traditionnel, Taïwan)", "中文(繁體,台灣)", "zh_Hant", "zh_Hant_TW"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
{"Serbe (cyrillique)", "Српски (ћирилица)", "sr", "sr_Cyrl"},
|
||||
{"Serbe (latin)", "Srpski (latinica)", "sr_Latn", "sr_Latn"},
|
||||
},
|
||||
{{"fr-Cyrl", "fr-Arab"},
|
||||
{"Français (arabe)", "Français (arabe)", "fr_Arab", "fr_Arab"},
|
||||
{"Français (cyrillique)", "Français (cyrillique)", "fr_Cyrl", "fr_Cyrl"},
|
||||
},
|
||||
{{"fr-Cyrl-BE", "fr-Arab-CA"},
|
||||
{"Français (arabe, Canada)", "Français (arabe, Canada)", "fr_Arab_CA", "fr_Arab_CA"},
|
||||
{"Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE"},
|
||||
}
|
||||
};
|
||||
ULocale french = ULocale.FRENCH;
|
||||
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french,
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
|
||||
for (Type type : DisplayContext.Type.values()) {
|
||||
logln("Contexts: " + names.getContext(type).toString());
|
||||
}
|
||||
Collator collator = Collator.getInstance(french);
|
||||
{{"iw", "iw-US", "no", "no-Cyrl", "in", "in-YU"},
|
||||
{"Hébreu (États-Unis)", "עברית (ארצות הברית)", "iw_US", "iw_US"},
|
||||
{"Hébreu (Israël)", "עברית (ישראל)", "iw", "iw_IL"},
|
||||
{"Indonésien (Indonésie)", "Indonesia (Indonesia)", "in", "in_ID"},
|
||||
{"Indonésien (Serbie)", "Indonesia (Serbia)", "in_YU", "in_YU"},
|
||||
{"Norvégien (cyrillique)", "Norsk (kyrillisk)", "no_Cyrl", "no_Cyrl"},
|
||||
{"Norvégien (latin)", "Norsk (latinsk)", "no", "no_Latn"},
|
||||
},
|
||||
{{"zh-Hant-TW", "en", "en-gb", "fr", "zh-Hant", "de", "de-CH", "zh-TW"},
|
||||
{"Allemand (Allemagne)", "Deutsch (Deutschland)", "de", "de_DE"},
|
||||
{"Allemand (Suisse)", "Deutsch (Schweiz)", "de_CH", "de_CH"},
|
||||
{"Anglais (États-Unis)", "English (United States)", "en", "en_US"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois (traditionnel)", "中文(繁體)", "zh_Hant", "zh_Hant"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
{{"zh", "en-gb", "en-CA", "fr-Latn-FR"},
|
||||
{"Anglais (Canada)", "English (Canada)", "en_CA", "en_CA"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois", "中文", "zh", "zh"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
},
|
||||
{{"en-gb", "fr", "zh-Hant", "zh-SG", "sr", "sr-Latn"},
|
||||
{"Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB"},
|
||||
{"Chinois (simplifié, Singapour)", "中文(简体,新加坡)", "zh_SG", "zh_Hans_SG"},
|
||||
{"Chinois (traditionnel, Taïwan)", "中文(繁體,台灣)", "zh_Hant", "zh_Hant_TW"},
|
||||
{"Français", "Français", "fr", "fr"},
|
||||
{"Serbe (cyrillique)", "Српски (ћирилица)", "sr", "sr_Cyrl"},
|
||||
{"Serbe (latin)", "Srpski (latinica)", "sr_Latn", "sr_Latn"},
|
||||
},
|
||||
{{"fr-Cyrl", "fr-Arab"},
|
||||
{"Français (arabe)", "Français (arabe)", "fr_Arab", "fr_Arab"},
|
||||
{"Français (cyrillique)", "Français (cyrillique)", "fr_Cyrl", "fr_Cyrl"},
|
||||
},
|
||||
{{"fr-Cyrl-BE", "fr-Arab-CA"},
|
||||
{"Français (arabe, Canada)", "Français (arabe, Canada)", "fr_Arab_CA", "fr_Arab_CA"},
|
||||
{"Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE"},
|
||||
}
|
||||
};
|
||||
ULocale french = ULocale.FRENCH;
|
||||
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french,
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
|
||||
for (Type type : DisplayContext.Type.values()) {
|
||||
logln("Contexts: " + names.getContext(type).toString());
|
||||
}
|
||||
Collator collator = Collator.getInstance(french);
|
||||
|
||||
for (String[][] test : tests) {
|
||||
Set<ULocale> list = new LinkedHashSet<ULocale>();
|
||||
List<UiListItem> expected = new ArrayList<UiListItem>();
|
||||
for (String item : test[0]) {
|
||||
list.add(new ULocale(item));
|
||||
}
|
||||
for (int i = 1; i < test.length; ++i) {
|
||||
String[] rawRow = test[i];
|
||||
expected.add(new UiListItem(new ULocale(rawRow[2]), new ULocale(rawRow[3]), rawRow[0], rawRow[1]));
|
||||
}
|
||||
List<UiListItem> newList = names.getUiList(list, false, collator);
|
||||
if (!expected.equals(newList)) {
|
||||
if (expected.size() != newList.size()) {
|
||||
errln(list.toString() + ": wrong size" + expected + ", " + newList);
|
||||
} else {
|
||||
errln(list.toString());
|
||||
for (int i = 0; i < expected.size(); ++i) {
|
||||
assertEquals(i+"", expected.get(i), newList.get(i));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assertEquals(list.toString(), expected, newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String[][] test : tests) {
|
||||
Set<ULocale> list = new LinkedHashSet<ULocale>();
|
||||
List<UiListItem> expected = new ArrayList<UiListItem>();
|
||||
for (String item : test[0]) {
|
||||
list.add(new ULocale(item));
|
||||
}
|
||||
for (int i = 1; i < test.length; ++i) {
|
||||
String[] rawRow = test[i];
|
||||
expected.add(new UiListItem(new ULocale(rawRow[2]), new ULocale(rawRow[3]), rawRow[0], rawRow[1]));
|
||||
}
|
||||
List<UiListItem> newList = names.getUiList(list, false, collator);
|
||||
if (!expected.equals(newList)) {
|
||||
if (expected.size() != newList.size()) {
|
||||
errln(list.toString() + ": wrong size" + expected + ", " + newList);
|
||||
} else {
|
||||
errln(list.toString());
|
||||
for (int i = 0; i < expected.size(); ++i) {
|
||||
assertEquals(i+"", expected.get(i), newList.get(i));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assertEquals(list.toString(), expected, newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestIllformedLocale() {
|
||||
ULocale french = ULocale.FRENCH;
|
||||
Collator collator = Collator.getInstance(french);
|
||||
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french,
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
|
||||
ULocale french = ULocale.FRENCH;
|
||||
Collator collator = Collator.getInstance(french);
|
||||
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french,
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
|
||||
for (String malformed : Arrays.asList("en-a", "$", "ü--a", "en--US")) {
|
||||
try {
|
||||
Set<ULocale> supported = Collections.singleton(new ULocale(malformed));
|
||||
@ -333,7 +339,7 @@ public class ULocaleCollationTest extends TestFmwk {
|
||||
assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
|
||||
} catch (IllformedLocaleException e) {
|
||||
logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -24,6 +26,7 @@ import com.ibm.icu.text.BidiClassifier;
|
||||
* BiDi conformance test, using the Unicode BidiTest.txt and BidiCharacterTest.txt files.
|
||||
* Ported from ICU4C intltest/bidiconf.cpp .
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class BiDiConformanceTest extends TestFmwk {
|
||||
public BiDiConformanceTest() {}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
package com.ibm.icu.dev.test.bidi;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
@ -19,6 +21,7 @@ import com.ibm.icu.text.BidiTransform.Order;
|
||||
* @author Lina Kemmel
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class TestBidiTransform extends TestFmwk {
|
||||
|
||||
static final char LATN_ZERO = '\u0030';
|
||||
|
@ -14,6 +14,8 @@ package com.ibm.icu.dev.test.bigdec;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -97,6 +99,7 @@ import com.ibm.icu.math.BigDecimal;
|
||||
* @author Mike Cowlishaw
|
||||
*/
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DiagBigDecimalTest extends TestFmwk {
|
||||
private static final com.ibm.icu.math.BigDecimal zero = com.ibm.icu.math.BigDecimal.ZERO;
|
||||
private static final com.ibm.icu.math.BigDecimal one = com.ibm.icu.math.BigDecimal.ONE;
|
||||
|
@ -14,6 +14,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.CalendarAstronomer;
|
||||
@ -27,6 +29,7 @@ import com.ibm.icu.util.TimeZone;
|
||||
|
||||
// TODO: try finding next new moon after 07/28/1984 16:00 GMT
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class AstroTest extends TestFmwk {
|
||||
static final double PI = Math.PI;
|
||||
|
||||
@ -350,7 +353,7 @@ public class AstroTest extends TestFmwk {
|
||||
// astro.setDate(cal3.getTime());
|
||||
// astro.foo();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestMoonAge(){
|
||||
GregorianCalendar gc = new GregorianCalendar(new SimpleTimeZone(0,"GMT"));
|
||||
@ -363,7 +366,7 @@ public class AstroTest extends TestFmwk {
|
||||
{2012, 5, 20, 14, 55, 59},
|
||||
{2012, 5, 21, 7, 40, 40},
|
||||
{2023, 9, 25, 10,00, 00},
|
||||
{2008, 7, 7, 15, 00, 33},
|
||||
{2008, 7, 7, 15, 00, 33},
|
||||
{1832, 9, 24, 2, 33, 41 },
|
||||
{2016, 1, 31, 23, 59, 59},
|
||||
{2099, 5, 20, 14, 55, 59}
|
||||
|
@ -23,6 +23,8 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
@ -43,6 +45,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* 4145158 4145983 4147269 4149677 4162587 4165343 4166109 4167060 4173516
|
||||
* 4174361 4177484 4197699 4209071 4288792
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class CalendarRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
static final String[] FIELD_NAME = {
|
||||
"ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH",
|
||||
|
@ -27,7 +27,7 @@ import com.ibm.icu.util.SimpleTimeZone;
|
||||
* Defines various useful utility methods and constants
|
||||
*/
|
||||
public class CalendarTestFmwk extends TestFmwk {
|
||||
|
||||
|
||||
// Constants for use by subclasses, solely to save typing
|
||||
public final static int SUN = Calendar.SUNDAY;
|
||||
public final static int MON = Calendar.MONDAY;
|
||||
@ -49,7 +49,7 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
public final static int WOM = Calendar.WEEK_OF_MONTH;
|
||||
public final static int DOW = Calendar.DAY_OF_WEEK;
|
||||
public final static int DOWM = Calendar.DAY_OF_WEEK_IN_MONTH;
|
||||
|
||||
|
||||
public final static SimpleTimeZone UTC = new SimpleTimeZone(0, "GMT");
|
||||
|
||||
private static final String[] FIELD_NAME = {
|
||||
@ -75,14 +75,14 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
protected void doTestCases(TestCase[] cases, Calendar cal)
|
||||
{
|
||||
cal.setTimeZone(UTC);
|
||||
|
||||
|
||||
// Get a format to use for printing dates in the calendar system we're testing
|
||||
DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.SHORT, -1, Locale.getDefault());
|
||||
|
||||
final String pattern = (cal instanceof ChineseCalendar) ?
|
||||
"E MMl/dd/y G HH:mm:ss.S z" :
|
||||
"E, MM/dd/yyyy G HH:mm:ss.S z";
|
||||
|
||||
|
||||
((SimpleDateFormat)format).applyPattern(pattern);
|
||||
|
||||
// This format is used for printing Gregorian dates.
|
||||
@ -93,13 +93,13 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
pureGreg.setGregorianChange(new Date(Long.MIN_VALUE));
|
||||
DateFormat pureGregFmt = new SimpleDateFormat("E M/d/yyyy G");
|
||||
pureGregFmt.setCalendar(pureGreg);
|
||||
|
||||
|
||||
// Now iterate through the test cases and see what happens
|
||||
for (int i = 0; i < cases.length; i++)
|
||||
{
|
||||
logln("\ntest case: " + i);
|
||||
TestCase test = cases[i];
|
||||
|
||||
|
||||
//
|
||||
// First we want to make sure that the millis -> fields calculation works
|
||||
// test.applyTime will call setTime() on the calendar object, and
|
||||
@ -116,7 +116,7 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
|
||||
//
|
||||
// If that was OK, check the fields -> millis calculation
|
||||
// test.applyFields will set all of the calendar's fields to
|
||||
// test.applyFields will set all of the calendar's fields to
|
||||
// match those in the test case.
|
||||
//
|
||||
cal.clear();
|
||||
@ -128,10 +128,10 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public final boolean ROLL = true;
|
||||
static public final boolean ADD = false;
|
||||
|
||||
|
||||
/**
|
||||
* Process test cases for <code>add</code> and <code>roll</code> methods.
|
||||
* Each test case is an array of integers, as follows:
|
||||
@ -158,7 +158,7 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
protected void doRollAdd(boolean roll, Calendar cal, int[][] tests)
|
||||
{
|
||||
String name = roll ? "rolling" : "adding";
|
||||
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
int[] test = tests[i];
|
||||
|
||||
@ -346,7 +346,7 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
int testTime = TestFmwk.getExhaustiveness() <= 5 ? -3 : -120; // in seconds
|
||||
doLimitsTest(cal, fieldsToTest, startDate, testTime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the functions getMaximum/getGeratestMinimum logically correct.
|
||||
* This method assumes day of week cycle is consistent.
|
||||
@ -412,7 +412,7 @@ public class CalendarTestFmwk extends TestFmwk {
|
||||
errln("FAIL: Least maximum value of WEEK_OF_MONTH is incorrect: " + lmaxWOM + "/expected: " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert year,month,day values to the form "year/month/day".
|
||||
* On input the month value is zero-based, but in the result string it is one-based.
|
||||
|
@ -10,6 +10,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.text.ChineseDateFormat;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -63,6 +65,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* Tue May 22 2096 = 4733-04*-01, Year 53, Cycle 79
|
||||
* Sun Mar 22 2099 = 4736-02*-01, Year 56, Cycle 79
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class ChineseTest extends CalendarTestFmwk {
|
||||
/**
|
||||
* Test basic mapping to and from Gregorian.
|
||||
@ -79,7 +82,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
1964, 9, 7, 4601, 8,0, 2,
|
||||
1961, 12, 25, 4598, 11,0, 18,
|
||||
1999, 6, 4, 4636, 4,0, 21,
|
||||
|
||||
|
||||
1990, 5, 23, 4627, 4,0, 29,
|
||||
1990, 5, 24, 4627, 5,0, 1,
|
||||
1990, 6, 22, 4627, 5,0, 30,
|
||||
@ -205,7 +208,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
// ** Millis->fields gives 0-based month -1
|
||||
// These failures were fixed by changing the start search date
|
||||
// for the winter solstice from Dec 15 to Dec 1.
|
||||
//
|
||||
//
|
||||
// Julian Day Era Year Month Leap DOM WkDay
|
||||
new ChineseTestCase(1507231.5, 35, 11, 6, false, 12, SUN),
|
||||
new ChineseTestCase(1660037.5, 42, 9, 10, false, 27, WED),
|
||||
@ -222,7 +225,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
new ChineseTestCase(2195261.5, 66, 35, 3, false, 9, SUN), //*
|
||||
new ChineseTestCase(2229274.5, 68, 8, 5, false, 2, SUN), //*
|
||||
new ChineseTestCase(2245580.5, 68, 53, 1, false, 8, WED), //**
|
||||
new ChineseTestCase(2266100.5, 69, 49, 3, false, 4, SAT),
|
||||
new ChineseTestCase(2266100.5, 69, 49, 3, false, 4, SAT),
|
||||
new ChineseTestCase(2288542.5, 70, 50, 8, false, 2, SAT), //*
|
||||
new ChineseTestCase(2290901.5, 70, 57, 1, false, 29, SAT), //*
|
||||
new ChineseTestCase(2323140.5, 72, 25, 4, true, 20, WED), //*
|
||||
@ -268,14 +271,14 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
|
||||
java.util.Calendar tempcal = java.util.Calendar.getInstance();
|
||||
tempcal.clear();
|
||||
|
||||
|
||||
Date[] DATA = new Date[2];
|
||||
tempcal.set(2001, Calendar.MAY, 22);
|
||||
DATA[0] = tempcal.getTime();
|
||||
tempcal.set(2001, Calendar.MAY, 23);
|
||||
DATA[1] = tempcal.getTime();
|
||||
// Wed May 23 2001 = Month 4(leap), Day 1, Year 18, Cycle 78
|
||||
|
||||
|
||||
for (int i=0; i<DATA.length; ++i) {
|
||||
String s = fmt.format(DATA[i]);
|
||||
try {
|
||||
@ -315,14 +318,14 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
Calendar.DAY_OF_YEAR, 1,
|
||||
END,
|
||||
1,0,1, // Expect 1-1
|
||||
|
||||
|
||||
// If we set MONTH only, that should be used
|
||||
Calendar.IS_LEAP_MONTH, 1,
|
||||
Calendar.DAY_OF_MONTH, 1,
|
||||
Calendar.MONTH, 3,
|
||||
END,
|
||||
4,1,1, // Expect 4*-1
|
||||
|
||||
|
||||
// If we set the DOY last, that should take precedence
|
||||
Calendar.MONTH, 1, // Should ignore
|
||||
Calendar.IS_LEAP_MONTH, 1, // Should ignore
|
||||
@ -330,7 +333,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
Calendar.DAY_OF_YEAR, 121,
|
||||
END,
|
||||
4,1,2, // Expect 4*-2
|
||||
|
||||
|
||||
// I've disabled this test because it doesn't work this way,
|
||||
// not even with a GregorianCalendar! MONTH alone isn't enough
|
||||
// to supersede DAY_OF_YEAR. Some other month-related field is
|
||||
@ -342,7 +345,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
//! Calendar.MONTH, 3,
|
||||
//! END,
|
||||
//! 4,1,1, // Expect 4*-1
|
||||
|
||||
|
||||
// If we set IS_LEAP_MONTH last, that should take precedence
|
||||
Calendar.MONTH, 3,
|
||||
Calendar.DAY_OF_MONTH, 1,
|
||||
@ -448,7 +451,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
{ 4638, 4,0, 30, MONTH, 2, 4638, 5,0, 30 }, // no dom pin
|
||||
{ 4638, 4,0, 30, MONTH, 3, 4638, 6,0, 29 }, // dom should pin
|
||||
};
|
||||
|
||||
|
||||
ChineseCalendar cal = new ChineseCalendar();
|
||||
doRollAdd(ADD, cal, tests);
|
||||
}
|
||||
@ -480,14 +483,14 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
{ 4638, 4,0, 30, MONTH, 15, 4638, 5,0, 30 }, // no dom pin
|
||||
{ 4638, 4,0, 30, MONTH, -10, 4638, 6,0, 29 }, // dom should pin
|
||||
};
|
||||
|
||||
|
||||
ChineseCalendar cal = new ChineseCalendar();
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
|
||||
void doRollAdd(boolean roll, ChineseCalendar cal, int[][] tests) {
|
||||
String name = roll ? "rolling" : "adding";
|
||||
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
int[] test = tests[i];
|
||||
|
||||
@ -601,11 +604,11 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
errln("could not create ChineseCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
// new ChineseCalendar(TimeZone)
|
||||
ChineseCalendar cal = new ChineseCalendar(TimeZone.getDefault());
|
||||
ChineseCalendar cal = new ChineseCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create ChineseCalendar with TimeZone");
|
||||
}
|
||||
@ -689,7 +692,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
// if the chinese calendar current millis isn't called, the default year is wrong.
|
||||
// this test is assuming the 'year' is the current cycle
|
||||
// so when we cross a cycle boundary, the target will need to change
|
||||
// that shouldn't be for awhile yet...
|
||||
// that shouldn't be for awhile yet...
|
||||
|
||||
ChineseCalendar cc = new ChineseCalendar();
|
||||
cc.set(Calendar.YEAR, 22);
|
||||
@ -704,7 +707,7 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
cc.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
cc.add(Calendar.DATE, 1);
|
||||
|
||||
|
||||
Calendar cal = new GregorianCalendar(2005, Calendar.FEBRUARY, 28);
|
||||
Date target = cal.getTime();
|
||||
Date result = cc.getTime();
|
||||
@ -713,38 +716,38 @@ public class ChineseTest extends CalendarTestFmwk {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test6510()
|
||||
{
|
||||
Calendar gregorianCalendar;
|
||||
ChineseCalendar chineseCalendar, chineseCalendar2;
|
||||
ChineseDateFormat dateFormat;
|
||||
SimpleDateFormat simpleDateFormat;
|
||||
|
||||
simpleDateFormat = new com.ibm.icu.text.SimpleDateFormat("MM/dd/yyyy G 'at' HH:mm:ss vvvv", Locale.US);
|
||||
dateFormat = new com.ibm.icu.text.ChineseDateFormat("MM/dd/yyyy(G) HH:mm:ss", Locale.CHINA);
|
||||
|
||||
// lunar to gregorian
|
||||
chineseCalendar = new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6, 0, 0, 0);
|
||||
public void Test6510()
|
||||
{
|
||||
Calendar gregorianCalendar;
|
||||
ChineseCalendar chineseCalendar, chineseCalendar2;
|
||||
ChineseDateFormat dateFormat;
|
||||
SimpleDateFormat simpleDateFormat;
|
||||
|
||||
simpleDateFormat = new com.ibm.icu.text.SimpleDateFormat("MM/dd/yyyy G 'at' HH:mm:ss vvvv", Locale.US);
|
||||
dateFormat = new com.ibm.icu.text.ChineseDateFormat("MM/dd/yyyy(G) HH:mm:ss", Locale.CHINA);
|
||||
|
||||
// lunar to gregorian
|
||||
chineseCalendar = new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6, 0, 0, 0);
|
||||
// coverage
|
||||
assertEquals("equivalent ChineseCalendar() constructors", chineseCalendar,
|
||||
new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6));
|
||||
|
||||
gregorianCalendar = Calendar.getInstance(Locale.US);
|
||||
gregorianCalendar.setTime(chineseCalendar.getTime());
|
||||
|
||||
// gregorian to lunar
|
||||
chineseCalendar2 = new ChineseCalendar();
|
||||
chineseCalendar2.setTimeInMillis(gregorianCalendar.getTimeInMillis());
|
||||
gregorianCalendar = Calendar.getInstance(Locale.US);
|
||||
gregorianCalendar.setTime(chineseCalendar.getTime());
|
||||
|
||||
// validate roundtrip
|
||||
if (chineseCalendar.getTimeInMillis() != chineseCalendar2.getTimeInMillis())
|
||||
{
|
||||
errln("time1: " + chineseCalendar.getTimeInMillis());
|
||||
errln("time2: " + chineseCalendar2.getTimeInMillis());
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar));
|
||||
errln("**PROBLEM Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar2));
|
||||
}
|
||||
}
|
||||
// gregorian to lunar
|
||||
chineseCalendar2 = new ChineseCalendar();
|
||||
chineseCalendar2.setTimeInMillis(gregorianCalendar.getTimeInMillis());
|
||||
|
||||
// validate roundtrip
|
||||
if (chineseCalendar.getTimeInMillis() != chineseCalendar2.getTimeInMillis())
|
||||
{
|
||||
errln("time1: " + chineseCalendar.getTimeInMillis());
|
||||
errln("time2: " + chineseCalendar2.getTimeInMillis());
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar));
|
||||
errln("**PROBLEM Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar));
|
||||
errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,12 @@
|
||||
package com.ibm.icu.dev.test.calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.util.Calendar;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ChineseTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
@ -34,7 +38,7 @@ public class ChineseTestCase extends TestCase {
|
||||
boolean isLeapMonth, int dayOfMonth, int dayOfWeek) {
|
||||
|
||||
setTime(new Date(JULIAN_EPOCH + (long)(ONE_DAY * julian)));
|
||||
|
||||
|
||||
set(Calendar.ERA, era);
|
||||
set(Calendar.YEAR, year);
|
||||
set(Calendar.MONTH, month - 1);
|
||||
@ -46,6 +50,7 @@ public class ChineseTestCase extends TestCase {
|
||||
/**
|
||||
* Return a String representation of this test case's time.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return dowToString(get(Calendar.DAY_OF_WEEK)) +
|
||||
get(Calendar.YEAR) + "of" + get(Calendar.ERA) +
|
||||
|
@ -18,14 +18,18 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.GregorianCalendar;
|
||||
import com.ibm.icu.util.SimpleTimeZone;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
|
||||
public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class CompatibilityTest extends TestFmwk {
|
||||
static final String[] FIELD_NAME = {
|
||||
"ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH",
|
||||
"DAY_OF_MONTH", "DAY_OF_YEAR", "DAY_OF_WEEK",
|
||||
@ -40,12 +44,12 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
*/
|
||||
@Test
|
||||
public void TestGregorianChangeover() {
|
||||
|
||||
|
||||
java.util.TimeZone jdkGMT = java.util.TimeZone.getTimeZone("GMT");
|
||||
java.util.Calendar jdkCal = java.util.Calendar.getInstance(jdkGMT);
|
||||
jdkCal.clear();
|
||||
jdkCal.set(1582, Calendar.OCTOBER, 15);
|
||||
|
||||
|
||||
// if(jdkCal instanceof java.util.GregorianCalendar) {
|
||||
// logln("jdk IS grego");
|
||||
// java.util.GregorianCalendar jdkgc = (java.util.GregorianCalendar)
|
||||
@ -170,7 +174,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
final long ONE_DAY = 24*60*60*1000L;
|
||||
int[] DATA = {
|
||||
// Julian# Year Month DOM JULIAN:Year, Month, DOM
|
||||
2440588, 1970, Calendar.JANUARY, 1, 1969, Calendar.DECEMBER, 19,
|
||||
2440588, 1970, Calendar.JANUARY, 1, 1969, Calendar.DECEMBER, 19,
|
||||
2415080, 1900, Calendar.MARCH, 1, 1900, Calendar.FEBRUARY, 17,
|
||||
2451604, 2000, Calendar.FEBRUARY, 29, 2000, Calendar.FEBRUARY, 16,
|
||||
2452269, 2001, Calendar.DECEMBER, 25, 2001, Calendar.DECEMBER, 12,
|
||||
@ -208,7 +212,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
if (delta != 0 || year != year2 || month != month2 ||
|
||||
dom != dom2) errln(s + " FAIL");
|
||||
else logln(s);
|
||||
|
||||
|
||||
// Test Julian computation
|
||||
year = DATA[i+4];
|
||||
month = DATA[i+5];
|
||||
@ -274,7 +278,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
int tzoffset = 123400;
|
||||
|
||||
SimpleTimeZone zone = new SimpleTimeZone(tzoffset, tzid);
|
||||
Calendar cal = (Calendar)Calendar.getInstance((SimpleTimeZone)zone.clone());
|
||||
Calendar cal = Calendar.getInstance((SimpleTimeZone)zone.clone());
|
||||
|
||||
if (!zone.equals(cal.getTimeZone())) errln("FAIL: Calendar.getTimeZone failed");
|
||||
|
||||
@ -300,7 +304,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
cal.after(cal2)) errln("FAIL: equals/before/after failed");
|
||||
|
||||
// Roll back to January
|
||||
cal.roll(Calendar.MONTH, (int)(1 + Calendar.DECEMBER - cal.get(Calendar.MONTH)));
|
||||
cal.roll(Calendar.MONTH, 1 + Calendar.DECEMBER - cal.get(Calendar.MONTH));
|
||||
if (cal.equals(cal2) ||
|
||||
cal2.before(cal) ||
|
||||
cal.after(cal2)) errln("FAIL: equals/before/after failed");
|
||||
@ -786,7 +790,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public int getDay() { return day; }
|
||||
public int getHour() { return hour; }
|
||||
}
|
||||
final TransitionItem[] transitionItems = {
|
||||
final TransitionItem[] transitionItems = {
|
||||
new TransitionItem( "America/Caracas", 2007, Calendar.DECEMBER, 8, 10 ), // day before change in ZONE_OFFSET
|
||||
new TransitionItem( "US/Pacific", 2011, Calendar.MARCH, 12, 10 ), // day before change in DST_OFFSET
|
||||
};
|
||||
@ -1151,7 +1155,7 @@ public class CompatibilityTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
// jb4406 is probably not a bug, this is to document the behavior
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
final int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
|
||||
|
||||
|
||||
logln("julian day value jumps at changeover");
|
||||
for (int day = 12; day < 18; ++day) {
|
||||
cal.set(1582, 9, day);
|
||||
|
@ -12,6 +12,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -26,7 +28,8 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>CopticCalendar</code> class.
|
||||
*/
|
||||
public class CopticTest extends CalendarTestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class CopticTest extends CalendarTestFmwk
|
||||
{
|
||||
/** Constants to save typing. */
|
||||
public static final int TOUT = CopticCalendar.TOUT;
|
||||
@ -45,49 +48,49 @@ public class CopticTest extends CalendarTestFmwk
|
||||
|
||||
/* Test dates from:
|
||||
* "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
|
||||
*
|
||||
*
|
||||
* Coptic Gregorian JD
|
||||
* 20/02/1579 29/10/1862 2401443
|
||||
* 20/02/1579 29/10/1862 2401443
|
||||
* 29/10/1581 05/07/1865 2402423
|
||||
* 22/05/1582 29/01/1866 2402631
|
||||
* 10/08/1582 17/04/1866 2402709
|
||||
* 28/04/1583 05/01/1867 2402972
|
||||
* 05/05/1584 13/01/1868 2403345
|
||||
*
|
||||
*
|
||||
* --------------------------------------------------
|
||||
*
|
||||
*
|
||||
* From the Calendrica applet: http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
|
||||
*
|
||||
*
|
||||
* Coptic Gregorian JD
|
||||
* 07/05/-284 01/01/0000 1721060
|
||||
* 08/05/-283 01/01/0001 1721426
|
||||
* 06/13/-1 29/08/0283 1824664
|
||||
*
|
||||
*
|
||||
* 01/01/0000 30/08/0283 1824665
|
||||
* 01/01/0001 29/08/0284 1825030
|
||||
* 01/01/0002 29/08/0285 1825395
|
||||
* 01/01/0003 29/08/0286 1825760
|
||||
* 01/01/0004 30/08/0287 1826126
|
||||
* 05/13/0000 28/08/0284 1825029
|
||||
* 05/13/0000 28/08/0284 1825029
|
||||
* 05/13/0001 28/08/0285 1825394
|
||||
* 05/13/0002 28/08/0286 1825759
|
||||
* 05/13/0003 28/08/0287 1826124
|
||||
* 06/13/0003 29/08/0287 1826125 first coptic leap year
|
||||
* 05/13/0004 28/08/0288 1826490
|
||||
*
|
||||
*
|
||||
* 06/02/1299 13/10/1582 2299159
|
||||
* 07/02/1299 14/10/1582 2299160 Julian 04/10/1582
|
||||
* 08/02/1299 15/10/1582 2299161
|
||||
* 09/02/1299 16/10/1582 2299162
|
||||
*
|
||||
*
|
||||
* 23/04/1616 01/01/1900 2415021
|
||||
* 23/04/1721 01/01/2005 2453372
|
||||
* 23/04/1721 01/01/2005 2453372
|
||||
* 05/13/2000 12/09/2284 2555529
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
@ -134,7 +137,7 @@ public class CopticTest extends CalendarTestFmwk
|
||||
new TestCase(2453371.5, 1, 1721, 4, 23, SAT, 0, 0, 0), // Gregorian: 01/01/2005
|
||||
new TestCase(2555528.5, 1, 2000, 13, 5, FRI, 0, 0, 0), // Gregorian: 12/09/2284
|
||||
};
|
||||
|
||||
|
||||
CopticCalendar testCalendar = new CopticCalendar();
|
||||
testCalendar.setLenient(true);
|
||||
doTestCases(tests, testCalendar);
|
||||
@ -157,8 +160,8 @@ public class CopticTest extends CalendarTestFmwk
|
||||
m == month &&
|
||||
d == day)) {
|
||||
errln("y: " + y +
|
||||
" m: " + m +
|
||||
" d: " + d +
|
||||
" m: " + m +
|
||||
" d: " + d +
|
||||
" --> jd: " + jd +
|
||||
" --> y: " + eyear +
|
||||
" m: " + month +
|
||||
@ -194,13 +197,13 @@ public class CopticTest extends CalendarTestFmwk
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30-> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
@ -238,19 +241,19 @@ public class CopticTest extends CalendarTestFmwk
|
||||
|
||||
int expected = (month != maxMonth) ? 30 : (isLeap ? 6 : 5);
|
||||
if (maxDayOfMonth != expected) {
|
||||
errln("FAIL: Expected maximum " + expected + " days for month #"
|
||||
+ (month + 1) + " - returned:" + maxDayOfMonth);
|
||||
errln("FAIL: Expected maximum " + expected + " days for month #"
|
||||
+ (month + 1) + " - returned:" + maxDayOfMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault());
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone");
|
||||
}
|
||||
@ -263,7 +266,7 @@ public class CopticTest extends CalendarTestFmwk
|
||||
errln("could not create CopticCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new CopticCalendar(Locale)
|
||||
CopticCalendar cal = new CopticCalendar(Locale.getDefault());
|
||||
@ -271,23 +274,23 @@ public class CopticTest extends CalendarTestFmwk
|
||||
errln("could not create CopticCalendar with Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone, Locale)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault(),Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone, Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone, ULocale)
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone, Locale)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault(),Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone, Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone, ULocale)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault(),ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone, ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone, ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(Date)
|
||||
CopticCalendar cal = new CopticCalendar(new Date());
|
||||
@ -311,7 +314,7 @@ public class CopticTest extends CalendarTestFmwk
|
||||
errln("could not create CopticCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
@ -420,7 +423,7 @@ public class CopticTest extends CalendarTestFmwk
|
||||
int endMonth = testCalendar.get(Calendar.MONTH);
|
||||
int endDay = testCalendar.get(Calendar.DATE);
|
||||
if ( endYear != item.getEndYear() || endMonth != item.getEndMonth() || endDay != item.getEndDay() ) {
|
||||
errln("CToJD FAILS: field " + item.getField() + " delta " + item.getDelta() +
|
||||
errln("CToJD FAILS: field " + item.getField() + " delta " + item.getDelta() +
|
||||
" expected yr " + item.getEndYear() + " mo " + item.getEndMonth() + " da " + item.getEndDay() +
|
||||
" got yr " + endYear + " mo " + endMonth + " da " + endDay);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ package com.ibm.icu.dev.test.calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
@ -18,6 +20,7 @@ import com.ibm.icu.util.GregorianCalendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DangiTest extends CalendarTestFmwk {
|
||||
/**
|
||||
* Test basic mapping to and from Gregorian.
|
||||
@ -33,7 +36,7 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
1964, 9, 7, 4297, 8,0, 2,
|
||||
1961, 12, 25, 4294, 11,0, 18,
|
||||
1999, 6, 4, 4332, 4,0, 21,
|
||||
|
||||
|
||||
1990, 5, 23, 4323, 4,0, 29,
|
||||
1990, 5, 24, 4323, 5,0, 1,
|
||||
1990, 6, 22, 4323, 5,0, 30,
|
||||
@ -190,14 +193,14 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
Calendar.DAY_OF_YEAR, 1,
|
||||
END,
|
||||
1,0,1, // Expect 1-1
|
||||
|
||||
|
||||
// If we set MONTH only, that should be used
|
||||
Calendar.IS_LEAP_MONTH, 1,
|
||||
Calendar.DAY_OF_MONTH, 1,
|
||||
Calendar.MONTH, 3,
|
||||
END,
|
||||
4,1,1, // Expect 4*-1
|
||||
|
||||
|
||||
// If we set the DOY last, that should take precedence
|
||||
Calendar.MONTH, 1, // Should ignore
|
||||
Calendar.IS_LEAP_MONTH, 1, // Should ignore
|
||||
@ -205,7 +208,7 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
Calendar.DAY_OF_YEAR, 121,
|
||||
END,
|
||||
4,1,2, // Expect 4*-2
|
||||
|
||||
|
||||
// If we set IS_LEAP_MONTH last, that should take precedence
|
||||
Calendar.MONTH, 3,
|
||||
Calendar.DAY_OF_MONTH, 1,
|
||||
@ -309,7 +312,7 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
{ 4334, 3,0, 30, MONTH, 3, 4334, 5,0, 30 }, // no dom pin
|
||||
{ 4334, 3,0, 30, MONTH, 4, 4334, 6,0, 29 }, // dom should pin
|
||||
};
|
||||
|
||||
|
||||
Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
|
||||
doRollAddDangi(ADD, cal, tests);
|
||||
}
|
||||
@ -341,11 +344,11 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
{ 4334, 3,0, 30, MONTH, 16, 4334, 5,0, 30 }, // no dom pin
|
||||
{ 4334, 3,0, 30, MONTH, -9, 4334, 6,0, 29 }, // dom should pin
|
||||
};
|
||||
|
||||
|
||||
Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
|
||||
doRollAddDangi(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
|
||||
void doRollAddDangi(boolean roll, Calendar cal, int[][] tests) {
|
||||
String name = roll ? "rolling" : "adding";
|
||||
|
||||
@ -410,7 +413,7 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
// If the chinese calendar current millis isn't called, the default year is wrong.
|
||||
// this test is assuming the 'year' is the current cycle
|
||||
// so when we cross a cycle boundary, the target will need to change
|
||||
// that shouldn't be for awhile yet...
|
||||
// that shouldn't be for awhile yet...
|
||||
|
||||
Calendar cc = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
|
||||
cc.set(Calendar.EXTENDED_YEAR, 4338);
|
||||
@ -425,7 +428,7 @@ public class DangiTest extends CalendarTestFmwk {
|
||||
cc.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
cc.add(Calendar.DATE, 1);
|
||||
|
||||
|
||||
Calendar cal = new GregorianCalendar(2005, Calendar.FEBRUARY, 28);
|
||||
Date target = cal.getTime();
|
||||
Date result = cc.getTime();
|
||||
|
@ -12,6 +12,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -25,7 +27,8 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>EthiopicCalendar</code> class.
|
||||
*/
|
||||
public class EthiopicTest extends CalendarTestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class EthiopicTest extends CalendarTestFmwk
|
||||
{
|
||||
/** Constants to save typing. */
|
||||
public static final int MESKEREM = EthiopicCalendar.MESKEREM;
|
||||
@ -42,13 +45,13 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
public static final int NEHASSE = EthiopicCalendar.NEHASSE;
|
||||
public static final int PAGUMEN = EthiopicCalendar.PAGUMEN;
|
||||
|
||||
/* DY[20050507] I don't know what this is for yet:
|
||||
/* DY[20050507] I don't know what this is for yet:
|
||||
@Test
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
|
||||
{ 0001, QIDAH, 2, MONTH, 1, 0001, HIJJAH, 2 }, // non-leap years
|
||||
{ 0001, QIDAH, 2, MONTH, 2, 0001, MUHARRAM, 2 },
|
||||
{ 0001, QIDAH, 2, MONTH, -1, 0001, SHAWWAL, 2 },
|
||||
@ -62,7 +65,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
{ 0001, MUHARRAM, 30, MONTH, 1, 0001, SAFAR, 29 },
|
||||
{ 0002, HIJJAH, 30, YEAR, -1, 0001, HIJJAH, 29 },
|
||||
};
|
||||
|
||||
|
||||
EthiopicCalendar cal = newCivil();
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
@ -71,9 +74,9 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
|
||||
/* Test dates from:
|
||||
* "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
|
||||
*
|
||||
*
|
||||
* Ethiopic Gregorian JD
|
||||
* 20/02/1855 29/10/1862 2401443
|
||||
* 29/10/1857 05/07/1865 2402423
|
||||
@ -81,16 +84,16 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
* 10/08/1858 17/04/1866 2402709
|
||||
* 28/04/1859 05/01/1867 2402972
|
||||
* 05/05/1860 13/01/1868 2403345
|
||||
*
|
||||
*
|
||||
* --------------------------------------------------
|
||||
*
|
||||
*
|
||||
* From the Calendrica applet: http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
|
||||
*
|
||||
*
|
||||
* Ethiopic Gregorian JD
|
||||
* 07/05/-8 01/01/0000 1721060
|
||||
* 08/05/-7 01/01/0001 1721426
|
||||
* 06/13/-1 27/08/0007 1723855
|
||||
*
|
||||
*
|
||||
* 01/01/0000 28/08/0007 1723856
|
||||
* 01/01/0001 27/08/0008 1724221
|
||||
* 01/01/0002 27/08/0009 1724586
|
||||
@ -102,17 +105,17 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
* 05/13/0003 26/08/0011 1725315
|
||||
* 06/13/0003 27/08/0011 1725316 first ethiopian leap year
|
||||
* 05/13/0004 26/08/0012 1725561
|
||||
*
|
||||
*
|
||||
* 06/02/1575 13/10/1582 2299159
|
||||
* 07/02/1575 14/10/1582 2299160 Julian 04/10/1582
|
||||
* 08/02/1575 15/10/1582 2299161
|
||||
* 09/02/1575 16/10/1582 2299162
|
||||
*
|
||||
*
|
||||
* 23/04/1892 01/01/1900 2415021
|
||||
* 23/04/1997 01/01/2005 2453372
|
||||
* 05/13/2000 10/09/2008 2454720
|
||||
*/
|
||||
|
||||
|
||||
/** A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
@ -134,7 +137,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
new TestCase(2402708.5, 1, 1858, 8, 10, TUE, 0, 0, 0), // Gregorian: 17/04/1866
|
||||
new TestCase(2402971.5, 1, 1859, 4, 28, SAT, 0, 0, 0), // Gregorian: 05/01/1867
|
||||
new TestCase(2403344.5, 1, 1860, 5, 5, MON, 0, 0, 0), // Gregorian: 13/01/1868
|
||||
|
||||
|
||||
// Miscellaneous:
|
||||
/* Skip these tests until JD bug fixed in the Gregorian calendar:
|
||||
* http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest
|
||||
@ -157,7 +160,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
new TestCase(1725315.5, 1, 3, 13, 6, SAT, 0, 0, 0), // Gregorian: 27/08/0011 - first ethiopic leap year
|
||||
// new TestCase(1725560.5, 1, 4, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012 - dlf
|
||||
new TestCase(1725680.5, 1, 4, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012
|
||||
new TestCase(2299158.5, 1, 1575, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
|
||||
new TestCase(2299158.5, 1, 1575, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
|
||||
new TestCase(2299159.5, 1, 1575, 2, 7, THU, 0, 0, 0), // Gregorian: 14/10/1582 Julian 04/10/1582
|
||||
|
||||
new TestCase(2299160.5, 1, 1575, 2, 8, FRI, 0, 0, 0), // Gregorian: 15/10/1582
|
||||
@ -183,7 +186,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
new TestCase(2402708.5, 0, 7358, 8, 10, TUE, 0, 0, 0), // Gregorian: 17/04/1866
|
||||
new TestCase(2402971.5, 0, 7359, 4, 28, SAT, 0, 0, 0), // Gregorian: 05/01/1867
|
||||
new TestCase(2403344.5, 0, 7360, 5, 5, MON, 0, 0, 0), // Gregorian: 13/01/1868
|
||||
|
||||
|
||||
// Miscellaneous:
|
||||
/* Skip these tests until JD bug fixed in the Gregorian calendar:
|
||||
* http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest
|
||||
@ -206,7 +209,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
new TestCase(1725315.5, 0, 5503, 13, 6, SAT, 0, 0, 0), // Gregorian: 27/08/0011 - first ethiopic leap year
|
||||
// new TestCase(1725560.5, 0, 5504, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012 - dlf
|
||||
new TestCase(1725680.5, 0, 5504, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012
|
||||
new TestCase(2299158.5, 0, 7075, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
|
||||
new TestCase(2299158.5, 0, 7075, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
|
||||
new TestCase(2299159.5, 0, 7075, 2, 7, THU, 0, 0, 0), // Gregorian: 14/10/1582 Julian 04/10/1582
|
||||
|
||||
new TestCase(2299160.5, 0, 7075, 2, 8, FRI, 0, 0, 0), // Gregorian: 15/10/1582
|
||||
@ -244,11 +247,11 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
assertEquals("Ethiopic Date", "Tue Jan 01, 5500 BC", fmt.format(cal));
|
||||
|
||||
// The gregorian calendar gets off by two days when
|
||||
// the date gets low, unless the gregorian changeover is set to
|
||||
// the date gets low, unless the gregorian changeover is set to
|
||||
// very early. The funny thing is, it's ok for dates in the year
|
||||
// 283, but not in the year 7, and it claims to be ok until the year 4.
|
||||
// should track down when the dates start to differ...
|
||||
|
||||
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
gc.setGregorianChange(new Date(Long.MIN_VALUE)); // act like proleptic Gregorian
|
||||
gc.setTime(cal.getTime());
|
||||
@ -263,16 +266,16 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30-> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestJD(){
|
||||
int jd = EthiopicCalendar.EthiopicToJD(1567,8,9);
|
||||
@ -300,13 +303,13 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
doTheoreticalLimitsTest(ethiopic, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(TimeZone)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault());
|
||||
EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with TimeZone");
|
||||
}
|
||||
@ -319,7 +322,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
errln("could not create EthiopicCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(Locale)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(Locale.getDefault());
|
||||
@ -343,7 +346,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
errln("could not create EthiopicCalendar with TimeZone,ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(Date)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(new Date());
|
||||
@ -393,7 +396,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
|
||||
logln(cal.getTime().toString());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
@ -420,7 +423,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static EthiopicCalendar newAmeteAlemEraCalendar() {
|
||||
EthiopicCalendar alemawiCalendar = new EthiopicCalendar();
|
||||
alemawiCalendar.setAmeteAlemEra(true);
|
||||
@ -477,7 +480,7 @@ public class EthiopicTest extends CalendarTestFmwk
|
||||
int endMonth = testCalendar.get(Calendar.MONTH);
|
||||
int endDay = testCalendar.get(Calendar.DATE);
|
||||
if ( endYear != item.getEndYear() || endMonth != item.getEndMonth() || endDay != item.getEndDay() ) {
|
||||
errln("EToJD FAILS: field " + item.getField() + " delta " + item.getDelta() +
|
||||
errln("EToJD FAILS: field " + item.getField() + " delta " + item.getDelta() +
|
||||
" expected yr " + item.getEndYear() + " mo " + item.getEndMonth() + " da " + item.getEndDay() +
|
||||
" got yr " + endYear + " mo " + endMonth + " da " + endDay);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -24,6 +26,7 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>HebrewCalendar</code> class.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class HebrewTest extends CalendarTestFmwk {
|
||||
// Constants to save typing.
|
||||
public static final int TISHRI = HebrewCalendar.TISHRI;
|
||||
@ -50,7 +53,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
|
||||
{ 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years
|
||||
{ 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 },
|
||||
@ -64,13 +67,13 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5757, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5757, SHEVAT, 2 },
|
||||
{ 5757, AV, 1, MONTH, 12, 5757, TAMUZ, 1 }, // Alan
|
||||
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, KISLEV, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, KISLEV, 2 }, // 30-day month
|
||||
|
||||
|
||||
// Try some other fields too
|
||||
{ 5757, TISHRI, 1, YEAR, 1, 5758, TISHRI, 1 },
|
||||
|
||||
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 5757, TISHRI, 30, MONTH, 1, 5757, HESHVAN, 29 },
|
||||
@ -78,13 +81,13 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
};
|
||||
// try{
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
// }catch(MissingResourceException ex){
|
||||
// warnln("Got Exception: "+ ex.getMessage());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the behavior of HebrewCalendar.roll
|
||||
* The only real nastiness with roll is the MONTH field, since a year can
|
||||
@ -106,18 +109,18 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
{ 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5758, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5758, SHEVAT, 2 },
|
||||
|
||||
|
||||
{ 5762, AV, 1, MONTH, 1, 5762, ELUL, 1 }, // JB#2327
|
||||
{ 5762, AV, 30, DATE, 1, 5762, ELUL, 1 }, // JB#2327
|
||||
{ 5762, ELUL, 1, DATE, -1, 5762, AV, 30 }, // JB#2327
|
||||
{ 5762, ELUL, 1, MONTH, -1, 5762, AV, 1 }, // JB#2327
|
||||
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, TEVET, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, TEVET, 2 }, // 30-day month
|
||||
};
|
||||
try{
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
|
||||
doRollAdd(ADD, cal, tests);
|
||||
}catch( MissingResourceException ex){
|
||||
warnln("Could not load the locale data");
|
||||
@ -208,8 +211,8 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
new TestCase(2459464.5, 0, 5782, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2467142.5, 0, 5803, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2455448.5, 0, 5771, 1, 1, THU, 0, 0, 0),
|
||||
|
||||
// Test cases for JB#2327
|
||||
|
||||
// Test cases for JB#2327
|
||||
// http://www.fourmilab.com/documents/calendar/
|
||||
// http://www.calendarhome.com/converter/
|
||||
// 2452465.5, 2002, JULY, 10, 5762, AV, 1,
|
||||
@ -225,7 +228,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
new TestCase(2452524.5, 0, 5763,TISHRI+1, 1, SAT, 0, 0, 0),
|
||||
};
|
||||
doTestCases(testCases, new HebrewCalendar());
|
||||
|
||||
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Got Exception: "+ ex.getMessage());
|
||||
}
|
||||
@ -265,14 +268,14 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
// I hope that year = 0 does not exists
|
||||
// because the test fails for it !
|
||||
cal.clear();
|
||||
|
||||
|
||||
cal.set(Calendar.YEAR, year);
|
||||
cal.set(Calendar.MONTH, ELUL);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
|
||||
int yact = cal.get(Calendar.YEAR);
|
||||
int mact = cal.get(Calendar.MONTH);
|
||||
|
||||
|
||||
if (year != yact || ELUL != mact) {
|
||||
errln("Fail: " + ELUL + "/" + year +
|
||||
" -> " +
|
||||
@ -281,9 +284,9 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
}
|
||||
}catch(MissingResourceException ex){
|
||||
warnln("Got Exception: "+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test of the behavior of the month field. This requires special
|
||||
* handling in the Hebrew calendar because of the pattern of leap
|
||||
@ -298,7 +301,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
// We can't test complete() on some lines below because of ADAR_1 -- if
|
||||
// the calendar is set to ADAR_1 on a non-leap year, the result is undefined.
|
||||
int[] DATA = {
|
||||
// m1/y1 - month/year before (month is 1-based)
|
||||
// m1/y1 - month/year before (month is 1-based)
|
||||
// delta - amount to add to month field
|
||||
// m2/y2 - month/year after add(MONTH, delta)
|
||||
// m3/y3 - month/year after set(MONTH, m1+delta)
|
||||
@ -319,7 +322,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
int m2 = DATA[i++], y2 = DATA[i++];
|
||||
int m3 = DATA[i++], y3 = DATA[i++];
|
||||
int mact, yact;
|
||||
|
||||
|
||||
cal.clear();
|
||||
cal.set(Calendar.YEAR, y);
|
||||
cal.set(Calendar.MONTH, m-1);
|
||||
@ -341,7 +344,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
(cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cal.clear();
|
||||
cal.set(Calendar.YEAR, y);
|
||||
cal.set(Calendar.MONTH, m + monthDelta - 1);
|
||||
@ -415,7 +418,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
errln("could not create HebrewCalendar with TimeZone");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new HebrewCalendar(ULocale)
|
||||
HebrewCalendar cal = new HebrewCalendar(ULocale.getDefault());
|
||||
@ -423,7 +426,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
errln("could not create HebrewCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new HebrewCalendar(Locale)
|
||||
HebrewCalendar cal = new HebrewCalendar(Locale.getDefault());
|
||||
@ -431,7 +434,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
errln("could not create HebrewCalendar with locale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new HebrewCalendar(Date)
|
||||
HebrewCalendar cal = new HebrewCalendar(new Date());
|
||||
@ -439,16 +442,16 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
errln("could not create HebrewCalendar with date");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
HebrewCalendar cal = new HebrewCalendar(2800, HebrewCalendar.SHEVAT, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
|
||||
String[] calendarLocales = {
|
||||
"iw_IL"
|
||||
};
|
||||
|
||||
|
||||
String[] formatLocales = {
|
||||
"en", "fi", "fr", "hu", "iw", "nl"
|
||||
};
|
||||
@ -456,7 +459,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new HebrewCalendar(calLocale);
|
||||
|
||||
|
||||
for (int j = 0; j < formatLocales.length; ++j) {
|
||||
String locName = formatLocales[j];
|
||||
Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
|
||||
@ -476,7 +479,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
HebrewCalendar hc = new HebrewCalendar (5742, HebrewCalendar.AV, 22);
|
||||
DateFormat df = hc.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());
|
||||
String dateString = df.format(hc.getTime());
|
||||
|
||||
|
||||
for (int year = 5600; year < 5800; year ++) {
|
||||
boolean leapYear = HebrewCalendar.isLeapYear (year);
|
||||
for (int month = HebrewCalendar.TISHRI; month <= HebrewCalendar.ELUL;month++) {
|
||||
@ -506,7 +509,7 @@ public class HebrewTest extends CalendarTestFmwk {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test case for Ticket#10313. HebrewCalendar requires
|
||||
|
@ -13,6 +13,8 @@ import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
@ -29,6 +31,7 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>Holiday</code> class.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class HolidayTest extends TestFmwk {
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
@ -38,7 +41,7 @@ public class HolidayTest extends TestFmwk {
|
||||
now = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Calendar cal;
|
||||
private Date longTimeAgo;
|
||||
private Date now;
|
||||
@ -135,8 +138,8 @@ public class HolidayTest extends TestFmwk {
|
||||
// logln("rule: " + h.getRule().toString());
|
||||
|
||||
// h.setRule(h.getRule());
|
||||
|
||||
|
||||
|
||||
|
||||
logln("HolidayCalendarDemo test");
|
||||
{
|
||||
final Calendar c = Calendar.getInstance(TimeZone.GMT_ZONE); // Temporary copy
|
||||
@ -253,7 +256,7 @@ public class HolidayTest extends TestFmwk {
|
||||
logln("first between " + abd + " and " + xbd + " is " + rdr.firstBetween(abd, xbd));
|
||||
logln("first between " + abd + " and " + null + " is " + rdr.firstBetween(abd, null));
|
||||
logln("first between " + xbd + " and " + null + " is " + rdr.firstBetween(xbd, null));
|
||||
|
||||
|
||||
//getRule, setRule
|
||||
logln("The rule in the holiday: " + h[1].getRule());
|
||||
exerciseHoliday(h[1], Locale.getDefault());
|
||||
@ -264,16 +267,16 @@ public class HolidayTest extends TestFmwk {
|
||||
}
|
||||
exerciseHoliday(h[1], Locale.getDefault());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestEaster(){
|
||||
public void TestEaster(){
|
||||
// Verify that Easter is working. Should be April 20, 2014
|
||||
final Holiday h = new EasterHoliday("Easter Sunday");
|
||||
final Date beginApril = getDate(2014, Calendar.APRIL, 1);
|
||||
final Date endApril = getDate(2014, Calendar.APRIL, 30);
|
||||
final Date expect = getDate(2014, Calendar.APRIL, 20);
|
||||
final Date actual = h.firstBetween(beginApril, endApril);
|
||||
|
||||
|
||||
if(actual == null) {
|
||||
errln("Error: Easter 2014 should be on " + expect + " but got null.");
|
||||
} else {
|
||||
@ -289,13 +292,13 @@ public class HolidayTest extends TestFmwk {
|
||||
public void TestIsOn() {
|
||||
// jb 1901
|
||||
SimpleHoliday sh = new SimpleHoliday(Calendar.AUGUST, 15, "Doug's Day", 1958, 2058);
|
||||
|
||||
|
||||
Calendar gcal = new GregorianCalendar();
|
||||
gcal.clear();
|
||||
gcal.set(Calendar.YEAR, 2000);
|
||||
gcal.set(Calendar.MONTH, Calendar.AUGUST);
|
||||
gcal.set(Calendar.DAY_OF_MONTH, 15);
|
||||
|
||||
|
||||
Date d0 = gcal.getTime();
|
||||
gcal.add(Calendar.SECOND, 1);
|
||||
Date d1 = gcal.getTime();
|
||||
@ -329,7 +332,7 @@ public class HolidayTest extends TestFmwk {
|
||||
logln("firstAfter: " + h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestDisplayName() {
|
||||
Holiday[] holidays = Holiday.getHolidays(ULocale.US);
|
||||
|
@ -15,6 +15,8 @@ import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.CalendarAstronomer;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
@ -35,6 +37,7 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* @summary Tests of new functionality in IBMCalendar
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class IBMCalendarTest extends CalendarTestFmwk {
|
||||
/**
|
||||
* Test weekend support in IBMCalendar.
|
||||
|
@ -12,6 +12,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -25,10 +27,11 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>IndianCalendar</code> class.
|
||||
*/
|
||||
public class IndianTest extends CalendarTestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IndianTest extends CalendarTestFmwk
|
||||
{
|
||||
// Months in indian calendar are 0-based. Here taking 1-based names:
|
||||
public static final int CHAITRA = IndianCalendar.CHAITRA + 1;
|
||||
public static final int CHAITRA = IndianCalendar.CHAITRA + 1;
|
||||
public static final int VAISAKHA = IndianCalendar.VAISAKHA + 1;
|
||||
public static final int JYAISTHA = IndianCalendar.JYAISTHA + 1;
|
||||
public static final int ASADHA = IndianCalendar.ASADHA + 1;
|
||||
@ -43,8 +46,8 @@ public class IndianTest extends CalendarTestFmwk
|
||||
|
||||
/** Constants to save typing. */
|
||||
/* Test dates generated from:
|
||||
* http://www.fourmilab.ch/documents/calendar/
|
||||
|
||||
* http://www.fourmilab.ch/documents/calendar/
|
||||
|
||||
/** A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the Indian civil calendar.
|
||||
*/
|
||||
@ -100,7 +103,7 @@ public class IndianTest extends CalendarTestFmwk
|
||||
new TestCase(2465737.5, 0, 1960, KARTIKA, 19, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 2016, ASADHA, 27, SUN, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
IndianCalendar testCalendar = new IndianCalendar();
|
||||
testCalendar.setLenient(true);
|
||||
doTestCases(tests, testCalendar);
|
||||
@ -113,13 +116,13 @@ public class IndianTest extends CalendarTestFmwk
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30-> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
@ -127,7 +130,7 @@ public class IndianTest extends CalendarTestFmwk
|
||||
public void TestCoverage() {
|
||||
{
|
||||
// new IndianCalendar(TimeZone)
|
||||
IndianCalendar cal = new IndianCalendar(TimeZone.getDefault());
|
||||
IndianCalendar cal = new IndianCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create IndianCalendar with TimeZone");
|
||||
}
|
||||
@ -140,7 +143,7 @@ public class IndianTest extends CalendarTestFmwk
|
||||
errln("could not create IndianCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new IndianCalendar(Locale)
|
||||
IndianCalendar cal = new IndianCalendar(Locale.getDefault());
|
||||
@ -148,23 +151,23 @@ public class IndianTest extends CalendarTestFmwk
|
||||
errln("could not create IndianCalendar with Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new IndianCalendar(TimeZone, Locale)
|
||||
IndianCalendar cal = new IndianCalendar(TimeZone.getDefault(),Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create IndianCalendar with TimeZone, Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new IndianCalendar(TimeZone, ULocale)
|
||||
|
||||
{
|
||||
// new IndianCalendar(TimeZone, Locale)
|
||||
IndianCalendar cal = new IndianCalendar(TimeZone.getDefault(),Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create IndianCalendar with TimeZone, Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new IndianCalendar(TimeZone, ULocale)
|
||||
IndianCalendar cal = new IndianCalendar(TimeZone.getDefault(),ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create IndianCalendar with TimeZone, ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
if(cal == null){
|
||||
errln("could not create IndianCalendar with TimeZone, ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new IndianCalendar(Date)
|
||||
IndianCalendar cal = new IndianCalendar(new Date());
|
||||
@ -186,7 +189,7 @@ public class IndianTest extends CalendarTestFmwk
|
||||
errln("could not create IndianCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
String[] calendarLocales = {
|
||||
@ -246,7 +249,7 @@ public class IndianTest extends CalendarTestFmwk
|
||||
doLimitsTest(indian, null, cal.getTime());
|
||||
doTheoreticalLimitsTest(indian, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Problem reported by Bruno Haible <bruno.haible@de.ibm.com>
|
||||
* -- see ticket 8419 -- http://bugs.icu-project.org/trac/ticket/8419
|
||||
@ -282,14 +285,14 @@ public class IndianTest extends CalendarTestFmwk
|
||||
|
||||
@Test
|
||||
public void TestCoverage12424() {
|
||||
class StubCalendar extends IndianCalendar {
|
||||
class StubCalendar extends IndianCalendar {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public StubCalendar() {
|
||||
assertEquals("Indian month 0 length", 30, handleGetMonthLength(1000, 0));
|
||||
assertEquals("Indian month 2 length", 31, handleGetMonthLength(1000, 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
new StubCalendar();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
@ -32,6 +34,7 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>IslamicCalendar</code> class.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class IslamicTest extends CalendarTestFmwk {
|
||||
/** Constants to save typing. */
|
||||
public static final int MUHARRAM = IslamicCalendar.MUHARRAM;
|
||||
@ -52,7 +55,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
|
||||
{ 0001, QIDAH, 2, MONTH, 1, 0001, HIJJAH, 2 }, // non-leap years
|
||||
{ 0001, QIDAH, 2, MONTH, 2, 0001, MUHARRAM, 2 },
|
||||
{ 0001, QIDAH, 2, MONTH, -1, 0001, SHAWWAL, 2 },
|
||||
@ -66,10 +69,10 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
{ 0001, MUHARRAM, 30, MONTH, 1, 0001, SAFAR, 29 },
|
||||
{ 0002, HIJJAH, 30, YEAR, -1, 0001, HIJJAH, 29 },
|
||||
};
|
||||
|
||||
|
||||
IslamicCalendar cal = newCivil();
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
|
||||
|
||||
cal = newIslamicUmalqura();
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
@ -125,7 +128,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
new TestCase(2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
IslamicCalendar civilCalendar = newCivil();
|
||||
civilCalendar.setLenient(true);
|
||||
doTestCases(tests, civilCalendar);
|
||||
@ -138,13 +141,13 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
@ -160,7 +163,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
doTheoreticalLimitsTest(islamic, true);
|
||||
|
||||
|
||||
// number of days to test - Islamic calendar starts to exhibit
|
||||
// number of days to test - Islamic calendar starts to exhibit
|
||||
// rounding errors after year AH3954 - about 2500 years out.
|
||||
|
||||
IslamicCalendar islamic2 = new IslamicCalendar();
|
||||
@ -180,11 +183,11 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
cal.add(IslamicCalendar.MONTH,1);
|
||||
if ( cal.get(IslamicCalendar.MONTH) != IslamicCalendar.MUHARRAM ||
|
||||
( cal.get(IslamicCalendar.YEAR) != 1432 )) {
|
||||
errln("Error incrementing month at the end of a leap year. Expected Month:0 Year:1432 - Got Month:" +
|
||||
errln("Error incrementing month at the end of a leap year. Expected Month:0 Year:1432 - Got Month:" +
|
||||
cal.get(IslamicCalendar.MONTH) + " Year:" + cal.get(IslamicCalendar.YEAR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCoverage() {
|
||||
{
|
||||
@ -202,7 +205,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
errln("could not create IslamicCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new IslamicCalendar(Locale)
|
||||
IslamicCalendar cal = new IslamicCalendar(Locale.getDefault());
|
||||
@ -251,7 +254,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
if (cal.isCivil()) {
|
||||
errln("islamic calendar is civil");
|
||||
}
|
||||
|
||||
|
||||
// ensure calculation type getter returns correct object and value
|
||||
cal.setCalculationType(CalculationType.ISLAMIC_UMALQURA);
|
||||
Object ctObj = cal.getCalculationType();
|
||||
@ -263,7 +266,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
} else {
|
||||
errln("wrong object type returned from getCalculationType");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Date now = new Date();
|
||||
cal.setTime(now);
|
||||
@ -281,14 +284,14 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
|
||||
logln(cal.getTime().toString());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
IslamicCalendar cal = new IslamicCalendar(800, IslamicCalendar.RAMADAN, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
String[] calendarLocales = {
|
||||
"ar_AE", "ar_BH", "ar_DZ", "ar_EG", "ar_JO", "ar_KW", "ar_OM",
|
||||
"ar_AE", "ar_BH", "ar_DZ", "ar_EG", "ar_JO", "ar_KW", "ar_OM",
|
||||
"ar_QA", "ar_SA", "ar_SY", "ar_YE", "ms_MY"
|
||||
};
|
||||
|
||||
@ -320,7 +323,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
civilCalendar.setCalculationType(CalculationType.ISLAMIC);
|
||||
return civilCalendar;
|
||||
}
|
||||
|
||||
|
||||
private static IslamicCalendar newIslamicUmalqura() {
|
||||
IslamicCalendar civilCalendar = new IslamicCalendar();
|
||||
civilCalendar.setCalculationType(CalculationType.ISLAMIC_UMALQURA);
|
||||
@ -339,8 +342,8 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
verifyType(newIslamic(),"islamic");
|
||||
verifyType(newCivil(),"islamic-civil");
|
||||
verifyType(newIslamicUmalqura(), "islamic-umalqura");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setAndTestCalendar(IslamicCalendar cal, int initMonth, int initDay, int initYear) {
|
||||
cal.clear();
|
||||
cal.setLenient(false);
|
||||
@ -357,18 +360,18 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
|
||||
private void setAndTestWholeYear(IslamicCalendar cal, int startYear) {
|
||||
for(int startMonth = 0; startMonth < 12; startMonth++) {
|
||||
for(int startDay = 1; startDay < 31; startDay++ ) {
|
||||
for(int startDay = 1; startDay < 31; startDay++ ) {
|
||||
try {
|
||||
setAndTestCalendar(cal, startMonth, startDay, startYear);
|
||||
} catch(IllegalArgumentException iae) {
|
||||
if(startDay != 30) {
|
||||
errln("unexpected exception that wasn't for trying to set a date to '30'. errmsg - " + iae.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestIslamicUmAlQura() {
|
||||
|
||||
@ -804,15 +807,15 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
/*/
|
||||
int lastYear = 1480; // the whole shootin' match
|
||||
//*/
|
||||
|
||||
ULocale umalquraLoc = new ULocale("ar_SA@calendar=islamic-umalqura");
|
||||
ULocale gregoLoc = new ULocale("ar_SA@calendar=gregorian");
|
||||
|
||||
ULocale umalquraLoc = new ULocale("ar_SA@calendar=islamic-umalqura");
|
||||
ULocale gregoLoc = new ULocale("ar_SA@calendar=gregorian");
|
||||
TimeZone tzSA = TimeZone.getTimeZone("Asia/Riyadh");
|
||||
IslamicCalendar tstCal = new IslamicCalendar(tzSA, umalquraLoc);
|
||||
GregorianCalendar gregCal = new GregorianCalendar(tzSA, gregoLoc);
|
||||
tstCal.clear();
|
||||
tstCal.setLenient(false);
|
||||
|
||||
|
||||
int day=0, month=0, year=0, initDay = 27, initMonth = IslamicCalendar.RAJAB, initYear = 1434;
|
||||
|
||||
try {
|
||||
@ -840,7 +843,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
} catch(IllegalArgumentException iae) {
|
||||
errln("unexpected exception received!!!");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
tstCal.clear();
|
||||
initMonth = 2;
|
||||
@ -850,7 +853,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
} catch(IllegalArgumentException iae) {
|
||||
// expected this
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
tstCal.clear();
|
||||
initMonth = 3;
|
||||
@ -859,9 +862,9 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
} catch(IllegalArgumentException iae) {
|
||||
errln("unexpected exception received!!!");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = formatter.parse("1975-05-06");
|
||||
IslamicCalendar is_cal = new IslamicCalendar();
|
||||
is_cal.setCalculationType(CalculationType.ISLAMIC_UMALQURA);
|
||||
@ -880,11 +883,11 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
String expectedFormatResult = "\u0661\u0663\u0669\u0665-\u0631\u0628\u064A\u0639 \u0627\u0644\u0622\u062E\u0631-\u0662\u0664";
|
||||
if(!str.equals(expectedFormatResult))
|
||||
errln("unexpected formatted result: "+str);
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
errln(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
|
||||
// check against data
|
||||
gregCal.clear();
|
||||
tstCal.clear();
|
||||
@ -902,18 +905,18 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestSerialization8449() {
|
||||
try {
|
||||
ByteArrayOutputStream icuStream = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
IslamicCalendar tstCalendar = new IslamicCalendar();
|
||||
tstCalendar.setCivil(false);
|
||||
|
||||
|
||||
long expectMillis = 1187912520931L; // with seconds (not ms) cleared.
|
||||
tstCalendar.setTimeInMillis(expectMillis);
|
||||
|
||||
|
||||
logln("instantiated: "+tstCalendar);
|
||||
logln("getMillis: "+tstCalendar.getTimeInMillis());
|
||||
tstCalendar.set(IslamicCalendar.SECOND, 0);
|
||||
@ -930,11 +933,11 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
icuOut.writeObject(tstCalendar);
|
||||
icuOut.flush();
|
||||
icuOut.close();
|
||||
|
||||
|
||||
ObjectInputStream icuIn = new ObjectInputStream(new ByteArrayInputStream(icuStream.toByteArray()));
|
||||
tstCalendar = null;
|
||||
tstCalendar = (IslamicCalendar)icuIn.readObject();
|
||||
|
||||
|
||||
logln("serialized back in: "+tstCalendar);
|
||||
{
|
||||
long gotMillis = tstCalendar.getTimeInMillis();
|
||||
@ -944,9 +947,9 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
logln("getMillis: "+gotMillis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tstCalendar.set(IslamicCalendar.SECOND, 0);
|
||||
|
||||
|
||||
logln("setSecond=0: "+tstCalendar);
|
||||
{
|
||||
long gotMillis = tstCalendar.getTimeInMillis();
|
||||
@ -964,7 +967,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
cnf.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestIslamicTabularDates() {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@ -988,7 +991,7 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
int is_year2 = is_cal2.get(Calendar.YEAR);
|
||||
if( (is_month != is_month2) || (is_year != is_year2))
|
||||
errln("unexpected difference between islamic and tbla month "+is_month+" : "+is_month2+" and/or year "+is_year+" : "+is_year2);
|
||||
|
||||
|
||||
int is_day = is_cal.get(Calendar.DAY_OF_MONTH);
|
||||
int is_day2 = is_cal2.get(Calendar.DAY_OF_MONTH);
|
||||
if(is_day2 - is_day != 1)
|
||||
@ -998,30 +1001,30 @@ public class IslamicTest extends CalendarTestFmwk {
|
||||
|
||||
@Test
|
||||
public void TestCreationByLocale() {
|
||||
ULocale islamicLoc = new ULocale("ar_SA@calendar=islamic-umalqura");
|
||||
ULocale islamicLoc = new ULocale("ar_SA@calendar=islamic-umalqura");
|
||||
IslamicCalendar is_cal = new IslamicCalendar(islamicLoc);
|
||||
String thisCalcType = is_cal.getType();
|
||||
String thisCalcType = is_cal.getType();
|
||||
if(!"islamic-umalqura".equalsIgnoreCase(thisCalcType)) {
|
||||
errln("non umalqura calc type generated - " + thisCalcType);
|
||||
}
|
||||
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-civil");
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-civil");
|
||||
is_cal = new IslamicCalendar(islamicLoc);
|
||||
thisCalcType = is_cal.getType();
|
||||
thisCalcType = is_cal.getType();
|
||||
if(!"islamic-civil".equalsIgnoreCase(thisCalcType)) {
|
||||
errln("non civil calc type generated - " + thisCalcType);
|
||||
}
|
||||
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-tbla");
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-tbla");
|
||||
is_cal = new IslamicCalendar(islamicLoc);
|
||||
thisCalcType = is_cal.getType();
|
||||
thisCalcType = is_cal.getType();
|
||||
if(!"islamic-tbla".equalsIgnoreCase(thisCalcType)) {
|
||||
errln("non tbla calc type generated - " + thisCalcType);
|
||||
}
|
||||
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-xyzzy");
|
||||
islamicLoc = new ULocale("ar_SA@calendar=islamic-xyzzy");
|
||||
is_cal = new IslamicCalendar(islamicLoc);
|
||||
thisCalcType = is_cal.getType();
|
||||
thisCalcType = is_cal.getType();
|
||||
if(!"islamic".equalsIgnoreCase(thisCalcType)) {
|
||||
errln("incorrect default calc type generated - " + thisCalcType);
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -26,8 +28,9 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Tests for the <code>JapaneseCalendar</code> class.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class JapaneseTest extends CalendarTestFmwk {
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCoverage() {
|
||||
{
|
||||
@ -143,7 +146,7 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void Test3860()
|
||||
{
|
||||
@ -160,10 +163,10 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
cal.setTime(aDate);
|
||||
int gotYear = cal.get(Calendar.YEAR);
|
||||
int gotEra = cal.get(Calendar.ERA);
|
||||
|
||||
|
||||
int expectYear = 1;
|
||||
int expectEra = JapaneseCalendar.CURRENT_ERA;
|
||||
|
||||
|
||||
if((gotYear != expectYear) || (gotEra != expectEra)) {
|
||||
errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
|
||||
} else {
|
||||
@ -196,9 +199,9 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
expectYear = 1;
|
||||
expectEra = JapaneseCalendar.CURRENT_ERA;
|
||||
if((gotYear != 1) || (gotEra != expectEra)) {
|
||||
errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
|
||||
errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
|
||||
" and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
|
||||
} else {
|
||||
} else {
|
||||
logln(" year: " + gotYear + ", era: " + gotEra);
|
||||
}
|
||||
}
|
||||
@ -231,14 +234,14 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
Date otherDate;
|
||||
try {
|
||||
otherDate = fmt.parse(expected);
|
||||
if(!otherDate.equals(aDate)) {
|
||||
if(!otherDate.equals(aDate)) {
|
||||
String str3;
|
||||
// ParsePosition pp;
|
||||
Date dd = fmt.parse(expected);
|
||||
str3 = fmt.format(otherDate);
|
||||
long oLong = otherDate.getTime();
|
||||
long aLong = otherDate.getTime();
|
||||
|
||||
|
||||
errln("FAIL: Parse incorrect of " + expected + ": wanted " + aDate + " ("+aLong+"), but got " + " " +
|
||||
otherDate + " ("+oLong+") = " + str3 + " not " + dd.toString() );
|
||||
|
||||
@ -267,7 +270,7 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
int fieldNum = expected[i+0];
|
||||
int expectedVal = expected[i+1];
|
||||
int actualVal = c.get(fieldNum);
|
||||
|
||||
|
||||
if(expectedVal == actualVal) {
|
||||
logln(FIELD_NAME[fieldNum]+": "+ actualVal);
|
||||
} else {
|
||||
@ -275,7 +278,7 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void Test5345calendar() {
|
||||
logln("** testIncompleteCalendar()");
|
||||
@ -283,7 +286,7 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
JapaneseCalendar c = new JapaneseCalendar(TimeZone.getDefault());
|
||||
logln("test clear");
|
||||
c.clear();
|
||||
|
||||
|
||||
// Showa 45 = Gregorian 1970
|
||||
int expected0[] = { Calendar.ERA, 234,
|
||||
Calendar.YEAR, 45 };
|
||||
@ -292,8 +295,8 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
logln("test setting era");
|
||||
c.clear();
|
||||
c.set(Calendar.ERA, JapaneseCalendar.MEIJI);
|
||||
|
||||
|
||||
|
||||
|
||||
int expectedA[] = { Calendar.ERA, JapaneseCalendar.MEIJI };
|
||||
checkExpected(c, expectedA);
|
||||
|
||||
@ -316,11 +319,11 @@ public class JapaneseTest extends CalendarTestFmwk {
|
||||
c.set(Calendar.MONTH, Calendar.JANUARY);
|
||||
c.set(Calendar.DATE, 1);
|
||||
c.set(Calendar.ERA, JapaneseCalendar.MEIJI);
|
||||
|
||||
|
||||
|
||||
|
||||
checkExpected(c, expectedC);
|
||||
|
||||
|
||||
|
||||
|
||||
logln("test setting era and year");
|
||||
c.clear();
|
||||
c.set(Calendar.YEAR, 1);
|
||||
|
@ -10,11 +10,14 @@ package com.ibm.icu.dev.test.calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.PersianCalendar;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class PersianTest extends CalendarTestFmwk {
|
||||
/**
|
||||
* Test basic mapping to and from Gregorian.
|
||||
@ -24,7 +27,7 @@ public class PersianTest extends CalendarTestFmwk {
|
||||
final int[] DATA = {
|
||||
// (Note: months are 1-based)
|
||||
2011, 1, 11, 1389, 10, 21,
|
||||
1986, 2, 25, 1364, 12, 6,
|
||||
1986, 2, 25, 1364, 12, 6,
|
||||
1934, 3, 14, 1312, 12, 23,
|
||||
|
||||
2090, 3, 19, 1468, 12, 29,
|
||||
@ -127,17 +130,17 @@ public class PersianTest extends CalendarTestFmwk {
|
||||
|
||||
@Test
|
||||
public void TestCoverage12424() {
|
||||
class StubCalendar extends PersianCalendar {
|
||||
class StubCalendar extends PersianCalendar {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public StubCalendar() {
|
||||
assertEquals("Persian month 0 length", 31, handleGetMonthLength(1000, 0));
|
||||
assertEquals("Persian month 7 length", 30, handleGetMonthLength(1000, 7));
|
||||
|
||||
|
||||
int leastWeeks = handleGetLimit(Calendar.WEEK_OF_YEAR, Calendar.LEAST_MAXIMUM);
|
||||
assertEquals("Persian Week of Year least maximum", 52, leastWeeks);
|
||||
assertEquals("Persian Week of Year least maximum", 52, leastWeeks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
new StubCalendar();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
@ -38,6 +40,7 @@ import com.ibm.icu.text.CharsetMatch;
|
||||
/**
|
||||
* @author andy
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class TestCharsetDetector extends TestFmwk
|
||||
{
|
||||
public TestCharsetDetector()
|
||||
@ -57,27 +60,27 @@ public class TestCharsetDetector extends TestFmwk
|
||||
}
|
||||
errln(msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String stringFromReader(Reader reader)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
char[] buffer = new char[1024];
|
||||
int bytesRead = 0;
|
||||
|
||||
|
||||
try {
|
||||
while ((bytesRead = reader.read(buffer, 0, 1024)) >= 0) {
|
||||
sb.append(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
errln("stringFromReader() failed: " + e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestConstruction() {
|
||||
int i;
|
||||
@ -88,7 +91,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
String [] charsetNames = CharsetDetector.getAllDetectableCharsets();
|
||||
CheckAssert(charsetNames.length != 0);
|
||||
for (i=0; i<charsetNames.length; i++) {
|
||||
CheckAssert(charsetNames[i].equals("") == false);
|
||||
CheckAssert(charsetNames[i].equals("") == false);
|
||||
// System.out.println("\"" + charsetNames[i] + "\"");
|
||||
}
|
||||
|
||||
@ -131,31 +134,31 @@ public class TestCharsetDetector extends TestFmwk
|
||||
byte[] bytes = s.getBytes("ISO-8859-1");
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch m;
|
||||
|
||||
|
||||
det.enableInputFilter(true);
|
||||
if (!det.inputFilterEnabled()){
|
||||
errln("input filter should be enabled");
|
||||
}
|
||||
|
||||
|
||||
det.setText(bytes);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (! m.getLanguage().equals("fr")) {
|
||||
errln("input filter did not strip markup!");
|
||||
}
|
||||
|
||||
|
||||
det.enableInputFilter(false);
|
||||
det.setText(bytes);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (! m.getLanguage().equals("en")) {
|
||||
errln("unfiltered input did not detect as English!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestUTF8() throws Exception {
|
||||
|
||||
|
||||
String s = "This is a string with some non-ascii characters that will " +
|
||||
"be converted to UTF-8, then shoved through the detection process. " +
|
||||
"\u0391\u0392\u0393\u0394\u0395" +
|
||||
@ -164,10 +167,10 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
String retrievedS;
|
||||
Reader reader;
|
||||
|
||||
|
||||
retrievedS = det.getString(bytes, "UTF-8");
|
||||
CheckAssert(s.equals(retrievedS));
|
||||
|
||||
|
||||
reader = det.getReader(new ByteArrayInputStream(bytes), "UTF-8");
|
||||
try {
|
||||
CheckAssert(s.equals(stringFromReader(reader)));
|
||||
@ -176,79 +179,79 @@ public class TestCharsetDetector extends TestFmwk
|
||||
}
|
||||
det.setDeclaredEncoding("UTF-8"); // Jitterbug 4451, for coverage
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestUTF16() throws Exception
|
||||
{
|
||||
String source =
|
||||
String source =
|
||||
"u0623\u0648\u0631\u0648\u0628\u0627, \u0628\u0631\u0645\u062c\u064a\u0627\u062a " +
|
||||
"\u0627\u0644\u062d\u0627\u0633\u0648\u0628 \u002b\u0020\u0627\u0646\u062a\u0631\u0646\u064a\u062a";
|
||||
|
||||
|
||||
byte[] beBytes = source.getBytes("UnicodeBig");
|
||||
byte[] leBytes = source.getBytes("UnicodeLittle");
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch m;
|
||||
|
||||
|
||||
det.setText(beBytes);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (! m.getName().equals("UTF-16BE")) {
|
||||
errln("Encoding detection failure: expected UTF-16BE, got " + m.getName());
|
||||
}
|
||||
|
||||
|
||||
det.setText(leBytes);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (! m.getName().equals("UTF-16LE")) {
|
||||
errln("Encoding detection failure: expected UTF-16LE, got " + m.getName());
|
||||
}
|
||||
|
||||
// Jitterbug 4451, for coverage
|
||||
int confidence = m.getConfidence();
|
||||
int confidence = m.getConfidence();
|
||||
if(confidence != 100){
|
||||
errln("Did not get the expected confidence level " + confidence);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestC1Bytes() throws Exception
|
||||
{
|
||||
String sISO =
|
||||
"This is a small sample of some English text. Just enough to be sure that it detects correctly.";
|
||||
|
||||
|
||||
String sWindows =
|
||||
"This is another small sample of some English text. Just enough to be sure that it detects correctly. It also includes some \u201CC1\u201D bytes.";
|
||||
|
||||
byte[] bISO = sISO.getBytes("ISO-8859-1");
|
||||
byte[] bWindows = sWindows.getBytes("windows-1252");
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch m;
|
||||
|
||||
|
||||
det.setText(bWindows);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (!m.getName().equals("windows-1252")) {
|
||||
errln("Text with C1 bytes not correctly detected as windows-1252.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
det.setText(bISO);
|
||||
m = det.detect();
|
||||
|
||||
|
||||
if (!m.getName().equals("ISO-8859-1")) {
|
||||
errln("Text without C1 bytes not correctly detected as ISO-8859-1.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestShortInput() {
|
||||
// Test that detection with very short byte strings does not crash and burn.
|
||||
// The shortest input that should produce positive detection result is two bytes,
|
||||
// The shortest input that should produce positive detection result is two bytes,
|
||||
// a UTF-16 BOM.
|
||||
// TODO: Detector confidence levels needs to be refined for very short input.
|
||||
// Too high now, for some charsets that happen to be compatible with a few bytes of input.
|
||||
byte [][] shortBytes = new byte [][]
|
||||
byte [][] shortBytes = new byte [][]
|
||||
{
|
||||
{},
|
||||
{(byte)0x0a},
|
||||
@ -256,7 +259,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
{(byte)'A', (byte)'B', (byte)'C'},
|
||||
{(byte)'A', (byte)'B', (byte)'C', (byte)'D'}
|
||||
};
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch m;
|
||||
for (int i=0; i<shortBytes.length; i++) {
|
||||
@ -265,7 +268,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
logln("i=" + i + " -> " + m.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBufferOverflow()
|
||||
{
|
||||
@ -279,7 +282,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
{(byte) 0x74, (byte) 0x68, (byte) 0xa1}, /* Could be a single byte shift-jis at the end */
|
||||
{(byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0xa1} /* Could be a single byte shift-jis at the end, but now we have English creeping in. */
|
||||
};
|
||||
|
||||
|
||||
String testResults[] = {
|
||||
"windows-1252",
|
||||
"windows-1252",
|
||||
@ -290,7 +293,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
null,
|
||||
"ISO-8859-1"
|
||||
};
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch match;
|
||||
|
||||
@ -325,7 +328,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
// Open and read the test data file.
|
||||
//
|
||||
//InputStreamReader isr = null;
|
||||
|
||||
|
||||
try {
|
||||
InputStream is = TestCharsetDetector.class.getResourceAsStream("CharsetDetectionTests.xml");
|
||||
if (is == null) {
|
||||
@ -335,11 +338,11 @@ public class TestCharsetDetector extends TestFmwk
|
||||
|
||||
// Set up an xml parser.
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
|
||||
factory.setIgnoringComments(true);
|
||||
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
|
||||
// Parse the xml content from the test case file.
|
||||
Document doc;
|
||||
try {
|
||||
@ -348,9 +351,9 @@ public class TestCharsetDetector extends TestFmwk
|
||||
is.close();
|
||||
}
|
||||
Element root = doc.getDocumentElement();
|
||||
|
||||
|
||||
NodeList testCases = root.getElementsByTagName("test-case");
|
||||
|
||||
|
||||
// Process each test case
|
||||
Map<String, byte[]> encToBytes = new TreeMap<String, byte[]>();
|
||||
for (int n = 0; n < testCases.getLength(); n += 1) {
|
||||
@ -408,7 +411,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
}
|
||||
encToBytes.clear();
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
errln("exception while processing test cases: " + e.toString());
|
||||
}
|
||||
@ -421,7 +424,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
errln(id + ": encoding detection failure - expected " + encoding + ", got " + m.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String charsetMatchLanguage = m.getLanguage();
|
||||
if ((language != null && !charsetMatchLanguage.equals(language))
|
||||
|| (language == null && charsetMatchLanguage != null)
|
||||
@ -439,20 +442,20 @@ public class TestCharsetDetector extends TestFmwk
|
||||
logln("Skipping roundtrip check on IBM Java 8: " + id + ", " + encoding);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String decoded = m.getString();
|
||||
|
||||
|
||||
if (! testString.equals(decoded)) {
|
||||
errln(id + ", " + encoding + ": getString() didn't return the original string!");
|
||||
}
|
||||
|
||||
|
||||
decoded = stringFromReader(m.getReader());
|
||||
|
||||
|
||||
if (! testString.equals(decoded)) {
|
||||
errln(id + ", " + encoding + ": getReader() didn't yield the original string!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkEncoding(String testString,
|
||||
String encoding, String language, boolean checkRoundtrip,
|
||||
byte[] bytes, String id) {
|
||||
@ -485,25 +488,25 @@ public class TestCharsetDetector extends TestFmwk
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestJapanese() throws Exception {
|
||||
String s = "\u3000\u3001\u3002\u3003\u3005\u3006\u3007\u3008\u3009\u300A\u300B\u300C\u300D\u300E\u300F\u3010\u3011\u3012\u3013\u3014" +
|
||||
"\u3015\u301C\u3041\u3042\u3043\u3044\u3045\u3046\u3047\u3048\u3049\u304A\u304B\u304C\u304D\u304E\u304F\u3050\u3051\u3052" +
|
||||
"\u3053\u3054\u3055\u3056\u3057\u3058\u3059\u305A\u305B\u305C\u305D\u305E\u305F\u3060\u3061\u3062\u3063\u3064\u3065\u3066" +
|
||||
"\u3067\u3068\u3069\u306A\u306B\u306C\u306D\u306E\u306F\u3070\u3071\u3072\u3073\u3074\u3075\u3076\u3077\u3078\u3079\u307A" +
|
||||
"\u307B\u307C\u307D\u307E\u307F\u3080\u3081\u3082\u3083\u3084\u3085\u3086\u3087\u3088\u3089\u308A\u308B\u308C\u308D\u308E" +
|
||||
"\u308F\u3090\u3091\u3092\u3093\u309B\u309C\u309D\u309E\u30A1\u30A2\u30A3\u30A4\u30A5\u30A6\u30A7\u30A8\u30A9\u30AA\u30AB" +
|
||||
"\u30AC\u30AD\u30AE\u30AF\u30B0\u30B1\u30B2\u30B3\u30B4\u30B5\u30B6\u30B7\u30B8\u30B9\u30BA\u30BB\u30BC\u30BD\u30BE\u30BF" +
|
||||
"\u30C0\u30C1\u30C2\u30C3\u30C4\u30C5\u30C6\u30C7\u30C8\u30C9\u30CA\u30CB\u30CC\u30CD\u30CE\u30CF\u30D0\u30D1\u30D2\u30D3" +
|
||||
"\u30D4\u30D5\u30D6\u30D7\u30D8\u30D9\u30DA\u30DB\u30DC\u30DD\u30DE\u30DF\u30E0\u30E1\u30E2\u30E3\u30E4\u30E5\u30E6\u30E7" +
|
||||
"\u30E8\u30E9\u30EA\u30EB\u30EC\u30ED\u30EE\u30EF\u30F0\u30F1\u30F2\u30F3\u30F4\u30F5\u30F6\u30FB\u30FC\u30FD\u30FE\u4E00" +
|
||||
"\u4E01\u4E02\u4E03\u4E04\u4E05\u4E07\u4E08\u4E09\u4E0A\u4E0B\u4E0C\u4E0D\u4E0E\u4E10\u4E11\u4E12\u4E14\u4E15\u4E16\u4E17" +
|
||||
"\u4E18\u4E19\u4E1E\u4E1F\u4E21\u4E23\u4E24\u4E26\u4E28\u4E2A\u4E2B\u4E2D\u4E2E\u4E2F\u4E30\u4E31\u4E32\u4E35\u4E36\u4E38" +
|
||||
"\u4E39\u4E3B\u4E3C\u4E3F\u4E40\u4E41\u4E42\u4E43\u4E44\u4E45\u4E47\u4E4B\u4E4D\u4E4E\u4E4F\u4E51\u4E55\u4E56\u4E57\u4E58" +
|
||||
"\u4E59\u4E5A\u4E5C\u4E5D\u4E5E\u4E5F\u4E62\u4E63\u4E68\u4E69\u4E71\u4E73\u4E74\u4E75\u4E79\u4E7E\u4E7F\u4E80\u4E82\u4E85" +
|
||||
String s = "\u3000\u3001\u3002\u3003\u3005\u3006\u3007\u3008\u3009\u300A\u300B\u300C\u300D\u300E\u300F\u3010\u3011\u3012\u3013\u3014" +
|
||||
"\u3015\u301C\u3041\u3042\u3043\u3044\u3045\u3046\u3047\u3048\u3049\u304A\u304B\u304C\u304D\u304E\u304F\u3050\u3051\u3052" +
|
||||
"\u3053\u3054\u3055\u3056\u3057\u3058\u3059\u305A\u305B\u305C\u305D\u305E\u305F\u3060\u3061\u3062\u3063\u3064\u3065\u3066" +
|
||||
"\u3067\u3068\u3069\u306A\u306B\u306C\u306D\u306E\u306F\u3070\u3071\u3072\u3073\u3074\u3075\u3076\u3077\u3078\u3079\u307A" +
|
||||
"\u307B\u307C\u307D\u307E\u307F\u3080\u3081\u3082\u3083\u3084\u3085\u3086\u3087\u3088\u3089\u308A\u308B\u308C\u308D\u308E" +
|
||||
"\u308F\u3090\u3091\u3092\u3093\u309B\u309C\u309D\u309E\u30A1\u30A2\u30A3\u30A4\u30A5\u30A6\u30A7\u30A8\u30A9\u30AA\u30AB" +
|
||||
"\u30AC\u30AD\u30AE\u30AF\u30B0\u30B1\u30B2\u30B3\u30B4\u30B5\u30B6\u30B7\u30B8\u30B9\u30BA\u30BB\u30BC\u30BD\u30BE\u30BF" +
|
||||
"\u30C0\u30C1\u30C2\u30C3\u30C4\u30C5\u30C6\u30C7\u30C8\u30C9\u30CA\u30CB\u30CC\u30CD\u30CE\u30CF\u30D0\u30D1\u30D2\u30D3" +
|
||||
"\u30D4\u30D5\u30D6\u30D7\u30D8\u30D9\u30DA\u30DB\u30DC\u30DD\u30DE\u30DF\u30E0\u30E1\u30E2\u30E3\u30E4\u30E5\u30E6\u30E7" +
|
||||
"\u30E8\u30E9\u30EA\u30EB\u30EC\u30ED\u30EE\u30EF\u30F0\u30F1\u30F2\u30F3\u30F4\u30F5\u30F6\u30FB\u30FC\u30FD\u30FE\u4E00" +
|
||||
"\u4E01\u4E02\u4E03\u4E04\u4E05\u4E07\u4E08\u4E09\u4E0A\u4E0B\u4E0C\u4E0D\u4E0E\u4E10\u4E11\u4E12\u4E14\u4E15\u4E16\u4E17" +
|
||||
"\u4E18\u4E19\u4E1E\u4E1F\u4E21\u4E23\u4E24\u4E26\u4E28\u4E2A\u4E2B\u4E2D\u4E2E\u4E2F\u4E30\u4E31\u4E32\u4E35\u4E36\u4E38" +
|
||||
"\u4E39\u4E3B\u4E3C\u4E3F\u4E40\u4E41\u4E42\u4E43\u4E44\u4E45\u4E47\u4E4B\u4E4D\u4E4E\u4E4F\u4E51\u4E55\u4E56\u4E57\u4E58" +
|
||||
"\u4E59\u4E5A\u4E5C\u4E5D\u4E5E\u4E5F\u4E62\u4E63\u4E68\u4E69\u4E71\u4E73\u4E74\u4E75\u4E79\u4E7E\u4E7F\u4E80\u4E82\u4E85" +
|
||||
"\u4E86\u4E88\u4E89\u4E8A\u4E8B\u4E8C";
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
CharsetMatch m;
|
||||
String charsetMatch;
|
||||
@ -514,7 +517,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
m = det.detect();
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("EUC-JP"));
|
||||
|
||||
|
||||
// Tests "public String getLanguage()"
|
||||
CheckAssert(m.getLanguage().equals("ja"));
|
||||
}
|
||||
@ -523,17 +526,17 @@ public class TestCharsetDetector extends TestFmwk
|
||||
@Test
|
||||
public void TestArabic() throws Exception {
|
||||
String s = "\u0648\u0636\u0639\u062A \u0648\u0646\u0641\u0630\u062A \u0628\u0631\u0627" +
|
||||
"\u0645\u062C \u062A\u0623\u0645\u064A\u0646 \u0639\u062F\u064A\u062F\u0629 \u0641\u064A " +
|
||||
"\u0645\u0624\u0633\u0633\u0629 \u0627\u0644\u062A\u0623\u0645\u064A\u0646 \u0627\u0644" +
|
||||
"\u0648\u0637\u0646\u064A, \u0645\u0639 \u0645\u0644\u0627\u0626\u0645\u062A\u0647\u0627 " +
|
||||
"\u062F\u0627\u0626\u0645\u0627 \u0644\u0644\u0627\u062D\u062A\u064A\u0627\u062C" +
|
||||
"\u0627\u062A \u0627\u0644\u0645\u062A\u063A\u064A\u0631\u0629 \u0644\u0644\u0645\u062C" +
|
||||
"\u062A\u0645\u0639 \u0648\u0644\u0644\u062F\u0648\u0644\u0629. \u062A\u0648\u0633\u0639" +
|
||||
"\u062A \u0648\u062A\u0637\u0648\u0631\u062A \u0627\u0644\u0645\u0624\u0633\u0633\u0629 " +
|
||||
"\u0628\u0647\u062F\u0641 \u0636\u0645\u0627\u0646 \u0634\u0628\u0643\u0629 \u0623\u0645" +
|
||||
"\u0627\u0646 \u0644\u0633\u0643\u0627\u0646 \u062F\u0648\u0644\u0629 \u0627\u0633\u0631" +
|
||||
"\u0627\u0626\u064A\u0644 \u0628\u0648\u062C\u0647 \u0627\u0644\u0645\u062E\u0627\u0637" +
|
||||
"\u0631 \u0627\u0644\u0627\u0642\u062A\u0635\u0627\u062F\u064A\u0629 \u0648\u0627\u0644" +
|
||||
"\u0645\u062C \u062A\u0623\u0645\u064A\u0646 \u0639\u062F\u064A\u062F\u0629 \u0641\u064A " +
|
||||
"\u0645\u0624\u0633\u0633\u0629 \u0627\u0644\u062A\u0623\u0645\u064A\u0646 \u0627\u0644" +
|
||||
"\u0648\u0637\u0646\u064A, \u0645\u0639 \u0645\u0644\u0627\u0626\u0645\u062A\u0647\u0627 " +
|
||||
"\u062F\u0627\u0626\u0645\u0627 \u0644\u0644\u0627\u062D\u062A\u064A\u0627\u062C" +
|
||||
"\u0627\u062A \u0627\u0644\u0645\u062A\u063A\u064A\u0631\u0629 \u0644\u0644\u0645\u062C" +
|
||||
"\u062A\u0645\u0639 \u0648\u0644\u0644\u062F\u0648\u0644\u0629. \u062A\u0648\u0633\u0639" +
|
||||
"\u062A \u0648\u062A\u0637\u0648\u0631\u062A \u0627\u0644\u0645\u0624\u0633\u0633\u0629 " +
|
||||
"\u0628\u0647\u062F\u0641 \u0636\u0645\u0627\u0646 \u0634\u0628\u0643\u0629 \u0623\u0645" +
|
||||
"\u0627\u0646 \u0644\u0633\u0643\u0627\u0646 \u062F\u0648\u0644\u0629 \u0627\u0633\u0631" +
|
||||
"\u0627\u0626\u064A\u0644 \u0628\u0648\u062C\u0647 \u0627\u0644\u0645\u062E\u0627\u0637" +
|
||||
"\u0631 \u0627\u0644\u0627\u0642\u062A\u0635\u0627\u062F\u064A\u0629 \u0648\u0627\u0644" +
|
||||
"\u0627\u062C\u062A\u0645\u0627\u0639\u064A\u0629.";
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
@ -550,7 +553,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
m = det.detect();
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("windows-1256"));
|
||||
|
||||
|
||||
// Tests "public String getLanguage()"
|
||||
CheckAssert(m.getLanguage().endsWith("ar"));
|
||||
}
|
||||
@ -592,7 +595,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
m = det.detect();
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("IBM420_rtl"));
|
||||
|
||||
|
||||
// Tests "public String getLanguage()"
|
||||
CheckAssert(m.getLanguage().endsWith("ar"));
|
||||
}
|
||||
@ -643,32 +646,32 @@ public class TestCharsetDetector extends TestFmwk
|
||||
@Test
|
||||
public void TestHebrew() throws Exception {
|
||||
String s = "\u05D4\u05E4\u05E8\u05E7\u05DC\u05D9\u05D8 \u05D4\u05E6\u05D1\u05D0\u05D9 \u05D4" +
|
||||
"\u05E8\u05D0\u05E9\u05D9, \u05EA\u05EA \u05D0\u05DC\u05D5\u05E3 \u05D0\u05D1\u05D9" +
|
||||
"\u05D7\u05D9 \u05DE\u05E0\u05D3\u05DC\u05D1\u05DC\u05D9\u05D8, \u05D4\u05D5\u05E8" +
|
||||
"\u05D4 \u05E2\u05DC \u05E4\u05EA\u05D9\u05D7\u05EA \u05D7\u05E7\u05D9\u05E8\u05EA " +
|
||||
"\u05DE\u05E6\"\u05D7 \u05D1\u05E2\u05E7\u05D1\u05D5\u05EA \u05E2\u05D3\u05D5\u05D9" +
|
||||
"\u05D5\u05EA \u05D7\u05D9\u05D9\u05DC\u05D9 \u05E6\u05D4\"\u05DC \u05DE\u05DE\u05D1" +
|
||||
"\u05E8\u05D0\u05E9\u05D9, \u05EA\u05EA \u05D0\u05DC\u05D5\u05E3 \u05D0\u05D1\u05D9" +
|
||||
"\u05D7\u05D9 \u05DE\u05E0\u05D3\u05DC\u05D1\u05DC\u05D9\u05D8, \u05D4\u05D5\u05E8" +
|
||||
"\u05D4 \u05E2\u05DC \u05E4\u05EA\u05D9\u05D7\u05EA \u05D7\u05E7\u05D9\u05E8\u05EA " +
|
||||
"\u05DE\u05E6\"\u05D7 \u05D1\u05E2\u05E7\u05D1\u05D5\u05EA \u05E2\u05D3\u05D5\u05D9" +
|
||||
"\u05D5\u05EA \u05D7\u05D9\u05D9\u05DC\u05D9 \u05E6\u05D4\"\u05DC \u05DE\u05DE\u05D1" +
|
||||
"\u05E6\u05E2 \u05E2\u05D5\u05E4\u05E8\u05EA \u05D9\u05E6\u05D5\u05E7\u05D4 \u05D1+ " +
|
||||
"\u05E8\u05E6\u05D5\u05E2\u05EA \u05E2\u05D6\u05D4. \u05DC\u05D3\u05D1\u05E8\u05D9 " +
|
||||
"\u05E8\u05E6\u05D5\u05E2\u05EA \u05E2\u05D6\u05D4. \u05DC\u05D3\u05D1\u05E8\u05D9 " +
|
||||
"\u05D4\u05E4\u05E6\"\u05E8, \u05DE\u05D4\u05E2\u05D3\u05D5\u05D9\u05D5\u05EA \u05E2" +
|
||||
"\u05D5\u05DC\u05D4 \u05EA\u05DE\u05D5\u05E0\u05D4 \u05E9\u05DC \"\u05D4\u05EA\u05E0" +
|
||||
"\u05D4\u05D2\u05D5\u05EA \u05E4\u05E1\u05D5\u05DC\u05D4 \u05DC\u05DB\u05D0\u05D5\u05E8" +
|
||||
"\u05D4 \u05E9\u05DC \u05D7\u05D9\u05D9\u05DC\u05D9\u05DD \u05D1\u05DE\u05D4\u05DC\u05DA" +
|
||||
" \u05DE\u05D1\u05E6\u05E2 \u05E2\u05D5\u05E4\u05E8\u05EA \u05D9\u05E6\u05D5\u05E7\u05D4\"." +
|
||||
"\u05D5\u05DC\u05D4 \u05EA\u05DE\u05D5\u05E0\u05D4 \u05E9\u05DC \"\u05D4\u05EA\u05E0" +
|
||||
"\u05D4\u05D2\u05D5\u05EA \u05E4\u05E1\u05D5\u05DC\u05D4 \u05DC\u05DB\u05D0\u05D5\u05E8" +
|
||||
"\u05D4 \u05E9\u05DC \u05D7\u05D9\u05D9\u05DC\u05D9\u05DD \u05D1\u05DE\u05D4\u05DC\u05DA" +
|
||||
" \u05DE\u05D1\u05E6\u05E2 \u05E2\u05D5\u05E4\u05E8\u05EA \u05D9\u05E6\u05D5\u05E7\u05D4\"." +
|
||||
" \u05DE\u05E0\u05D3\u05DC\u05D1\u05DC\u05D9\u05D8 \u05E7\u05D9\u05D1\u05DC \u05D0\u05EA" +
|
||||
" \u05D4\u05D7\u05DC\u05D8\u05EA\u05D5 \u05DC\u05D0\u05D7\u05E8 \u05E9\u05E2\u05D9\u05D9" +
|
||||
"\u05DF \u05D1\u05EA\u05DE\u05DC\u05D9\u05DC \u05D4\u05E2\u05D3\u05D5\u05D9\u05D5\u05EA";
|
||||
|
||||
|
||||
CharsetMatch m = _test1255(s);
|
||||
String charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("ISO-8859-8-I"));
|
||||
CheckAssert(m.getLanguage().equals("he"));
|
||||
|
||||
|
||||
m = _test1255_reverse(s);
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("ISO-8859-8"));
|
||||
CheckAssert(m.getLanguage().equals("he"));
|
||||
|
||||
|
||||
m = _testIBM424_he_rtl(s);
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("IBM424_rtl"));
|
||||
@ -678,7 +681,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
} catch (Exception ex) {
|
||||
errln("Error getting string for charsetMatch: " + charsetMatch);
|
||||
}
|
||||
|
||||
|
||||
m = _testIBM424_he_ltr(s);
|
||||
charsetMatch = m.getName();
|
||||
CheckAssert(charsetMatch.equals("IBM424_ltr"));
|
||||
@ -689,7 +692,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
errln("Error getting string for charsetMatch: " + charsetMatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CharsetMatch _test1255(String s) throws Exception {
|
||||
byte [] bytes = s.getBytes("ISO-8859-8");
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
@ -697,18 +700,18 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetMatch m = det.detect();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
private CharsetMatch _test1255_reverse(String s) throws Exception {
|
||||
StringBuffer reverseStrBuf = new StringBuffer(s);
|
||||
reverseStrBuf = reverseStrBuf.reverse();
|
||||
byte [] bytes = reverseStrBuf.toString().getBytes("ISO-8859-8");
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
det.setText(bytes);
|
||||
CharsetMatch m = det.detect();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
private CharsetMatch _testIBM424_he_rtl(String s) throws Exception {
|
||||
byte [] bytes = s.getBytes("IBM424");
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
@ -720,16 +723,16 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetMatch m = det.detect();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
private CharsetMatch _testIBM424_he_ltr(String s) throws Exception {
|
||||
/**
|
||||
* transformation of input string to CP420 left to right requires reversing the string
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
StringBuffer ltrStrBuf = new StringBuffer(s);
|
||||
ltrStrBuf = ltrStrBuf.reverse();
|
||||
byte [] bytes = ltrStrBuf.toString().getBytes("IBM424");
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
det.setDetectableCharset("IBM424_rtl", true);
|
||||
det.setDetectableCharset("IBM424_ltr", true);
|
||||
@ -739,7 +742,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetMatch m = det.detect();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test the method int match(CharsetDetector det) in CharsetRecog_UTF_16_LE
|
||||
*/
|
||||
@ -767,7 +770,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
detector1.setText(data1);
|
||||
CharsetMatch match1 = detector1.detect();
|
||||
assertEquals("Expected GB18030", "GB18030", match1.getName());
|
||||
|
||||
|
||||
CharsetDetector detector2 = new CharsetDetector();
|
||||
byte[] data2 = createData2();
|
||||
detector2.setText(data2);
|
||||
@ -775,12 +778,12 @@ public class TestCharsetDetector extends TestFmwk
|
||||
// It is actually GB18030 but the sample size is way too small to be reliable.
|
||||
assertEquals("Expected ISO-8859-1, even though that isn't strictly correct", "ISO-8859-1", match2.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestReusingDetector() throws Exception
|
||||
{
|
||||
CharsetDetector detector = new CharsetDetector();
|
||||
|
||||
|
||||
byte[] data1 = createData1();
|
||||
detector.setText(data1);
|
||||
CharsetMatch match1 = detector.detect();
|
||||
@ -793,7 +796,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetMatch match2a = detector.detect();
|
||||
assertEquals("[second]Expected ISO-8859-1, even though that isn't strictly correct", "ISO-8859-1", match2a.getName());
|
||||
}
|
||||
|
||||
|
||||
private static byte[] createData1()
|
||||
{
|
||||
return bytesFromString("3B 3B 3B 20 2D 2A 2D 20 4D 6F 64 65 3A 20 4C 49 53 50 3B 20 53 79 6E 74 61 78 " +
|
||||
@ -1084,15 +1087,15 @@ public class TestCharsetDetector extends TestFmwk
|
||||
"23 27 6D 61 74 63 68 69 6E 67 2D 73 75 62 73 74 72 69 6E 67 3F 29 29 0D 0A 09 " +
|
||||
"20 20 0D 0A");
|
||||
}
|
||||
|
||||
|
||||
private static byte[] createData2()
|
||||
{
|
||||
return bytesFromString("0A D0 A1 CA B1 20 3B 3B 20 48 6F 75 72 28 73 29 0A D0 C7 C6 DA 20 3B 3B 20 57 " +
|
||||
"65 65 6B 28 73 29 0A B5 B1 B5 D8 20 CA B1 BC E4 20 3B 3B 20 6C 6F 63 61 6C 20 " +
|
||||
"74 69 6D 65 0A");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a byte array by decoding the hex string passed in.
|
||||
*
|
||||
@ -1117,7 +1120,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
out.write(Integer.parseInt(new String(number), 16));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
//
|
||||
@ -1129,7 +1132,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
public void TestBug9267() {
|
||||
// Test a long input of Lam Alef characters for CharsetRecog_IBM420_ar.
|
||||
// Bug 9267 was an array out of bounds problem in the unshaping code for these.
|
||||
byte [] input = new byte [7700];
|
||||
byte [] input = new byte [7700];
|
||||
int i;
|
||||
for (i=0; i<input.length; i++) {
|
||||
input[i] = (byte)0xb2;
|
||||
@ -1138,7 +1141,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
det.setText(input);
|
||||
det.detect();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBug6954 () throws Exception {
|
||||
// Ticket 6954 - trouble with the haveC1Bytes flag that is used to distinguish between
|
||||
@ -1166,14 +1169,14 @@ public class TestCharsetDetector extends TestFmwk
|
||||
CharsetMatch match2 = csd2.detect();
|
||||
String name2 = match2.getName();
|
||||
assertEquals("Initial use of second detector", "ISO-8859-1", name2);
|
||||
|
||||
|
||||
// Recheck the 1252 results from the first detector, which should not have been
|
||||
// altered by the use of a different detector.
|
||||
|
||||
name1 = match1.getName();
|
||||
assertEquals("Wrong charset name after running a second charset detector", "windows-1252", name1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBug6889() {
|
||||
// Verify that CharsetDetector.detectAll() does not return the same encoding multiple times.
|
||||
@ -1187,18 +1190,18 @@ public class TestCharsetDetector extends TestFmwk
|
||||
fail("Unexpected exception " + e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
det.setText(textBytes);
|
||||
CharsetMatch matches[] = det.detectAll();
|
||||
|
||||
|
||||
HashSet<String> detectedEncodings = new HashSet<String>();
|
||||
for (CharsetMatch m: matches) {
|
||||
assertTrue("Charset " + m.getName() + " encountered before",
|
||||
detectedEncodings.add(m.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestMultithreaded() {
|
||||
String s = "This is some random plain text to run charset detection on.";
|
||||
@ -1210,16 +1213,17 @@ public class TestCharsetDetector extends TestFmwk
|
||||
fail("Unexpected exception " + e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
class WorkerThread extends Thread {
|
||||
WorkerThread(int num) {
|
||||
n = num;
|
||||
}
|
||||
private int n;
|
||||
}
|
||||
private int n;
|
||||
@Override
|
||||
public void run() {
|
||||
// System.out.println("Thread " + n + " is running.");
|
||||
CharsetDetector det = new CharsetDetector();
|
||||
det.setText(bytes);
|
||||
det.setText(bytes);
|
||||
for (int i=0; i<10000; i++) {
|
||||
CharsetMatch matches[] = det.detectAll();
|
||||
for (CharsetMatch m: matches) {
|
||||
@ -1229,7 +1233,7 @@ public class TestCharsetDetector extends TestFmwk
|
||||
// System.out.println("Thread " + n + " is finished.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Thread threads[] = new Thread[10];
|
||||
for (int i=0; i<10; i++) {
|
||||
threads[i] = new WorkerThread(i);
|
||||
@ -1245,5 +1249,5 @@ public class TestCharsetDetector extends TestFmwk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,10 +9,13 @@
|
||||
package com.ibm.icu.dev.test.compression;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.UnicodeDecompressor;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DecompressionTest extends TestFmwk {
|
||||
/** Print out a segment of a character array, if in verbose mode */
|
||||
private void log(char [] chars, int start, int count) {
|
||||
@ -42,7 +45,7 @@ public class DecompressionTest extends TestFmwk {
|
||||
count1 = myDecompressor.decompress(segment1, 0, segment1.length,
|
||||
bytesRead,
|
||||
charBuffer, 0, charBuffer.length);
|
||||
|
||||
|
||||
logln("Segment 1 (" + segment1.length + " bytes) " +
|
||||
"decompressed into " + count1 + " chars");
|
||||
logln("Bytes consumed: " + bytesRead[0]);
|
||||
@ -53,16 +56,16 @@ public class DecompressionTest extends TestFmwk {
|
||||
|
||||
count2 = myDecompressor.decompress(segment2, 0, segment2.length,
|
||||
bytesRead,
|
||||
charBuffer, count1,
|
||||
charBuffer, count1,
|
||||
charBuffer.length);
|
||||
|
||||
|
||||
logln("Segment 2 (" + segment2.length + " bytes) " +
|
||||
"decompressed into " + count2 + " chars");
|
||||
logln("Bytes consumed: " + bytesRead[0]);
|
||||
|
||||
logln("Got chars: ");
|
||||
logln(charBuffer, count1, count2);
|
||||
|
||||
|
||||
s.append(charBuffer, count1, count2);
|
||||
|
||||
logln("Result: ");
|
||||
@ -84,7 +87,7 @@ public class DecompressionTest extends TestFmwk {
|
||||
// continuation
|
||||
/* IDX , S . */
|
||||
byte [] segment2 = { 0x01, 0x2c, 0x20, 0x53, 0x2e };
|
||||
|
||||
|
||||
result = decompressTest(segment1, segment2);
|
||||
if(! result.equals("Booth, S.")) {
|
||||
errln("Decompression test failed");
|
||||
@ -120,16 +123,16 @@ public class DecompressionTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Testing the method
|
||||
* public int decompress(***
|
||||
* public int decompress(***
|
||||
*/
|
||||
@Test
|
||||
public void TestDecompress(){
|
||||
char[] charBufferBlank = {};
|
||||
char[] charBuffer1 = {'a'};
|
||||
char[] charValid = {'d','u','m','m','y'};
|
||||
|
||||
|
||||
// Test when "if(charBuffer.length < 2 || (charBufferLimit - charBufferStart) < 2)" is true
|
||||
// The following tests when "charBuffer.length < 2"
|
||||
UnicodeDecompressor ud = new UnicodeDecompressor();
|
||||
@ -137,42 +140,42 @@ public class DecompressionTest extends TestFmwk {
|
||||
ud.decompress(null, 0, 0, null, null, 4, 0);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charBufferBlank, 4, 0);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charBuffer1, 4, 0);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
// The following tests when "(charBufferLimit - charBufferStart) < 2"
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charValid, 0, 0);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charValid, 1, 0);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charValid, 1, 1);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud.decompress(null, 0, 0, null, charValid, 0, 1);
|
||||
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
|
||||
} catch(Exception e){}
|
||||
|
||||
|
||||
try{
|
||||
ud = new UnicodeDecompressor();
|
||||
byte[] b = {
|
||||
(byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84,
|
||||
(byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84,
|
||||
(byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89,
|
||||
(byte) 0x8A, (byte) 0x8B, (byte) 0x8C, (byte) 0x8D, (byte) 0x8E,
|
||||
(byte) 0x8F, (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93,
|
||||
@ -220,7 +223,7 @@ public class DecompressionTest extends TestFmwk {
|
||||
(byte) 0x7A, (byte) 0x7B, (byte) 0x7C, (byte) 0x7D, (byte) 0x7E,
|
||||
(byte) 0x7F,
|
||||
(byte) UnicodeDecompressor.SQUOTEU,
|
||||
(byte) UnicodeDecompressor.SCHANGEU,
|
||||
(byte) UnicodeDecompressor.SCHANGEU,
|
||||
(byte) UnicodeDecompressor.SQUOTE0, (byte) UnicodeDecompressor.SQUOTE1, (byte) UnicodeDecompressor.SQUOTE2, (byte) UnicodeDecompressor.SQUOTE3,
|
||||
(byte) UnicodeDecompressor.SQUOTE4, (byte) UnicodeDecompressor.SQUOTE5, (byte) UnicodeDecompressor.SQUOTE6, (byte) UnicodeDecompressor.SQUOTE7,
|
||||
(byte) UnicodeDecompressor.SCHANGE0, (byte) UnicodeDecompressor.SCHANGE1, (byte) UnicodeDecompressor.SCHANGE2, (byte) UnicodeDecompressor.SCHANGE3,
|
||||
|
@ -9,11 +9,14 @@
|
||||
package com.ibm.icu.dev.test.compression;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.UnicodeCompressor;
|
||||
import com.ibm.icu.text.UnicodeDecompressor;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ExhaustiveTest extends TestFmwk {
|
||||
/** Test simple compress/decompress API, returning # of errors */
|
||||
@Test
|
||||
@ -25,10 +28,10 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
private void simpleTest(String s) throws Exception {
|
||||
byte [] compressed = UnicodeCompressor.compress(s);
|
||||
String res = UnicodeDecompressor.decompress(compressed);
|
||||
if (logDiffs(s.toCharArray(), s.length(),
|
||||
if (logDiffs(s.toCharArray(), s.length(),
|
||||
res.toCharArray(), res.length()) == false) {
|
||||
logln(s.length() + " chars ===> "
|
||||
+ compressed.length + " bytes ===> "
|
||||
logln(s.length() + " chars ===> "
|
||||
+ compressed.length + " bytes ===> "
|
||||
+ res.length() + " chars");
|
||||
} else {
|
||||
logln("Compressed:");
|
||||
@ -47,7 +50,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
private void myTest(char[] chars, int len) {
|
||||
UnicodeCompressor myCompressor = new UnicodeCompressor();
|
||||
UnicodeDecompressor myDecompressor = new UnicodeDecompressor();
|
||||
|
||||
|
||||
// variables for my compressor
|
||||
int myByteCount = 0;
|
||||
int myCharCount = 0;
|
||||
@ -57,7 +60,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
char[] myDecompressed = new char[myDecompressedSize];
|
||||
int[] unicharsRead = new int[1];
|
||||
int[] bytesRead = new int[1];
|
||||
|
||||
|
||||
myByteCount = myCompressor.compress(chars, 0, len, unicharsRead,
|
||||
myCompressed, 0, myCompressedSize);
|
||||
|
||||
@ -65,8 +68,8 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
bytesRead, myDecompressed, 0, myDecompressedSize);
|
||||
|
||||
if (logDiffs(chars, len, myDecompressed, myCharCount) == false) {
|
||||
logln(len + " chars ===> "
|
||||
+ myByteCount + " bytes ===> "
|
||||
logln(len + " chars ===> "
|
||||
+ myByteCount + " bytes ===> "
|
||||
+ myCharCount + " chars");
|
||||
} else {
|
||||
logln("Compressed:");
|
||||
@ -85,9 +88,9 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
private void myMultipassTest(char [] chars, int len) throws Exception {
|
||||
UnicodeCompressor myCompressor = new UnicodeCompressor();
|
||||
UnicodeDecompressor myDecompressor = new UnicodeDecompressor();
|
||||
|
||||
|
||||
// variables for my compressor
|
||||
|
||||
|
||||
// for looping
|
||||
int byteBufferSize = 4;//Math.max(4, len / 4);
|
||||
byte[] byteBuffer = new byte [byteBufferSize];
|
||||
@ -107,7 +110,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
|
||||
int[] unicharsRead = new int[1];
|
||||
int[] bytesRead = new int[1];
|
||||
|
||||
|
||||
int totalCharsCompressed = 0;
|
||||
int totalBytesWritten = 0;
|
||||
|
||||
@ -119,21 +122,21 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
|
||||
// perform the compression in a loop
|
||||
do {
|
||||
|
||||
|
||||
// do the compression
|
||||
bytesWritten = myCompressor.compress(chars, totalCharsCompressed,
|
||||
bytesWritten = myCompressor.compress(chars, totalCharsCompressed,
|
||||
len, unicharsRead, byteBuffer, 0, byteBufferSize);
|
||||
|
||||
// copy the current set of bytes into the target buffer
|
||||
System.arraycopy(byteBuffer, 0, compressed,
|
||||
System.arraycopy(byteBuffer, 0, compressed,
|
||||
totalBytesWritten, bytesWritten);
|
||||
|
||||
|
||||
// update the no. of characters compressed
|
||||
totalCharsCompressed += unicharsRead[0];
|
||||
|
||||
|
||||
// update the no. of bytes written
|
||||
totalBytesWritten += bytesWritten;
|
||||
|
||||
|
||||
/*System.out.logln("Compression pass complete. Compressed "
|
||||
+ unicharsRead[0] + " chars into "
|
||||
+ bytesWritten + " bytes.");*/
|
||||
@ -145,40 +148,40 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
} else {
|
||||
logln("MP: " + len + " chars ===> " + totalBytesWritten + " bytes.");
|
||||
}
|
||||
|
||||
|
||||
// perform the decompression in a loop
|
||||
do {
|
||||
|
||||
|
||||
// do the decompression
|
||||
unicharsWritten = myDecompressor.decompress(compressed,
|
||||
totalBytesDecompressed, totalBytesWritten,
|
||||
unicharsWritten = myDecompressor.decompress(compressed,
|
||||
totalBytesDecompressed, totalBytesWritten,
|
||||
bytesRead, unicharBuffer, 0, unicharBufferSize);
|
||||
|
||||
// copy the current set of chars into the target buffer
|
||||
System.arraycopy(unicharBuffer, 0, decompressed,
|
||||
System.arraycopy(unicharBuffer, 0, decompressed,
|
||||
totalCharsWritten, unicharsWritten);
|
||||
|
||||
|
||||
// update the no. of bytes decompressed
|
||||
totalBytesDecompressed += bytesRead[0];
|
||||
|
||||
|
||||
// update the no. of chars written
|
||||
totalCharsWritten += unicharsWritten;
|
||||
|
||||
|
||||
/*System.out.logln("Decompression pass complete. Decompressed "
|
||||
+ bytesRead[0] + " bytes into "
|
||||
+ unicharsWritten + " chars.");*/
|
||||
} while (totalBytesDecompressed < totalBytesWritten);
|
||||
|
||||
if (totalBytesDecompressed != totalBytesWritten) {
|
||||
errln("ERROR: Number of bytes decompressed("
|
||||
+ totalBytesDecompressed
|
||||
+ ") != totalBytesWritten("
|
||||
errln("ERROR: Number of bytes decompressed("
|
||||
+ totalBytesDecompressed
|
||||
+ ") != totalBytesWritten("
|
||||
+ totalBytesWritten + ")");
|
||||
} else {
|
||||
logln("MP: " + totalBytesWritten
|
||||
+ " bytes ===> " + totalCharsWritten + " chars.");
|
||||
}
|
||||
|
||||
|
||||
if (logDiffs(chars, len, decompressed, totalCharsWritten)) {
|
||||
errln("ERROR: buffer contents incorrect");
|
||||
}
|
||||
@ -187,7 +190,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
/** Print differences between two character buffers */
|
||||
private boolean logDiffs(char[] s1, int s1len, char[] s2, int s2len) {
|
||||
boolean result = false;
|
||||
|
||||
|
||||
if(s1len != s2len) {
|
||||
logln("====================");
|
||||
logln("Length doesn't match: expected " + s1len
|
||||
@ -198,7 +201,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
printChars(s2, s2len);
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
||||
int len = Math.min(s1len, s2len);
|
||||
for(int i = 0; i < len; ++i) {
|
||||
if(s1[i] != s2[i]) {
|
||||
@ -216,7 +219,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -225,7 +228,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
char[] result = new char [len];
|
||||
int runLen = 0;
|
||||
int used = 0;
|
||||
|
||||
|
||||
while(used < len) {
|
||||
runLen = (int) (30 * random.nextDouble());
|
||||
if(used + runLen >= len) {
|
||||
@ -234,7 +237,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
randomRun(result, used, runLen, random);
|
||||
used += runLen;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}*/
|
||||
|
||||
@ -287,7 +290,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
|
||||
"\ud800\udc00", // smallest surrogate
|
||||
"\ud8ff\udcff", // largest surrogate pair
|
||||
|
||||
|
||||
// regression tests
|
||||
"\u6441\ub413\ua733\uf8fe\ueedb\u587f\u195f\u4899\uf23d\u49fd\u0aac\u5792\ufc22\ufc3c\ufc46\u00aa",
|
||||
"\u30f9\u8321\u05e5\u181c\ud72b\u2019\u99c9\u2f2f\uc10c\u82e1\u2c4d\u1ebc\u6013\u66dc\ubbde\u94a5\u4726\u74af\u3083\u55b9\u000c",
|
||||
@ -303,7 +306,7 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
//==========================
|
||||
private final static int SINGLEBYTEMODE = 0;
|
||||
private final static int UNICODEMODE = 1;
|
||||
|
||||
|
||||
//==========================
|
||||
// Single-byte mode tags
|
||||
//==========================
|
||||
@ -364,11 +367,11 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
private final static int UDEFINEX = 0xF1;
|
||||
//private final static int URESERVED = 0xF2; // this is a reserved value
|
||||
|
||||
/* Print out an array of characters, with non-printables (for me)
|
||||
/* Print out an array of characters, with non-printables (for me)
|
||||
displayed as hex values */
|
||||
private void printChars(char[] chars, int len) {
|
||||
for(int i = 0; i < len; i++) {
|
||||
int c = (int)chars[i];
|
||||
int c = chars[i];
|
||||
if(c < 0x0020 || c >= 0x7f) {
|
||||
log("[0x");
|
||||
log(Integer.toHexString(c));
|
||||
@ -385,137 +388,137 @@ public class ExhaustiveTest extends TestFmwk {
|
||||
int byteBufferLimit = len;
|
||||
int mode = SINGLEBYTEMODE;
|
||||
int aByte = 0x00;
|
||||
|
||||
|
||||
if(len > byteBuffer.length) {
|
||||
logln("Warning: printBytes called with length too large. Truncating");
|
||||
byteBufferLimit = byteBuffer.length;
|
||||
}
|
||||
|
||||
|
||||
while(curByteIndex < byteBufferLimit) {
|
||||
switch(mode) {
|
||||
switch(mode) {
|
||||
case SINGLEBYTEMODE:
|
||||
while(curByteIndex < byteBufferLimit
|
||||
while(curByteIndex < byteBufferLimit
|
||||
&& mode == SINGLEBYTEMODE) {
|
||||
aByte = ((int)byteBuffer[curByteIndex++]) & 0xFF;
|
||||
aByte = (byteBuffer[curByteIndex++]) & 0xFF;
|
||||
switch(aByte) {
|
||||
default:
|
||||
log(Integer.toHexString(((int) aByte) & 0xFF) + " ");
|
||||
log(Integer.toHexString((aByte) & 0xFF) + " ");
|
||||
break;
|
||||
// quote unicode
|
||||
case SQUOTEU:
|
||||
log("SQUOTEU ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// switch to Unicode mode
|
||||
case SSWITCHU:
|
||||
log("SSWITCHU ");
|
||||
mode = UNICODEMODE;
|
||||
break;
|
||||
|
||||
|
||||
// handle all quote tags
|
||||
case SQUOTE0: case SQUOTE1: case SQUOTE2: case SQUOTE3:
|
||||
case SQUOTE4: case SQUOTE5: case SQUOTE6: case SQUOTE7:
|
||||
log("SQUOTE" + (aByte - SQUOTE0) + " ");
|
||||
if(curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// handle all switch tags
|
||||
case SSWITCH0: case SSWITCH1: case SSWITCH2: case SSWITCH3:
|
||||
case SSWITCH4: case SSWITCH5: case SSWITCH6: case SSWITCH7:
|
||||
log("SSWITCH" + (aByte - SSWITCH0) + " ");
|
||||
break;
|
||||
|
||||
|
||||
// handle all define tags
|
||||
case SDEFINE0: case SDEFINE1: case SDEFINE2: case SDEFINE3:
|
||||
case SDEFINE4: case SDEFINE5: case SDEFINE6: case SDEFINE7:
|
||||
log("SDEFINE" + (aByte - SDEFINE0) + " ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// handle define extended tag
|
||||
case SDEFINEX:
|
||||
log("SDEFINEX ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
} // end switch
|
||||
} // end while
|
||||
break;
|
||||
|
||||
|
||||
case UNICODEMODE:
|
||||
while(curByteIndex < byteBufferLimit && mode == UNICODEMODE) {
|
||||
aByte = ((int)byteBuffer[curByteIndex++]) & 0xFF;
|
||||
aByte = (byteBuffer[curByteIndex++]) & 0xFF;
|
||||
switch(aByte) {
|
||||
// handle all define tags
|
||||
case UDEFINE0: case UDEFINE1: case UDEFINE2: case UDEFINE3:
|
||||
case UDEFINE4: case UDEFINE5: case UDEFINE6: case UDEFINE7:
|
||||
log("UDEFINE" + (aByte - UDEFINE0) + " ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
mode = SINGLEBYTEMODE;
|
||||
break;
|
||||
|
||||
|
||||
// handle define extended tag
|
||||
case UDEFINEX:
|
||||
log("UDEFINEX ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// handle all switch tags
|
||||
case USWITCH0: case USWITCH1: case USWITCH2: case USWITCH3:
|
||||
case USWITCH4: case USWITCH5: case USWITCH6: case USWITCH7:
|
||||
log("USWITCH" + (aByte - USWITCH0) + " ");
|
||||
mode = SINGLEBYTEMODE;
|
||||
break;
|
||||
|
||||
|
||||
// quote unicode
|
||||
case UQUOTEU:
|
||||
log("UQUOTEU ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
log(Integer.toHexString(((int) aByte) & 0xFF) + " ");
|
||||
log(Integer.toHexString((aByte) & 0xFF) + " ");
|
||||
if (curByteIndex < byteBufferLimit) {
|
||||
log(Integer.toHexString(((int) byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
log(Integer.toHexString((byteBuffer[curByteIndex++]) & 0xFF) + " ");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
} // end switch
|
||||
} // end while
|
||||
break;
|
||||
|
||||
|
||||
} // end switch( mode )
|
||||
} // end while
|
||||
|
||||
|
||||
logln("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,11 +15,14 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.impl.XMLRecordReader;
|
||||
import com.ibm.icu.impl.duration.impl.XMLRecordWriter;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DataReadWriteTest extends TestFmwk {
|
||||
// strip line ends and trailing spaces
|
||||
private String normalize(String str) {
|
||||
@ -80,7 +83,7 @@ public class DataReadWriteTest extends TestFmwk {
|
||||
{ true, false },
|
||||
{ true, false, true },
|
||||
};
|
||||
|
||||
|
||||
String[] targets = {
|
||||
"<testList></testList>",
|
||||
"<testList><test>true</test></testList>",
|
||||
@ -255,7 +258,7 @@ public class DataReadWriteTest extends TestFmwk {
|
||||
String s4 = " It is\n only a test\t ";
|
||||
String s4x = " It is only a test ";
|
||||
|
||||
String[][] datas = {
|
||||
String[][] datas = {
|
||||
{},
|
||||
{ s1 },
|
||||
{ s2, s1 },
|
||||
@ -268,11 +271,11 @@ public class DataReadWriteTest extends TestFmwk {
|
||||
"<testList></testList>",
|
||||
"<testList><test>" + s1 + "</test></testList>",
|
||||
"<testList><test>" + s2 + "</test><test>" + s1 + "</test></testList>",
|
||||
"<testList><test>" + s3 + "</test><test>" + s2 +
|
||||
"<testList><test>" + s3 + "</test><test>" + s2 +
|
||||
"</test><test>" + s1 + "</test></testList>",
|
||||
"<testList><test>" + s3 + "</test><test>Null</test><test>" + s1 +
|
||||
"<testList><test>" + s3 + "</test><test>Null</test><test>" + s1 +
|
||||
"</test><test>Null</test></testList>",
|
||||
"<testList><test>" + s4x + "</test><test>" + s1 +
|
||||
"<testList><test>" + s4x + "</test><test>" + s1 +
|
||||
"</test><test>" + s3 + "</test><test>" + s2 + "</test></testList>",
|
||||
};
|
||||
|
||||
@ -311,7 +314,7 @@ public class DataReadWriteTest extends TestFmwk {
|
||||
String s3 = "This is a test";
|
||||
String s4 = "It is only a test";
|
||||
|
||||
String[][] table = {
|
||||
String[][] table = {
|
||||
{},
|
||||
{ s1 },
|
||||
{ s2, s1 },
|
||||
@ -324,7 +327,7 @@ public class DataReadWriteTest extends TestFmwk {
|
||||
"<testList></testList>" +
|
||||
"<testList><test></test></testList>" +
|
||||
"<testList><test> </test><test></test></testList>" +
|
||||
"<testList><test>This is a test</test><test> </test>" +
|
||||
"<testList><test>This is a test</test><test> </test>" +
|
||||
"<test></test></testList>" +
|
||||
"<testList>Null</testList>" +
|
||||
"<testList><test>It is only a test</test><test></test>" +
|
||||
|
@ -20,6 +20,8 @@ import javax.xml.datatype.DatatypeConstants.Field;
|
||||
import javax.xml.datatype.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DurationFormat;
|
||||
@ -30,6 +32,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class ICUDurationTest extends TestFmwk {
|
||||
/**
|
||||
* Allows us to not depend on javax.xml.datatype.DatatypeFactory.
|
||||
@ -161,7 +164,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public ICUDurationTest() {
|
||||
}
|
||||
@ -174,7 +177,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
DurationFormat df;
|
||||
String expect;
|
||||
String formatted;
|
||||
|
||||
|
||||
df = DurationFormat.getInstance(new ULocale("it"));
|
||||
formatted = df.formatDurationFromNow(4096);
|
||||
expect = "fra quattro secondi";
|
||||
@ -183,7 +186,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
} else {
|
||||
logln("format duration -> " + formatted);
|
||||
}
|
||||
|
||||
|
||||
formatted = df.formatDurationFromNowTo(new Date(0));
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int years = cal.get(Calendar.YEAR) - 1970; // year of Date(0)
|
||||
@ -193,7 +196,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
} else {
|
||||
logln("format date -> " + formatted);
|
||||
}
|
||||
|
||||
|
||||
formatted = df.formatDurationFrom(1000*3600*24, new Date(0).getTime());
|
||||
expect = "fra un giorno";
|
||||
if(!expect.equals(formatted)) {
|
||||
@ -218,7 +221,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
String out;
|
||||
String expected;
|
||||
String expected2;
|
||||
|
||||
|
||||
// test 1
|
||||
d = newDuration(1, 2, 46, 40); // "PT2H46M40S"
|
||||
df = DurationFormat.getInstance(new ULocale("en"));
|
||||
@ -229,7 +232,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
} else {
|
||||
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
|
||||
}
|
||||
|
||||
|
||||
// test 2
|
||||
d = newDuration(10000);
|
||||
df = DurationFormat.getInstance(new ULocale("en"));
|
||||
@ -313,7 +316,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
|
||||
DurationFormat df = DurationFormat.getInstance(locale);
|
||||
String output = df.format(d);
|
||||
|
||||
|
||||
if(output.equals(to)) {
|
||||
logln("SUCCESS: locale: " + loc + ", from " + from + " ["+d.toString()+"] " +" to " + to + "= " + output);
|
||||
} else {
|
||||
@ -364,7 +367,7 @@ public class ICUDurationTest extends TestFmwk {
|
||||
errln("FAIL: null DurationFormat returned.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Tests the class
|
||||
* DurationFormat
|
||||
*/
|
||||
@ -372,14 +375,18 @@ public class ICUDurationTest extends TestFmwk {
|
||||
public void TestDurationFormat(){
|
||||
@SuppressWarnings("serial")
|
||||
class TestDurationFormat extends DurationFormat {
|
||||
@Override
|
||||
public StringBuffer format(Object object, StringBuffer toAppend, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public String formatDurationFrom(long duration, long referenceDate) {return null;}
|
||||
@Override
|
||||
public String formatDurationFromNow(long duration) {return null;}
|
||||
@Override
|
||||
public String formatDurationFromNowTo(Date targetDate) {return null;}
|
||||
public TestDurationFormat() {super();}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Tests the constructor and the following method
|
||||
// public Object parseObject(String source, ParsePosition pos)
|
||||
try{
|
||||
|
@ -21,6 +21,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.BasicPeriodFormatterService;
|
||||
@ -37,10 +39,11 @@ import com.ibm.icu.impl.duration.impl.DataRecord.EUnitVariant;
|
||||
/**
|
||||
* Test cases for en
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public abstract class LanguageTestFmwk extends TestFmwk implements TimeUnitConstants {
|
||||
|
||||
private static final TimeUnit[] units = {
|
||||
TimeUnit.YEAR, TimeUnit.MONTH, TimeUnit.WEEK, TimeUnit.DAY, TimeUnit.HOUR,
|
||||
TimeUnit.YEAR, TimeUnit.MONTH, TimeUnit.WEEK, TimeUnit.DAY, TimeUnit.HOUR,
|
||||
TimeUnit.MINUTE, TimeUnit.SECOND, TimeUnit.MILLISECOND
|
||||
};
|
||||
|
||||
@ -63,7 +66,7 @@ public abstract class LanguageTestFmwk extends TestFmwk implements TimeUnitConst
|
||||
private static final Map datacache = new HashMap(); // String->TestData
|
||||
|
||||
private static final long[] approxDurations = {
|
||||
36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L,
|
||||
36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L,
|
||||
60*60*1000L, 60*1000L, 1000L, 1L
|
||||
};
|
||||
|
||||
@ -536,46 +539,57 @@ class FileTestData extends LanguageTestFmwk.TestData {
|
||||
private String[] fractionalUnitTargets;
|
||||
private String[] multipleUnitTargets;
|
||||
|
||||
@Override
|
||||
int[] getFullPluralizedFormCounts() {
|
||||
return fullPluralizedFormCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getFullPluralizedFormTargets() {
|
||||
return fullPluralizedFormTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getMediumFormTargets() {
|
||||
return mediumFormTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getShortFormTargets() {
|
||||
return shortFormTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getCustomMinuteTargets() {
|
||||
return customMinuteTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getLimitedUnitTargets() {
|
||||
return limitedUnitTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
int[] getHalfUnitCounts() {
|
||||
return halfUnitCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getHalfUnitTargets() {
|
||||
return halfUnitTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
float[] getFractionalUnitCounts() {
|
||||
return fractionalUnitCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getFractionalUnitTargets() {
|
||||
return fractionalUnitTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getMultipleUnitTargets() {
|
||||
return multipleUnitTargets;
|
||||
}
|
||||
@ -695,46 +709,57 @@ class DefaultData extends LanguageTestFmwk.TestData {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
int[] getFullPluralizedFormCounts() {
|
||||
return fullPluralizedFormCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getFullPluralizedFormTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getMediumFormTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getShortFormTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getCustomMinuteTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getLimitedUnitTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
int[] getHalfUnitCounts() {
|
||||
return halfUnitCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getHalfUnitTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
float[] getFractionalUnitCounts() {
|
||||
return fractionalUnitCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getFractionalUnitTargets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getMultipleUnitTargets() {
|
||||
return null;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
package com.ibm.icu.dev.test.duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.BasicPeriodFormatterService;
|
||||
@ -21,14 +23,15 @@ import com.ibm.icu.impl.duration.PeriodBuilderFactory;
|
||||
import com.ibm.icu.impl.duration.TimeUnit;
|
||||
import com.ibm.icu.impl.duration.TimeUnitConstants;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class PeriodBuilderFactoryTest extends TestFmwk implements TimeUnitConstants {
|
||||
private PeriodBuilderFactory pbf;
|
||||
|
||||
private static final long[] approxDurations = {
|
||||
36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L,
|
||||
36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L,
|
||||
60*60*1000L, 60*1000L, 1000L, 1L
|
||||
};
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetAvailableUnitRange() {
|
||||
// sanity check, make sure by default all units are set
|
||||
@ -86,7 +89,7 @@ public class PeriodBuilderFactoryTest extends TestFmwk implements TimeUnitConsta
|
||||
assertNotNull(null, pbf.getOneOrTwoUnitBuilder());
|
||||
assertNotNull(null, pbf.getMultiUnitBuilder(2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuilderFactoryPeriodConstruction() {
|
||||
// see ticket #8307
|
||||
@ -98,7 +101,7 @@ public class PeriodBuilderFactoryTest extends TestFmwk implements TimeUnitConsta
|
||||
assertEquals("hours", 1.0f, p.getCount(HOUR));
|
||||
assertEquals("minutes", 35.501f, p.getCount(MINUTE));
|
||||
assertFalse("seconds", p.isSet(SECOND));
|
||||
|
||||
|
||||
pb = pbf.getMultiUnitBuilder(3);
|
||||
p = pb.create(H1M35S30M100);
|
||||
assertEquals("hours", 1.0f, p.getCount(HOUR));
|
||||
|
@ -12,11 +12,14 @@
|
||||
package com.ibm.icu.dev.test.duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.Period;
|
||||
import com.ibm.icu.impl.duration.TimeUnit;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class PeriodTest extends TestFmwk {
|
||||
@Test
|
||||
public void testIsSet() {
|
||||
|
@ -9,6 +9,8 @@
|
||||
package com.ibm.icu.dev.test.duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.BasicPeriodFormatterService;
|
||||
@ -18,23 +20,24 @@ import com.ibm.icu.impl.duration.PeriodFormatterService;
|
||||
import com.ibm.icu.text.DurationFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class RegressionTest extends TestFmwk {
|
||||
// bug6397
|
||||
@Test
|
||||
public void TestDisallowedMillis() {
|
||||
// original test case
|
||||
// if we don't support milliseconds, format times less than 1 second as
|
||||
// if we don't support milliseconds, format times less than 1 second as
|
||||
// 'less than 1 second'
|
||||
{
|
||||
ULocale ul = new ULocale("th");
|
||||
DurationFormat df = DurationFormat.getInstance(ul);
|
||||
String result = df.formatDurationFromNow(500);
|
||||
assertEquals(
|
||||
"original test case",
|
||||
"\u0E44\u0E21\u0E48\u0E16\u0E36\u0E07\u0E2D\u0E35\u0E01 1 \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35",
|
||||
"original test case",
|
||||
"\u0E44\u0E21\u0E48\u0E16\u0E36\u0E07\u0E2D\u0E35\u0E01 1 \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35",
|
||||
result);
|
||||
}
|
||||
|
||||
|
||||
// same issue, but using English and the internal APIs
|
||||
{
|
||||
PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
|
||||
@ -49,10 +52,10 @@ public class RegressionTest extends TestFmwk {
|
||||
"english test case",
|
||||
"less than 1 second from now",
|
||||
result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// if the limit is set on milliseconds, and they are not supported,
|
||||
|
||||
// if the limit is set on milliseconds, and they are not supported,
|
||||
// use an effective limit based on seconds
|
||||
{
|
||||
PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
|
||||
|
@ -15,11 +15,14 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.duration.impl.PeriodFormatterData;
|
||||
import com.ibm.icu.impl.duration.impl.ResourceBasedPeriodFormatterDataService;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ResourceBasedPeriodFormatterDataServiceTest extends TestFmwk {
|
||||
@Test
|
||||
public void testAvailable() {
|
||||
|
@ -12,6 +12,8 @@ import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
@ -23,6 +25,7 @@ import com.ibm.icu.text.NumberFormat;
|
||||
* @test
|
||||
* General test of Big NumberFormat
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class BigNumberFormatTest extends TestFmwk {
|
||||
|
||||
static final int ILLEGAL = -1;
|
||||
|
@ -25,6 +25,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.number.Properties;
|
||||
@ -37,6 +39,7 @@ import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.CurrencyAmount;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class CompactDecimalFormatTest extends TestFmwk {
|
||||
Object[][] EnglishTestData = {
|
||||
// default is 2 digits of accuracy
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v1.8.1 : format : DateFormatMiscTests
|
||||
* Source File: $ICU4CRoot/source/test/intltest/miscdtfm.cpp
|
||||
**/
|
||||
@ -20,14 +20,18 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormatSymbols;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Performs miscellaneous tests for DateFormat, SimpleDateFormat, DateFormatSymbols
|
||||
**/
|
||||
public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateFormatMiscTests extends TestFmwk {
|
||||
/*
|
||||
* @bug 4097450
|
||||
*/
|
||||
@ -38,13 +42,13 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
//
|
||||
String dstring[] = {
|
||||
"97", "1997", "97", "1997", "01", "2001", "01", "2001",
|
||||
"1", "1", "11", "11", "111", "111"};
|
||||
|
||||
String dformat[] =
|
||||
"1", "1", "11", "11", "111", "111"};
|
||||
|
||||
String dformat[] =
|
||||
{
|
||||
"yy", "yy", "yyyy", "yyyy", "yy", "yy", "yyyy", "yyyy",
|
||||
"yy", "yyyy", "yy", "yyyy", "yy", "yyyy"};
|
||||
|
||||
"yy", "yy", "yyyy", "yyyy", "yy", "yy", "yyyy", "yyyy",
|
||||
"yy", "yyyy", "yy", "yyyy", "yy", "yyyy"};
|
||||
|
||||
SimpleDateFormat formatter;
|
||||
SimpleDateFormat resultFormatter = new SimpleDateFormat("yyyy");
|
||||
logln("Format\tSource\tResult");
|
||||
@ -55,7 +59,7 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
try {
|
||||
StringBuffer str = new StringBuffer("");
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
logln(resultFormatter.format(formatter.parse(dstring[i]), str, pos).toString());
|
||||
logln(resultFormatter.format(formatter.parse(dstring[i]), str, pos).toString());
|
||||
}
|
||||
catch (ParseException exception) {
|
||||
errln("exception --> " + exception);
|
||||
@ -63,7 +67,7 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @Bug 4099975
|
||||
* SimpleDateFormat constructor SimpleDateFormat(String, DateFormatSymbols)
|
||||
* should clone the DateFormatSymbols parameter
|
||||
@ -76,15 +80,15 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
DateFormatSymbols symbols = new DateFormatSymbols(Locale.US);
|
||||
SimpleDateFormat df = new SimpleDateFormat("E hh:mm", symbols);
|
||||
SimpleDateFormat dfClone = (SimpleDateFormat) df.clone();
|
||||
|
||||
|
||||
logln(df.toLocalizedPattern());
|
||||
String s0 = df.format(d);
|
||||
String s_dfClone = dfClone.format(d);
|
||||
|
||||
|
||||
symbols.setLocalPatternChars("abcdefghijklmonpqr"); // change value of field
|
||||
logln(df.toLocalizedPattern());
|
||||
String s1 = df.format(d);
|
||||
|
||||
|
||||
if (!s1.equals(s0) || !s1.equals(s_dfClone)) {
|
||||
errln("Constructor: the formats are not equal");
|
||||
}
|
||||
@ -98,15 +102,15 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
SimpleDateFormat df = new SimpleDateFormat("E hh:mm");
|
||||
df.setDateFormatSymbols(symbols);
|
||||
SimpleDateFormat dfClone = (SimpleDateFormat) df.clone();
|
||||
|
||||
|
||||
logln(df.toLocalizedPattern());
|
||||
String s0 = df.format(d);
|
||||
String s_dfClone = dfClone.format(d);
|
||||
|
||||
|
||||
symbols.setLocalPatternChars("abcdefghijklmonpqr"); // change value of field
|
||||
logln(df.toLocalizedPattern());
|
||||
String s1 = df.format(d);
|
||||
|
||||
|
||||
if (!s1.equals(s0) || !s1.equals(s_dfClone)) {
|
||||
errln("setDateFormatSymbols: the formats are not equal");
|
||||
}
|
||||
@ -115,7 +119,7 @@ public class DateFormatMiscTests extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @bug 4117335
|
||||
*/
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v1.8.1 : format : DateFormatRegressionTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/dtfmrgts.cpp
|
||||
**/
|
||||
@ -28,7 +28,10 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
@ -39,10 +42,11 @@ import com.ibm.icu.util.SimpleTimeZone;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Performs regression test for DateFormat
|
||||
**/
|
||||
public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateFormatRegressionTest extends TestFmwk {
|
||||
/**
|
||||
* @bug 4029195
|
||||
*/
|
||||
@ -58,7 +62,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
fmtd = sdf.format(today, fmtd, pos);
|
||||
logln("today: " + fmtd);
|
||||
|
||||
|
||||
sdf.applyPattern("G yyyy DDD");
|
||||
StringBuffer todayS = new StringBuffer("");
|
||||
todayS = sdf.format(today, todayS, pos);
|
||||
@ -69,7 +73,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch (Exception e) {
|
||||
errln("Error reparsing date: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
StringBuffer rt = new StringBuffer("");
|
||||
rt = sdf.format(sdf.parse(todayS.toString()), rt, pos);
|
||||
@ -81,24 +85,24 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4052408
|
||||
*/
|
||||
@Test
|
||||
public void Test4052408() {
|
||||
|
||||
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
|
||||
|
||||
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(97 + 1900, Calendar.MAY, 3, 8, 55);
|
||||
Date dt = cal.getTime();
|
||||
String str = fmt.format(dt);
|
||||
logln(str);
|
||||
|
||||
|
||||
if (!str.equals("5/3/97, 8:55 AM"))
|
||||
errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str);
|
||||
|
||||
|
||||
String expected[] = {
|
||||
"", //"ERA_FIELD",
|
||||
"97", //"YEAR_FIELD",
|
||||
@ -118,27 +122,27 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
"8", //"HOUR1_FIELD",
|
||||
"", //"HOUR0_FIELD",
|
||||
"" //"TIMEZONE_FIELD"
|
||||
};
|
||||
};
|
||||
String fieldNames[] = {
|
||||
"ERA_FIELD",
|
||||
"YEAR_FIELD",
|
||||
"MONTH_FIELD",
|
||||
"DATE_FIELD",
|
||||
"HOUR_OF_DAY1_FIELD",
|
||||
"HOUR_OF_DAY0_FIELD",
|
||||
"MINUTE_FIELD",
|
||||
"SECOND_FIELD",
|
||||
"MILLISECOND_FIELD",
|
||||
"DAY_OF_WEEK_FIELD",
|
||||
"DAY_OF_YEAR_FIELD",
|
||||
"DAY_OF_WEEK_IN_MONTH_FIELD",
|
||||
"WEEK_OF_YEAR_FIELD",
|
||||
"WEEK_OF_MONTH_FIELD",
|
||||
"AM_PM_FIELD",
|
||||
"HOUR1_FIELD",
|
||||
"HOUR0_FIELD",
|
||||
"TIMEZONE_FIELD"};
|
||||
|
||||
"ERA_FIELD",
|
||||
"YEAR_FIELD",
|
||||
"MONTH_FIELD",
|
||||
"DATE_FIELD",
|
||||
"HOUR_OF_DAY1_FIELD",
|
||||
"HOUR_OF_DAY0_FIELD",
|
||||
"MINUTE_FIELD",
|
||||
"SECOND_FIELD",
|
||||
"MILLISECOND_FIELD",
|
||||
"DAY_OF_WEEK_FIELD",
|
||||
"DAY_OF_YEAR_FIELD",
|
||||
"DAY_OF_WEEK_IN_MONTH_FIELD",
|
||||
"WEEK_OF_YEAR_FIELD",
|
||||
"WEEK_OF_MONTH_FIELD",
|
||||
"AM_PM_FIELD",
|
||||
"HOUR1_FIELD",
|
||||
"HOUR0_FIELD",
|
||||
"TIMEZONE_FIELD"};
|
||||
|
||||
boolean pass = true;
|
||||
for (int i = 0; i <= 17; ++i) {
|
||||
FieldPosition pos = new FieldPosition(i);
|
||||
@ -148,7 +152,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String dst = buf.substring(pos.getBeginIndex(), pos.getEndIndex());
|
||||
str = dst;
|
||||
log(i + ": " + fieldNames[i] + ", \"" + str + "\", "
|
||||
+ pos.getBeginIndex() + ", " + pos.getEndIndex());
|
||||
+ pos.getBeginIndex() + ", " + pos.getEndIndex());
|
||||
String exp = expected[i];
|
||||
if ((exp.length() == 0 && str.length() == 0) || str.equals(exp))
|
||||
logln(" ok");
|
||||
@ -160,14 +164,14 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
if (!pass)
|
||||
errln("Fail: FieldPosition not set right by DateFormat");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4056591
|
||||
* Verify the function of the [s|g]et2DigitYearStart() API.
|
||||
*/
|
||||
@Test
|
||||
public void Test4056591() {
|
||||
|
||||
|
||||
try {
|
||||
SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd", Locale.US);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -189,11 +193,11 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
cal.clear();
|
||||
cal.set(1861, Calendar.DECEMBER, 25);
|
||||
Date d4 = cal.getTime();
|
||||
|
||||
|
||||
Date dates[] = {d1, d2, d3, d4};
|
||||
|
||||
String strings[] = {"091225", "091224", "091226", "611225"};
|
||||
|
||||
|
||||
String strings[] = {"091225", "091224", "091226", "611225"};
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String s = strings[i];
|
||||
Date exp = dates[i];
|
||||
@ -207,40 +211,40 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4059917
|
||||
*/
|
||||
@Test
|
||||
public void Test4059917() {
|
||||
public void Test4059917() {
|
||||
SimpleDateFormat fmt;
|
||||
String myDate;
|
||||
fmt = new SimpleDateFormat("yyyy/MM/dd");
|
||||
myDate = "1997/01/01";
|
||||
aux917( fmt, myDate );
|
||||
aux917( fmt, myDate );
|
||||
fmt = new SimpleDateFormat("yyyyMMdd");
|
||||
myDate = "19970101";
|
||||
aux917( fmt, myDate );
|
||||
}
|
||||
|
||||
|
||||
public void aux917(SimpleDateFormat fmt, String str) {
|
||||
|
||||
|
||||
String pat = fmt.toPattern();
|
||||
logln("==================");
|
||||
logln("testIt: pattern=" + pat + " string=" + str);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Object o = fmt.parseObject(str, pos);
|
||||
//logln( UnicodeString("Parsed object: ") + o );
|
||||
|
||||
|
||||
StringBuffer formatted = new StringBuffer("");
|
||||
FieldPosition poss = new FieldPosition(0);
|
||||
formatted = fmt.format(o, formatted, poss);
|
||||
|
||||
|
||||
logln("Formatted string: " + formatted);
|
||||
if (!formatted.toString().equals(str))
|
||||
errln("Fail: Want " + str + " Got " + formatted);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4060212
|
||||
*/
|
||||
@ -252,14 +256,14 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-DDD.hh:mm:ss");
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date myDate = formatter.parse(dateString, pos);
|
||||
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
|
||||
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
|
||||
String myString = fmt.format(myDate);
|
||||
logln(myString);
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(myDate);
|
||||
if ((cal.get(Calendar.DAY_OF_YEAR) != 40))
|
||||
errln("Fail: Got " + cal.get(Calendar.DAY_OF_YEAR) + " Want 40");
|
||||
|
||||
|
||||
logln("Using yyyy-ddd.hh:mm:ss");
|
||||
formatter = new SimpleDateFormat("yyyy-ddd.hh:mm:ss");
|
||||
pos.setIndex(0);
|
||||
@ -275,7 +279,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
*/
|
||||
@Test
|
||||
public void Test4061287() {
|
||||
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
|
||||
try {
|
||||
logln(df.parse("35/01/1971").toString());
|
||||
@ -293,7 +297,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
if (!ok)
|
||||
errln("Fail: Lenient not working");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4065240
|
||||
*/
|
||||
@ -304,7 +308,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String strShortDate, strFullDate;
|
||||
Locale saveLocale = Locale.getDefault();
|
||||
TimeZone saveZone = TimeZone.getDefault();
|
||||
|
||||
|
||||
try {
|
||||
Locale curLocale = new Locale("de", "DE");
|
||||
Locale.setDefault(curLocale);
|
||||
@ -324,16 +328,16 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
strFullDate = "The current date (long form) is ";
|
||||
String temp2 = fulldate.format(curDate);
|
||||
strFullDate += temp2;
|
||||
|
||||
|
||||
logln(strShortDate);
|
||||
logln(strFullDate);
|
||||
|
||||
|
||||
// {sfb} What to do with resource bundle stuff?????
|
||||
|
||||
|
||||
// Check to see if the resource is present; if not, we can't test
|
||||
//ResourceBundle bundle = //The variable is never used
|
||||
// ICULocaleData.getBundle("DateFormatZoneData", curLocale);
|
||||
|
||||
// ICULocaleData.getBundle("DateFormatZoneData", curLocale);
|
||||
|
||||
// {sfb} API change to ResourceBundle -- add getLocale()
|
||||
/*if (bundle.getLocale().getLanguage().equals("de")) {
|
||||
// UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
|
||||
@ -349,16 +353,16 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
Locale.setDefault(saveLocale);
|
||||
TimeZone.setDefault(saveZone);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
DateFormat.equals is too narrowly defined. As a result, MessageFormat
|
||||
does not work correctly. DateFormat.equals needs to be written so
|
||||
that the Calendar sub-object is not compared using Calendar.equals,
|
||||
but rather compared for equivalency. This may necessitate adding a
|
||||
(package private) method to Calendar to test for equivalency.
|
||||
|
||||
|
||||
Currently this bug breaks MessageFormat.toPattern
|
||||
*/
|
||||
/**
|
||||
@ -368,7 +372,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public void Test4071441() {
|
||||
DateFormat fmtA = DateFormat.getInstance();
|
||||
DateFormat fmtB = DateFormat.getInstance();
|
||||
|
||||
|
||||
// {sfb} Is it OK to cast away const here?
|
||||
Calendar calA = fmtA.getCalendar();
|
||||
Calendar calB = fmtB.getCalendar();
|
||||
@ -388,14 +392,14 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
errln("Fail: DateFormat unequal when Calendars equivalent");
|
||||
logln("DateFormat.equals ok");
|
||||
}
|
||||
|
||||
|
||||
/* The java.text.DateFormat.parse(String) method expects for the
|
||||
US locale a string formatted according to mm/dd/yy and parses it
|
||||
correctly.
|
||||
|
||||
|
||||
When given a string mm/dd/yyyy it only parses up to the first
|
||||
two y's, typically resulting in a date in the year 1919.
|
||||
|
||||
|
||||
Please extend the parsing method(s) to handle strings with
|
||||
four-digit year values (probably also applicable to various
|
||||
other locales. */
|
||||
@ -423,9 +427,9 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch (ParseException e) {
|
||||
errln("Fail: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4089106
|
||||
*/
|
||||
@ -442,24 +446,24 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
TimeZone.setDefault(def);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4100302
|
||||
*/
|
||||
@Test
|
||||
public void Test4100302() {
|
||||
|
||||
|
||||
Locale locales[] = {
|
||||
Locale.CANADA, Locale.CANADA_FRENCH, Locale.CHINA,
|
||||
Locale.CHINESE, Locale.ENGLISH, Locale.FRANCE, Locale.FRENCH,
|
||||
Locale.GERMAN, Locale.GERMANY, Locale.ITALIAN, Locale.ITALY,
|
||||
Locale.JAPAN, Locale.JAPANESE, Locale.KOREA, Locale.KOREAN,
|
||||
Locale.PRC, Locale.SIMPLIFIED_CHINESE, Locale.TAIWAN,
|
||||
Locale.TRADITIONAL_CHINESE, Locale.UK, Locale.US};
|
||||
Locale.CANADA, Locale.CANADA_FRENCH, Locale.CHINA,
|
||||
Locale.CHINESE, Locale.ENGLISH, Locale.FRANCE, Locale.FRENCH,
|
||||
Locale.GERMAN, Locale.GERMANY, Locale.ITALIAN, Locale.ITALY,
|
||||
Locale.JAPAN, Locale.JAPANESE, Locale.KOREA, Locale.KOREAN,
|
||||
Locale.PRC, Locale.SIMPLIFIED_CHINESE, Locale.TAIWAN,
|
||||
Locale.TRADITIONAL_CHINESE, Locale.UK, Locale.US};
|
||||
try {
|
||||
boolean pass = true;
|
||||
for (int i = 0; i < 21; i++) {
|
||||
Format format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locales[i]);
|
||||
Format format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locales[i]);
|
||||
byte[] bytes;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
@ -471,7 +475,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
Object o = ois.readObject();
|
||||
if (!format.equals(o)) {
|
||||
pass = false;
|
||||
logln("DateFormat instance for locale " + locales[i] + " is incorrectly serialized/deserialized.");
|
||||
logln("DateFormat instance for locale " + locales[i] + " is incorrectly serialized/deserialized.");
|
||||
} else {
|
||||
logln("DateFormat instance for locale " + locales[i] + " is OKAY.");
|
||||
}
|
||||
@ -485,9 +489,9 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch (ClassNotFoundException e) {
|
||||
errln("Fail: " + e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4101483
|
||||
*/
|
||||
@ -504,7 +508,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
if (fp.getBeginIndex() == fp.getEndIndex())
|
||||
errln("Fail: Empty field");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4103340
|
||||
* @bug 4138203
|
||||
@ -515,25 +519,25 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
*/
|
||||
@Test
|
||||
public void Test4103340() {
|
||||
|
||||
// choose a date that is the FIRST of some month
|
||||
|
||||
// choose a date that is the FIRST of some month
|
||||
// and some arbitrary time
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(1997, 3, 1, 1, 1, 1);
|
||||
Date d = cal.getTime();
|
||||
Date d = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat("MMMM", Locale.US);
|
||||
String s = d.toString();
|
||||
StringBuffer s2 = new StringBuffer("");
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
s2 = df.format(d, s2, pos);
|
||||
logln("Date=" + s);
|
||||
logln("Date=" + s);
|
||||
logln("DF=" + s2);
|
||||
String substr = s2.substring(0,2);
|
||||
if (s.indexOf(substr) == -1)
|
||||
errln("Months should match");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4103341
|
||||
*/
|
||||
@ -551,7 +555,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
TimeZone.setDefault(saveZone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4104136
|
||||
*/
|
||||
@ -582,7 +586,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
errln( "Fail: Expected result " + exp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4104522
|
||||
* CANNOT REPRODUCE
|
||||
@ -605,9 +609,9 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
pp.setIndex(0);
|
||||
text = "time";
|
||||
dt = sdf.parse(text, pp);
|
||||
logln(" text: \"" + text + "\"" + " date: " + dt);
|
||||
logln(" text: \"" + text + "\"" + " date: " + dt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4106807
|
||||
*/
|
||||
@ -615,19 +619,19 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public void Test4106807() {
|
||||
Date dt;
|
||||
DateFormat df = DateFormat.getDateTimeInstance();
|
||||
|
||||
|
||||
SimpleDateFormat sdfs[] = {
|
||||
new SimpleDateFormat("yyyyMMddHHmmss"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss'Z'"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss''"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss'a''a'"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss %")};
|
||||
new SimpleDateFormat("yyyyMMddHHmmss"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss'Z'"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss''"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss'a''a'"),
|
||||
new SimpleDateFormat("yyyyMMddHHmmss %")};
|
||||
String strings[] = {
|
||||
"19980211140000",
|
||||
"19980211140000",
|
||||
"19980211140000",
|
||||
"19980211140000a",
|
||||
"19980211140000 "};
|
||||
"19980211140000",
|
||||
"19980211140000",
|
||||
"19980211140000",
|
||||
"19980211140000a",
|
||||
"19980211140000 "};
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
TimeZone timeZone = TimeZone.getDefault();
|
||||
TimeZone gmt = (TimeZone) timeZone.clone();
|
||||
@ -639,12 +643,12 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
format.setTimeZone(gmt);
|
||||
dt = format.parse(dateString);
|
||||
// {sfb} some of these parses will fail purposely
|
||||
|
||||
|
||||
StringBuffer fmtd = new StringBuffer("");
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
fmtd = df.format(dt, fmtd, pos);
|
||||
logln(fmtd.toString());
|
||||
//logln(df.format(dt));
|
||||
//logln(df.format(dt));
|
||||
gc.setTime(dt);
|
||||
logln("" + gc.get(Calendar.ZONE_OFFSET));
|
||||
StringBuffer s = new StringBuffer("");
|
||||
@ -655,35 +659,35 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Synopsis: Chinese time zone CTT is not recogonized correctly.
|
||||
Description: Platform Chinese Windows 95 - ** Time zone set to CST **
|
||||
Description: Platform Chinese Windows 95 - ** Time zone set to CST **
|
||||
*/
|
||||
/**
|
||||
* @bug 4108407
|
||||
*/
|
||||
|
||||
// {sfb} what to do with this one ??
|
||||
|
||||
// {sfb} what to do with this one ??
|
||||
@Test
|
||||
public void Test4108407() {
|
||||
/*
|
||||
// TODO user.timezone is a protected system property, catch securityexception and warn
|
||||
// if this is reenabled
|
||||
long l = System.currentTimeMillis();
|
||||
long l = System.currentTimeMillis();
|
||||
logln("user.timezone = " + System.getProperty("user.timezone", "?"));
|
||||
logln("Time Zone :" +
|
||||
DateFormat.getDateInstance().getTimeZone().getID());
|
||||
logln("Default format :" +
|
||||
DateFormat.getDateInstance().format(new Date(l)));
|
||||
logln("Full format :" +
|
||||
DateFormat.getDateInstance(DateFormat.FULL).format(new
|
||||
Date(l)));
|
||||
logln("Time Zone :" +
|
||||
DateFormat.getDateInstance().getTimeZone().getID());
|
||||
logln("Default format :" +
|
||||
DateFormat.getDateInstance().format(new Date(l)));
|
||||
logln("Full format :" +
|
||||
DateFormat.getDateInstance(DateFormat.FULL).format(new
|
||||
Date(l)));
|
||||
logln("*** Set host TZ to CST ***");
|
||||
logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4134203
|
||||
* SimpleDateFormat won't parse "GMT"
|
||||
@ -692,7 +696,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public void Test4134203() {
|
||||
String dateFormat = "MM/dd/yy HH:mm:ss zzz";
|
||||
SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
|
||||
|
||||
|
||||
ParsePosition p0 = new ParsePosition(0);
|
||||
Date d = fmt.parse("01/22/92 04:52:00 GMT", p0);
|
||||
logln(d.toString());
|
||||
@ -701,15 +705,15 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
// In the failure case an exception is thrown by parse();
|
||||
// if no exception is thrown, the test passes.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4151631
|
||||
* SimpleDateFormat incorrect handling of 2 single quotes in format()
|
||||
*/
|
||||
@Test
|
||||
public void Test4151631() {
|
||||
String pattern =
|
||||
"'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
|
||||
String pattern =
|
||||
"'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
|
||||
logln("pattern=" + pattern);
|
||||
SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US);
|
||||
StringBuffer result = new StringBuffer("");
|
||||
@ -718,14 +722,14 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
cal.clear();
|
||||
cal.set(1998, Calendar.JUNE, 30, 13, 30, 0);
|
||||
Date d = cal.getTime();
|
||||
result = format.format(d, result, pos);
|
||||
result = format.format(d, result, pos);
|
||||
if (!result.toString().equals("TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')")) {
|
||||
errln("Fail: result=" + result);
|
||||
} else {
|
||||
logln("Pass: result=" + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4151706
|
||||
* 'z' at end of date format throws index exception in SimpleDateFormat
|
||||
@ -751,7 +755,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
logln(dateString + " . " + fmt.format(d, temp, pos));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @bug 4162071
|
||||
* Cannot reproduce this bug under 1.2 FCS -- it may be a convoluted duplicate
|
||||
@ -771,7 +775,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
errln("Parse format \"" + format + "\" failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DateFormat shouldn't parse year "-1" as a two-digit year (e.g., "-1" . 1999).
|
||||
*/
|
||||
@ -784,10 +788,10 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
* greater than "99", are treated as literal years. So "1/2/3456"
|
||||
* becomes 3456 AD. Likewise, "1/2/-3" becomes -3 AD == 2 BC.
|
||||
*/
|
||||
final String STRINGS[] =
|
||||
{"02/29/00", "01/23/01", "04/05/-1", "01/23/-9", "11/12/1314", "10/31/1", "09/12/+1", "09/12/001",};
|
||||
final String STRINGS[] =
|
||||
{"02/29/00", "01/23/01", "04/05/-1", "01/23/-9", "11/12/1314", "10/31/1", "09/12/+1", "09/12/001",};
|
||||
int STRINGS_COUNT = STRINGS.length;
|
||||
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Date FAIL_DATE = cal.getTime();
|
||||
cal.clear();
|
||||
@ -808,16 +812,16 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
cal.clear();
|
||||
cal.set(1, Calendar.OCTOBER, 31);
|
||||
Date d5 = cal.getTime();
|
||||
cal.clear();
|
||||
cal.clear();
|
||||
cal.set(1, Calendar.SEPTEMBER, 12);
|
||||
Date d7 = cal.getTime();
|
||||
Date DATES[] = {d0, d1, d2, d3, d4, d5, FAIL_DATE, d7};
|
||||
|
||||
|
||||
String out = "";
|
||||
boolean pass = true;
|
||||
for (int i = 0; i < STRINGS_COUNT; ++i) {
|
||||
String str = STRINGS[i];
|
||||
Date expected = DATES[i];
|
||||
Date expected = DATES[i];
|
||||
Date actual = null;
|
||||
try {
|
||||
actual = fmt.parse(str);
|
||||
@ -831,7 +835,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
// Yuck: See j25
|
||||
actStr = ((DateFormat) dispFmt).format(actual);
|
||||
}
|
||||
|
||||
|
||||
if (expected.getTime() == (actual.getTime())) {
|
||||
out += str + " => " + actStr + "\n";
|
||||
} else {
|
||||
@ -852,18 +856,18 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
err(out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* j32 {JDK Bug 4210209 4209272}
|
||||
* DateFormat cannot parse Feb 29 2000 when setLenient(false)
|
||||
*/
|
||||
@Test
|
||||
public void Test4210209() {
|
||||
|
||||
|
||||
String pattern = "MMM d, yyyy";
|
||||
DateFormat fmt = new SimpleDateFormat(pattern, Locale.US);
|
||||
DateFormat disp = new SimpleDateFormat("MMM dd yyyy GG", Locale.US);
|
||||
|
||||
|
||||
Calendar calx = fmt.getCalendar();
|
||||
calx.setLenient(false);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@ -880,7 +884,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
if (pos.getErrorIndex() != -1) {
|
||||
errln("FAIL: Error index should be -1");
|
||||
}
|
||||
|
||||
|
||||
// The underlying bug is in GregorianCalendar. If the following lines
|
||||
// succeed, the bug is fixed. If the bug isn't fixed, they will throw
|
||||
// an exception.
|
||||
@ -891,7 +895,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
d = cal.getTime();
|
||||
logln("Attempt to set Calendar to Feb 29 2000: " + disp.format(d));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void Test714() {
|
||||
//TimeZone Offset
|
||||
@ -982,7 +986,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what + "=" + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kHindiZero || first>(kHindiZero+9)) {
|
||||
errln(what + "- wrong digit, got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + "- wrong digit, got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -993,7 +997,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what + ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kArabicZero || first>(kArabicZero+9)) {
|
||||
errln(what + " wrong digit, got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit, got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1004,7 +1008,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what + ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kArabicZero || first>(kArabicZero+9)) {
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -1014,7 +1018,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what + ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kLatinZero || first>(kLatinZero+9)) {
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1025,7 +1029,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what+ ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kArabicZero || first>(kArabicZero+9)) {
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1036,7 +1040,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what+ ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kArabicZero || first>(kArabicZero+9)) {
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1047,7 +1051,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(what+ ": " + s);
|
||||
first = s.charAt(0);
|
||||
if(first<kArabicZero || first>(kArabicZero+9)) {
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer((int)first).toString());
|
||||
errln(what + " wrong digit but got " + s + " (integer digit value " + new Integer(first).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1138,7 +1142,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String twelfthMonthLocalizedCivil = shortMonthsCivil[11];
|
||||
|
||||
islamicCivilTwelfthMonthLocalized[i] = twelfthMonthLocalizedCivil;
|
||||
|
||||
|
||||
com.ibm.icu.util.IslamicCalendar islamicCalendar = new com.ibm.icu.util.IslamicCalendar(locale);
|
||||
islamicCalendar.setCivil(false);
|
||||
com.ibm.icu.text.SimpleDateFormat islamicDateFormat = (com.ibm.icu.text.SimpleDateFormat) islamicCalendar
|
||||
@ -1195,7 +1199,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestParsing() {
|
||||
String pattern = "EEE-WW-MMMM-yyyy";
|
||||
@ -1205,7 +1209,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||
Calendar cal = GregorianCalendar.getInstance(Locale.US);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
|
||||
|
||||
try {
|
||||
format.parse(text, cal, pos);
|
||||
} catch (Exception e) {
|
||||
@ -1231,7 +1235,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String dangiDateStr = fmt.format(d);
|
||||
assertEquals("Bad date format", "Mo1 20, 2013", dangiDateStr);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestT10110() {
|
||||
try {
|
||||
@ -1250,7 +1254,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
@Test
|
||||
public void TestT10239() {
|
||||
|
||||
|
||||
class TestDateFormatItem {
|
||||
public String parseString;
|
||||
public String pattern;
|
||||
@ -1262,7 +1266,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
expectedResult = expResult;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
final TestDateFormatItem[] items = {
|
||||
// parse String pattern expected result
|
||||
new TestDateFormatItem("1 Oct 13 2013", "e MMM dd yyyy", "1 Oct 13 2013"),
|
||||
@ -1277,7 +1281,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
Date d = new Date();
|
||||
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
|
||||
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
|
||||
SimpleDateFormat sdfmt = new SimpleDateFormat();
|
||||
ParsePosition p = new ParsePosition(0);
|
||||
for (TestDateFormatItem item: items) {
|
||||
@ -1307,7 +1311,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void TestT10334() {
|
||||
@ -1315,11 +1319,11 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String text = new String("--mon-02-march-2011");
|
||||
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||
|
||||
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_LITERAL_MATCH, false);
|
||||
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_LITERAL_MATCH, false);
|
||||
try {
|
||||
format.parse(text);
|
||||
errln("parse partial match did NOT fail in strict mode!");
|
||||
} catch (ParseException pe) {
|
||||
} catch (ParseException pe) {
|
||||
// expected
|
||||
}
|
||||
|
||||
@ -1335,7 +1339,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
format.applyPattern(pattern);
|
||||
Date referenceDate = null;
|
||||
try {
|
||||
referenceDate = format.parse(text);
|
||||
referenceDate = format.parse(text);
|
||||
} catch (ParseException pe) {
|
||||
errln("unable to instantiate reference date: " + pe.getLocalizedMessage());
|
||||
}
|
||||
@ -1343,7 +1347,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
FieldPosition fp = new FieldPosition(0);
|
||||
pattern = new String("YYYY LL dd ee cc qq QQ");
|
||||
format.applyPattern(pattern);
|
||||
StringBuffer formattedString = new StringBuffer();
|
||||
StringBuffer formattedString = new StringBuffer();
|
||||
formattedString = format.format(referenceDate, formattedString, fp);
|
||||
logln("ref date: " + formattedString);
|
||||
|
||||
@ -1352,13 +1356,13 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
text = new String("2013 12 10 03 3 04 04");
|
||||
format.applyPattern(pattern);
|
||||
logln(format.format(referenceDate));
|
||||
|
||||
|
||||
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_ALLOW_NUMERIC, true);
|
||||
ParsePosition pp = new ParsePosition(0);
|
||||
format.parse(text, pp);
|
||||
int errorIdx = pp.getErrorIndex();
|
||||
if (errorIdx != -1) {
|
||||
|
||||
|
||||
errln("numeric parse error at["+errorIdx+"] on char["+pattern.substring(errorIdx, errorIdx+1)+"] in pattern["+pattern+"]");
|
||||
}
|
||||
|
||||
@ -1369,7 +1373,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch (ParseException pe) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* test to verify new code (and improve code coverage) for normal quarter processing
|
||||
*/
|
||||
@ -1384,7 +1388,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
@Test
|
||||
public void TestT10619() {
|
||||
|
||||
|
||||
class TestDateFormatLeniencyItem {
|
||||
public boolean leniency;
|
||||
public String parseString;
|
||||
@ -1412,7 +1416,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
Date d = new Date();
|
||||
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
|
||||
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
|
||||
SimpleDateFormat sdfmt = new SimpleDateFormat();
|
||||
ParsePosition p = new ParsePosition(0);
|
||||
for (TestDateFormatLeniencyItem item: items) {
|
||||
@ -1443,7 +1447,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestT10906()
|
||||
{
|
||||
@ -1454,7 +1458,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
try {
|
||||
format.parse(text, pp);
|
||||
int errorIdx = pp.getErrorIndex();
|
||||
if (errorIdx == -1) {
|
||||
if (errorIdx == -1) {
|
||||
errln("failed to report invalid (negative) starting parse position");
|
||||
}
|
||||
} catch(StringIndexOutOfBoundsException e) {
|
||||
@ -1476,6 +1480,7 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String s0 = fmt.format(d);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
@ -20,31 +20,35 @@ import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.DateFormatSymbols;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
|
||||
public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateFormatRegressionTestJ extends TestFmwk {
|
||||
|
||||
private static final String TIME_STRING = "2000/11/17 08:01:00";
|
||||
private static final long UTC_LONG = 974476860000L;
|
||||
private SimpleDateFormat sdf_;
|
||||
|
||||
|
||||
@Before
|
||||
public void init()throws Exception {
|
||||
sdf_ = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
sdf_ = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
}
|
||||
|
||||
|
||||
//Return value of getAmPmStrings
|
||||
@Test
|
||||
public void Test4103926() {
|
||||
String act_Ampms[];
|
||||
String exp_Ampms[]={"AM","PM"};
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
|
||||
DateFormatSymbols dfs = new DateFormatSymbols();
|
||||
act_Ampms = dfs.getAmPmStrings();
|
||||
if(act_Ampms.length != exp_Ampms.length) {
|
||||
@ -57,24 +61,24 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
// Missing digit in millisecond format in SimpleDateFormat
|
||||
// Missing digit in millisecond format in SimpleDateFormat
|
||||
@Test
|
||||
public void Test4148168() {
|
||||
Date d = new Date(1002705212906L);
|
||||
String[] ISOPattern = {
|
||||
"''yyyy-MM-dd-hh.mm.ss.S''", "''yyyy-MM-dd-hh.mm.ss.SS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSS''", "''yyyy-MM-dd-hh.mm.ss.SSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.S''", "''yyyy-MM-dd-hh.mm.ss.SS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSS''", "''yyyy-MM-dd-hh.mm.ss.SSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSS000''"};
|
||||
SimpleDateFormat aSimpleDF = (SimpleDateFormat)DateFormat.getDateTimeInstance();
|
||||
|
||||
|
||||
for(int i = 0; i<ISOPattern.length; i++) {
|
||||
aSimpleDF.applyPattern( ISOPattern[i] );
|
||||
logln( "Pattern = " + aSimpleDF.toPattern());
|
||||
logln( "Format = " + aSimpleDF.format(d));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//DateFormat getDateTimeInstance(int, int), invalid styles no exception
|
||||
@Test
|
||||
public void Test4213086() {
|
||||
@ -87,8 +91,8 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch(Exception e){
|
||||
logln("dateStyle = 2" + "\t timeStyle = -2");
|
||||
logln("Exception caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
DateFormat df3 = DateFormat.getDateTimeInstance(4, 2);
|
||||
d = df3.format(someDate);
|
||||
@ -98,7 +102,7 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("Exception caught!");
|
||||
logln("********************************************");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
DateFormat df4 = DateFormat.getDateTimeInstance(-12, -12);
|
||||
d = df4.format(someDate);
|
||||
@ -108,10 +112,10 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("Exception caught!");
|
||||
logln("********************************************");
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
DateFormat df5 = DateFormat.getDateTimeInstance(2, 123);
|
||||
d = df5.format(someDate);
|
||||
d = df5.format(someDate);
|
||||
errln("we should catch an exception here");
|
||||
} catch(Exception e){
|
||||
logln("dateStyle = 2" + "\t timeStyle = 123");
|
||||
@ -123,7 +127,7 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("The value of d: " + d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//DateFormat.format works wrongly?
|
||||
@Test
|
||||
public void Test4250359() {
|
||||
@ -135,26 +139,26 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
String act_result = tf.format(d);
|
||||
String exp_result = "5:53 PM";
|
||||
|
||||
|
||||
if(!act_result.equals(exp_result)){
|
||||
errln("The result is not expected");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//pattern "s.S, parse '1ms'"
|
||||
@Test
|
||||
public void Test4253490() {
|
||||
Date d = new Date(1002705212231L);
|
||||
|
||||
String[] ISOPattern = {
|
||||
"''yyyy-MM-dd-hh.mm.ss.S''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSSSS''"};
|
||||
|
||||
"''yyyy-MM-dd-hh.mm.ss.S''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSSS''",
|
||||
"''yyyy-MM-dd-hh.mm.ss.SSSSSSS''"};
|
||||
|
||||
SimpleDateFormat aSimpleDF = (SimpleDateFormat) DateFormat.getDateTimeInstance();
|
||||
for (int i = 0; i < ISOPattern.length; i++) {
|
||||
aSimpleDF.applyPattern(ISOPattern[i]);
|
||||
@ -162,7 +166,7 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("Format = " + aSimpleDF.format(d));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//about regression test
|
||||
@Test
|
||||
public void Test4266432() {
|
||||
@ -170,13 +174,13 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
Locale loc = Locale.getDefault();
|
||||
String dateFormat = "MM/dd/yy HH:mm:ss zzz";
|
||||
SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
|
||||
|
||||
|
||||
ParsePosition p0 = new ParsePosition(0);
|
||||
logln("Under " + loc +" locale");
|
||||
Date d = fmt.parse("01/22/92 04:52:00 GMT", p0);
|
||||
logln(d.toString());
|
||||
}
|
||||
|
||||
|
||||
//SimpleDateFormat inconsistent for number of digits for years
|
||||
@Test
|
||||
public void Test4358730() {
|
||||
@ -185,22 +189,22 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
cal.clear();
|
||||
cal.set(2001,11,10);
|
||||
Date today = cal.getTime();
|
||||
|
||||
|
||||
sdf.applyPattern("MM d y");
|
||||
logln(sdf.format(today));
|
||||
sdf.applyPattern("MM d yy");
|
||||
logln(sdf.format(today));
|
||||
|
||||
|
||||
sdf.applyPattern("MM d yyy");
|
||||
logln(sdf.format(today));
|
||||
|
||||
|
||||
sdf.applyPattern("MM d yyyy");
|
||||
logln(sdf.format(today));
|
||||
|
||||
|
||||
sdf.applyPattern("MM d yyyyy");
|
||||
logln(sdf.format(today));
|
||||
}
|
||||
|
||||
|
||||
//Parse invalid string
|
||||
@Test
|
||||
public void Test4375399() {
|
||||
@ -227,7 +231,7 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {}
|
||||
}*/
|
||||
|
||||
|
||||
@Test
|
||||
public void Test4468663() {
|
||||
Date d =new Date(-93716671115767L);
|
||||
@ -240,23 +244,24 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("original date: " + origin_d.toString());
|
||||
str = sdf.format(d);
|
||||
logln(" after format----->" + str);
|
||||
|
||||
|
||||
d = sdf.parse(str, new ParsePosition(0));
|
||||
logln(" after parse----->" + d.toString());
|
||||
|
||||
|
||||
str = sdf.format(d);
|
||||
logln(" after format----->" + str);
|
||||
|
||||
|
||||
d = sdf.parse(str, new ParsePosition(0));
|
||||
logln(" after parse----->" + d.toString());
|
||||
|
||||
|
||||
str = sdf.format(d);
|
||||
logln(" after format----->" + str);
|
||||
logln(" after format----->" + str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Class used by Test4407042
|
||||
class DateParseThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleDateFormat sdf = (SimpleDateFormat) sdf_.clone();
|
||||
TimeZone defaultTZ = TimeZone.getDefault();
|
||||
@ -272,7 +277,7 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
long t = date.getTime();
|
||||
i++;
|
||||
if (t != ms) {
|
||||
throw new ParseException("Parse Error: " + i + " (" + sdf.format(date)
|
||||
throw new ParseException("Parse Error: " + i + " (" + sdf.format(date)
|
||||
+ ") " + t + " != " + ms, 0);
|
||||
}
|
||||
}
|
||||
@ -281,10 +286,11 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Class used by Test4407042
|
||||
class DateFormatThread extends Thread {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleDateFormat sdf = (SimpleDateFormat) sdf_.clone();
|
||||
TimeZone tz = TimeZone.getTimeZone("PST");
|
||||
sdf.setTimeZone(tz);
|
||||
@ -293,11 +299,11 @@ public class DateFormatRegressionTestJ extends com.ibm.icu.dev.test.TestFmwk {
|
||||
i++;
|
||||
String s = sdf.format(new Date(UTC_LONG));
|
||||
if (!s.equals(TIME_STRING)) {
|
||||
errln("Format Error: " + i + " " + s + " != "
|
||||
errln("Format Error: " + i + " " + s + " != "
|
||||
+ TIME_STRING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,10 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
@ -31,7 +34,8 @@ import com.ibm.icu.util.TimeZone;
|
||||
/**
|
||||
* Performs round-trip tests for DateFormat
|
||||
**/
|
||||
public class DateFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateFormatRoundTripTest extends TestFmwk {
|
||||
public boolean INFINITE = false;
|
||||
public boolean quick = true;
|
||||
private SimpleDateFormat dateFormat;
|
||||
|
@ -37,7 +37,10 @@ import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.text.ChineseDateFormat;
|
||||
@ -63,7 +66,8 @@ import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateFormatTest extends TestFmwk {
|
||||
/**
|
||||
* Verify that patterns have the correct values and could produce the
|
||||
* the DateFormat instances that contain the correct localized patterns.
|
||||
@ -2394,9 +2398,9 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
f.format((Object)cal, buf, pos);
|
||||
f.format((Object)now, buf, pos);
|
||||
f.format((Object)new Long(now.getTime()), buf, pos);
|
||||
f.format(new Long(now.getTime()), buf, pos);
|
||||
try {
|
||||
f.format((Object)"Howdy", buf, pos);
|
||||
f.format("Howdy", buf, pos);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
@ -4000,7 +4004,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String expected = data[i + 1];
|
||||
if (!out.equals(expected))
|
||||
{
|
||||
errln((String)"FAIL: " + in + " -> " + out + " expected -> " + expected);
|
||||
errln("FAIL: " + in + " -> " + out + " expected -> " + expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4023,7 +4027,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String res1 = result.toString();
|
||||
String expected = "\u4e8c\u3007\u3007\u4e5d\u5e74\u4e03\u6708\u4e8c\u5341\u516b\u65e5";
|
||||
if (! res1.equals(expected)) {
|
||||
errln((String)"FAIL: -> " + result.toString() + " expected -> " + expected);
|
||||
errln("FAIL: -> " + result.toString() + " expected -> " + expected);
|
||||
}
|
||||
ParsePosition pp = new ParsePosition(0);
|
||||
Date parsedate = sdf.parse(expected, pp);
|
||||
@ -4090,7 +4094,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
String expected = DATA[i][1];
|
||||
|
||||
if (!result.equals(expected))
|
||||
errln((String) "FAIL: -> " + result.toString() + " expected -> " + expected);
|
||||
errln("FAIL: -> " + result.toString() + " expected -> " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,8 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.PatternTokenizer;
|
||||
@ -40,6 +42,7 @@ import com.ibm.icu.util.SimpleTimeZone;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateTimeGeneratorTest extends TestFmwk {
|
||||
public static boolean GENERATE_TEST_DATA;
|
||||
static {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: JDK 1.4b1 : java.text.Format.IntlTestDateFormat
|
||||
* Source File: java/text/format/IntlTestDateFormat.java
|
||||
**/
|
||||
@ -25,12 +25,16 @@ import java.util.Random;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDateFormat extends TestFmwk {
|
||||
// Values in milliseconds (== Date)
|
||||
private static final long ONESECOND = 1000;
|
||||
private static final long ONEMINUTE = 60 * ONESECOND;
|
||||
@ -52,12 +56,12 @@ public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public IntlTestDateFormat() {
|
||||
//Constructure
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
fFormat = DateFormat.getInstance();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestULocale() {
|
||||
localeTest(ULocale.getDefault(), "Default Locale");
|
||||
@ -144,7 +148,7 @@ public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
|
||||
SimpleDateFormat s = (SimpleDateFormat) fFormat;
|
||||
logln(fTestName + " Pattern " + s.toPattern());
|
||||
}
|
||||
|
||||
|
||||
private void tryDate(Date theDate) {
|
||||
final int DEPTH = 10;
|
||||
Date[] date = new Date[DEPTH];
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: JDK 1.4b1 : java.text.Format.IntlTestDateFormatAPI
|
||||
* Source File: java/text/format/IntlTestDateFormatAPI.java
|
||||
**/
|
||||
@ -25,7 +25,10 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import com.ibm.icu.dev.test.TestUtil.JavaVendor;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
@ -33,7 +36,8 @@ import com.ibm.icu.text.NumberFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
|
||||
public class IntlTestDateFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDateFormatAPI extends TestFmwk
|
||||
{
|
||||
// Test that the equals method works correctly.
|
||||
@Test
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: ICU4C v1.8.1 : format : IntlTestDateFormatAPI
|
||||
* Source File: $ICU4CRoot/source/test/intltest/dtfmapts.cpp
|
||||
**/
|
||||
@ -19,7 +19,10 @@ import java.text.ParsePosition;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
@ -30,7 +33,8 @@ import com.ibm.icu.text.SimpleDateFormat;
|
||||
* try to test the full functionality. It just calls each function in the class and
|
||||
* verifies that it works on a basic level.
|
||||
*/
|
||||
public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDateFormatAPIC extends TestFmwk {
|
||||
/**
|
||||
* Test hiding of parse() and format() APIs in the Format hierarchy.
|
||||
* We test the entire hierarchy, even though this test is located in
|
||||
@ -38,17 +42,17 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
*/
|
||||
@Test
|
||||
public void TestNameHiding() {
|
||||
|
||||
|
||||
// N.B.: This test passes if it COMPILES, since it's a test of
|
||||
// compile-time name hiding.
|
||||
|
||||
|
||||
Date dateObj = new Date(0);
|
||||
Number numObj = new Double(3.1415926535897932384626433832795);
|
||||
StringBuffer strBuffer = new StringBuffer("");
|
||||
String str;
|
||||
FieldPosition fpos = new FieldPosition(0);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
|
||||
|
||||
// DateFormat calling Format API
|
||||
{
|
||||
logln("DateFormat");
|
||||
@ -60,7 +64,7 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
errln("FAIL: Can't create DateFormat");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SimpleDateFormat calling Format & DateFormat API
|
||||
{
|
||||
logln("SimpleDateFormat");
|
||||
@ -78,7 +82,7 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
System.out.println(pe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// NumberFormat calling Format API
|
||||
{
|
||||
logln("NumberFormat");
|
||||
@ -90,7 +94,7 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
errln("FAIL: Can't create NumberFormat");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DecimalFormat calling Format & NumberFormat API
|
||||
{
|
||||
logln("DecimalFormat");
|
||||
@ -113,7 +117,7 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
System.out.println(pe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ICU4J have not the classes ChoiceFormat and MessageFormat
|
||||
/*
|
||||
// ChoiceFormat calling Format & NumberFormat API
|
||||
@ -135,8 +139,8 @@ public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
System.out.println(pe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// MessageFormat calling Format API
|
||||
{
|
||||
logln("MessageFormat");
|
||||
|
@ -6,11 +6,11 @@
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: JDK 1.4b1 : java.text.Format.IntlTestDateFormatSymbols
|
||||
* Source File: java/text/format/IntlTestDateFormatSymbols.java
|
||||
**/
|
||||
|
||||
|
||||
/*
|
||||
@test 1.4 98/03/06
|
||||
@summary test International Date Format Symbols
|
||||
@ -21,12 +21,16 @@ package com.ibm.icu.dev.test.format;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormatSymbols;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDateFormatSymbols extends TestFmwk
|
||||
{
|
||||
// Test getMonths
|
||||
@Test
|
||||
@ -56,7 +60,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
|
||||
int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
|
||||
int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
|
||||
|
||||
|
||||
for (int i = 0; i < context.length; i++) {
|
||||
for (int j = 0; j < width.length; j++) {
|
||||
String[] month =symbol.getMonths(context[i],width[j]);
|
||||
@ -70,7 +74,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestGetWeekdays2(){
|
||||
DateFormatSymbols symbol;
|
||||
@ -78,7 +82,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
|
||||
int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
|
||||
int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
|
||||
|
||||
|
||||
for (int i = 0; i < context.length; i++) {
|
||||
for (int j = 0; j < width.length; j++) {
|
||||
String[] wd =symbol.getWeekdays(context[i],width[j]);
|
||||
@ -91,9 +95,9 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestGetEraNames(){
|
||||
DateFormatSymbols symbol;
|
||||
@ -102,7 +106,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
logln(s[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean UnicodeStringsArePrefixes(String[] prefixArray, String[] baseArray){
|
||||
@ -508,7 +512,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
if(! en.equals(fr)) {
|
||||
errln("ERROR: Clone failed");
|
||||
}
|
||||
|
||||
|
||||
final String[] shortYearNames = zhChiCal.getYearNames(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
|
||||
final String[] narrowYearNames = zhChiCal.getYearNames(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
|
||||
if (shortYearNames == null || shortYearNames.length != 60 ||
|
||||
@ -537,7 +541,7 @@ public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
!testZodiacNames[0].equals("Rat") || !testZodiacNames[11].equals("Pig")) {
|
||||
errln("ERROR: setZodiacNames then getZodiacNames not working for zh@calendar=chinese");
|
||||
}
|
||||
|
||||
|
||||
String leapMonthPatternFmtAbbrev = zhChiCal.getLeapMonthPattern(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
|
||||
if (leapMonthPatternFmtAbbrev == null || !leapMonthPatternFmtAbbrev.equals("\u95F0{0}")) {
|
||||
errln("ERROR: invalid FORMAT/ABBREVIATED leapMonthPattern from zh@calendar=chinese");
|
||||
|
@ -25,14 +25,18 @@ import java.text.ParsePosition;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.math.BigDecimal;
|
||||
import com.ibm.icu.math.MathContext;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
|
||||
public class IntlTestDecimalFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDecimalFormatAPI extends TestFmwk
|
||||
{
|
||||
/**
|
||||
* Problem 1: simply running
|
||||
|
@ -24,7 +24,10 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.CurrencyPluralInfo;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
@ -34,7 +37,8 @@ import com.ibm.icu.util.ULocale;
|
||||
// This is an API test, not a unit test. It doesn't test very many cases, and doesn't
|
||||
// try to test the full functionality. It just calls each function in the class and
|
||||
// verifies that it works on a basic level.
|
||||
public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDecimalFormatAPIC extends TestFmwk {
|
||||
|
||||
// This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
|
||||
@Test
|
||||
|
@ -23,14 +23,18 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.text.NumberingSystem;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class IntlTestDecimalFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDecimalFormatSymbols extends TestFmwk
|
||||
{
|
||||
// Test the API of DecimalFormatSymbols; primarily a simple get/set set.
|
||||
@Test
|
||||
|
@ -18,14 +18,18 @@ import java.text.FieldPosition;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
|
||||
/**
|
||||
* Tests for DecimalFormatSymbols
|
||||
**/
|
||||
public class IntlTestDecimalFormatSymbolsC extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestDecimalFormatSymbolsC extends TestFmwk {
|
||||
/**
|
||||
* Test the API of DecimalFormatSymbols; primarily a simple get/set set.
|
||||
*/
|
||||
|
@ -17,6 +17,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
@ -26,7 +28,8 @@ import com.ibm.icu.text.NumberFormat;
|
||||
* This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
|
||||
* NumberFormat.
|
||||
*/
|
||||
public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestNumberFormat extends TestFmwk {
|
||||
|
||||
public NumberFormat fNumberFormat;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1996-2009, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**/
|
||||
/**
|
||||
/**
|
||||
* Port From: JDK 1.4b1 : java.text.Format.IntlTestNumberFormatAPI
|
||||
* Source File: java/text/format/IntlTestNumberFormatAPI.java
|
||||
**/
|
||||
@ -24,11 +24,15 @@ import java.text.ParsePosition;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestNumberFormatAPI extends TestFmwk
|
||||
{
|
||||
// This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
|
||||
@Test
|
||||
@ -52,17 +56,17 @@ public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
NumberFormat per = NumberFormat.getPercentInstance();
|
||||
|
||||
NumberFormat per_fr = NumberFormat.getPercentInstance(Locale.FRENCH);
|
||||
|
||||
|
||||
NumberFormat integer = NumberFormat.getIntegerInstance();
|
||||
|
||||
|
||||
NumberFormat int_fr = NumberFormat.getIntegerInstance(Locale.FRENCH);
|
||||
|
||||
|
||||
//Fix "The variable is never used" compilation warnings
|
||||
logln("Currency : " + cur.format(1234.5));
|
||||
logln("Percent : " + per.format(1234.5));
|
||||
logln("Integer : " + integer.format(1234.5));
|
||||
logln("Int_fr : " + int_fr.format(1234.5));
|
||||
|
||||
|
||||
// ======= Test equality
|
||||
|
||||
logln("Testing equality operator");
|
||||
@ -201,7 +205,7 @@ public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
// errln("ERROR: Couldn't create a DecimalFormat");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// Jitterbug 4451, for coverage
|
||||
@Test
|
||||
public void TestCoverage(){
|
||||
@ -216,11 +220,17 @@ public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
errln("NumberFormat.getPattern(Locale, int) should delegate to (ULocale,)");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
|
||||
@Override
|
||||
public Number parse(String text, ParsePosition parsePosition) {return null;}
|
||||
}
|
||||
new StubNumberFormat().run();
|
||||
|
@ -12,11 +12,11 @@
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
**/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Port From: JDK 1.4b1 : java.text.Format.IntlTestSimpleDateFormatAPI
|
||||
* Source File: java/text/format/IntlTestSimpleDateFormatAPI.java
|
||||
**/
|
||||
|
||||
|
||||
package com.ibm.icu.dev.test.format;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
@ -27,7 +27,10 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormatSymbols;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
||||
@ -35,7 +38,8 @@ import com.ibm.icu.text.SimpleDateFormat;
|
||||
* @test 1.4 98/03/06
|
||||
* @summary test International Simple Date Format API
|
||||
*/
|
||||
public class IntlTestSimpleDateFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntlTestSimpleDateFormatAPI extends TestFmwk
|
||||
{
|
||||
// This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
|
||||
@Test
|
||||
@ -154,7 +158,7 @@ public class IntlTestSimpleDateFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
if( ! s3.equals(p1) ) {
|
||||
errln("ERROR: toLocalizedPattern() result did not match pattern applied");
|
||||
}
|
||||
|
||||
|
||||
// ======= Test for Ticket 5684 (Parsing patterns with 'Y' and 'e'
|
||||
logln("Testing parse()");
|
||||
|
||||
@ -182,7 +186,7 @@ public class IntlTestSimpleDateFormatAPI extends com.ibm.icu.dev.test.TestFmwk
|
||||
// errln("ERROR: Couldn't create a SimpleDateFormat");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// Jitterbug 4451, for coverage
|
||||
@Test
|
||||
public void TestCoverage(){
|
||||
|
@ -12,11 +12,14 @@ import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.ListFormatter;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ListFormatterTest extends TestFmwk {
|
||||
String[] HardcodedTestData = {
|
||||
"",
|
||||
@ -141,7 +144,7 @@ public class ListFormatterTest extends TestFmwk {
|
||||
assertEquals("4", strings[4], listFormat.format("A", "B", "C", "D"));
|
||||
assertEquals("5", strings[5], listFormat.format("A", "B", "C", "D", "E"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestFromList() {
|
||||
ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH);
|
||||
@ -151,16 +154,16 @@ public class ListFormatterTest extends TestFmwk {
|
||||
list.add("C");
|
||||
assertEquals("list", "A, B, and C", listFormatter.format(list));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCreatePatternForNumItems() {
|
||||
ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH);
|
||||
assertEquals(
|
||||
"createPatternForNumItems",
|
||||
"{0}, {1}, and {2}",
|
||||
listFormatter.getPatternForNumItems(3));
|
||||
listFormatter.getPatternForNumItems(3));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestGetPatternForNumItemsException() {
|
||||
ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH);
|
||||
@ -171,13 +174,13 @@ public class ListFormatterTest extends TestFmwk {
|
||||
// expected.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestGetLocale() {
|
||||
assertEquals(
|
||||
"getLocale", ULocale.ENGLISH, ListFormatter.getInstance(ULocale.ENGLISH).getLocale());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void Test9946() {
|
||||
ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH);
|
||||
|
@ -28,6 +28,8 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.serializable.FormatHandler;
|
||||
@ -50,6 +52,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* for information on how to update with each new release.
|
||||
* @author markdavis
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class MeasureUnitTest extends TestFmwk {
|
||||
|
||||
static class OrderedPair<F extends Comparable, S extends Comparable> extends Pair<F, S> implements Comparable<OrderedPair<F, S>> {
|
||||
|
@ -4,12 +4,15 @@
|
||||
package com.ibm.icu.dev.test.format;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.MeasureUnit;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class MeasureUnitThreadTest extends TestFmwk {
|
||||
|
||||
@Test
|
||||
|
@ -17,7 +17,10 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.MessagePattern;
|
||||
import com.ibm.icu.text.MessagePatternUtil;
|
||||
import com.ibm.icu.text.MessagePatternUtil.ArgNode;
|
||||
@ -31,7 +34,8 @@ import com.ibm.icu.text.MessagePatternUtil.VariantNode;
|
||||
* Test MessagePatternUtil (MessagePattern-as-tree-of-nodes API)
|
||||
* by building parallel trees of nodes and verifying that they match.
|
||||
*/
|
||||
public final class MessagePatternUtilTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public final class MessagePatternUtilTest extends TestFmwk {
|
||||
// The following nested "Expect..." classes are used to build
|
||||
// a tree structure parallel to what the MessagePatternUtil class builds.
|
||||
// These nested test classes are not static so that they have access to TestFmwk methods.
|
||||
|
@ -46,12 +46,16 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class MessageRegressionTest extends TestFmwk {
|
||||
/* @bug 4074764
|
||||
* Null exception when formatting pattern with MessageFormat
|
||||
* with no parameters.
|
||||
@ -178,7 +182,7 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
pos.setErrorIndex(4);
|
||||
if (pos.getErrorIndex() != 4)
|
||||
errln("setErrorIndex failed, got " + pos.getErrorIndex() + " instead of 4");
|
||||
|
||||
|
||||
if (objs != null) {
|
||||
errln("objs should be null");
|
||||
}
|
||||
@ -526,8 +530,8 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
*/
|
||||
@Test
|
||||
public void Test4142938() {
|
||||
String pat = "''Vous'' {0,choice,0#n''|1#}avez s\u00E9lectionne\u00E9 " +
|
||||
"{0,choice,0#aucun|1#{0}} client{0,choice,0#s|1#|2#s} " +
|
||||
String pat = "''Vous'' {0,choice,0#n''|1#}avez s\u00E9lectionne\u00E9 " +
|
||||
"{0,choice,0#aucun|1#{0}} client{0,choice,0#s|1#|2#s} " +
|
||||
"personnel{0,choice,0#s|1#|2#s}.";
|
||||
MessageFormat mf = new MessageFormat(pat);
|
||||
|
||||
@ -535,13 +539,13 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
"'Vous' n'avez s\u00E9lectionne\u00E9 aucun clients personnels.",
|
||||
"'Vous' avez s\u00E9lectionne\u00E9 ",
|
||||
"'Vous' avez s\u00E9lectionne\u00E9 "
|
||||
};
|
||||
};
|
||||
String[] SUFFIX = {
|
||||
null,
|
||||
" client personnel.",
|
||||
" clients personnels."
|
||||
};
|
||||
|
||||
|
||||
for (int i=0; i<3; i++) {
|
||||
String out = mf.format(new Object[]{new Integer(i)});
|
||||
if (SUFFIX[i] == null) {
|
||||
@ -646,7 +650,7 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
throw new RuntimeException("didn't get exception for invalid input");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test4293229() {
|
||||
MessageFormat format = new MessageFormat("'''{'0}'' '''{0}'''");
|
||||
@ -658,12 +662,12 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
expected + "\", got \"" + result + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This test basically ensures that the tests defined above also work with
|
||||
// valid named arguments.
|
||||
@Test
|
||||
public void testBugTestsWithNamesArguments() {
|
||||
|
||||
|
||||
{ // Taken from Test4031438().
|
||||
String pattern1 = "Impossible {arg1} has occurred -- status code is {arg0} and message is {arg2}.";
|
||||
String pattern2 = "Double '' Quotes {ARG_ZERO} test and quoted '{ARG_ONE}' test plus 'other {ARG_TWO} stuff'.";
|
||||
@ -812,7 +816,7 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("\"" + mf.format(objs3) + "\"");
|
||||
} catch (Exception e) {
|
||||
errln("Exception thrown for null argument tests.");
|
||||
}
|
||||
}
|
||||
}{ // Taken from Test4118594().
|
||||
String argName = "something_stupid";
|
||||
MessageFormat mf = new MessageFormat("{"+ argName + "}, {" + argName + "}, {" + argName + "}");
|
||||
@ -870,7 +874,7 @@ public class MessageRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
ostream.writeObject(original);
|
||||
ostream.flush();
|
||||
byte bytes[] = baos.toByteArray();
|
||||
|
||||
|
||||
ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
MessageFormat reconstituted = (MessageFormat)istream.readObject();
|
||||
return reconstituted;
|
||||
|
@ -11,12 +11,16 @@ package com.ibm.icu.dev.test.format;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
import com.ibm.icu.text.NumberFormat.SimpleNumberFormatFactory;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberFormatRegistrationTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestRegistration() {
|
||||
final ULocale SRC_LOC = ULocale.FRANCE;
|
||||
@ -34,6 +38,7 @@ public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk
|
||||
currencyStyle = NumberFormat.getIntegerInstance(swapLoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberFormat createFormat(ULocale loc, int formatType) {
|
||||
if (formatType == FORMAT_CURRENCY) {
|
||||
return currencyStyle;
|
||||
|
@ -23,7 +23,10 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
@ -34,7 +37,8 @@ import com.ibm.icu.util.ULocale;
|
||||
/**
|
||||
* Performs regression test for MessageFormat
|
||||
**/
|
||||
public class NumberFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberFormatRegressionTest extends TestFmwk {
|
||||
/**
|
||||
* alphaWorks upgrade
|
||||
*/
|
||||
@ -76,7 +80,7 @@ public class NumberFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
// or this (with changes to fr_CH per cldrbug:9370):
|
||||
//nf.setGroupingUsed(false);
|
||||
// so they are done in DateFormat.setNumberFormat
|
||||
|
||||
|
||||
// create the DateFormat
|
||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, loc);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Porting From: ICU4C v1.8.1 : format : NumberFormatRoundTripTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/nmfmtrt.cpp
|
||||
**/
|
||||
@ -18,15 +18,19 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Performs round-trip tests for NumberFormat
|
||||
**/
|
||||
public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberFormatRoundTripTest extends TestFmwk {
|
||||
|
||||
public double MAX_ERROR = 1e-14;
|
||||
public double max_numeric_error = 0.0;
|
||||
public double min_numeric_error = 1.0;
|
||||
@ -35,27 +39,27 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
public boolean EXACT_NUMERIC_COMPARE = false;
|
||||
public boolean DEBUG = false;
|
||||
public boolean quick = true;
|
||||
|
||||
|
||||
@Test
|
||||
public void TestNumberFormatRoundTrip() {
|
||||
|
||||
|
||||
NumberFormat fmt = null;
|
||||
|
||||
|
||||
logln("Default Locale");
|
||||
|
||||
|
||||
logln("Default Number format");
|
||||
fmt = NumberFormat.getInstance();
|
||||
_test(fmt);
|
||||
|
||||
|
||||
logln("Currency Format");
|
||||
fmt = NumberFormat.getCurrencyInstance();
|
||||
_test(fmt);
|
||||
|
||||
|
||||
logln("Percent Format");
|
||||
fmt = NumberFormat.getPercentInstance();
|
||||
_test(fmt);
|
||||
|
||||
|
||||
|
||||
|
||||
int locCount = 0;
|
||||
final Locale[] loc = NumberFormat.getAvailableLocales();
|
||||
if(quick) {
|
||||
@ -65,20 +69,20 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
}
|
||||
for(int i = 0; i < locCount; ++i) {
|
||||
logln(loc[i].getDisplayName());
|
||||
|
||||
|
||||
fmt = NumberFormat.getInstance(loc[i]);
|
||||
_test(fmt);
|
||||
|
||||
|
||||
fmt = NumberFormat.getCurrencyInstance(loc[i]);
|
||||
_test(fmt);
|
||||
|
||||
|
||||
fmt = NumberFormat.getPercentInstance(loc[i]);
|
||||
_test(fmt);
|
||||
}
|
||||
|
||||
|
||||
logln("Numeric error " + min_numeric_error + " to " + max_numeric_error);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a random value from -range..+range.
|
||||
*/
|
||||
@ -88,14 +92,14 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
random = createRandom(); // use test framework's random seed
|
||||
}
|
||||
return random.nextDouble() * range;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void _test(NumberFormat fmt) {
|
||||
|
||||
|
||||
_test(fmt, Double.NaN);
|
||||
_test(fmt, Double.POSITIVE_INFINITY);
|
||||
_test(fmt, Double.NEGATIVE_INFINITY);
|
||||
|
||||
|
||||
_test(fmt, 500);
|
||||
_test(fmt, 0);
|
||||
_test(fmt, -0);
|
||||
@ -106,50 +110,50 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
_test(fmt, 9223372036854775808.0d);
|
||||
_test(fmt, -9223372036854775809.0d);
|
||||
//_test(fmt, 6.936065876100493E74d);
|
||||
|
||||
|
||||
// _test(fmt, 6.212122845281909E48d);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(10000));
|
||||
|
||||
|
||||
_test(fmt, Math.floor((randomDouble(10000))));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e50));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-50));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e100));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e75));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e308) / ((DecimalFormat) fmt).getMultiplier());
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e75) / ((DecimalFormat) fmt).getMultiplier());
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e65) / ((DecimalFormat) fmt).getMultiplier());
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-292));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-78));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-323));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-100));
|
||||
|
||||
|
||||
_test(fmt, randomDouble(1e-78));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void _test(NumberFormat fmt, double value) {
|
||||
_test(fmt, new Double(value));
|
||||
}
|
||||
|
||||
|
||||
private void _test(NumberFormat fmt, long value) {
|
||||
_test(fmt, new Long(value));
|
||||
}
|
||||
|
||||
|
||||
private void _test(NumberFormat fmt, Number value) {
|
||||
logln("test data = " + value);
|
||||
fmt.setMaximumFractionDigits(999);
|
||||
@ -158,7 +162,7 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
s = fmt.format(value.doubleValue());
|
||||
else
|
||||
s = fmt.format(value.longValue());
|
||||
|
||||
|
||||
Number n = new Double(0);
|
||||
boolean show = verbose;
|
||||
if (DEBUG)
|
||||
@ -169,25 +173,25 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} catch (java.text.ParseException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
|
||||
if (DEBUG)
|
||||
logln(s + " P> " /*+ n.getString(temp)*/);
|
||||
|
||||
|
||||
if (value.getClass().getName().equalsIgnoreCase("java.lang.Double"))
|
||||
s2 = fmt.format(n.doubleValue());
|
||||
else
|
||||
s2 = fmt.format(n.longValue());
|
||||
|
||||
|
||||
if (DEBUG)
|
||||
logln(/*n.getString(temp) +*/ " F> " + s2);
|
||||
|
||||
|
||||
if (STRING_COMPARE) {
|
||||
if (!s.equals(s2)) {
|
||||
errln("*** STRING ERROR \"" + s + "\" != \"" + s2 + "\"");
|
||||
show = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (EXACT_NUMERIC_COMPARE) {
|
||||
if (value != n) {
|
||||
errln("*** NUMERIC ERROR");
|
||||
@ -196,42 +200,42 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
} else {
|
||||
// Compute proportional error
|
||||
double error = proportionalError(value, n);
|
||||
|
||||
|
||||
if (error > MAX_ERROR) {
|
||||
errln("*** NUMERIC ERROR " + error);
|
||||
show = true;
|
||||
}
|
||||
|
||||
|
||||
if (error > max_numeric_error)
|
||||
max_numeric_error = error;
|
||||
if (error < min_numeric_error)
|
||||
min_numeric_error = error;
|
||||
}
|
||||
|
||||
|
||||
if (show)
|
||||
logln(
|
||||
/*value.getString(temp) +*/ value.getClass().getName() + " F> " + s + " P> " +
|
||||
/*n.getString(temp) +*/ n.getClass().getName() + " F> " + s2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private double proportionalError(Number a, Number b) {
|
||||
double aa,bb;
|
||||
|
||||
|
||||
if(a.getClass().getName().equalsIgnoreCase("java.lang.Double"))
|
||||
aa = a.doubleValue();
|
||||
else
|
||||
aa = a.longValue();
|
||||
|
||||
|
||||
if(a.getClass().getName().equalsIgnoreCase("java.lang.Double"))
|
||||
bb = b.doubleValue();
|
||||
else
|
||||
bb = b.longValue();
|
||||
|
||||
|
||||
double error = aa - bb;
|
||||
if(aa != 0 && bb != 0)
|
||||
if(aa != 0 && bb != 0)
|
||||
error /= aa;
|
||||
|
||||
|
||||
return Math.abs(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
package com.ibm.icu.dev.test.format;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
@ -21,6 +23,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author rocketman
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestBasicPatterns() {
|
||||
@ -32,9 +35,9 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "1234,567", formatFrWithPattern(num, "###0.#####"));
|
||||
assertEquals("", "1234,5670", formatFrWithPattern(num, "###0.0000#"));
|
||||
assertEquals("", "01234,5670", formatFrWithPattern(num, "00000.0000"));
|
||||
assertEquals("", "1 234,57 €", formatFrWithPattern(num, "#,##0.00 ¤"));
|
||||
assertEquals("", "1 234,57 €", formatFrWithPattern(num, "#,##0.00 ¤"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestNfSetters() {
|
||||
NumberFormat nf = nfWithPattern("#,##0.##");
|
||||
@ -42,9 +45,9 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
nf.setMinimumIntegerDigits(4);
|
||||
assertEquals("", "34 567,89", format(1234567.89, nf));
|
||||
assertEquals("", "0 034,56", format(34.56, nf));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestRounding() {
|
||||
assertEquals("", "1,0", formatFrWithPattern(1.25, "0.5"));
|
||||
@ -58,7 +61,7 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "273,00", formatFrWithPattern(272.0, "2.73"));
|
||||
assertEquals("", "1 03,60", formatFrWithPattern(104.0, "#,#3.70"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestSignificantDigits() {
|
||||
assertEquals("", "1230", formatFrWithPattern(1234.0, "@@@"));
|
||||
@ -70,9 +73,9 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "12 34 567", formatFrWithPattern(1234567.0, "@@@@,@@,@##"));
|
||||
assertEquals("", "12 34 567", formatFrWithPattern(1234567.001, "@@@@,@@,@##"));
|
||||
assertEquals("", "12 34 567", formatFrWithPattern(1234567.001, "@@@@,@@,###"));
|
||||
assertEquals("", "1 200", formatFrWithPattern(1234.0, "#,#@@"));
|
||||
assertEquals("", "1 200", formatFrWithPattern(1234.0, "#,#@@"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestScientificNotation() {
|
||||
assertEquals("", "1,23E4", formatFrWithPattern(12345.0, "0.00E0"));
|
||||
@ -89,7 +92,7 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "170,0E-3", formatFrWithPattern(0.17, "##0.000#E0"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPercent() {
|
||||
assertEquals("", "57,3%", formatFrWithPattern(0.573, "0.0%"));
|
||||
@ -99,9 +102,9 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "%3,260", formatFrWithPattern(0.0326, "%@@@@"));
|
||||
assertEquals("", "%1 540", formatFrWithPattern(15.43, "%#,@@@"));
|
||||
assertEquals("", "%1 656,4", formatFrWithPattern(16.55, "%#,##4.1"));
|
||||
assertEquals("", "%16,3E3", formatFrWithPattern(162.55, "%##0.00E0"));
|
||||
assertEquals("", "%16,3E3", formatFrWithPattern(162.55, "%##0.00E0"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPerMilli() {
|
||||
assertEquals("", "573,0‰", formatFrWithPattern(0.573, "0.0‰"));
|
||||
@ -113,7 +116,7 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
assertEquals("", "‰16 551,7", formatFrWithPattern(16.55, "‰#,##4.1"));
|
||||
assertEquals("", "‰163E3", formatFrWithPattern(162.55, "‰##0.00E0"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestPadding() {
|
||||
assertEquals("", "$***1 234", formatFrWithPattern(1234, "$**####,##0"));
|
||||
@ -132,31 +135,31 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
DecimalFormat fmt = new DecimalFormat("¤¤ **#######0", sym);
|
||||
fmt.setCurrency(Currency.getInstance("JPY"));
|
||||
if (!logKnownIssue("11025", "Padding broken when used with currencies")) {
|
||||
assertEquals("", "JPY ****433", fmt.format(433.22));
|
||||
assertEquals("", "JPY ****433", fmt.format(433.22));
|
||||
}
|
||||
}
|
||||
{
|
||||
DecimalFormatSymbols sym = new DecimalFormatSymbols(ULocale.US);
|
||||
DecimalFormat fmt = new DecimalFormat("¤¤ **#######0;¤¤ (#)", sym);
|
||||
assertEquals("", "USD (433.22)", fmt.format(-433.22));
|
||||
assertEquals("", "USD (433.22)", fmt.format(-433.22));
|
||||
}
|
||||
assertEquals("", "QU***43,3E-1", formatFrWithPattern(4.33, "QU**00.#####E0"));
|
||||
{
|
||||
DecimalFormatSymbols sym = new DecimalFormatSymbols(ULocale.FRANCE);
|
||||
sym.setExponentSeparator("EE");
|
||||
DecimalFormat fmt = new DecimalFormat("QU**00.#####E0", sym);
|
||||
assertEquals("", "QU**43,3EE-1", fmt.format(4.33));
|
||||
assertEquals("", "QU**43,3EE-1", fmt.format(4.33));
|
||||
}
|
||||
// padding cannot work as intended with scientific notation.
|
||||
assertEquals("", "QU**43,32E-1", formatFrWithPattern(4.332, "QU**00.#####E0"));
|
||||
}
|
||||
|
||||
|
||||
private static String formatFrWithPattern(double d, String pattern) {
|
||||
DecimalFormatSymbols sym = new DecimalFormatSymbols(ULocale.FRANCE);
|
||||
DecimalFormat fmt = new DecimalFormat(pattern, sym);
|
||||
return fmt.format(d).replace('\u00a0', ' ');
|
||||
}
|
||||
|
||||
|
||||
private static NumberFormat nfWithPattern(String pattern) {
|
||||
DecimalFormatSymbols sym = new DecimalFormatSymbols(ULocale.FRANCE);
|
||||
return new DecimalFormat(pattern, sym);
|
||||
@ -165,6 +168,6 @@ public class NumberFormatSpecificationTest extends TestFmwk {
|
||||
private static String format(double d, NumberFormat nf) {
|
||||
return nf.format(d).replace('\u00a0', ' ');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
@ -66,6 +68,7 @@ import com.ibm.icu.util.Currency.CurrencyUsage;
|
||||
import com.ibm.icu.util.CurrencyAmount;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberFormatTest extends TestFmwk {
|
||||
|
||||
@Test
|
||||
|
@ -39,6 +39,8 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
@ -51,6 +53,7 @@ import com.ibm.icu.util.GregorianCalendar;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class NumberRegressionTests extends TestFmwk {
|
||||
private static final char EURO = '\u20ac';
|
||||
|
||||
|
@ -13,6 +13,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
@ -25,6 +27,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author tschumann (Tim Schumann)
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class PluralFormatTest extends TestFmwk {
|
||||
private void helperTestRules(String localeIDs, String testPattern, Map<Integer,String> changes) {
|
||||
String[] locales = Utility.split(localeIDs, ',');
|
||||
|
@ -19,6 +19,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
@ -35,6 +37,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author tschumann (Tim Schumann)
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class PluralFormatUnitTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestConstructor() {
|
||||
@ -402,7 +405,7 @@ public class PluralFormatUnitTest extends TestFmwk {
|
||||
assertEquals("offset-decimals format(2)", "another 1.0 meters", pf2.format(2));
|
||||
assertEquals("offset-decimals format(2.5)", "another 1.5 meters", pf2.format(2.5));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestNegative() {
|
||||
PluralFormat pluralFormat = new PluralFormat(ULocale.ENGLISH, "one{# foot}other{# feet}");
|
||||
|
@ -11,6 +11,8 @@ package com.ibm.icu.dev.test.format;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.SimpleFormatterImpl;
|
||||
@ -26,8 +28,9 @@ import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
* @author markdavis
|
||||
*
|
||||
*
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class PluralRangesTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestLocaleData() {
|
||||
|
@ -33,6 +33,8 @@ import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.serializable.SerializableTestUtility;
|
||||
@ -55,6 +57,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author dougfelt (Doug Felt)
|
||||
* @author markdavis (Mark Davis) [for fractional support]
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class PluralRulesTest extends TestFmwk {
|
||||
|
||||
PluralRulesFactory factory = PluralRulesFactory.NORMAL;
|
||||
@ -862,14 +865,14 @@ public class PluralRulesTest extends TestFmwk {
|
||||
enum StandardPluralCategories {
|
||||
zero, one, two, few, many, other;
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final Set<StandardPluralCategories> ALL = Collections.unmodifiableSet(EnumSet
|
||||
.allOf(StandardPluralCategories.class));
|
||||
|
||||
/**
|
||||
* Return a mutable set
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@ -882,6 +885,7 @@ public class PluralRulesTest extends TestFmwk {
|
||||
}
|
||||
|
||||
static final Comparator<Set<StandardPluralCategories>> SHORTEST_FIRST = new Comparator<Set<StandardPluralCategories>>() {
|
||||
@Override
|
||||
public int compare(Set<StandardPluralCategories> arg0, Set<StandardPluralCategories> arg1) {
|
||||
int diff = arg0.size() - arg1.size();
|
||||
if (diff != 0) {
|
||||
@ -927,6 +931,7 @@ public class PluralRulesTest extends TestFmwk {
|
||||
}
|
||||
|
||||
private static final Comparator<PluralRules> PLURAL_RULE_COMPARATOR = new Comparator<PluralRules>() {
|
||||
@Override
|
||||
public int compare(PluralRules o1, PluralRules o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
@ -1066,12 +1071,14 @@ public class PluralRulesTest extends TestFmwk {
|
||||
}
|
||||
|
||||
public static class FixedDecimalHandler implements SerializableTestUtility.Handler {
|
||||
@Override
|
||||
public Object[] getTestObjects() {
|
||||
FixedDecimal items[] = { new FixedDecimal(3d), new FixedDecimal(3d, 2), new FixedDecimal(3.1d, 1),
|
||||
new FixedDecimal(3.1d, 2), };
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSameBehavior(Object a, Object b) {
|
||||
FixedDecimal a1 = (FixedDecimal) a;
|
||||
FixedDecimal b1 = (FixedDecimal) b;
|
||||
|
@ -11,11 +11,14 @@ package com.ibm.icu.dev.test.format;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.RuleBasedNumberFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class RBNFParseTest extends TestFmwk {
|
||||
@Test
|
||||
public void TestParse() {
|
||||
|
@ -11,10 +11,13 @@ package com.ibm.icu.dev.test.format;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.RuleBasedNumberFormat;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class RbnfRoundTripTest extends TestFmwk {
|
||||
/**
|
||||
* Perform an exhaustive round-trip test on the English spellout rules
|
||||
|
@ -14,6 +14,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.math.BigDecimal;
|
||||
@ -28,6 +30,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* This does not test lenient parse mode, since testing the default implementation
|
||||
* introduces a dependency on collation. See RbnfLenientScannerTest.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class RbnfTest extends TestFmwk {
|
||||
static String fracRules =
|
||||
"%main:\n" +
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user