From 5249eca1bd60c72a1650876fd50b34c3984ec275 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Tue, 17 Dec 2019 10:25:02 +0000 Subject: [PATCH] Don't depend on annotation processors XmlWriter. The annotation processor is being modified to produce an intermediate output that will then be processed to produce the config that ends up on device. As such, using XmlWriter in frameworks test code no longer makes sense. Instead, hard-code XML config in the test to break this problematic dependency. Test: atest CompatConfigTest Change-Id: I371ba32bd83d6a84de94d594169dbb5c63f3d9be Merged-In: I371ba32bd83d6a84de94d594169dbb5c63f3d9be --- services/tests/servicestests/Android.bp | 1 - .../server/compat/CompatConfigTest.java | 51 ++++++++----------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/services/tests/servicestests/Android.bp b/services/tests/servicestests/Android.bp index eecdeed2cd255..d4dd24580aad8 100644 --- a/services/tests/servicestests/Android.bp +++ b/services/tests/servicestests/Android.bp @@ -39,7 +39,6 @@ android_test { "platformprotosnano", "hamcrest-library", "servicestests-utils", - "xml-writer-device-lib", ], aidl: { diff --git a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java index 72679769be8e5..cb99c118a407e 100644 --- a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java +++ b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java @@ -22,15 +22,13 @@ import android.content.pm.ApplicationInfo; import androidx.test.runner.AndroidJUnit4; -import com.android.compat.annotation.Change; -import com.android.compat.annotation.XmlWriter; - import org.junit.Test; import org.junit.runner.RunWith; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.UUID; @RunWith(AndroidJUnit4.class) @@ -50,18 +48,10 @@ public class CompatConfigTest { return dir; } - private void writeChangesToFile(Change[] changes, File f) { - XmlWriter writer = new XmlWriter(); - for (Change change: changes) { - writer.addChange(change); - } - try { - f.createNewFile(); - writer.write(new FileOutputStream(f)); - } catch (IOException e) { - throw new RuntimeException( - "Encountered an error while writing compat config file", e); - } + private void writeToFile(File dir, String filename, String content) throws IOException { + OutputStream os = new FileOutputStream(new File(dir, filename)); + os.write(content.getBytes()); + os.close(); } @Test @@ -173,13 +163,15 @@ public class CompatConfigTest { } @Test - public void testReadConfig() { - Change[] changes = {new Change(1234L, "MY_CHANGE1", false, 2, null), new Change(1235L, - "MY_CHANGE2", true, null, "description"), new Change(1236L, "MY_CHANGE3", false, - null, "")}; + public void testReadConfig() throws IOException { + String configXml = "" + + "" + + "" + + "" + + ""; File dir = createTempDir(); - writeChangesToFile(changes, new File(dir.getPath() + "/platform_compat_config.xml")); + writeToFile(dir, "platform_compat_config.xml", configXml); CompatConfig pc = new CompatConfig(); pc.initConfigFromLib(dir); @@ -191,17 +183,18 @@ public class CompatConfigTest { } @Test - public void testReadConfigMultipleFiles() { - Change[] changes1 = {new Change(1234L, "MY_CHANGE1", false, 2, null)}; - Change[] changes2 = {new Change(1235L, "MY_CHANGE2", true, null, ""), new Change(1236L, - "MY_CHANGE3", false, null, null)}; + public void testReadConfigMultipleFiles() throws IOException { + String configXml1 = "" + + "" + + ""; + String configXml2 = "" + + "" + + "" + + ""; File dir = createTempDir(); - writeChangesToFile(changes1, - new File(dir.getPath() + "/libcore_platform_compat_config.xml")); - writeChangesToFile(changes2, - new File(dir.getPath() + "/frameworks_platform_compat_config.xml")); - + writeToFile(dir, "libcore_platform_compat_config.xml", configXml1); + writeToFile(dir, "frameworks_platform_compat_config.xml", configXml2); CompatConfig pc = new CompatConfig(); pc.initConfigFromLib(dir);