Skip to content
Snippets Groups Projects
Commit 8b616b68 authored by Jooyung Han's avatar Jooyung Han
Browse files

Fix VintfObjectTest

Removed hard-coded "version"s in assertions. Instead, the test now
parses XML documents and then compare root elements and "type"s.

Plus, the test now checks if report() reports all four
matrices/manifests.

Bug: 317747397
Test: atest VintfObjectTest
Change-Id: I4bb514e9c0bd78214cb3f03e1b12afec8a301915
parent 8c8c81dd
No related branches found
No related tags found
No related merge requests found
......@@ -16,16 +16,25 @@
package android.os;
import static org.junit.Assert.assertTrue;
import static com.google.common.truth.Truth.assertThat;
import static java.util.stream.Collectors.toList;
import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.util.stream.Stream;
import javax.xml.parsers.DocumentBuilderFactory;
@RunWith(AndroidJUnit4.class)
@IgnoreUnderRavenwood(blockedBy = VintfObject.class)
......@@ -39,12 +48,26 @@ public class VintfObjectTest {
@Test
public void testReport() {
String[] xmls = VintfObject.report();
assertTrue(xmls.length > 0);
// From /system/manifest.xml
assertTrue(String.join("", xmls).contains(
"<manifest version=\"1.0\" type=\"framework\">"));
// From /system/compatibility-matrix.xml
assertTrue(String.join("", xmls).contains(
"<compatibility-matrix version=\"1.0\" type=\"framework\""));
assertThat(Stream.of(xmls).map(xml -> rootAndType(xml)).collect(toList()))
.containsExactly(
Pair.create("manifest", "framework"),
Pair.create("compatibility-matrix", "framework"),
Pair.create("manifest", "device"),
Pair.create("compatibility-matrix", "device")
);
}
private static Pair<String, String> rootAndType(String content) {
try {
var factory = DocumentBuilderFactory.newInstance();
var builder = factory.newDocumentBuilder();
var inputSource = new InputSource(new StringReader(content));
var document = builder.parse(inputSource);
var root = document.getDocumentElement();
return Pair.create(root.getTagName(), root.getAttribute("type"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment