1 /* 2 * Copyright (C) 2017 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; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static java.util.stream.Collectors.toList; 22 23 import android.platform.test.annotations.IgnoreUnderRavenwood; 24 import android.platform.test.ravenwood.RavenwoodRule; 25 import android.util.Pair; 26 27 import androidx.test.ext.junit.runners.AndroidJUnit4; 28 29 import org.junit.Rule; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.xml.sax.InputSource; 33 34 import java.io.StringReader; 35 import java.util.stream.Stream; 36 37 import javax.xml.parsers.DocumentBuilderFactory; 38 39 @RunWith(AndroidJUnit4.class) 40 @IgnoreUnderRavenwood(blockedBy = VintfObject.class) 41 public class VintfObjectTest { 42 @Rule 43 public final RavenwoodRule mRavenwood = new RavenwoodRule(); 44 45 /** 46 * Quick check for {@link VintfObject#report VintfObject.report()}. 47 */ 48 @Test testReport()49 public void testReport() { 50 String[] xmls = VintfObject.report(); 51 52 assertThat(Stream.of(xmls).map(xml -> rootAndType(xml)).collect(toList())) 53 .containsExactly( 54 Pair.create("manifest", "framework"), 55 Pair.create("compatibility-matrix", "framework"), 56 Pair.create("manifest", "device"), 57 Pair.create("compatibility-matrix", "device") 58 ); 59 } 60 rootAndType(String content)61 private static Pair<String, String> rootAndType(String content) { 62 try { 63 var factory = DocumentBuilderFactory.newInstance(); 64 var builder = factory.newDocumentBuilder(); 65 var inputSource = new InputSource(new StringReader(content)); 66 var document = builder.parse(inputSource); 67 var root = document.getDocumentElement(); 68 return Pair.create(root.getTagName(), root.getAttribute("type")); 69 } catch (Exception e) { 70 throw new RuntimeException(e); 71 } 72 } 73 } 74