1 /* 2 * Copyright (C) 2023 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 com.android.tests.chromium.host; 18 19 import com.google.gson.JsonElement; 20 import com.google.gson.JsonParser; 21 22 import java.io.File; 23 import java.io.FileReader; 24 import java.io.IOException; 25 26 public class GTestsMetaData { 27 28 private final boolean isOutputParsedCorrectly; 29 private final int totalTests; 30 private final int failedTests; 31 GTestsMetaData(int totalTests, int failedTests, boolean isOutputParsedCorrectly)32 private GTestsMetaData(int totalTests, int failedTests, boolean isOutputParsedCorrectly) { 33 this.totalTests = totalTests; 34 this.failedTests = failedTests; 35 this.isOutputParsedCorrectly = isOutputParsedCorrectly; 36 } 37 isOutputParsedCorrectly()38 public boolean isOutputParsedCorrectly() { 39 return isOutputParsedCorrectly; 40 } 41 parseFile(File gtestOutputFile)42 public static GTestsMetaData parseFile(File gtestOutputFile) throws IOException { 43 try (FileReader fileReader = new FileReader(gtestOutputFile)) { 44 JsonElement root = JsonParser.parseReader(fileReader); 45 if (!root.isJsonObject()) { 46 return new GTestsMetaData(0, 0, false); 47 } 48 return new GTestsMetaData(root.getAsJsonObject().get("tests").getAsInt(), 49 root.getAsJsonObject().get("failures").getAsInt(), true); 50 } 51 } 52 hasAnyFailures()53 public boolean hasAnyFailures() { 54 return failedTests > 0; 55 } 56 getTotalTests()57 public int getTotalTests() { 58 return totalTests; 59 } 60 } 61