Path: blob/master/test/jdk/java/awt/ComponentOrientation/BasicTest.java
41149 views
/*1* Copyright (c) 1998, 2021, 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 6396378 826320226* @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");101102orient = ComponentOrientation.getOrientation(new Locale("he", ""));103Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "he == RIGHT_TO_LEFT");104105orient = ComponentOrientation.getOrientation(new Locale("yi", ""));106Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "yi == RIGHT_TO_LEFT");107108System.out.println(" } Pass");109}110111// TestBundle112//113// Make sure that getOrientation(ResourceBundle) works right, especially114// the fallback mechasm115//116static void TestBundle() {117System.out.println(" TestBundle {");118119// This will fall back to the default locale's bundle or root bundle120ResourceBundle rb = ResourceBundle.getBundle("TestBundle",121new Locale("et", ""));122if (rb.getLocale().getLanguage().equals(new Locale("iw").getLanguage())) {123assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "et == RIGHT_TO_LEFT" );124} else if (rb.getLocale().getLanguage() == "es") {125assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "et == LEFT_TO_RIGHT" );126} else {127assertEquals(rb, ComponentOrientation.UNKNOWN, "et == UNKNOWN" );128}129130// We have actual bundles for "es" and "iw", so it should just fetch131// the orientation object out of them132rb = ResourceBundle.getBundle("TestBundle",new Locale("es", ""));133assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "es == LEFT_TO_RIGHT" );134135rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", "IL"));136assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "iw == RIGHT_TO_LEFT" );137138// Test with "he" locale. This should load TestBundle_iw and fetch the orientation from there139rb = ResourceBundle.getBundle("TestBundle", new Locale("he", "IL"));140assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "he == RIGHT_TO_LEFT" );141142// This bundle has no orientation setting at all, so we should get143// the system's default orientation for Arabic144rb = ResourceBundle.getBundle("TestBundle1", new Locale("ar", ""));145assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "ar == RIGHT_TO_LEFT" );146147System.out.println(" } Pass");148}149150static void assertEquals(ResourceBundle rb, ComponentOrientation o, String str) {151Assert(ComponentOrientation.getOrientation(rb) == o, str);152}153154static void Assert(boolean condition, String str) {155if (!condition) {156System.err.println(" ASSERT FAILED: " + str);157throw new RuntimeException("Assert Failed: " + str);158}159}160}161162163