1 /*
2  * Copyright 2022 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 android.media.cts;
18 
19 import android.util.Log;
20 
21 import androidx.test.platform.app.InstrumentationRegistry;
22 
23 import java.util.regex.Pattern;
24 
25 /**
26  * Contains arguments passed to the tests.
27  */
28 public final class TestArgs {
29     private final static String TAG = "TestArgs";
30     private static final String CODEC_PREFIX_KEY = "codec-prefix";
31     public static final String CODEC_FILTER_KEY = "codec-filter";
32     private static final String CODEC_PREFIX;
33     public static Pattern codecFilter;
34     private static final String MEDIA_TYPE_PREFIX_KEY = "media-type-prefix";
35     private static final String MEDIA_TYPE_PREFIX;
36 
37     static {
38         android.os.Bundle args = InstrumentationRegistry.getArguments();
39         CODEC_PREFIX = args.getString(CODEC_PREFIX_KEY);
40         MEDIA_TYPE_PREFIX = args.getString(MEDIA_TYPE_PREFIX_KEY);
41         String codecFilterStr = args.getString(CODEC_FILTER_KEY);
42         if (codecFilterStr != null) {
43             codecFilter = Pattern.compile(codecFilterStr);
44         }
45     }
46 
shouldSkipMediaType(String mediaType)47     public static boolean shouldSkipMediaType(String mediaType) {
48         if (MEDIA_TYPE_PREFIX != null && !mediaType.startsWith(MEDIA_TYPE_PREFIX)) {
49             Log.d(TAG, "Skipping tests for mediaType: " + mediaType);
50             return true;
51         }
52         return false;
53     }
54 
shouldSkipCodec(String name)55     public static boolean shouldSkipCodec(String name) {
56         if ((CODEC_PREFIX != null && !name.startsWith(CODEC_PREFIX))
57                 || (codecFilter != null && !codecFilter.matcher(name).matches())) {
58             Log.d(TAG, "Skipping tests for codec: " + name + " as codec prefix is " + CODEC_PREFIX);
59             return true;
60         }
61         if (!TestUtils.isTestableCodecInCurrentMode(name)) {
62             Log.d(TAG, "Skipping tests for codec: " + name);
63             return true;
64         }
65         return false;
66     }
67 }
68