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 */
29
30 import java.util.Random;
31
32 public class ToString {
33
34 private static Random generator = new Random();
35
36 public static void main(String args[]) throws Exception {
37 // boolean wrapper
38 boolean b = false;
39 Boolean B = new Boolean(b);
40 if (!B.toString().equals(Boolean.toString(b)))
41 throw new RuntimeException("Boolean wrapper toString() failure.");
42 b = true;
43 B = new Boolean(b);
44 if (!B.toString().equals(Boolean.toString(b)))
45 throw new RuntimeException("Boolean wrapper toString() failure.");
46
83 if (!L.toString().equals(Long.toString(l)))
84 throw new RuntimeException("Long wrapper toString() failure.");
85 }
86
87 // float wrapper
88 for(int x=0; x<100; x++) {
89 float f = generator.nextFloat();
90 Float F = new Float(f);
91 if (!F.toString().equals(Float.toString(f)))
92 throw new RuntimeException("Float wrapper toString() failure.");
93 }
94
95 // double wrapper
96 for(int x=0; x<100; x++) {
97 double d = generator.nextDouble();
98 Double D = new Double(d);
99 if (!D.toString().equals(Double.toString(d)))
100 throw new RuntimeException("Double wrapper toString() failure.");
101 }
102
103 }
104 }
|
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 8042990
27 * @summary Test the primitive wrappers static toString()
28 */
29
30 import java.util.Random;
31
32 public class ToString {
33
34 private static Random generator = new Random();
35
36 public static void main(String args[]) throws Exception {
37 // boolean wrapper
38 boolean b = false;
39 Boolean B = new Boolean(b);
40 if (!B.toString().equals(Boolean.toString(b)))
41 throw new RuntimeException("Boolean wrapper toString() failure.");
42 b = true;
43 B = new Boolean(b);
44 if (!B.toString().equals(Boolean.toString(b)))
45 throw new RuntimeException("Boolean wrapper toString() failure.");
46
83 if (!L.toString().equals(Long.toString(l)))
84 throw new RuntimeException("Long wrapper toString() failure.");
85 }
86
87 // float wrapper
88 for(int x=0; x<100; x++) {
89 float f = generator.nextFloat();
90 Float F = new Float(f);
91 if (!F.toString().equals(Float.toString(f)))
92 throw new RuntimeException("Float wrapper toString() failure.");
93 }
94
95 // double wrapper
96 for(int x=0; x<100; x++) {
97 double d = generator.nextDouble();
98 Double D = new Double(d);
99 if (!D.toString().equals(Double.toString(d)))
100 throw new RuntimeException("Double wrapper toString() failure.");
101 }
102
103 // unsigned hex int
104 for(int x=0; x<100; x++) {
105 int i = generator.nextInt();
106 int w = 1 + generator.nextInt(9);
107 String s = String.format("%0" + w + "x", i);
108 if (!s.equals(Integer.toHexString(i, w)))
109 throw new RuntimeException("Integer wrapper toHexString() failed for " + i + ".");
110 }
111
112 // unsigned hex long
113 for(int x=0; x<100; x++) {
114 long l = generator.nextLong();
115 int w = 1 + generator.nextInt(19);
116 String s = String.format("%0" + w + "x", l);
117 if (!s.equals(Long.toHexString(l, w)))
118 throw new RuntimeException("Long wrapper toHexString() failed for " + l + ".");
119 }
120 }
121 }
|