Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/ComponentOrientation/BasicTest.java
41149 views
1
/*
2
* Copyright (c) 1998, 2021, 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 4108453 4778440 6304780 6396378 8263202
27
* @summary Basic tests for java.awt.ComponentOrientation
28
* @build TestBundle TestBundle_es TestBundle_iw
29
* @build TestBundle1 TestBundle1_ar
30
*
31
* @run main BasicTest
32
*/
33
/*
34
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
35
*
36
* The original version of this source code and documentation is copyrighted
37
* and owned by IBM, Inc. These materials are provided under terms of a
38
* License Agreement between IBM and Sun. This technology is protected by
39
* multiple US and International patents. This notice and attribution to IBM
40
* may not be removed.
41
*/
42
43
import java.awt.ComponentOrientation;
44
import java.util.Locale;
45
import java.util.ResourceBundle;
46
47
public class BasicTest {
48
public static void main(String args[]) {
49
System.out.println("BasicTest {");
50
TestInvariants();
51
TestLocale();
52
TestBundle();
53
54
System.out.println("} Pass");
55
}
56
57
// TestInvariants
58
//
59
// Various no-brainer tests to make sure the constants behave properly
60
// and so on.
61
//
62
static void TestInvariants() {
63
System.out.println(" TestInvariants {");
64
65
Assert(ComponentOrientation.LEFT_TO_RIGHT.isLeftToRight(),
66
"LEFT_TO_RIGHT.isLeftToRight()");
67
68
Assert(ComponentOrientation.UNKNOWN.isLeftToRight(),
69
"UNKNOWN.isLeftToRight()");
70
71
Assert(!ComponentOrientation.RIGHT_TO_LEFT.isLeftToRight(),
72
"!RIGHT_TO_LEFT.isLeftToRight()");
73
74
Assert(ComponentOrientation.LEFT_TO_RIGHT.isHorizontal(),
75
"LEFT_TO_RIGHT.isHorizontal()");
76
77
Assert(ComponentOrientation.UNKNOWN.isHorizontal(),
78
"UNKNOWN.isHorizontal()");
79
80
Assert(ComponentOrientation.RIGHT_TO_LEFT.isHorizontal(),
81
"RIGHT_TO_LEFT.isHorizontal()");
82
83
System.out.println(" } Pass");
84
}
85
86
// TestLocale
87
//
88
// Make sure that getOrientation(Locale) works, and that the appropriate
89
// system locales are RIGHT_TO_LEFT
90
//
91
static void TestLocale() {
92
System.out.println(" TestLocale {");
93
94
ComponentOrientation orient = ComponentOrientation.getOrientation(Locale.US);
95
Assert(orient == ComponentOrientation.LEFT_TO_RIGHT, "US == LEFT_TO_RIGHT");
96
97
orient = ComponentOrientation.getOrientation(new Locale("iw", ""));
98
Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "iw == RIGHT_TO_LEFT");
99
100
orient = ComponentOrientation.getOrientation(new Locale("ar", ""));
101
Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "ar == RIGHT_TO_LEFT");
102
103
orient = ComponentOrientation.getOrientation(new Locale("he", ""));
104
Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "he == RIGHT_TO_LEFT");
105
106
orient = ComponentOrientation.getOrientation(new Locale("yi", ""));
107
Assert(orient == ComponentOrientation.RIGHT_TO_LEFT, "yi == RIGHT_TO_LEFT");
108
109
System.out.println(" } Pass");
110
}
111
112
// TestBundle
113
//
114
// Make sure that getOrientation(ResourceBundle) works right, especially
115
// the fallback mechasm
116
//
117
static void TestBundle() {
118
System.out.println(" TestBundle {");
119
120
// This will fall back to the default locale's bundle or root bundle
121
ResourceBundle rb = ResourceBundle.getBundle("TestBundle",
122
new Locale("et", ""));
123
if (rb.getLocale().getLanguage().equals(new Locale("iw").getLanguage())) {
124
assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "et == RIGHT_TO_LEFT" );
125
} else if (rb.getLocale().getLanguage() == "es") {
126
assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "et == LEFT_TO_RIGHT" );
127
} else {
128
assertEquals(rb, ComponentOrientation.UNKNOWN, "et == UNKNOWN" );
129
}
130
131
// We have actual bundles for "es" and "iw", so it should just fetch
132
// the orientation object out of them
133
rb = ResourceBundle.getBundle("TestBundle",new Locale("es", ""));
134
assertEquals(rb, ComponentOrientation.LEFT_TO_RIGHT, "es == LEFT_TO_RIGHT" );
135
136
rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", "IL"));
137
assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "iw == RIGHT_TO_LEFT" );
138
139
// Test with "he" locale. This should load TestBundle_iw and fetch the orientation from there
140
rb = ResourceBundle.getBundle("TestBundle", new Locale("he", "IL"));
141
assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "he == RIGHT_TO_LEFT" );
142
143
// This bundle has no orientation setting at all, so we should get
144
// the system's default orientation for Arabic
145
rb = ResourceBundle.getBundle("TestBundle1", new Locale("ar", ""));
146
assertEquals(rb, ComponentOrientation.RIGHT_TO_LEFT, "ar == RIGHT_TO_LEFT" );
147
148
System.out.println(" } Pass");
149
}
150
151
static void assertEquals(ResourceBundle rb, ComponentOrientation o, String str) {
152
Assert(ComponentOrientation.getOrientation(rb) == o, str);
153
}
154
155
static void Assert(boolean condition, String str) {
156
if (!condition) {
157
System.err.println(" ASSERT FAILED: " + str);
158
throw new RuntimeException("Assert Failed: " + str);
159
}
160
}
161
}
162
163