1 /*
2  * Copyright (C) 2019 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.os.ext.cts;
18 
19 import android.os.Build;
20 import android.os.ext.SdkExtensions;
21 import junit.framework.TestCase;
22 
23 public class SdkExtensionsTest extends TestCase {
24 
25     /** Verify that getExtensionVersion only accepts valid extension SDKs */
testBadArgument()26     public void testBadArgument() throws Exception {
27         // R is the first SDK version with extensions.
28         for (int sdk = -1_000_000; sdk < Build.VERSION_CODES.R; sdk++) {
29             try {
30                 SdkExtensions.getExtensionVersion(sdk);
31                 fail("expected IllegalArgumentException");
32             } catch (IllegalArgumentException expected) { }
33         }
34     }
35 
36     /** Verifies that getExtensionVersion only return existing versions */
testValidValues()37     public void testValidValues() throws Exception {
38         for (int sdk = Build.VERSION_CODES.R; sdk <= 1_000_000; sdk++) {
39             // No extension SDKs versions yet.
40             assertEquals(0, SdkExtensions.getExtensionVersion(sdk));
41         }
42     }
43 }
44