Changeset 1797 for trunk/autoquest-plugin-android/src/main/java/de
- Timestamp:
- 10/21/14 23:04:34 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/plugin/android/AndroidLogParser.java
r1783 r1797 38 38 39 39 import de.ugoe.cs.autoquest.eventcore.Event; 40 import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 40 41 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 41 42 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; … … 44 45 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModelException; 45 46 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 46 import de.ugoe.cs.autoquest.plugin.android.guimodel.AndroidGUIElementSpec; 47 import de.ugoe.cs.autoquest.plugin.android.guimodel.ANDROIDGUIElement; 48 import de.ugoe.cs.autoquest.plugin.android.guimodel.ANDROIDGUIElementSpec; 47 49 import de.ugoe.cs.util.console.Console; 48 50 … … 71 73 * </p> 72 74 */ 73 private String currentEventId ;75 private String currentEventId = null; 74 76 75 77 /** … … 102 104 * </p> 103 105 */ 104 private Long currentGUIElementHash ;106 private Long currentGUIElementHash = null; 105 107 106 108 /** … … 116 118 * </p> 117 119 */ 118 private A ndroidGUIElementSpec currentGUIElementSpec;120 private ANDROIDGUIElementSpec currentGUIElementSpec; 119 121 120 122 /** … … 147 149 * </p> 148 150 */ 149 private Map<Long, List<Event>> eventsWithoutTargets;151 // private Map<Long, List<Event>> eventsWithoutTargets; 150 152 151 153 /** … … 164 166 public AndroidLogParser() { 165 167 sequences = new LinkedList<List<Event>>(); 166 //currentSequence = null;168 currentSequence = null; 167 169 } 168 170 … … 228 230 return; 229 231 } 232 230 233 if (inputSource != null) { 231 234 inputSource.setSystemId("file://" + file.getAbsolutePath()); … … 252 255 } 253 256 } 254 if (!eventsWithoutTargets.isEmpty()) {255 Console.printerr("Some events reference GUI elements that are not part of logfile. "256 + "These events have been parsed without target.");257 }258 257 } 259 258 … … 290 289 Attributes atts) throws SAXException { 291 290 if (qName.equals("sessions")) { 292 // currentSequence = new LinkedList<Event>(); Up to know it is 293 // necessary to handle different sessions. All components are known 294 // before an event occurs. 295 if (currentGUIElementTree == null) 291 currentSequence = new LinkedList<Event>(); 292 if (currentGUIElementTree == null) { 296 293 currentGUIElementTree = new GUIElementTree<Long>(); 294 } 295 297 296 } 298 297 299 298 if (qName.equals("component")) { 300 299 currentGUIElementHash = Long.parseLong(atts.getValue("hash")); 301 currentGUIElementSpec = new A ndroidGUIElementSpec();300 currentGUIElementSpec = new ANDROIDGUIElementSpec(); 302 301 currentGUIElementSpec.setHashCode((int) currentGUIElementHash 303 302 .longValue()); 303 304 304 } else if (qName.equals("event")) { 305 305 currentEventId = atts.getValue("id"); 306 306 currentEventParameters = new HashMap<String, String>(); 307 307 308 308 309 } else if (qName.equals("param")) { … … 345 346 public void endElement(String uri, String localName, String qName) 346 347 throws SAXException { 348 349 if (qName.equals("sessions")) { 350 if (currentSequence != null) { 351 sequences.add(currentSequence); 352 } 353 } 347 354 if (qName.equals("component") && currentGUIElementHash != null) { 348 355 try { … … 357 364 currentGUIElementHash = null; 358 365 currentParentHash = null; 359 } else if (currentEventId != null) { 360 if (qName.equals("event")) { 361 IGUIElement currentGUIElement; 362 currentGUIElement = currentGUIElementTree 363 .find(currentEventSource); 364 Event event; 365 366 // up to now only onClick events are implemented and each 367 // onclick event is processed as a mouse click 368 int x = Integer.parseInt(currentEventParameters.get("X")); 369 int y = Integer.parseInt(currentEventParameters.get("Y")); 370 MouseButtonInteraction.Button button = null; 371 button = MouseButtonInteraction.Button.LEFT; 372 373 // maybe it would be necessary in the future to check weather 374 // the GUI element exits. 375 event = new Event(new MouseClick(button, x, y), 376 currentGUIElement); 377 366 } else if (currentEventId != null && qName.equals("event")) { 367 368 IGUIElement currentGUIElement; 369 currentGUIElement = currentGUIElementTree.find(currentEventSource); 370 Event event; 371 372 // up to now only onClick events are implemented and each 373 // onclick event is processed as a mouse click 374 if (currentGUIElement == null) { 375 376 } else { 377 378 event = new Event(instantiateInteraction(currentEventId, currentEventParameters), currentGUIElement); 379 ANDROIDGUIElement currentEventTarget = (ANDROIDGUIElement) event.getTarget(); 380 currentEventTarget.markUsed(); 378 381 event.setTimestamp(currentEventTimestamp); 379 382 currentSequence.add(event); 380 381 currentEventParameters = null; 382 currentEventId = null; 383 currentEventTimestamp = -1l; 384 } 385 } else if (qName.equals("sessions")) { 386 if (currentSequence != null) { 387 sequences.add(currentSequence); 388 } 389 } 383 } 384 currentEventParameters = null; 385 currentEventId = null; 386 currentEventTimestamp = -1l; 387 } 388 } 389 390 /** 391 * <p> 392 * depending on the event id and the event parameters, this method 393 * instantiates the concrete interaction, that took place, i.e. the event 394 * type 395 * </p> 396 * 397 * @param eventId 398 * the id of the event 399 * @param eventParameters 400 * the parameters provided for the event 401 * 402 * @return as described 403 * 404 * @throws SAXException 405 * thrown if the provided event id is unknown 406 */ 407 private IInteraction instantiateInteraction(String event, 408 Map<String, String> eventParameters) 409 throws SAXException 410 { 411 412 switch(event) 413 { 414 case "onClick": 415 int x = Integer.parseInt(currentEventParameters.get("X")); 416 int y = Integer.parseInt(currentEventParameters.get("Y")); 417 MouseButtonInteraction.Button button = null; 418 button = MouseButtonInteraction.Button.LEFT; 419 420 return new MouseClick(button, x, y); 421 422 default: 423 throw new SAXException("unhandled event id " + event); 424 } 425 390 426 } 391 427
Note: See TracChangeset
for help on using the changeset viewer.