Add unit tests for plugin library.
Bug: 275465610
Test: atest
Change-Id: I83777ea588995b4c70bb6d6d6c2a2899f6eab066
diff --git a/tests/plugintests/Android.bp b/tests/plugintests/Android.bp
new file mode 100644
index 0000000..09c5ad5
--- /dev/null
+++ b/tests/plugintests/Android.bp
@@ -0,0 +1,58 @@
+// Copyright (C) 2022 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "OnDevicePersonalizationPluginTests",
+ srcs: [
+ "src/**/*.java",
+ ],
+ libs: [
+ "android.test.base",
+ "android.test.mock.stubs",
+ "android.test.runner",
+ "auto_value_annotations",
+ "framework-annotations-lib",
+ "framework-ondevicepersonalization.impl",
+ "truth-prebuilt",
+ ],
+ static_libs: [
+ "androidx.test.ext.junit",
+ "androidx.test.ext.truth",
+ "androidx.test.rules",
+ "mockito-target-extended-minus-junit4",
+ "modules-utils-build",
+ "modules-utils-preconditions",
+ "ondevicepersonalization-plugin-lib",
+ ],
+ manifest: "AndroidManifest.xml",
+ plugins: ["auto_value_plugin"],
+ sdk_version: "module_current",
+ target_sdk_version: "current",
+ min_sdk_version: "Tiramisu",
+ certificate: "platform",
+ compile_multilib: "both",
+ test_config: "AndroidTest.xml",
+ test_suites: [
+ "general-tests",
+ "mts-ondevicepersonalization",
+ ],
+ jni_libs: [
+ "libdexmakerjvmtiagent",
+ "libstaticjvmtiagent",
+ ],
+}
diff --git a/tests/plugintests/AndroidManifest.xml b/tests/plugintests/AndroidManifest.xml
new file mode 100644
index 0000000..d298988
--- /dev/null
+++ b/tests/plugintests/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2022 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="com.android.ondevicepersonalization.plugintests">
+
+ <application android:label="OnDevicePersonalizationPluginTests">
+ <uses-library android:name="android.test.runner" />
+ </application>
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.ondevicepersonalization.plugintests"
+ android:label="OnDevicePersonalization Plugin Tests">
+ </instrumentation>
+
+</manifest>
diff --git a/tests/plugintests/AndroidTest.xml b/tests/plugintests/AndroidTest.xml
new file mode 100644
index 0000000..fbd396c
--- /dev/null
+++ b/tests/plugintests/AndroidTest.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 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 OnDevicePersonalization services unit tests">
+ <option name="config-descriptor:metadata" key="component" value="framework" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_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="OnDevicePersonalizationPluginTests.apk"/>
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="hidden-api-checks" value="false" /> <!-- Allow hidden API uses -->
+ <option name="package" value="com.android.ondevicepersonalization.plugintests"/>
+ </test>
+
+ <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">
+ <option name="mainline-module-package-name" value="com.google.android.ondevicepersonalization" />
+ </object>
+ <option name="config-descriptor:metadata" key="mainline-param" value="com.google.android.ondevicepersonalization.apex" />
+</configuration>
diff --git a/tests/plugintests/src/com/android/ondevicepersonalization/libraries/plugin/PluginTests.java b/tests/plugintests/src/com/android/ondevicepersonalization/libraries/plugin/PluginTests.java
new file mode 100644
index 0000000..123644a
--- /dev/null
+++ b/tests/plugintests/src/com/android/ondevicepersonalization/libraries/plugin/PluginTests.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2023 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 com.android.ondevicepersonalization.libraries.plugin;
+
+import static org.junit.Assert.assertEquals;
+
+import android.os.Parcel;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class PluginTests {
+ @Test
+ public void testFailureType() throws Exception {
+ FailureType ft = FailureType.ERROR_LOADING_PLUGIN;
+
+ Parcel parcel = Parcel.obtain();
+ ft.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ FailureType ft2 = FailureType.CREATOR.createFromParcel(parcel);
+
+ assertEquals(ft, ft2);
+ assertEquals(0, ft2.describeContents());
+ }
+
+ @Test
+ public void testPluginState() throws Exception {
+ PluginState ps = PluginState.STATE_LOADED;
+
+ Parcel parcel = Parcel.obtain();
+ ps.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ PluginState ps2 = PluginState.CREATOR.createFromParcel(parcel);
+
+ assertEquals(ps, ps2);
+ assertEquals(0, ps2.describeContents());
+ }
+}