1 /* 2 * Copyright (C) 2018 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 package com.android.tradefed.util.testmapping; 17 18 /** Stores the test option details set in a TEST_MAPPING file. */ 19 public class TestOption implements Comparable<TestOption> { 20 // Name of the option 21 private String mName = null; 22 // Value of the option, can be empty. 23 private String mValue = null; 24 TestOption(String name, String value)25 public TestOption(String name, String value) { 26 mName = name; 27 mValue = value; 28 } 29 getName()30 public String getName() { 31 return mName; 32 } 33 getValue()34 public String getValue() { 35 return mValue; 36 } 37 38 /** {@inheritDoc} */ 39 @Override compareTo(TestOption option)40 public int compareTo(TestOption option) { 41 return (mName.compareTo(option.getName())); 42 } 43 44 /** 45 * Check if the option is used to only include certain tests. 46 * 47 * <p>Some sample inclusive options are: 48 * 49 * <p>include-filter 50 * 51 * <p>positive-testname-filter (GTest) 52 * 53 * <p>test-file-include-filter (AndroidJUnitTest) 54 * 55 * <p>include-annotation (AndroidJUnitTest) 56 * 57 * @return true if the option is used to only include certain tests. 58 */ isInclusive()59 public boolean isInclusive() { 60 return mName.contains("include") || mName.contains("positive"); 61 } 62 63 /** 64 * Check if the option is used to only exclude certain tests. 65 * 66 * <p>Some sample exclusive options are: 67 * 68 * <p>exclude-filter 69 * 70 * <p>negative-testname-filter (GTest) 71 * 72 * <p>test-file-exclude-filter (AndroidJUnitTest) 73 * 74 * <p>exclude-annotation (AndroidJUnitTest) 75 * 76 * @return true if the option is used to only exclude certain tests. 77 */ isExclusive()78 public boolean isExclusive() { 79 return mName.contains("exclude") || mName.contains("negative"); 80 } 81 82 @Override hashCode()83 public int hashCode() { 84 return this.toString().hashCode(); 85 } 86 87 @Override equals(Object obj)88 public boolean equals(Object obj) { 89 return mName.equals(((TestOption) obj).getName()) 90 && mValue.equals(((TestOption) obj).getValue()); 91 } 92 93 @Override toString()94 public String toString() { 95 return String.format("%s:%s", mName, mValue); 96 } 97 } 98