1 /* 2 * Copyright (c) 2015, 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 package test.java.lang.String.CompactString; 24 25 import org.testng.annotations.DataProvider; 26 import org.testng.annotations.Test; 27 28 import static org.testng.Assert.assertEquals; 29 30 /* 31 * @test 32 * @bug 8077559 33 * @summary Tests Compact String. This one is for String.valueOf. 34 * valueOf(char[] data) is not tested here. 35 * @run testng/othervm -XX:+CompactStrings ValueOf 36 * @run testng/othervm -XX:-CompactStrings ValueOf 37 */ 38 39 public class ValueOf { 40 41 /* 42 * Data provider for testValueOf 43 * 44 * @return input parameter for testValueOf 45 */ 46 @DataProvider valueOfs()47 public Object[][] valueOfs() { 48 return new Object[][] { { String.valueOf(true), "true" }, 49 { String.valueOf(false), "false" }, 50 { String.valueOf(1.0f), "1.0" }, 51 { String.valueOf(0.0f), "0.0" }, 52 { String.valueOf(Float.MAX_VALUE), "3.4028235E38" }, 53 { String.valueOf(Float.MIN_VALUE), "1.4E-45" }, 54 { String.valueOf(1.0d), "1.0" }, 55 { String.valueOf(0.0d), "0.0" }, 56 { String.valueOf(Double.MAX_VALUE), "1.7976931348623157E308" }, 57 { String.valueOf(Double.MIN_VALUE), "4.9E-324" }, 58 { String.valueOf(1), "1" }, { String.valueOf(0), "0" }, 59 { String.valueOf(Integer.MAX_VALUE), "2147483647" }, 60 { String.valueOf(Integer.MIN_VALUE), "-2147483648" }, 61 { String.valueOf(1L), "1" }, { String.valueOf(0L), "0" }, 62 { String.valueOf(Long.MAX_VALUE), "9223372036854775807" }, 63 { String.valueOf(Long.MIN_VALUE), "-9223372036854775808" } }; 64 } 65 66 /* 67 * test String.valueOf(xxx). 68 * 69 * @param res 70 * real result 71 * @param expected 72 * expected result 73 */ 74 @Test(dataProvider = "valueOfs") testValueOf(String res, String expected)75 public void testValueOf(String res, String expected) { 76 assertEquals(res, expected); 77 } 78 79 } 80