Home | History | Annotate | Download | only in collator
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5  *******************************************************************************
      6  * Copyright (C) 2002-2014, International Business Machines Corporation and
      7  * others. All Rights Reserved.
      8  *******************************************************************************
      9  */
     10 
     11 /**
     12  * Port From:   ICU4C v2.1 : Collate/CollationCurrencyTest
     13  * Source File: $ICU4CRoot/source/test/intltest/currcoll.cpp
     14  **/
     15 
     16 package android.icu.dev.test.collator;
     17 
     18 import java.util.Locale;
     19 
     20 import org.junit.Test;
     21 import org.junit.runner.RunWith;
     22 import org.junit.runners.JUnit4;
     23 
     24 import android.icu.dev.test.TestFmwk;
     25 import android.icu.text.CollationKey;
     26 import android.icu.text.Collator;
     27 import android.icu.text.RuleBasedCollator;
     28 import android.icu.testsharding.MainTestShard;
     29 
     30 @MainTestShard
     31 @RunWith(JUnit4.class)
     32 public class CollationCurrencyTest extends TestFmwk {
     33     @Test
     34     public void TestCurrency() {
     35         // All the currency symbols, in collation order
     36         char[][] currency = {
     37             { 0x00A4 }, /*00A4; L; [14 36, 03, 03]    # [082B.0020.0002] # CURRENCY SIGN*/
     38             { 0x00A2 }, /*00A2; L; [14 38, 03, 03]    # [082C.0020.0002] # CENT SIGN*/
     39             { 0xFFE0 }, /*FFE0; L; [14 38, 03, 05]    # [082C.0020.0003] # FULLWIDTH CENT SIGN*/
     40             { 0x0024 }, /*0024; L; [14 3A, 03, 03]    # [082D.0020.0002] # DOLLAR SIGN*/
     41             { 0xFF04 }, /*FF04; L; [14 3A, 03, 05]    # [082D.0020.0003] # FULLWIDTH DOLLAR SIGN*/
     42             { 0xFE69 }, /*FE69; L; [14 3A, 03, 1D]    # [082D.0020.000F] # SMALL DOLLAR SIGN*/
     43             { 0x00A3 }, /*00A3; L; [14 3C, 03, 03]    # [082E.0020.0002] # POUND SIGN*/
     44             { 0xFFE1 }, /*FFE1; L; [14 3C, 03, 05]    # [082E.0020.0003] # FULLWIDTH POUND SIGN*/
     45             { 0x00A5 }, /*00A5; L; [14 3E, 03, 03]    # [082F.0020.0002] # YEN SIGN*/
     46             { 0xFFE5 }, /*FFE5; L; [14 3E, 03, 05]    # [082F.0020.0003] # FULLWIDTH YEN SIGN*/
     47             { 0x09F2 }, /*09F2; L; [14 40, 03, 03]    # [0830.0020.0002] # BENGALI RUPEE MARK*/
     48             { 0x09F3 }, /*09F3; L; [14 42, 03, 03]    # [0831.0020.0002] # BENGALI RUPEE SIGN*/
     49             { 0x0E3F }, /*0E3F; L; [14 44, 03, 03]    # [0832.0020.0002] # THAI CURRENCY SYMBOL BAHT*/
     50             { 0x17DB }, /*17DB; L; [14 46, 03, 03]    # [0833.0020.0002] # KHMER CURRENCY SYMBOL RIEL*/
     51             { 0x20A0 }, /*20A0; L; [14 48, 03, 03]    # [0834.0020.0002] # EURO-CURRENCY SIGN*/
     52             { 0x20A1 }, /*20A1; L; [14 4A, 03, 03]    # [0835.0020.0002] # COLON SIGN*/
     53             { 0x20A2 }, /*20A2; L; [14 4C, 03, 03]    # [0836.0020.0002] # CRUZEIRO SIGN*/
     54             { 0x20A3 }, /*20A3; L; [14 4E, 03, 03]    # [0837.0020.0002] # FRENCH FRANC SIGN*/
     55             { 0x20A4 }, /*20A4; L; [14 50, 03, 03]    # [0838.0020.0002] # LIRA SIGN*/
     56             { 0x20A5 }, /*20A5; L; [14 52, 03, 03]    # [0839.0020.0002] # MILL SIGN*/
     57             { 0x20A6 }, /*20A6; L; [14 54, 03, 03]    # [083A.0020.0002] # NAIRA SIGN*/
     58             { 0x20A7 }, /*20A7; L; [14 56, 03, 03]    # [083B.0020.0002] # PESETA SIGN*/
     59             { 0x20A9 }, /*20A9; L; [14 58, 03, 03]    # [083C.0020.0002] # WON SIGN*/
     60             { 0xFFE6 }, /*FFE6; L; [14 58, 03, 05]    # [083C.0020.0003] # FULLWIDTH WON SIGN*/
     61             { 0x20AA }, /*20AA; L; [14 5A, 03, 03]    # [083D.0020.0002] # NEW SHEQEL SIGN*/
     62             { 0x20AB }, /*20AB; L; [14 5C, 03, 03]    # [083E.0020.0002] # DONG SIGN*/
     63             { 0x20AC }, /*20AC; L; [14 5E, 03, 03]    # [083F.0020.0002] # EURO SIGN*/
     64             { 0x20AD }, /*20AD; L; [14 60, 03, 03]    # [0840.0020.0002] # KIP SIGN*/
     65             { 0x20AE }, /*20AE; L; [14 62, 03, 03]    # [0841.0020.0002] # TUGRIK SIGN*/
     66             { 0x20AF } /*20AF; L; [14 64, 03, 03]    # [0842.0020.0002] # DRACHMA SIGN*/
     67         };
     68 
     69         int i, j;
     70         int expectedResult = 0;
     71         RuleBasedCollator c = (RuleBasedCollator)Collator.getInstance(Locale.ENGLISH);
     72 
     73         // Compare each currency symbol against all the
     74         // currency symbols, including itself
     75         String source;
     76         String target;
     77 
     78         for (i = 0; i < currency.length; i += 1) {
     79             for (j = 0; j < currency.length; j += 1) {
     80                 source = new String(currency[i]);
     81                 target = new String(currency[j]);
     82 
     83                 if (i < j) {
     84                     expectedResult = -1;
     85                 } else if ( i == j) {
     86                     expectedResult = 0;
     87                 } else {
     88                     expectedResult = 1;
     89                 }
     90 
     91                 int compareResult = c.compare(source, target);
     92                 CollationKey sourceKey = null;
     93 
     94                 sourceKey = c.getCollationKey(source);
     95 
     96                 if (sourceKey == null) {
     97                     errln("Couldn't get collationKey for source");
     98                     continue;
     99                 }
    100 
    101                 CollationKey targetKey = null;
    102                 targetKey = c.getCollationKey(target);
    103                 if (targetKey == null) {
    104                     errln("Couldn't get collationKey for source");
    105                     continue;
    106                 }
    107 
    108                 int keyResult = sourceKey.compareTo(targetKey);
    109 
    110                 reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult );
    111             }
    112         }
    113     }
    114 
    115     private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
    116                                 int compareResult, int keyResult, int incResult, int expectedResult ) {
    117         if (expectedResult < -1 || expectedResult > 1) {
    118             errln("***** invalid call to reportCResult ****");
    119             return;
    120         }
    121 
    122         boolean ok1 = (compareResult == expectedResult);
    123         boolean ok2 = (keyResult == expectedResult);
    124         boolean ok3 = (incResult == expectedResult);
    125 
    126         if (ok1 && ok2 && ok3 && !isVerbose()) {
    127             return;
    128         } else {
    129             String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
    130             String msg2 = "\", \"";
    131             String msg3 = "\") returned ";
    132             String msg4 = "; expected ";
    133 
    134             String sExpect = new String("");
    135             String sResult = new String("");
    136             sResult = CollationTest.appendCompareResult(compareResult, sResult);
    137             sExpect = CollationTest.appendCompareResult(expectedResult, sExpect);
    138             if (ok1) {
    139                 logln(msg1 + source + msg2 + target + msg3 + sResult);
    140             } else {
    141                 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
    142             }
    143 
    144             msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
    145             msg2 = "\").compareTo(key(\"";
    146             msg3 = "\")) returned ";
    147             sResult = CollationTest.appendCompareResult(keyResult, sResult);
    148             if (ok2) {
    149                 logln(msg1 + source + msg2 + target + msg3 + sResult);
    150             } else {
    151                 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
    152                 msg1 = "  ";
    153                 msg2 = " vs. ";
    154                 errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey));
    155             }
    156 
    157             msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
    158             msg2 = "\", \"";
    159             msg3 = "\") returned ";
    160 
    161             sResult = CollationTest.appendCompareResult(incResult, sResult);
    162 
    163             if (ok3) {
    164                 logln(msg1 + source + msg2 + target + msg3 + sResult);
    165             } else {
    166                 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
    167             }
    168         }
    169     }
    170 }
    171