1 /* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 4114080 4150807 27 * @summary Test currency collation. For bug 4114080, make sure the collation 28 * of the euro sign behaves properly. For bug 4150807, make sure the collation 29 * order of ALL the current symbols is correct. This means they sort 30 * in English alphabetical order of their English names. This test can be 31 * easily extended to do simple spot checking. See other collation tests for 32 * more sophisticated testing. 33 */ 34 35 import java.io.IOException; 36 import java.io.OutputStream; 37 import java.io.PrintStream; 38 import java.util.Locale; 39 import java.text.Collator; 40 import java.text.RuleBasedCollator; 41 import java.text.CollationKey; 42 43 /* Author: Alan Liu 44 * (C) Copyright IBM Corp. 1998 - All Rights Reserved 45 */ 46 public class CurrencyCollate { 47 static Collator myCollation = Collator.getInstance(Locale.US); 48 49 public static void main(String[] args) { 50 String[] DATA = { 51 "\u20AC", ">", "$", // euro > dollar 52 "\u20AC", "<", "\u00A3", // euro < pound 53 54 // additional tests for general currency sort order (bug #4150807) 55 "\u00a4", "<", "\u0e3f", // generic currency < baht 56 "\u0e3f", "<", "\u00a2", // baht < cent 57 "\u00a2", "<", "\u20a1", // cent < colon 58 "\u20a1", "<", "\u20a2", // colon < cruzeiro 59 "\u20a2", "<", "\u0024", // cruzeiro < dollar 60 "\u0024", "<", "\u20ab", // dollar < dong 61 "\u20ab", "<", "\u20a3", // dong < franc 62 "\u20a3", "<", "\u20a4", // franc < lira 63 "\u20a4", "<", "\u20a5", // lira < mill 64 "\u20a5", "<", "\u20a6", // mill < naira 65 "\u20a6", "<", "\u20a7", // naira < peseta 66 "\u20a7", "<", "\u00a3", // peseta < pound 67 "\u00a3", "<", "\u20a8", // pound < rupee 68 "\u20a8", "<", "\u20aa", // rupee < shekel 69 "\u20aa", "<", "\u20a9", // shekel < won 70 "\u20a9", "<", "\u00a5" // won < yen 71 }; 72 for (int i=0; i<DATA.length; i+=3) { 73 int expected = DATA[i+1].equals(">") ? 1 : (DATA[i+1].equals("<") ? -1 : 0); 74 int actual = myCollation.compare(DATA[i], DATA[i+2]); 75 if (actual != expected) { 76 throw new RuntimeException("Collation of " + 77 DATA[i] + " vs. " + 78 DATA[i+2] + " yields " + actual + 79 "; expected " + expected); 80 } 81 } 82 System.out.println("Ok"); 83 } 84 } 85 86 //eof