Move CtsSdkExtensions into SdkExtension repository

These tests should live with the module they are testing.

Bug: 174123164
Test: presubmit (verify CtsSdkExtensions is running)
Merged-In: I7885e2307ae46248168de0b2fdbb154bf79bb406
Change-Id: I7885e2307ae46248168de0b2fdbb154bf79bb406
diff --git a/tests/cts/Android.bp b/tests/cts/Android.bp
new file mode 100644
index 0000000..89b241b
--- /dev/null
+++ b/tests/cts/Android.bp
@@ -0,0 +1,30 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+android_test {
+    name: "CtsSdkExtensionsTestCases",
+    defaults: ["cts_defaults"],
+    static_libs: [
+        "androidx.test.rules",
+        "ctstestrunner-axt",
+    ],
+    srcs: [ "src/**/*.java" ],
+    test_config: "CtsSdkExtensionsTestCases.xml",
+    test_suites: [
+        "cts",
+        "mts",
+        "general-tests",
+    ],
+    sdk_version: "system_current",
+}
diff --git a/tests/cts/AndroidManifest.xml b/tests/cts/AndroidManifest.xml
new file mode 100644
index 0000000..a6391b5
--- /dev/null
+++ b/tests/cts/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="android.os.ext.cts">
+
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.os.ext.cts"
+                     android:label="CTS tests of android.os.ext">
+        <meta-data android:name="listener"
+            android:value="com.android.cts.runner.CtsTestRunListener" />
+    </instrumentation>
+
+</manifest>
diff --git a/tests/cts/CtsSdkExtensionsTestCases.xml b/tests/cts/CtsSdkExtensionsTestCases.xml
new file mode 100644
index 0000000..a0b2055
--- /dev/null
+++ b/tests/cts/CtsSdkExtensionsTestCases.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<configuration description="Configuration for SdkExtension Tests">
+    <option name="test-suite-tag" value="cts" />
+    <option name="config-descriptor:metadata" key="component" value="framework" />
+    <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+    <option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
+    <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="CtsSdkExtensionsTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.os.ext.cts" />
+    </test>
+
+    <!-- Run CtsSdkExtensionsTestCases when "com.google.android.sdkext" is on device.
+      Otherwise skip. The logic only applies to situations when CtsSdkExtensionsTestCasesdoes
+      is triggered via mts-tradefed. It is disabled for all other *TS.
+    -->
+    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">
+        <option name="mainline-module-package-name" value="com.google.android.sdkext" />
+    </object>
+</configuration>
diff --git a/tests/cts/src/android/os/ext/cts/SdkExtensionsTest.java b/tests/cts/src/android/os/ext/cts/SdkExtensionsTest.java
new file mode 100644
index 0000000..884f5ef
--- /dev/null
+++ b/tests/cts/src/android/os/ext/cts/SdkExtensionsTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os.ext.cts;
+
+import android.os.Build;
+import android.os.ext.SdkExtensions;
+import junit.framework.TestCase;
+
+public class SdkExtensionsTest extends TestCase {
+
+    /** Verify that getExtensionVersion only accepts valid extension SDKs */
+    public void testBadArgument() throws Exception {
+        // R is the first SDK version with extensions.
+        for (int sdk = -1_000_000; sdk < Build.VERSION_CODES.R; sdk++) {
+            try {
+                SdkExtensions.getExtensionVersion(sdk);
+                fail("expected IllegalArgumentException");
+            } catch (IllegalArgumentException expected) { }
+        }
+    }
+
+    /** Verifies that getExtensionVersion only return existing versions */
+    public void testValidValues() throws Exception {
+        for (int sdk = Build.VERSION_CODES.R; sdk <= 1_000_000; sdk++) {
+            // No extension SDKs versions yet.
+            assertEquals(0, SdkExtensions.getExtensionVersion(sdk));
+        }
+    }
+}