|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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 | +import org.testng.annotations.Test; |
| 25 | + |
| 26 | +import static org.testng.Assert.assertEquals; |
| 27 | +import static org.testng.Assert.fail; |
| 28 | + |
| 29 | +/** |
| 30 | + * @test |
| 31 | + * @bug 8302877 |
| 32 | + * @summary Provides exhaustive verification of Character.toUpperCase and Character.toLowerCase |
| 33 | + * for all code points in the latin1 range 0-255. |
| 34 | + * @run testng Latin1CaseConversion |
| 35 | + */ |
| 36 | +public class Latin1CaseConversion { |
| 37 | + |
| 38 | + @Test |
| 39 | + public void shouldUpperCaseAndLowerCaseLatin1() { |
| 40 | + for (int c = 0; c < 256; c++) { |
| 41 | + int upper = Character.toUpperCase(c); |
| 42 | + int lower = Character.toLowerCase(c); |
| 43 | + |
| 44 | + if (c < 0x41) { // Before A |
| 45 | + assertUnchanged(upper, lower, c); |
| 46 | + } else if (c <= 0x5A) { // A-Z |
| 47 | + assertEquals(upper, c); |
| 48 | + assertEquals(lower, c + 32); |
| 49 | + } else if (c < 0x61) { // Between Z and a |
| 50 | + assertUnchanged(upper, lower, c); |
| 51 | + } else if (c <= 0x7A) { // a-z |
| 52 | + assertEquals(upper, c - 32); |
| 53 | + assertEquals(lower, c); |
| 54 | + } else if (c < 0xB5) { // Between z and Micro Sign |
| 55 | + assertUnchanged(upper, lower, c); |
| 56 | + } else if (c == 0xB5) { // Special case for Micro Sign |
| 57 | + assertEquals(upper, 0x39C); |
| 58 | + assertEquals(lower, c); |
| 59 | + } else if (c < 0xC0) { // Between my and A-grave |
| 60 | + assertUnchanged(upper, lower, c); |
| 61 | + } else if (c < 0xD7) { // A-grave - O with Diaeresis |
| 62 | + assertEquals(upper, c); |
| 63 | + assertEquals(lower, c + 32); |
| 64 | + } else if (c == 0xD7) { // Multiplication |
| 65 | + assertUnchanged(upper, lower, c); |
| 66 | + } else if (c <= 0xDE) { // O with slash - Thorn |
| 67 | + assertEquals(upper, c); |
| 68 | + assertEquals(lower, c + 32); |
| 69 | + } else if (c == 0xDF) { // Sharp s |
| 70 | + assertUnchanged(upper, lower, c); |
| 71 | + } else if (c < 0xF7) { // a-grave - divsion |
| 72 | + assertEquals(upper, c - 32); |
| 73 | + assertEquals(lower, c); |
| 74 | + } else if (c == 0xF7) { // Division |
| 75 | + assertUnchanged(upper, lower, c); |
| 76 | + } else if (c < 0xFF) { // o with slash - thorn |
| 77 | + assertEquals(upper, c - 32); |
| 78 | + assertEquals(lower, c); |
| 79 | + } else if (c == 0XFF) { // Special case for y with Diaeresis |
| 80 | + assertEquals(upper, 0x178); |
| 81 | + assertEquals(lower, c); |
| 82 | + } else { |
| 83 | + fail("Uncovered code point: " + Integer.toHexString(c)); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static void assertUnchanged(int upper, int lower, int c) { |
| 89 | + assertEquals(upper, c); |
| 90 | + assertEquals(lower, c); |
| 91 | + } |
| 92 | +} |
0 commit comments