[622] | 1 | // Module : $RCSfile: ReplayReaderTest.java,v $
|
---|
| 2 | // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 26.11.2011 15:10:08 $
|
---|
| 3 | // Project : TaskTreePerformanceTest
|
---|
| 4 | // Creation : 2011 by Patrick
|
---|
| 5 | // Copyright : Patrick Harms, 2011
|
---|
| 6 |
|
---|
| 7 | package de.ugoe.cs.quest.plugin.mfc;
|
---|
| 8 |
|
---|
| 9 | import static org.junit.Assert.assertEquals;
|
---|
| 10 | import static org.junit.Assert.assertNotNull;
|
---|
| 11 | import static org.junit.Assert.assertNotSame;
|
---|
| 12 | import static org.junit.Assert.assertTrue;
|
---|
| 13 |
|
---|
| 14 | import java.io.File;
|
---|
| 15 | import java.io.FileInputStream;
|
---|
| 16 | import java.io.InputStreamReader;
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
| 20 | import org.junit.After;
|
---|
| 21 | import org.junit.Before;
|
---|
| 22 | import org.junit.Test;
|
---|
| 23 |
|
---|
| 24 | import de.ugoe.cs.quest.ReplayGenerator;
|
---|
| 25 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
| 26 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModel;
|
---|
| 27 | import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement;
|
---|
| 28 | import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCGUIElement;
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * TODO comment
|
---|
| 32 | *
|
---|
| 33 | * @version $Revision: $ $Date: $
|
---|
| 34 | * @author 2011, last modified by $Author: $
|
---|
| 35 | */
|
---|
| 36 | public class MFCLogParserTest {
|
---|
| 37 |
|
---|
| 38 | /** */
|
---|
| 39 | private File tmpFile;
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | *
|
---|
| 43 | */
|
---|
| 44 | @Before
|
---|
| 45 | public void setUp() throws Exception {
|
---|
| 46 | tmpFile = new File("tmp.xml");
|
---|
| 47 |
|
---|
| 48 | if (tmpFile.exists()) {
|
---|
| 49 | assertTrue(tmpFile.delete());
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | *
|
---|
| 55 | */
|
---|
| 56 | @After
|
---|
| 57 | public void tearDown() throws Exception {
|
---|
| 58 | if (tmpFile.exists()) {
|
---|
| 59 | assertTrue(tmpFile.delete());
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | *
|
---|
| 66 | */
|
---|
| 67 | @Test
|
---|
| 68 | public void testTrace() throws Exception {
|
---|
| 69 | File traceFile = new File(ClassLoader.getSystemResource("trace.txt").getFile());
|
---|
| 70 |
|
---|
| 71 | new LogPreprocessor().convertToXml(traceFile.getAbsolutePath(),
|
---|
| 72 | tmpFile.getAbsolutePath());
|
---|
| 73 |
|
---|
| 74 | MFCLogParser parser = new MFCLogParser();
|
---|
| 75 | parser.parseFile(tmpFile);
|
---|
| 76 | Collection<List<Event>> events = parser.getSequences();
|
---|
| 77 |
|
---|
| 78 | assertNotNull(events);
|
---|
| 79 | assertTrue(events.size() > 0);
|
---|
| 80 |
|
---|
| 81 | System.err.println("{");
|
---|
| 82 | for (List<Event> session : events) {
|
---|
| 83 | System.err.println(" {");
|
---|
| 84 | for (Event event : session) {
|
---|
| 85 | System.err.print(" ");
|
---|
| 86 | System.err.print(event);
|
---|
| 87 | System.err.println(",");
|
---|
| 88 | }
|
---|
| 89 | System.err.println(" }");
|
---|
| 90 | }
|
---|
| 91 | System.err.println("}");
|
---|
| 92 | System.err.println("\n\n");
|
---|
| 93 |
|
---|
| 94 | GUIModel guiModel = parser.getGuiModel();
|
---|
| 95 | assertNotNull(guiModel);
|
---|
| 96 | assertNotSame(0, guiModel.getRootElements().size());
|
---|
| 97 |
|
---|
| 98 | for (IGUIElement root : guiModel.getRootElements()) {
|
---|
| 99 | dumpGUIElement(root, guiModel, "");
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | /**
|
---|
| 104 | *
|
---|
| 105 | */
|
---|
| 106 | @Test
|
---|
| 107 | public void testLogfile() throws Exception {
|
---|
| 108 | File logFile = new File(ClassLoader.getSystemResource("log.xml").getFile());
|
---|
| 109 |
|
---|
| 110 | MFCLogParser parser = new MFCLogParser();
|
---|
| 111 | parser.parseFile(logFile);
|
---|
| 112 | Collection<List<Event>> events = parser.getSequences();
|
---|
| 113 |
|
---|
| 114 | assertNotNull(events);
|
---|
| 115 | assertTrue(events.size() > 0);
|
---|
| 116 |
|
---|
| 117 | System.err.println("{");
|
---|
| 118 | for (List<Event> session : events) {
|
---|
| 119 | System.err.println(" {");
|
---|
| 120 | for (Event event : session) {
|
---|
| 121 | System.err.print(" ");
|
---|
| 122 | System.err.print(event);
|
---|
| 123 | System.err.println(",");
|
---|
| 124 | }
|
---|
| 125 | System.err.println(" }");
|
---|
| 126 | }
|
---|
| 127 | System.err.println("}");
|
---|
| 128 | System.err.println("\n\n");
|
---|
| 129 |
|
---|
| 130 | GUIModel guiModel = parser.getGuiModel();
|
---|
| 131 | assertNotNull(guiModel);
|
---|
| 132 |
|
---|
| 133 | for (IGUIElement root : guiModel.getRootElements()) {
|
---|
| 134 | dumpGUIElement(root, guiModel, "");
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | ReplayGenerator generator = new ReplayGenerator();
|
---|
| 138 | generator.createLogfileMultipleSessions(parser.getSequences(), tmpFile.getAbsolutePath());
|
---|
| 139 |
|
---|
| 140 | InputStreamReader reader1 =
|
---|
| 141 | new InputStreamReader(ClassLoader.getSystemResourceAsStream("replay.xml"), "UTF-8");
|
---|
| 142 |
|
---|
| 143 | InputStreamReader reader2 = new InputStreamReader(new FileInputStream(tmpFile), "UTF-8");
|
---|
| 144 |
|
---|
| 145 | try {
|
---|
| 146 | int sign1;
|
---|
| 147 | do {
|
---|
| 148 | sign1 = reader1.read();
|
---|
| 149 | assertEquals(sign1, reader2.read());
|
---|
| 150 | }
|
---|
| 151 | while (sign1 > -1);
|
---|
| 152 | }
|
---|
| 153 | finally {
|
---|
| 154 | reader1.close();
|
---|
| 155 | reader2.close();
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * TODO: comment
|
---|
| 161 | *
|
---|
| 162 | * @param root
|
---|
| 163 | * @param guiModel
|
---|
| 164 | */
|
---|
| 165 | private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) {
|
---|
| 166 | assertTrue(guiElement instanceof MFCGUIElement);
|
---|
| 167 |
|
---|
| 168 | System.err.print(indent);
|
---|
| 169 | System.err.print(guiElement);
|
---|
| 170 |
|
---|
| 171 | List<IGUIElement> children = guiModel.getChildren(guiElement);
|
---|
| 172 |
|
---|
| 173 | if ((children != null) && (children.size() > 0)) {
|
---|
| 174 | System.err.println(" {");
|
---|
| 175 |
|
---|
| 176 | for (IGUIElement child : children) {
|
---|
| 177 | dumpGUIElement(child, guiModel, indent + " ");
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | System.err.print(indent);
|
---|
| 181 | System.err.print("}");
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | System.err.println();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | }
|
---|