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 
  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 testing
  34  *          Integer/Long's methods related to String.
  35  * @run testng/othervm -XX:+CompactStrings Numbers
  36  * @run testng/othervm -XX:-CompactStrings Numbers
  37  */
  38 
  39 public class Numbers {
  40 
  41     /*
  42      * Data provider for testIntegerLong
  43      *
  44      * @return input parameter for testIntegerLong
  45      */
  46     @DataProvider
  47     public Object[][] numbers() {
  48         return new Object[][] {
  49                 { Integer.toBinaryString(Integer.MAX_VALUE),
  50                         "1111111111111111111111111111111" },
  51                 { Integer.toBinaryString(Integer.MIN_VALUE),
  52                         "10000000000000000000000000000000" },
  53                 { Integer.toBinaryString(7), "111" },
  54                 { Integer.toBinaryString(0), "0" },
  55                 { Integer.toOctalString(Integer.MAX_VALUE), "17777777777" },
  56                 { Integer.toOctalString(Integer.MIN_VALUE), "20000000000" },
  57                 { Integer.toOctalString(9), "11" },
  58                 { Integer.toOctalString(0), "0" },
  59                 { Integer.toHexString(Integer.MAX_VALUE), "7fffffff" },
  60                 { Integer.toHexString(Integer.MIN_VALUE), "80000000" },
  61                 { Integer.toHexString(17), "11" },
  62                 { Integer.toHexString(0), "0" },
  63                 { Integer.toString(Integer.MAX_VALUE, 2),
  64                         "1111111111111111111111111111111" },
  65                 { Integer.toString(Integer.MIN_VALUE, 2),
  66                         "-10000000000000000000000000000000" },
  67                 { Integer.toString(7, 2), "111" },
  68                 { Integer.toString(0, 2), "0" },
  69                 { Integer.toString(Integer.MAX_VALUE, 8), "17777777777" },
  70                 { Integer.toString(Integer.MIN_VALUE, 8), "-20000000000" },
  71                 { Integer.toString(9, 8), "11" },
  72                 { Integer.toString(Integer.MAX_VALUE, 16), "7fffffff" },
  73                 { Integer.toString(Integer.MIN_VALUE, 16), "-80000000" },
  74                 { Integer.toString(17, 16), "11" },
  75                 { Long.toBinaryString(Long.MAX_VALUE),
  76                         "111111111111111111111111111111111111111111111111111111111111111" },
  77                 { Long.toBinaryString(Long.MIN_VALUE),
  78                         "1000000000000000000000000000000000000000000000000000000000000000" },
  79                 { Long.toOctalString(Long.MAX_VALUE), "777777777777777777777" },
  80                 { Long.toOctalString(Long.MIN_VALUE), "1000000000000000000000" },
  81                 { Long.toHexString(Long.MAX_VALUE), "7fffffffffffffff" },
  82                 { Long.toHexString(Long.MIN_VALUE), "8000000000000000" },
  83                 { Long.toString(Long.MAX_VALUE, 2),
  84                         "111111111111111111111111111111111111111111111111111111111111111" },
  85                 { Long.toString(Long.MIN_VALUE, 2),
  86                         "-1000000000000000000000000000000000000000000000000000000000000000" },
  87                 { Long.toString(Long.MAX_VALUE, 8), "777777777777777777777" },
  88                 { Long.toString(Long.MIN_VALUE, 8), "-1000000000000000000000" },
  89                 { Long.toString(Long.MAX_VALUE, 16), "7fffffffffffffff" },
  90                 { Long.toString(Long.MIN_VALUE, 16), "-8000000000000000" } };
  91     }
  92 
  93     /*
  94      * test Integer/Long's methods related to String.
  95      *
  96      * @param res
  97      *            real result
  98      * @param expected
  99      *            expected result
 100      */
 101     @Test(dataProvider = "numbers")
 102     public void testIntegerLong(String res, String expected) {
 103         assertEquals(res, expected);
 104     }
 105 
 106 }