huangcm
2025-04-09 02d4ce54b909bd733f12e9f3fa4c1b03cf2d6f45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.DeviceTest.helper;
 
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.content.res.XmlResourceParser;
import android.os.SystemClock;
import android.util.Log;
import android.util.Xml;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlSerializer;
 
import com.DeviceTest.DeviceTest;
import android.content.res.Resources;
public class XmlDeal {
 
   private static final String TAG = "XmlDeal";
   /**/
   private static final String XML_ROOT_TAG = "TestCaseList";
   private static final String XML_NODE_TAG = "TestCase";
 
   private static final String CLASS_NAME_TAG = "class_name";
   private static final String TEST_NAME_TAG = "test_name";
   private static final String RESULT_TAG = "result";
   private static final String TEST_GROUP_TAG = "test_group";
   private static final String TEST_FIRST = "first_test";
 
   public List<TestCase> mTestCases = null;
   public Map<String, List<TestCase>> mCaseGroups = null;
 
   public XmlDeal(InputStream is) {
       mTestCases = new ArrayList<TestCase>();
       mCaseGroups = new HashMap<String, List<TestCase>>();
       if (!ParseXml(is)) {
           throw new RuntimeException();
       }
   }
 
   private boolean ParseXml(InputStream is) {
 
       DocumentBuilderFactory docBuilderFactory = null;
       DocumentBuilder docBuilder = null;
       Document doc = null;
       try {
           docBuilderFactory = DocumentBuilderFactory.newInstance();
           docBuilder = docBuilderFactory.newDocumentBuilder();
 
           doc = docBuilder.parse(is);
           NodeList nodeList = doc.getElementsByTagName(XML_ROOT_TAG);
 
           int length = nodeList.getLength();
           List<TestCase> caseGroup = null;
           for (int i = 0; i < length; i++) {
               Node item = nodeList.item(i);
 
               int testNo = 0;
               caseGroup = null;
               for (Node node = item.getFirstChild(); node != null; node = node
                       .getNextSibling()) {
                   if (node.getNodeType() == Node.ELEMENT_NODE) {
 
                       String testName = null;
                       String className = null;
                       boolean isfirsttest = false;
                       for (int j = 0; j < node.getAttributes().getLength(); j++) {
                           String attrValue = node.getAttributes().item(j)
                                   .getNodeValue();
                           String attrName = node.getAttributes().item(j)
                                   .getNodeName();
                           if (attrName.equals(CLASS_NAME_TAG)) {
                               className = attrValue;
                           } else if (attrName.equals(TEST_GROUP_TAG)) {
                               caseGroup = mCaseGroups.get(attrValue);
                               if (caseGroup == null) {
                                   caseGroup = new ArrayList<TestCase>();
                                   mCaseGroups.put(attrValue, caseGroup);
                               }
                           }else if(attrName.equals(TEST_FIRST)){
                               isfirsttest = true;
                           }
                       }
                        
 
                       testName = node.getFirstChild().getNodeValue();
                       Log.i(TAG, "-----getTestItemName:" + testName + "    isfirsttest = " + isfirsttest);
                       
                       
                          if (hasBackFacingCamera()&&hasFrontFacingCamera()){
                                if (testName.equals("CameraOnly")||testName.equals("单摄像头")) {
                                           continue;
                                        }
                              }else {
                             if (testName.equals("Camera")||testName.equals("摄像头")) {
                                         continue;
                             }
                             
                         }
                       TestCase testCase = new TestCase(testNo, testName,
                               className);
                       //testCase.setneedtest(isfirsttes);
                       mTestCases.add(testCase);
                       if(caseGroup != null) {
                           caseGroup.add(testCase);
                       }
                       testNo++;
                   
                    }
               }
           }
 
       } catch (Exception e) {
           Log.e(TAG, e.getMessage());
           return false;
       } finally {
           doc = null;
           docBuilder = null;
           docBuilderFactory = null;
       }
 
       if (mTestCases.size() == 0) {
           return false;
       }
 
       Log.i(TAG, "The cases count is :" + mTestCases.size());
       return true;
   }
private static boolean checkCameraFacing(final int facing) {
   
       final int cameraCount = Camera.getNumberOfCameras();
       CameraInfo info = new CameraInfo();
       for (int i = 0; i < cameraCount; i++) {
           Camera.getCameraInfo(i, info);
           if (facing == info.facing) {
               return true;
           }
       }
       return false;
   }
   public static boolean hasBackFacingCamera() {
       final int CAMERA_FACING_BACK = 0;
       return checkCameraFacing(CAMERA_FACING_BACK);
   }
   public static boolean hasFrontFacingCamera() {
       final int CAMERA_FACING_BACK = 1;
       return checkCameraFacing(CAMERA_FACING_BACK);
   }
   public static int getSdkVersion() {
       return android.os.Build.VERSION.SDK_INT;
   }
 
 
 
}