Fri, 24 Apr 2020 03:58:51 +0100
Merge
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 4869233 4872709 4868735 4921949 4921209 4965701 4934916 4975565 4974939 |
duke@1 | 27 | * @summary Boxing/unboxing positive unit and regression tests |
duke@1 | 28 | * @author gafter |
duke@1 | 29 | */ |
duke@1 | 30 | |
duke@1 | 31 | public class Boxing1 { |
duke@1 | 32 | |
duke@1 | 33 | static Boolean _Boolean = true; |
duke@1 | 34 | static boolean _boolean = _Boolean; |
duke@1 | 35 | |
duke@1 | 36 | static Byte _Byte = (byte)3; |
duke@1 | 37 | static byte _byte = _Byte; |
duke@1 | 38 | |
duke@1 | 39 | static Character _Character = 'a'; |
duke@1 | 40 | static char _char = _Character; |
duke@1 | 41 | |
duke@1 | 42 | static Short _Short = (short)4; |
duke@1 | 43 | static short _short = _Short; |
duke@1 | 44 | |
duke@1 | 45 | static Integer _Integer = 5; |
duke@1 | 46 | static int _int = _Integer; |
duke@1 | 47 | |
duke@1 | 48 | static Long _Long = 12L; |
duke@1 | 49 | static long _long = _Long; |
duke@1 | 50 | |
duke@1 | 51 | static Float _Float = 1.2f; |
duke@1 | 52 | static float _float = _Float; |
duke@1 | 53 | |
duke@1 | 54 | static Double _Double = 1.34; |
duke@1 | 55 | static double _double = _Double; |
duke@1 | 56 | |
duke@1 | 57 | public static void main(String[] args) { |
duke@1 | 58 | _Double = _Integer + _Integer + 0.0d; |
duke@1 | 59 | if (_Double != 10) throw new Error(); |
duke@1 | 60 | |
duke@1 | 61 | _Integer = 2; |
duke@1 | 62 | _float = _Integer; |
duke@1 | 63 | if (_float != 2.0f) throw new Error(); |
duke@1 | 64 | |
duke@1 | 65 | _int = 12; |
duke@1 | 66 | _Float = _int + 0.0f; |
duke@1 | 67 | if (_Float != 12.0f) throw new Error(); |
duke@1 | 68 | |
duke@1 | 69 | _Integer = 8; |
duke@1 | 70 | _float = (float)_Integer; |
duke@1 | 71 | if (_float != 8.0f) throw new Error(); |
duke@1 | 72 | |
duke@1 | 73 | _int = 9; |
duke@1 | 74 | _Float = (Float)(_int + 0.0f); |
duke@1 | 75 | if (_Float != 9.0f) throw new Error(); |
duke@1 | 76 | |
duke@1 | 77 | if (_Boolean) ; else throw new Error(); |
duke@1 | 78 | if (!_Boolean) throw new Error(); |
duke@1 | 79 | |
duke@1 | 80 | if (_Integer >= _Long) throw new Error(); |
duke@1 | 81 | |
duke@1 | 82 | _Character = 'a'; |
duke@1 | 83 | String s1 = ("_" + _Character + "_").intern(); |
duke@1 | 84 | if (s1 != "_a_") throw new Error(s1); |
duke@1 | 85 | |
duke@1 | 86 | /* assignment operators don't work; see 4921209 */ |
duke@1 | 87 | if (_Integer++ != 8) throw new Error(); |
duke@1 | 88 | if (_Integer++ != 9) throw new Error(); |
duke@1 | 89 | if (++_Integer != 11) throw new Error(); |
duke@1 | 90 | if ((_Integer += 3) != 14) throw new Error(); |
duke@1 | 91 | if ((_Integer -= 3) != 11) throw new Error(); |
duke@1 | 92 | |
duke@1 | 93 | Integer i = 0; |
duke@1 | 94 | i = i + 2; |
duke@1 | 95 | i += 2; |
duke@1 | 96 | if (i != 4) throw new Error(); |
duke@1 | 97 | |
duke@1 | 98 | int j = 0; |
duke@1 | 99 | j += i; |
duke@1 | 100 | if (j != 4) throw new Error(); |
duke@1 | 101 | |
duke@1 | 102 | Integer a[] = new Integer[1]; |
duke@1 | 103 | a[0] = 3; |
duke@1 | 104 | a[0] += 3; |
duke@1 | 105 | if (a[0] != 6) throw new Error(); |
duke@1 | 106 | |
duke@1 | 107 | Froobie x = new Froobie(); |
duke@1 | 108 | Froobie y = new Froobie(); |
duke@1 | 109 | x.next = y; |
duke@1 | 110 | x.next.i = 4; |
duke@1 | 111 | x.next.i += 4; |
duke@1 | 112 | if (--x.next.i != 7) throw new Error(); |
duke@1 | 113 | if (x.next.i-- != 7) throw new Error(); |
duke@1 | 114 | if (x.next.i != 6) throw new Error(); |
duke@1 | 115 | |
duke@1 | 116 | boxIndex(); |
duke@1 | 117 | boxArray(); |
duke@1 | 118 | } |
duke@1 | 119 | |
duke@1 | 120 | static void boxIndex() { |
duke@1 | 121 | String[] a = { "hello", "world" }; |
duke@1 | 122 | Integer i = 0; |
duke@1 | 123 | System.out.println(a[i]); |
duke@1 | 124 | } |
duke@1 | 125 | |
duke@1 | 126 | static void boxArray() { |
duke@1 | 127 | Integer[] a2 = { 0, 1, 2, 3 }; |
duke@1 | 128 | for (int i : a2) |
duke@1 | 129 | System.out.println(i); |
duke@1 | 130 | } |
duke@1 | 131 | |
duke@1 | 132 | static class Froobie { |
duke@1 | 133 | Froobie next = null; |
duke@1 | 134 | Integer i = 1; |
duke@1 | 135 | } |
duke@1 | 136 | |
duke@1 | 137 | static class Scott { |
duke@1 | 138 | Integer i[]; |
duke@1 | 139 | Integer j[]; |
duke@1 | 140 | Integer k; |
duke@1 | 141 | |
duke@1 | 142 | int q = i[j[k]]++; |
duke@1 | 143 | } |
duke@1 | 144 | |
duke@1 | 145 | class T4974939 { |
duke@1 | 146 | void f() { |
duke@1 | 147 | Byte b = 12; |
duke@1 | 148 | Byte c = 'a'; |
duke@1 | 149 | |
duke@1 | 150 | Short s = 'b'; |
duke@1 | 151 | Short t = 12; |
duke@1 | 152 | |
duke@1 | 153 | Character d = 12; |
duke@1 | 154 | } |
duke@1 | 155 | } |
duke@1 | 156 | } |