summaryrefslogtreecommitdiffstats
path: root/test/414-static-fields/src/Main.java
blob: 9c5cf133a033e6048a99f2f5a62ca05bf8b7b9c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main extends TestCase {
  public static void main(String[] args) {
    $opt$TestThisClassStaticField();
    $opt$TestOtherClassStaticField();
    $opt$TestAddThisClassStaticField();
    $opt$TestAddOtherClassStaticField();
    $opt$TestOtherClassWithClinitStaticField();
    $opt$TestAccess();
  }

  static int staticField = 42;

  static int getInt() {
    return 33;
  }

  static void $opt$TestThisClassStaticField() {
    assertEquals(42, staticField);
  }

  static void $opt$TestOtherClassStaticField() {
    assertEquals(41, Other.staticField);
  }

  static void $opt$TestAddThisClassStaticField() {
    int a = getInt();
    assertEquals(a + 42, a + staticField);
  }

  static void $opt$TestAddOtherClassStaticField() {
    int a = getInt();
    assertEquals(a + 41, a + Other.staticField);
  }

  static void $opt$TestOtherClassWithClinitStaticField() {
    assertEquals(40, OtherWithClinit.staticField);
  }

  static void $opt$TestAccess() {
    assertEquals(false, sZ);
    assertEquals(0, sB);
    assertEquals(0, sC);
    assertEquals(0, sI);
    assertEquals(0, sJ);
    assertEquals(0, sS);
    assertNull(sObject);

    long longValue = -1122198787987987987L;
    Object o = new Object();
    sZ = true;
    sB = -2;
    sC = 'c';
    sI = 42;
    sJ = longValue;
    sS = 68;
    sObject = o;

    assertEquals(true, sZ);
    assertEquals(-2, sB);
    assertEquals('c', sC);
    assertEquals(42, sI);
    assertEquals(longValue, sJ);
    assertEquals(68, sS);
    assertEquals(o, sObject);
  }

  static boolean sZ;
  static byte sB;
  static char sC;
  static double sD;
  static float sF;
  static int sI;
  static long sJ;
  static short sS;
  static Object sObject;
}