Changeset 1797


Ignore:
Timestamp:
10/21/14 23:04:34 (10 years ago)
Author:
funger
Message:

bug fix: add events

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/plugin/android/AndroidLogParser.java

    r1783 r1797  
    3838 
    3939import de.ugoe.cs.autoquest.eventcore.Event; 
     40import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 
    4041import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 
    4142import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
     
    4445import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModelException; 
    4546import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
    46 import de.ugoe.cs.autoquest.plugin.android.guimodel.AndroidGUIElementSpec; 
     47import de.ugoe.cs.autoquest.plugin.android.guimodel.ANDROIDGUIElement; 
     48import de.ugoe.cs.autoquest.plugin.android.guimodel.ANDROIDGUIElementSpec; 
    4749import de.ugoe.cs.util.console.Console; 
    4850 
     
    7173         * </p> 
    7274         */ 
    73         private String currentEventId; 
     75        private String currentEventId = null; 
    7476 
    7577        /** 
     
    102104         * </p> 
    103105         */ 
    104         private Long currentGUIElementHash; 
     106        private Long currentGUIElementHash = null; 
    105107 
    106108        /** 
     
    116118         * </p> 
    117119         */ 
    118         private AndroidGUIElementSpec currentGUIElementSpec; 
     120        private ANDROIDGUIElementSpec currentGUIElementSpec; 
    119121 
    120122        /** 
     
    147149         * </p> 
    148150         */ 
    149         private Map<Long, List<Event>> eventsWithoutTargets; 
     151        // private Map<Long, List<Event>> eventsWithoutTargets; 
    150152 
    151153        /** 
     
    164166        public AndroidLogParser() { 
    165167                sequences = new LinkedList<List<Event>>(); 
    166                 // currentSequence = null; 
     168                currentSequence = null; 
    167169        } 
    168170 
     
    228230                        return; 
    229231                } 
     232 
    230233                if (inputSource != null) { 
    231234                        inputSource.setSystemId("file://" + file.getAbsolutePath()); 
     
    252255                        } 
    253256                } 
    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                 } 
    258257        } 
    259258 
     
    290289                        Attributes atts) throws SAXException { 
    291290                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) { 
    296293                                currentGUIElementTree = new GUIElementTree<Long>(); 
     294                        } 
     295                         
    297296                } 
    298297 
    299298                if (qName.equals("component")) { 
    300299                        currentGUIElementHash = Long.parseLong(atts.getValue("hash")); 
    301                         currentGUIElementSpec = new AndroidGUIElementSpec(); 
     300                        currentGUIElementSpec = new ANDROIDGUIElementSpec(); 
    302301                        currentGUIElementSpec.setHashCode((int) currentGUIElementHash 
    303302                                        .longValue()); 
     303                         
    304304                } else if (qName.equals("event")) { 
    305305                        currentEventId = atts.getValue("id"); 
    306306                        currentEventParameters = new HashMap<String, String>(); 
     307                         
    307308 
    308309                } else if (qName.equals("param")) { 
     
    345346        public void endElement(String uri, String localName, String qName) 
    346347                        throws SAXException { 
     348                 
     349                if (qName.equals("sessions")) { 
     350                        if (currentSequence != null) { 
     351                                sequences.add(currentSequence); 
     352                        } 
     353                } 
    347354                if (qName.equals("component") && currentGUIElementHash != null) { 
    348355                        try { 
     
    357364                        currentGUIElementHash = null; 
    358365                        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(); 
    378381                                event.setTimestamp(currentEventTimestamp); 
    379382                                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 
    390426        } 
    391427 
Note: See TracChangeset for help on using the changeset viewer.