Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/ComponentOrientation/BasicTest.java
47490 views
/*1* Copyright (c) 1998, 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 4108453 4778440 6304780 639637826* @summary Basic tests for java.awt.ComponentOrientation27* @build TestBundle TestBundle_es TestBundle_iw28* @build TestBundle1 TestBundle1_ar29*30* @run main BasicTest31*/32/*33* (C) Copyright IBM Corp. 1998 - All Rights Reserved34*35* The original version of this source code and documentation is copyrighted36* and owned by IBM, Inc. These materials are provided under terms of a37* License Agreement between IBM and Sun. This technology is protected by38* multiple US and International patents. This notice and attribution to IBM39* may not be removed.40*/4142import java.awt.ComponentOrientation;43import java.util.Locale;44import java.util.ResourceBundle;4546public class BasicTest {47public static void main(String args[]) {48System.out.println("BasicTest {");49TestInvariants();50TestLocale();51TestBundle();5253System.out.println("} Pass");54}5556// TestInvariants57//58// Various no-brainer tests to make sure the constants behave properly59// and so on.60//61static void TestInvariants() {62System.out.println(" TestInvariants {");6364Assert(ComponentOrientation.LEFT_TO_RIGHT.isLeftToRight(),65"LEFT_TO_RIGHT.isLeftToRight()");6667Assert(ComponentOrientation.UNKNOWN.isLeftToRight(),68"UNKNOWN.isLeftToRight()");6970Assert(!ComponentOrientation.RIGHT_TO_LEFT.isLeftToRight(),71"!RIGHT_TO_LEFT.isLeftToRight()");7273Assert(ComponentOrientation.LEFT_TO_RIGHT.isHorizontal(),74"LEFT_TO_RIGHT.isHorizontal()");7576Assert(ComponentOrientation.UNKNOWN.isHorizontal(),77"UNKNOWN.isHorizontal()");7879Assert(ComponentOrientation.RIGHT_TO_LEFT.isHorizontal(),80"RIGHT_TO_LEFT.isHorizontal()");8182System.out.println(" } Pass");83}8485// TestLocale86//87// Make sure that getOrientation(Locale) works, and that the appropriate88// system locales are RIGHT_TO_LEFT89//90static void TestLocale() {91System.out.println(" TestLocale {");9293ComponentOrientation orient = ComponentOrientation.getOrientation(Locale.US);94Assert(orient == ComponentOrientation.LEFT_TO_RIGHT, "US == LEFT_TO_RIGHT");9596orient = ComponentOrientation.getOrientation(new Locale("iw", ""));97Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "iw == RIGHT_TO_LEFT");9899orient = ComponentOrientation.getOrientation(new Locale("ar", ""));100Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "ar == RIGHT_TO_LEFT");101102System.out.println(" } Pass");103}104105// TestBundle106//107// Make sure that getOrientation(ResourceBundle) works right, especially108// the fallback mechasm109//110static void TestBundle() {111System.out.println(" TestBundle {");112113// This will fall back to the default locale's bundle or root bundle114ResourceBundle rb = ResourceBundle.getBundle("TestBundle",115new Locale("et", ""));116if (rb.getLocale().getLanguage().equals(new Locale("iw").getLanguage())) {117assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "et == RIGHT_TO_LEFT" );118} else if (rb.getLocale().getLanguage() == "es") {119assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "et == LEFT_TO_RIGHT" );120} else {121assertEquals(rb, ComponentOrientation.UNKNOWN, "et == UNKNOWN" );122}123124// We have actual bundles for "es" and "iw", so it should just fetch125// the orientation object out of them126rb = ResourceBundle.getBundle("TestBundle",new Locale("es", ""));127assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "es == LEFT_TO_RIGHT" );128129rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", "IL"));130assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "iw == RIGHT_TO_LEFT" );131132// This bundle has no orientation setting at all, so we should get133// the system's default orientation for Arabic134rb = ResourceBundle.getBundle("TestBundle1", new Locale("ar", ""));135assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "ar == RIGHT_TO_LEFT" );136137System.out.println(" } Pass");138}139140static void assertEquals(ResourceBundle rb, ComponentOrientation o, String str) {141Assert(ComponentOrientation.getOrientation(rb) == o, str);142}143144static void Assert(boolean condition, String str) {145if (!condition) {146System.err.println(" ASSERT FAILED: " + str);147throw new RuntimeException("Assert Failed: " + str);148}149}150}151152153