summaryrefslogtreecommitdiffstats
path: root/jack-tests/tests/com/android/jack/field/FieldTests.java
blob: 9ce3b1e0c0ba818912b963b87c1ce0c8fadb1468 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* 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.
*/

package com.android.jack.field;

import com.android.jack.test.category.RuntimeRegressionTest;
import com.android.jack.test.comparator.ComparatorDex;
import com.android.jack.test.helper.CheckDexStructureTestHelper;
import com.android.jack.test.helper.RuntimeTestHelper;
import com.android.jack.test.helper.SourceToDexComparisonTestHelper;
import com.android.jack.test.runtime.RuntimeTest;
import com.android.jack.test.runtime.RuntimeTestInfo;
import com.android.jack.test.toolchain.AbstractTestTools;
import com.android.jack.test.toolchain.IToolchain;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.annotation.Nonnull;

public class FieldTests extends RuntimeTest {

  private RuntimeTestInfo INSTANCE001 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.instance001"),
    "com.android.jack.field.instance001.dx.Tests");

  private RuntimeTestInfo INSTANCE002 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.instance002"),
    "com.android.jack.field.instance002.dx.Tests");

  private RuntimeTestInfo INSTANCE003 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.instance003"),
    "com.android.jack.field.instance003.dx.Tests");

  private RuntimeTestInfo INSTANCE004 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.instance004"),
    "com.android.jack.field.instance004.dx.Tests");

  private RuntimeTestInfo STATIC001 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.static001"),
    "com.android.jack.field.static001.dx.Tests");

  private RuntimeTestInfo STATIC002 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.static002"),
    "com.android.jack.field.static002.dx.Tests");

  private RuntimeTestInfo STATIC004 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.static004"),
    "com.android.jack.field.static004.dx.Tests");

  private RuntimeTestInfo STATIC005 = new RuntimeTestInfo(
    AbstractTestTools.getTestRootDir("com.android.jack.field.static005"),
    "com.android.jack.field.static005.dx.Tests");


  @Test
  @Category(RuntimeRegressionTest.class)
  public void instance001() throws Exception {
    new RuntimeTestHelper(INSTANCE001).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void instance002() throws Exception {
    new RuntimeTestHelper(INSTANCE002).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void instance003() throws Exception {
    new RuntimeTestHelper(INSTANCE003).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void instance004() throws Exception {
    new RuntimeTestHelper(INSTANCE004).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void static001() throws Exception {
    new RuntimeTestHelper(STATIC001).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void static002() throws Exception {
    new RuntimeTestHelper(STATIC002).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void static004() throws Exception {
    new RuntimeTestHelper(STATIC004).compileAndRunTest();
  }

  @Test
  @Category(RuntimeRegressionTest.class)
  public void static005() throws Exception {
    new RuntimeTestHelper(STATIC005).compileAndRunTest();
  }

  @Test
  public void testCompileInstance6() throws Exception {
    compileTest("instance005");
  }

  @Test
  public void testCompileStatic() throws Exception {
    compileTest("static003");
  }

  /**
   * Compiles StaticField.java into a {@code DexFile} and compares it to a dex file created
   * using a reference compiler and {@code dx}.
   */
  @Test
  public void testStatic() throws Exception {
    checkStructure("static003");
  }

  /**
   * Compiles InstanceField.java into a {@code DexFile} and compares it to a dex file created
   * using a reference compiler and {@code dx}.
   */
  @Test
  public void testInstance() throws Exception {
    checkStructure("instance005");
  }

  private void compileTest(@Nonnull String test) throws Exception {
    IToolchain toolchain = AbstractTestTools.getCandidateToolchain();
    toolchain.addToClasspath(toolchain.getDefaultBootClasspath())
    .srcToExe(
        AbstractTestTools.createTempDir(),
        /* zipFile = */ false,
        AbstractTestTools.getTestRootDir("com.android.jack.field." + test + ".jack"));
  }

  private void checkStructure(@Nonnull String test) throws Exception {
    SourceToDexComparisonTestHelper helper = new CheckDexStructureTestHelper(
        AbstractTestTools.getTestRootDir("com.android.jack.field." + test + ".jack"));
    helper.runTest(new ComparatorDex(helper.getReferenceDex(), helper.getCandidateDex()));
  }

  @Override
  protected void fillRtTestInfos() {
    rtTestInfos.add(INSTANCE001);
    rtTestInfos.add(INSTANCE002);
    rtTestInfos.add(INSTANCE003);
    rtTestInfos.add(INSTANCE004);
    rtTestInfos.add(STATIC001);
    rtTestInfos.add(STATIC002);
    rtTestInfos.add(STATIC004);
    rtTestInfos.add(STATIC005);
  }
}