• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 package com.android.cts.tradefed.result;
17 
18 import com.android.tradefed.util.xml.AbstractXmlParser.ParseException;
19 
20 import org.xmlpull.v1.XmlPullParser;
21 import org.xmlpull.v1.XmlPullParserException;
22 
23 import android.tests.getinfo.DeviceInfoConstants;
24 
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 
28 /**
29  * A {@link ITestSummary} that parses summary data from the CTS result XML.
30  */
31 public class TestSummaryXml extends AbstractXmlPullParser implements ITestSummary  {
32 
33     private final int mId;
34     private final String mTimestamp;
35     private int mNumFailed = 0;
36     private int mNumNotExecuted = 0;
37     private int mNumPassed = 0;
38     private String mPlan = "NA";
39     private String mStartTime = "unknown";
40     private String mDeviceSerials = "unknown";
41 
42     /**
43      * @param id
44      * @param resultFile
45      * @throws ParseException
46      * @throws FileNotFoundException
47      */
TestSummaryXml(int id, String timestamp)48     public TestSummaryXml(int id, String timestamp) {
49         mId = id;
50         mTimestamp = timestamp;
51     }
52 
53     /**
54      * {@inheritDoc}
55      */
56     @Override
getId()57     public int getId() {
58         return mId;
59     }
60 
61     /**
62      * {@inheritDoc}
63      */
64     @Override
getTimestamp()65     public String getTimestamp() {
66         return mTimestamp;
67     }
68 
69     /**
70      * {@inheritDoc}
71      */
72     @Override
getNumIncomplete()73     public int getNumIncomplete() {
74         return mNumNotExecuted;
75     }
76 
77     /**
78      * {@inheritDoc}
79      */
80     @Override
getNumFailed()81     public int getNumFailed() {
82         return mNumFailed;
83     }
84 
85     /**
86      * {@inheritDoc}
87      */
88     @Override
getNumPassed()89     public int getNumPassed() {
90         return mNumPassed;
91     }
92 
93     /**
94      * {@inheritDoc}
95      */
96     @Override
getTestPlan()97     public String getTestPlan() {
98         return mPlan ;
99     }
100 
101 
102     @Override
parse(XmlPullParser parser)103     void parse(XmlPullParser parser) throws XmlPullParserException, IOException {
104         int eventType = parser.getEventType();
105         while (eventType != XmlPullParser.END_DOCUMENT) {
106             if (eventType == XmlPullParser.START_TAG && parser.getName().equals(
107                     CtsXmlResultReporter.RESULT_TAG)) {
108                 mPlan = getAttribute(parser, CtsXmlResultReporter.PLAN_ATTR);
109                 mStartTime = getAttribute(parser, CtsXmlResultReporter.STARTTIME_ATTR);
110             } else if (eventType == XmlPullParser.START_TAG && parser.getName().equals(
111                     DeviceInfoResult.BUILD_TAG)) {
112                 mDeviceSerials = getAttribute(parser, DeviceInfoConstants.SERIAL_NUMBER);
113             } else if (eventType == XmlPullParser.START_TAG && parser.getName().equals(
114                     TestResults.SUMMARY_TAG)) {
115                 mNumFailed = parseIntAttr(parser, TestResults.FAILED_ATTR) +
116                     parseIntAttr(parser, TestResults.TIMEOUT_ATTR);
117                 mNumNotExecuted = parseIntAttr(parser, TestResults.NOT_EXECUTED_ATTR);
118                 mNumPassed = parseIntAttr(parser, TestResults.PASS_ATTR);
119                 // abort after parsing Summary, which should be the last tag
120                 return;
121              }
122             eventType = parser.next();
123         }
124         throw new XmlPullParserException("Could not find Summary tag");
125     }
126 
127     /**
128      * {@inheritDoc}
129      */
130     @Override
getStartTime()131     public String getStartTime() {
132         return mStartTime;
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
getDeviceSerials()139     public String getDeviceSerials() {
140         return mDeviceSerials;
141     }
142 }
143