langtools/test/tools/javac/literals/BinaryLiterals.java
author ssides
Wed, 09 Jul 2014 15:14:06 +0400
changeset 25760 7955db32d6b0
parent 5520 86e4b9a9da40
permissions -rw-r--r--
8046597: fix doclint issues in swing classes, part 4 of 4 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3895
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     4
 *
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     8
 *
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    13
 * accompanied this code).
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    14
 *
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3895
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3895
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3895
diff changeset
    21
 * questions.
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    22
 */
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    23
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    24
/*
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    25
 * @test
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    26
 * @bug 6860965
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    27
 * @summary Project Coin: binary literals
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    28
 */
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    29
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    30
public class BinaryLiterals {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    31
    public static void main(String... args) throws Exception {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    32
        new BinaryLiterals().run();
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    33
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    34
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    35
    public void run() throws Exception {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    36
        test(0,  0B0);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    37
        test(1,  0B1);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    38
        test(2, 0B10);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    39
        test(3, 0B11);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    40
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    41
        test(0,  0b0);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    42
        test(1,  0b1);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    43
        test(2, 0b10);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    44
        test(3, 0b11);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    45
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    46
        test(-0,  -0b0);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    47
        test(-1,  -0b1);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    48
        test(-2, -0b10);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    49
        test(-3, -0b11);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    50
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    51
        test(-1,  0b11111111111111111111111111111111);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    52
        test(-2,  0b11111111111111111111111111111110);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    53
        test(-3,  0b11111111111111111111111111111101);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    54
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    55
        test( 1, -0b11111111111111111111111111111111);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    56
        test( 2, -0b11111111111111111111111111111110);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    57
        test( 3, -0b11111111111111111111111111111101);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    58
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    59
        test(0,     0b00);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    60
        test(1,    0b001);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    61
        test(2,  0b00010);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    62
        test(3, 0b000011);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    63
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    64
        //                 aaaabbbbccccddddeeeeffffgggghhhh
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    65
        test(      0x10,                            0b10000);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    66
        test(     0x100,                        0b100000000);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    67
        test(   0x10000,                0b10000000000000000);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    68
        test(0x80000000, 0b10000000000000000000000000000000);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    69
        test(0xffffffff, 0b11111111111111111111111111111111);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    70
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    71
        test(0L,  0b0L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    72
        test(1L,  0b1L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    73
        test(2L, 0b10L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    74
        test(3L, 0b11L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    75
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    76
        test(0,     0b00L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    77
        test(1,    0b001L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    78
        test(2,  0b00010L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    79
        test(3, 0b000011L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    80
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    81
        //                          aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    82
        test(              0x10L,                                                            0b10000L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    83
        test(             0x100L,                                                        0b100000000L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    84
        test(           0x10000L,                                                0b10000000000000000L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    85
        test(        0x80000000L,                                 0b10000000000000000000000000000000L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    86
        test(        0xffffffffL,                                 0b11111111111111111111111111111111L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    87
        test(0x8000000000000000L, 0b1000000000000000000000000000000000000000000000000000000000000000L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    88
        test(0xffffffffffffffffL, 0b1111111111111111111111111111111111111111111111111111111111111111L);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    89
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    90
        test(0l,  0b0l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    91
        test(1l,  0b1l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    92
        test(2l, 0b10l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    93
        test(3l, 0b11l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    94
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    95
        test(0,     0b00l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    96
        test(1,    0b001l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    97
        test(2,  0b00010l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    98
        test(3, 0b000011l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    99
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   100
        //                          aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   101
        test(              0x10l,                                                            0b10000l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   102
        test(             0x100l,                                                        0b100000000l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   103
        test(           0x10000l,                                                0b10000000000000000l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   104
        test(        0x80000000l,                                 0b10000000000000000000000000000000l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   105
        test(        0xffffffffl,                                 0b11111111111111111111111111111111l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   106
        test(0x8000000000000000l, 0b1000000000000000000000000000000000000000000000000000000000000000l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   107
        test(0xffffffffffffffffl, 0b1111111111111111111111111111111111111111111111111111111111111111l);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   108
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   109
        if (errors > 0)
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   110
             throw new Exception(errors + " errors found");
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   111
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   112
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   113
    void test(int expect, int found) {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   114
        count++;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   115
        if (found != expect)
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   116
            error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n   found: 0x" + Integer.toHexString(found));
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   117
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   118
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   119
    void test(long expect, long found) {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   120
        count++;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   121
        if (found != expect)
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   122
            error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n   found: 0x" + Long.toHexString(found));
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   123
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   124
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   125
    void error(String message) {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   126
        System.out.println(message);
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   127
        errors++;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   128
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   129
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   130
    int count;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   131
    int errors;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
   132
}