Path: blob/master/test/jdk/java/text/Collator/CurrencyCollate.java
41149 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4114080 415080726* @summary Test currency collation. For bug 4114080, make sure the collation27* of the euro sign behaves properly. For bug 4150807, make sure the collation28* order of ALL the current symbols is correct. This means they sort29* in English alphabetical order of their English names. This test can be30* easily extended to do simple spot checking. See other collation tests for31* more sophisticated testing.32*/3334import java.io.IOException;35import java.io.OutputStream;36import java.io.PrintStream;37import java.util.Locale;38import java.text.Collator;39import java.text.RuleBasedCollator;40import java.text.CollationKey;4142/* Author: Alan Liu43* (C) Copyright IBM Corp. 1998 - All Rights Reserved44*/45public class CurrencyCollate {46static Collator myCollation = Collator.getInstance(Locale.US);4748public static void main(String[] args) {49String[] DATA = {50"\u20AC", ">", "$", // euro > dollar51"\u20AC", "<", "\u00A3", // euro < pound5253// additional tests for general currency sort order (bug #4150807)54"\u00a4", "<", "\u0e3f", // generic currency < baht55"\u0e3f", "<", "\u00a2", // baht < cent56"\u00a2", "<", "\u20a1", // cent < colon57"\u20a1", "<", "\u20a2", // colon < cruzeiro58"\u20a2", "<", "\u0024", // cruzeiro < dollar59"\u0024", "<", "\u20ab", // dollar < dong60"\u20ab", "<", "\u20a3", // dong < franc61"\u20a3", "<", "\u20a4", // franc < lira62"\u20a4", "<", "\u20a5", // lira < mill63"\u20a5", "<", "\u20a6", // mill < naira64"\u20a6", "<", "\u20a7", // naira < peseta65"\u20a7", "<", "\u00a3", // peseta < pound66"\u00a3", "<", "\u20a8", // pound < rupee67"\u20a8", "<", "\u20aa", // rupee < shekel68"\u20aa", "<", "\u20a9", // shekel < won69"\u20a9", "<", "\u00a5" // won < yen70};71for (int i=0; i<DATA.length; i+=3) {72int expected = DATA[i+1].equals(">") ? 1 : (DATA[i+1].equals("<") ? -1 : 0);73int actual = myCollation.compare(DATA[i], DATA[i+2]);74if (actual != expected) {75throw new RuntimeException("Collation of " +76DATA[i] + " vs. " +77DATA[i+2] + " yields " + actual +78"; expected " + expected);79}80}81System.out.println("Ok");82}83}8485//eof868788