test/jdk/internal/misc/JavaLangAccess/FormatUnsigned.java

Print this page




   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 sun.misc.JavaLangAccess;
  25 import sun.misc.SharedSecrets;
  26 
  27 /*
  28  * @test
  29  * @bug 8050114
  30  * @summary Test JavaLangAccess.formatUnsignedInt/-Long
  31  * @modules java.base/sun.misc
  32  */
  33 public class FormatUnsigned {
  34 
  35     static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
  36 
  37     public static void testFormatUnsignedInt() {
  38         testFormatUnsignedInt("7fffffff", Integer.MAX_VALUE, 8, 4, 0, 8);
  39         testFormatUnsignedInt("80000000", Integer.MIN_VALUE, 8, 4, 0, 8);
  40         testFormatUnsignedInt("4711", 04711, 4, 3, 0, 4);
  41         testFormatUnsignedInt("4711", 0x4711, 4, 4, 0, 4);
  42         testFormatUnsignedInt("1010", 0b1010, 4, 1, 0, 4);
  43         testFormatUnsignedInt("00001010", 0b1010, 8, 1, 0, 8);
  44         testFormatUnsignedInt("\u0000\u000000001010", 0b1010, 10, 1, 2, 8);
  45     }
  46 
  47     public static void testFormatUnsignedLong() {
  48         testFormatUnsignedLong("7fffffffffffffff", Long.MAX_VALUE, 16, 4, 0, 16);
  49         testFormatUnsignedLong("8000000000000000", Long.MIN_VALUE, 16, 4, 0, 16);
  50         testFormatUnsignedLong("4711", 04711L, 4, 3, 0, 4);
  51         testFormatUnsignedLong("4711", 0x4711L, 4, 4, 0, 4);




   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 jdk.internal.misc.JavaLangAccess;
  25 import jdk.internal.misc.SharedSecrets;
  26 
  27 /*
  28  * @test
  29  * @bug 8050114
  30  * @summary Test JavaLangAccess.formatUnsignedInt/-Long
  31  * @modules java.base/jdk.internal.misc
  32  */
  33 public class FormatUnsigned {
  34 
  35     static final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
  36 
  37     public static void testFormatUnsignedInt() {
  38         testFormatUnsignedInt("7fffffff", Integer.MAX_VALUE, 8, 4, 0, 8);
  39         testFormatUnsignedInt("80000000", Integer.MIN_VALUE, 8, 4, 0, 8);
  40         testFormatUnsignedInt("4711", 04711, 4, 3, 0, 4);
  41         testFormatUnsignedInt("4711", 0x4711, 4, 4, 0, 4);
  42         testFormatUnsignedInt("1010", 0b1010, 4, 1, 0, 4);
  43         testFormatUnsignedInt("00001010", 0b1010, 8, 1, 0, 8);
  44         testFormatUnsignedInt("\u0000\u000000001010", 0b1010, 10, 1, 2, 8);
  45     }
  46 
  47     public static void testFormatUnsignedLong() {
  48         testFormatUnsignedLong("7fffffffffffffff", Long.MAX_VALUE, 16, 4, 0, 16);
  49         testFormatUnsignedLong("8000000000000000", Long.MIN_VALUE, 16, 4, 0, 16);
  50         testFormatUnsignedLong("4711", 04711L, 4, 3, 0, 4);
  51         testFormatUnsignedLong("4711", 0x4711L, 4, 4, 0, 4);