1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 public class Main extends TestCase {
main(String[] args)18   public static void main(String[] args) {
19     $opt$TestThisClassStaticField();
20     $opt$TestOtherClassStaticField();
21     $opt$TestAddThisClassStaticField();
22     $opt$TestAddOtherClassStaticField();
23     $opt$TestOtherClassWithClinitStaticField();
24     $opt$TestAccess();
25   }
26 
27   static int staticField = 42;
28 
getInt()29   static int getInt() {
30     return 33;
31   }
32 
$opt$TestThisClassStaticField()33   static void $opt$TestThisClassStaticField() {
34     assertEquals(42, staticField);
35   }
36 
$opt$TestOtherClassStaticField()37   static void $opt$TestOtherClassStaticField() {
38     assertEquals(41, Other.staticField);
39   }
40 
$opt$TestAddThisClassStaticField()41   static void $opt$TestAddThisClassStaticField() {
42     int a = getInt();
43     assertEquals(a + 42, a + staticField);
44   }
45 
$opt$TestAddOtherClassStaticField()46   static void $opt$TestAddOtherClassStaticField() {
47     int a = getInt();
48     assertEquals(a + 41, a + Other.staticField);
49   }
50 
$opt$TestOtherClassWithClinitStaticField()51   static void $opt$TestOtherClassWithClinitStaticField() {
52     assertEquals(40, OtherWithClinit.staticField);
53   }
54 
$opt$TestAccess()55   static void $opt$TestAccess() {
56     assertEquals(false, sZ);
57     assertEquals(0, sB);
58     assertEquals(0, sC);
59     assertEquals(0, sI);
60     assertEquals(0, sJ);
61     assertEquals(0, sS);
62     assertEquals(0.0f, sF);
63     assertEquals(0.0, sD);
64     assertNull(sObject);
65 
66     long longValue = -1122198787987987987L;
67     Object o = new Object();
68     sZ = true;
69     sB = -2;
70     sC = 'c';
71     sI = 42;
72     sJ = longValue;
73     sS = 68;
74     sObject = o;
75     sF = 2.3f;
76     sD = 5.3;
77 
78     assertEquals(true, sZ);
79     assertEquals(-2, sB);
80     assertEquals('c', sC);
81     assertEquals(42, sI);
82     assertEquals(longValue, sJ);
83     assertEquals(68, sS);
84     assertEquals(o, sObject);
85     assertEquals(2.3f, sF);
86     assertEquals(5.3, sD);
87   }
88 
89   static boolean sZ;
90   static byte sB;
91   static char sC;
92   static double sD;
93   static float sF;
94   static int sI;
95   static long sJ;
96   static short sS;
97   static Object sObject;
98 }
99