1 /* 2 * Copyright (C) 2023 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.adservices.common; 17 18 import com.android.adservices.common.annotations.SetDefaultLogcatTags; 19 import com.android.adservices.shared.testing.CallSuper; 20 import com.android.adservices.shared.testing.annotations.SetSyncDisabledModeForTest; 21 22 import org.junit.ClassRule; 23 import org.junit.Rule; 24 25 /** 26 * Base class for all CTS tests. 27 * 28 * <p>Contains only the bare minimum functionality required by them, like custom JUnit rules. 29 * 30 * <p>In fact, this class "reserves" the first 10 rules (as defined by order), so subclasses should 31 * start defining rules with {@code order = 11} (although for now they can use {@code order = 0} for 32 * {@code SdkLevelSupportRule}, as that rule cannot be defined here yet. 33 */ 34 @SetDefaultLogcatTags 35 @SetSyncDisabledModeForTest 36 public abstract class AdServicesCtsTestCase extends AdServicesTestCase { 37 38 // TODO(b/295321663): move these constants (and those from LogFactory 39 protected static final String LOGCAT_TAG_ADSERVICES = "adservices"; 40 protected static final String LOGCAT_TAG_ADSERVICES_SERVICE = LOGCAT_TAG_ADSERVICES + "-system"; 41 public static final String LOGCAT_TAG_TOPICS = LOGCAT_TAG_ADSERVICES + ".topics"; 42 public static final String LOGCAT_TAG_FLEDGE = LOGCAT_TAG_ADSERVICES + ".fledge"; 43 public static final String LOGCAT_TAG_MEASUREMENT = LOGCAT_TAG_ADSERVICES + ".measurement"; 44 protected static final String LOGCAT_TAG_UI = LOGCAT_TAG_ADSERVICES + ".ui"; 45 protected static final String LOGCAT_TAG_ADID = LOGCAT_TAG_ADSERVICES + ".adid"; 46 protected static final String LOGCAT_TAG_APPSETID = LOGCAT_TAG_ADSERVICES + ".appsetid"; 47 48 @ClassRule 49 public static final AdServicesFlagsPreparerClassRule sFlagsPreparer = 50 new AdServicesFlagsPreparerClassRule(); 51 52 @Rule(order = 5) 53 public final AdServicesFlagsSetterRule flags = getAdServicesFlagsSetterRule(); 54 55 /** 56 * Gets the {@link AdServicesFlagsSetterRule} for this test. 57 * 58 * <p>By default returns a rule with just the bare minimum set (like {@code logcat} tags) and 59 * subclasses can customize it using class annotations (such as {@link 60 * com.android.adservices.shared.testing.annotations.SetFlagEnabled}), but subclasses could 61 * extend it to support more complex scenarios. 62 */ getAdServicesFlagsSetterRule()63 protected AdServicesFlagsSetterRule getAdServicesFlagsSetterRule() { 64 return AdServicesFlagsSetterRule.newInstance(); 65 } 66 67 @CallSuper 68 @Override assertValidTestCaseFixtures()69 protected void assertValidTestCaseFixtures() throws Exception { 70 super.assertValidTestCaseFixtures(); 71 72 assertTestClassHasNoFieldsFromSuperclass( 73 AdServicesCtsTestCase.class, "sFlagsPreparer", "flags"); 74 } 75 } 76