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