Changeset 796


Ignore:
Timestamp:
09/07/12 15:21:30 (12 years ago)
Author:
fglaser
Message:
  • Interface for replayID calculation and corresponding test case extended
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-plugin-jfc-test/src/test/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculatorTest.java

    r675 r796  
    22 
    33import java.io.File; 
     4import java.util.ArrayList; 
    45import java.util.Collection; 
    56import java.util.HashSet; 
     
    1314 
    1415import de.ugoe.cs.quest.eventcore.Event; 
     16import de.ugoe.cs.quest.eventcore.IEventTarget; 
    1517import de.ugoe.cs.quest.plugin.jfc.eventcore.JFCEventId; 
     18import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElement; 
     19import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElementSpec; 
    1620 
    1721/** 
     
    4650         */ 
    4751        @Test 
    48         public void testCalculateReplayID_1() 
     52        public void testCalculateReplayIDwithEvent() 
    4953                throws Exception { 
    5054                Collection<JFCEventId> ignoredEvents = new HashSet<JFCEventId>(); 
     
    5761                 
    5862                String result = new JFCReplayIDCalculator().calculateReplayID(event); 
     63                assertEquals("e3561778462", result); 
     64        } 
     65         
     66        /** 
     67         * Run the String calculateReplayID(List<JFCGUIElementSpec>) method test. 
     68         * 
     69         * @throws Exception 
     70         */ 
     71        @Test 
     72        public void testCalculateReplayIDwithGuiElementPath() 
     73                throws Exception { 
     74                Collection<JFCEventId> ignoredEvents = new HashSet<JFCEventId>(); 
     75                ignoredEvents.add(JFCEventId.FOCUS_GAINED); 
     76                JFCLogParser parser = new JFCLogParser(ignoredEvents); 
     77                parser.parseFile(new File(ClassLoader.getSystemResource("freemind_trace.xml").getFile())); 
     78                 
     79                Collection<List<Event>> sequences = parser.getSequences(); 
     80                Event event = sequences.iterator().next().get(0); 
     81                 
     82                List<JFCGUIElementSpec> guiElementPath = new ArrayList<JFCGUIElementSpec>(); 
     83                 
     84                IEventTarget target = event.getTarget(); 
     85                JFCGUIElement jfcTarget = (JFCGUIElement) target; 
     86                 
     87                // extract element path 
     88                JFCGUIElement currentTarget = jfcTarget; 
     89                while (currentTarget != null){ 
     90                        JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 
     91                        guiElementPath.add(0, currentSpec); 
     92                        currentTarget = (JFCGUIElement) currentTarget.getParent(); 
     93                } 
     94                 
     95                String result = new JFCReplayIDCalculator().calculateReplayID(guiElementPath); 
    5996                assertEquals("e3561778462", result); 
    6097        } 
  • trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculator.java

    r785 r796  
    11package de.ugoe.cs.quest.plugin.jfc; 
    22 
     3import java.util.ArrayList; 
    34import java.util.Arrays; 
    45import java.util.LinkedHashMap; 
    56import java.util.List; 
     7import java.util.ListIterator; 
    68import java.util.Map; 
    7 import java.util.Stack; 
    89import java.util.regex.Matcher; 
    910import java.util.regex.Pattern; 
     
    5051         "javax.swing.JScrollPane$ScrollBar", 
    5152         "javax.swing.plaf.metal.MetalScrollButton"); 
    52          
    53          
    54         /** 
    55          * Calculates the replayID needed for compatibility with Guitar suite of a JFCEvent 
     53    
     54   /** 
     55    * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite 
     56    * @param List of {@link JFCGUIElementSpec}s that represent the component path of a event target 
     57    * for which the replayID should be calculated.  
     58    * @return replayID 
     59    */ 
     60         
     61   public String calculateReplayID(List<JFCGUIElementSpec> guiElementPath){ 
     62           String replayID = ""; 
     63           long hashCode = 1; 
     64          
     65           ListIterator<JFCGUIElementSpec> iterator = guiElementPath.listIterator(); 
     66            
     67           JFCGUIElementSpec currentSpec = iterator.next(); 
     68           String title = currentSpec.getName(); 
     69           String fuzzyTitle = getFuzzyTitle(title); 
     70           long windowHashCode = fuzzyTitle.hashCode(); 
     71           windowHashCode = (windowHashCode * 2) & 0xffffffffL; 
     72 
     73           long propagatedHashCode = windowHashCode; 
     74            
     75           // construct looks complicated but avoids going back and force through path 
     76           if (iterator.hasNext()) 
     77                   currentSpec = iterator.next(); 
     78           else 
     79                   currentSpec = null; 
     80 
     81           // walk through component path and calculate hashcode 
     82           while(currentSpec != null){ 
     83                   long localHashCode = getLocalHashCode(currentSpec); 
     84                   hashCode = propagatedHashCode * prime + localHashCode; 
     85                   hashCode = (hashCode * 2) & 0xffffffffL; 
     86 
     87                   if (iterator.hasNext()){ 
     88                           currentSpec = iterator.next(); 
     89                           Integer index = currentSpec.getIndex(); 
     90                           propagatedHashCode = prime * propagatedHashCode 
     91                                           + index.hashCode(); 
     92                   } 
     93                   else 
     94                           currentSpec = null; 
     95                            
     96           } 
     97 
     98           replayID = "e" + hashCode; 
     99 
     100           return replayID; 
     101   } 
     102    
     103    
     104        /** 
     105         * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite  
    56106         * @param event for which the ID should be calculated 
    57107         * @return replayID 
    58108         */ 
    59109        public String calculateReplayID(Event event){ 
    60                 String replayID = ""; 
    61                 long hashCode = 1; 
    62                 Stack<JFCGUIElement> path = new Stack<JFCGUIElement>(); 
     110                List<JFCGUIElementSpec> guiElementPath = new ArrayList<JFCGUIElementSpec>(); 
    63111                 
    64112                IEventTarget target = event.getTarget(); 
    65113                JFCGUIElement jfcTarget = (JFCGUIElement) target; 
    66114                 
    67                 // extract target path 
     115                // extract element path 
    68116                JFCGUIElement currentTarget = jfcTarget; 
    69117                while (currentTarget != null){ 
    70                         path.push(currentTarget); 
     118                        JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 
     119                        guiElementPath.add(0, currentSpec); 
    71120                        currentTarget = (JFCGUIElement) currentTarget.getParent(); 
    72121                } 
    73122                 
    74                 // calculate window hashcode 
    75                 currentTarget = path.pop(); 
    76                  
    77                 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 
    78                 String title = currentSpec.getName(); 
    79                 String fuzzyTitle = getFuzzyTitle(title); 
    80                 long windowHashCode = fuzzyTitle.hashCode(); 
    81                 windowHashCode = (windowHashCode * 2) & 0xffffffffL; 
    82                  
    83                 long propagatedHashCode = windowHashCode; 
    84                  
    85                 // walk through component path and calculate hashcode 
    86                  
    87                 while(!path.isEmpty()){ 
    88                         currentTarget = path.pop();  
    89                         currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 
    90                         long localHashCode = getLocalHashCode(currentSpec); 
    91                         hashCode = propagatedHashCode * prime + localHashCode; 
    92                 hashCode = (hashCode * 2) & 0xffffffffL; 
    93                          
    94                 if (!path.isEmpty()){ 
    95                         Integer index = ((JFCGUIElementSpec) path.lastElement().getSpecification()).getIndex(); 
    96                                 propagatedHashCode = prime * propagatedHashCode 
    97                                 + index.hashCode(); 
    98                 } 
    99                 } 
    100                  
    101                 replayID = "e" + hashCode; 
    102                  
    103                 return replayID; 
     123                // calculation is delegated to other calculateReplayID method 
     124                return this.calculateReplayID(guiElementPath); 
    104125        } 
    105126         
Note: See TracChangeset for help on using the changeset viewer.