Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2017 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 import art.Redefinition;
     18 import java.util.Arrays;
     19 
     20 public class Main {
     21 
     22   public static void main(String[] args) {
     23     Verification.doTest(new Transform());
     24     NewName.doTest(new Transform());
     25     DifferentAccess.doTest(new Transform());
     26     NewInterface.doTest(new Transform2());
     27     MissingInterface.doTest(new Transform2());
     28     ReorderInterface.doTest(new Transform2());
     29     MultiRedef.doTest(new Transform(), new Transform2());
     30     MultiRetrans.doTest(new Transform(), new Transform2());
     31     NewMethod.doTest(new Transform());
     32     MissingMethod.doTest(new Transform3());
     33     MethodChange.doTest(new Transform());
     34     NewField.doTest(new Transform());
     35     MissingField.doTest(new Transform4("there"));
     36     FieldChange.doTest(new Transform4("there again"));
     37     Unmodifiable.doTest(new Transform[] { new Transform(), });
     38   }
     39 
     40   // TODO Replace this shim with a better re-write of this test.
     41   private static Redefinition.CommonClassDefinition mapCCD(CommonClassDefinition d) {
     42     return new Redefinition.CommonClassDefinition(d.target, d.class_file_bytes, d.dex_file_bytes);
     43   }
     44 
     45   private static Redefinition.CommonClassDefinition[] toCCDA(CommonClassDefinition[] ds) {
     46     return Arrays.stream(ds).map(Main::mapCCD).toArray(Redefinition.CommonClassDefinition[]::new);
     47   }
     48 
     49   public static void doCommonClassRedefinition(Class<?> target,
     50                                                byte[] classfile,
     51                                                byte[] dexfile) throws Exception {
     52     Redefinition.doCommonClassRedefinition(target, classfile, dexfile);
     53   }
     54   public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception {
     55     Redefinition.doMultiClassRedefinition(toCCDA(defs));
     56   }
     57   public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception {
     58     Redefinition.addMultiTransformationResults(toCCDA(defs));
     59   }
     60   public static void doCommonMultiClassRedefinition(Class<?>[] targets,
     61                                                     byte[][] classfiles,
     62                                                     byte[][] dexfiles) throws Exception {
     63     Redefinition.doCommonMultiClassRedefinition(targets, classfiles, dexfiles);
     64   }
     65   public static void doCommonClassRetransformation(Class<?>... target) throws Exception {
     66     Redefinition.doCommonClassRetransformation(target);
     67   }
     68   public static void enableCommonRetransformation(boolean enable) {
     69     Redefinition.enableCommonRetransformation(enable);
     70   }
     71   public static void addCommonTransformationResult(String target_name,
     72                                                    byte[] class_bytes,
     73                                                    byte[] dex_bytes) {
     74     Redefinition.addCommonTransformationResult(target_name, class_bytes, dex_bytes);
     75   }
     76 }
     77