1 /*
2 * Copyright (c) 2000, 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 4031762
27 * @summary Test the primitive wrappers static toString()
28 * @key randomness
29 */
30
31 import java.util.Random;
32
33 public class ToString {
34
35 private static Random generator = new Random();
36
37 public static void main(String args[]) throws Exception {
38 // boolean wrapper
39 boolean b = false;
40 Boolean B = new Boolean(b);
41 if (!B.toString().equals(Boolean.toString(b)))
42 throw new RuntimeException("Boolean wrapper toString() failure.");
43 b = true;
44 B = new Boolean(b);
45 if (!B.toString().equals(Boolean.toString(b)))
46 throw new RuntimeException("Boolean wrapper toString() failure.");
47
48 // char wrapper
49 for(int x=0; x<100; x++) {
50 char c = (char)generator.nextInt();
51 Character C = new Character(c);
52 if (!C.toString().equals(Character.toString(c)))
53 throw new RuntimeException("Character wrapper toString() failure.");
54 }
55
56 // byte wrapper
57 for(int x=0; x<100; x++) {
58 byte y = (byte)generator.nextInt();
59 Byte Y = new Byte(y);
60 if (!Y.toString().equals(Byte.toString(y)))
61 throw new RuntimeException("Byte wrapper toString() failure.");
62 }
63
64 // short wrapper
65 for(int x=0; x<100; x++) {
66 short s = (short)generator.nextInt();
67 Short S = new Short(s);
68 if (!S.toString().equals(Short.toString(s)))
69 throw new RuntimeException("Short wrapper toString() failure.");
70 }
71
72 // int wrapper
73 for(int x=0; x<100; x++) {
74 int i = generator.nextInt();
75 Integer I = new Integer(i);
76 if (!I.toString().equals(Integer.toString(i)))
77 throw new RuntimeException("Integer wrapper toString() failure.");
78 }
79
80 // long wrapper
81 for(int x=0; x<100; x++) {
82 long l = generator.nextLong();
83 Long L = new Long(l);
84 if (!L.toString().equals(Long.toString(l)))
85 throw new RuntimeException("Long wrapper toString() failure.");
86 }
87
88 // float wrapper
89 for(int x=0; x<100; x++) {
90 float f = generator.nextFloat();
91 Float F = new Float(f);
92 if (!F.toString().equals(Float.toString(f)))
93 throw new RuntimeException("Float wrapper toString() failure.");
94 }
95
96 // double wrapper
97 for(int x=0; x<100; x++) {
98 double d = generator.nextDouble();
99 Double D = new Double(d);
100 if (!D.toString().equals(Double.toString(d)))
101 throw new RuntimeException("Double wrapper toString() failure.");
102 }
103
104 }
105 }
--- EOF ---