1 /* 2 * Copyright (C) 2015 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 package vogar.android; 18 19 import com.google.common.collect.ImmutableList; 20 import java.io.File; 21 import java.io.IOException; 22 import java.util.Arrays; 23 import java.util.List; 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.mockito.runners.MockitoJUnitRunner; 27 import vogar.Classpath; 28 import vogar.Mode; 29 import vogar.ModeId; 30 import vogar.Target; 31 import vogar.Variant; 32 import vogar.commands.Command; 33 import vogar.commands.VmCommandBuilder; 34 35 import static org.junit.Assert.assertEquals; 36 37 /** 38 * Test the behaviour of the {@link DeviceRuntime} class when run with {@link AdbTarget}. 39 */ 40 @RunWith(MockitoJUnitRunner.class) 41 public class DeviceRuntimeAdbTargetTest extends AbstractModeTest { 42 43 @Override createTarget()44 protected Target createTarget() { 45 DeviceFilesystem deviceFilesystem = 46 new DeviceFilesystem(console, ImmutableList.<String>of()); 47 DeviceFileCache deviceFileCache = 48 new DeviceFileCache(console, new File("runner"), deviceFilesystem); 49 return new AdbTarget(console, deviceFilesystem, deviceFileCache); 50 } 51 52 @Test 53 @VogarArgs({"action"}) testAdbTarget()54 public void testAdbTarget() 55 throws IOException { 56 57 Mode deviceRuntime = new DeviceRuntime(run, ModeId.DEVICE, Variant.X32, 58 deviceUserNameSupplier); 59 60 VmCommandBuilder builder = newVmCommandBuilder(deviceRuntime) 61 .classpath(classpath) 62 .mainClass("mainclass") 63 .args("-x", "a b"); 64 Command command = builder.build(run.target); 65 List<String> args = command.getArgs(); 66 assertEquals(Arrays.asList( 67 "adb", "shell", "" 68 + "cd /work" 69 + " &&" 70 + " ANDROID_DATA=runner" 71 + " dalvikvm32" 72 + " -classpath" 73 + " classes" 74 + " -Duser.home=runner/dir/user.home" 75 + " -Duser.name=fred" 76 + " -Duser.language=en" 77 + " -Duser.region=US" 78 + " -Xcheck:jni" 79 + " -Xjnigreflimit:2000" 80 + " mainclass" 81 + " -x a\\ b"), args); 82 } 83 84 @Test 85 @VogarArgs({"--benchmark", "action"}) testAdbTarget_Benchmark()86 public void testAdbTarget_Benchmark() 87 throws IOException { 88 89 Mode deviceRuntime = new DeviceRuntime(run, ModeId.DEVICE, Variant.X32, 90 deviceUserNameSupplier); 91 92 Classpath classpath = new Classpath(); 93 classpath.addAll(new File("classes")); 94 VmCommandBuilder builder = newVmCommandBuilder(deviceRuntime) 95 .classpath(classpath) 96 .mainClass("mainclass") 97 .args("-x", "a b"); 98 Command command = builder.build(run.target); 99 List<String> args = command.getArgs(); 100 assertEquals(Arrays.asList( 101 "adb", "shell", "" 102 + "cd /work" 103 + " &&" 104 + " ANDROID_DATA=runner" 105 + " dalvikvm32" 106 + " -classpath" 107 + " classes" 108 + " -Duser.home=runner/dir/user.home" 109 + " -Duser.name=fred" 110 + " -Duser.language=en" 111 + " -Duser.region=US" 112 + " -Xjnigreflimit:2000" 113 + " mainclass" 114 + " -x a\\ b"), args); 115 } 116 } 117