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 com.android.compatibility.common.tradefed.testtype; 18 19 import com.android.tradefed.config.ConfigurationDescriptor; 20 import com.android.tradefed.device.DeviceNotAvailableException; 21 import com.android.tradefed.metrics.proto.MetricMeasurement.Metric; 22 import com.android.tradefed.result.ITestInvocationListener; 23 import com.android.tradefed.targetprep.ITargetPreparer; 24 import com.android.tradefed.testtype.Abi; 25 import com.android.tradefed.testtype.IAbi; 26 import com.android.tradefed.testtype.IAbiReceiver; 27 import com.android.tradefed.testtype.IRemoteTest; 28 import com.android.tradefed.testtype.IRuntimeHintProvider; 29 import com.android.tradefed.testtype.ITestCollector; 30 import com.android.tradefed.testtype.ITestFilterReceiver; 31 import com.android.tradefed.util.AbiUtils; 32 33 import junit.framework.TestCase; 34 35 import org.easymock.EasyMock; 36 37 import java.util.ArrayList; 38 import java.util.HashMap; 39 import java.util.HashSet; 40 import java.util.List; 41 import java.util.Set; 42 43 public class ModuleDefTest extends TestCase { 44 45 private static final String NAME = "ModuleName"; 46 private static final String ABI = "mips64"; 47 private static final String ID = AbiUtils.createId(ABI, NAME); 48 testAccessors()49 public void testAccessors() throws Exception { 50 IAbi abi = new Abi(ABI, ""); 51 MockRemoteTest mockTest = new MockRemoteTest(); 52 IModuleDef def = new ModuleDef(NAME, abi, mockTest, new ArrayList<ITargetPreparer>(), 53 new ConfigurationDescriptor()); 54 assertEquals("Incorrect ID", ID, def.getId()); 55 assertEquals("Incorrect ABI", ABI, def.getAbi().getName()); 56 assertEquals("Incorrect Name", NAME, def.getName()); 57 } 58 testModuleFinisher()59 public void testModuleFinisher() throws Exception { 60 IAbi abi = new Abi(ABI, ""); 61 MockRemoteTest mockTest = new MockRemoteTest(); 62 IModuleDef def = new ModuleDef(NAME, abi, mockTest, 63 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()); 64 ITestInvocationListener mockListener = EasyMock.createMock(ITestInvocationListener.class); 65 // listener should receive testRunStarted/testRunEnded events even for no-op run() method 66 mockListener.testRunStarted(ID, 0); 67 EasyMock.expectLastCall().once(); 68 mockListener.testRunEnded(0, new HashMap<String, Metric>()); 69 EasyMock.expectLastCall().once(); 70 EasyMock.replay(mockListener); 71 def.run(mockListener); 72 EasyMock.verify(mockListener); 73 } 74 75 private class MockRemoteTest implements IRemoteTest, ITestFilterReceiver, IAbiReceiver, 76 IRuntimeHintProvider, ITestCollector { 77 78 private final List<String> mIncludeFilters = new ArrayList<>(); 79 private final List<String> mExcludeFilters = new ArrayList<>(); 80 81 @Override addIncludeFilter(String filter)82 public void addIncludeFilter(String filter) { 83 mIncludeFilters.add(filter); 84 } 85 86 @Override addAllIncludeFilters(Set<String> filters)87 public void addAllIncludeFilters(Set<String> filters) { 88 mIncludeFilters.addAll(filters); 89 } 90 91 @Override clearIncludeFilters()92 public void clearIncludeFilters() { 93 mIncludeFilters.clear(); 94 } 95 96 @Override getIncludeFilters()97 public Set<String> getIncludeFilters() { 98 return new HashSet<>(mIncludeFilters); 99 } 100 101 @Override addExcludeFilter(String filter)102 public void addExcludeFilter(String filter) { 103 mExcludeFilters.add(filter); 104 } 105 106 @Override addAllExcludeFilters(Set<String> filters)107 public void addAllExcludeFilters(Set<String> filters) { 108 mExcludeFilters.addAll(filters); 109 } 110 111 @Override clearExcludeFilters()112 public void clearExcludeFilters() { 113 mExcludeFilters.clear(); 114 } 115 116 @Override getExcludeFilters()117 public Set<String> getExcludeFilters() { 118 return new HashSet<>(mExcludeFilters); 119 } 120 121 @Override run(ITestInvocationListener listener)122 public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { 123 // Do nothing 124 } 125 126 @Override setAbi(IAbi abi)127 public void setAbi(IAbi abi) { 128 // Do nothing 129 } 130 131 @Override getAbi()132 public IAbi getAbi() { 133 return null; 134 } 135 136 @Override getRuntimeHint()137 public long getRuntimeHint() { 138 return 1L; 139 } 140 141 @Override setCollectTestsOnly(boolean shouldCollectTest)142 public void setCollectTestsOnly(boolean shouldCollectTest) { 143 // Do nothing 144 } 145 } 146 } 147