Changeset 797 for trunk/quest-plugin-jfc-test/src
- Timestamp:
- 09/09/12 13:59:37 (12 years ago)
- Location:
- trunk/quest-plugin-jfc-test/src/test
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc-test/src/test/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculatorTest.java
r796 r797 6 6 import java.util.HashSet; 7 7 import java.util.List; 8 import java.util.Set; 9 import java.util.logging.Level; 10 11 import javax.xml.parsers.DocumentBuilder; 12 import javax.xml.parsers.DocumentBuilderFactory; 8 13 9 14 import junit.framework.TestCase; … … 12 17 import org.junit.Before; 13 18 import org.junit.Test; 19 import org.w3c.dom.Document; 20 import org.w3c.dom.Node; 21 import org.w3c.dom.NodeList; 14 22 15 23 import de.ugoe.cs.quest.eventcore.Event; … … 18 26 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElement; 19 27 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElementSpec; 28 import de.ugoe.cs.util.console.TextConsole; 20 29 21 30 /** … … 96 105 assertEquals("e3561778462", result); 97 106 } 107 108 /** 109 * Run the String calculateReplayID(List<JFCGUIElementSpec>) method test. 110 * 111 * @throws Exception 112 */ 113 @Test 114 public void testCalculateReplayIDAllEvents() 115 throws Exception { 116 // generate list of known replayIDs from guitar efg file 117 File guiFile = new File(ClassLoader.getSystemResource("freemind.efg").getFile()); 118 119 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 120 DocumentBuilder builder = factory.newDocumentBuilder(); 121 Document freemindGUI = builder.parse(guiFile); 122 123 Node currentNode = freemindGUI.getFirstChild().getFirstChild(); 124 NodeList eventNodes = null; 125 List<String> knownIDs = new ArrayList<String>(); 126 127 while ((currentNode = currentNode.getNextSibling()) != null){ 128 if (currentNode.getNodeName().equals("Events")) 129 eventNodes = currentNode.getChildNodes(); 130 } 131 132 for (int i = 0; i < eventNodes.getLength(); i++){ 133 if (eventNodes.item(i).getNodeName().equals("Event")){ 134 NodeList attributes = eventNodes.item(i).getChildNodes(); 135 for (int j = 0; j < attributes.getLength(); j++){ 136 if (attributes.item(j).getNodeName().equals("EventId")){ 137 knownIDs.add(attributes.item(j).getTextContent()); 138 } 139 } 140 } 141 } 142 143 // calculate replayIDs from trace file 144 Collection<JFCEventId> ignoredEvents = new HashSet<JFCEventId>(); 145 ignoredEvents.add(JFCEventId.FOCUS_GAINED); 146 JFCLogParser parser = new JFCLogParser(ignoredEvents); 147 parser.parseFile(new File(ClassLoader.getSystemResource("freemind_trace2.xml").getFile())); 148 JFCReplayIDCalculator calculator = new JFCReplayIDCalculator(); 149 150 Set<String> generatedIDs = new HashSet<String>(); 151 152 Collection<List<Event>> sequences = parser.getSequences(); 153 154 assertTrue(sequences.size() > 0); 155 156 157 for (List<Event> currentSequence: sequences){ 158 for (Event currentEvent: currentSequence){ 159 String replayID = calculator.calculateReplayID(currentEvent); 160 generatedIDs.add(replayID); 161 System.out.println("Generated ID: " + replayID); 162 } 163 } 164 165 System.out.println(); 166 167 // check if generatedIDs are known 168 int known = 0; 169 for (String replayID: generatedIDs){ 170 if (knownIDs.contains(replayID)){ 171 System.out.println(replayID + "\t is known."); 172 known++; 173 } 174 else 175 System.out.println(replayID + "\t is unknown."); 176 } 177 System.out.println(); 178 179 float percentage = (float) known/generatedIDs.size()*100; 180 System.out.println(percentage + "% of the generated IDs are known."); 181 182 assertTrue(percentage > 75); 183 184 185 } 98 186 99 187 /** … … 108 196 public void setUp() 109 197 throws Exception { 110 // add additional set up code here198 new TextConsole(Level.FINEST); 111 199 } 112 200
Note: See TracChangeset
for help on using the changeset viewer.