• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.systemfeatures;
18 
19 import static com.android.internal.pm.SystemFeaturesMetadata.maybeGetSdkFeatureIndex;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import android.content.pm.PackageManager;
24 
25 import com.android.internal.pm.SystemFeaturesMetadata;
26 
27 import com.google.common.collect.Range;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.JUnit4;
32 
33 @RunWith(JUnit4.class)
34 public class SystemFeaturesMetadataProcessorTest {
35 
36     @Test
testSdkFeatureCount()37     public void testSdkFeatureCount() {
38         // See the fake PackageManager definition in this directory.
39         // It defines 6 annotated features, and any/all other constants should be ignored.
40         assertThat(SystemFeaturesMetadata.SDK_FEATURE_COUNT).isEqualTo(6);
41     }
42 
43     @Test
testSdkFeatureIndex()44     public void testSdkFeatureIndex() {
45         // Only SDK-defined features return valid indices.
46         final Range validIndexRange = Range.closedOpen(0, SystemFeaturesMetadata.SDK_FEATURE_COUNT);
47         assertThat(maybeGetSdkFeatureIndex(PackageManager.FEATURE_PC)).isIn(validIndexRange);
48         assertThat(maybeGetSdkFeatureIndex(PackageManager.FEATURE_VULKAN)).isIn(validIndexRange);
49         assertThat(maybeGetSdkFeatureIndex(PackageManager.FEATURE_NOT_ANNOTATED)).isEqualTo(-1);
50         assertThat(maybeGetSdkFeatureIndex(PackageManager.NOT_FEATURE)).isEqualTo(-1);
51         assertThat(maybeGetSdkFeatureIndex("foo")).isEqualTo(-1);
52         assertThat(maybeGetSdkFeatureIndex("0")).isEqualTo(-1);
53         assertThat(maybeGetSdkFeatureIndex("")).isEqualTo(-1);
54     }
55 }
56