source: trunk/autoquest-core-usability-test/src/test/java/de/ugoe/cs/autoquest/usability/AbstractUsabilityEvaluationTC.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
File size: 6.6 KB
Line 
1package de.ugoe.cs.autoquest.usability;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.fail;
5
6import java.util.ArrayList;
7import java.util.logging.Level;
8import java.util.regex.Matcher;
9import java.util.regex.Pattern;
10
11import org.junit.Before;
12
13import de.ugoe.cs.autoquest.eventcore.Event;
14import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
15import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
16import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
17import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
18import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
19import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
23import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskTreeBuilder;
24import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskTreeNodeFactory;
25import de.ugoe.cs.autoquest.test.DummyGUIElement;
26import de.ugoe.cs.autoquest.test.DummyInteraction;
27import de.ugoe.cs.autoquest.test.DummyTextField;
28import de.ugoe.cs.autoquest.usability.UsabilityDefect;
29import de.ugoe.cs.autoquest.usability.UsabilityEvaluationResult;
30import de.ugoe.cs.util.console.TextConsole;
31
32/**
33 * TODO comment
34 *
35 * @version $Revision: $ $Date: 18.07.2012$
36 * @author 2012, last modified by $Author: pharms$
37 */
38public class AbstractUsabilityEvaluationTC {
39
40    /** */
41    private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder();
42
43    /** */
44    private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory();
45
46    /**
47   *
48   */
49    @Before
50    public void setUp() {
51        new TextConsole(Level.FINEST);
52    }
53
54    /**
55   *
56   */
57    protected ITaskTree createTaskTree(String spec) {
58        Matcher matcher =
59            Pattern.compile("(\\s*(\\w+)\\s*(\\(((\\w*\\s*)*)\\))?\\s*(\\{))|(\\})").matcher(spec);
60
61        if (!matcher.find()) {
62            if (!matcher.hitEnd()) {
63                throw new IllegalArgumentException("could not parse task specification");
64            }
65        }
66
67        return taskTreeNodeFactory.createTaskTree(parseTask(matcher, new int[1]));
68    }
69
70    /**
71     * TODO: comment
72     *
73     * @param expectedDefects
74     * @param evaluateUsability
75     */
76    protected void assertUsabilityEvaluationResult(UsabilityDefect[]         expectedDefects,
77                                                   UsabilityEvaluationResult evaluationResult)
78    {
79        assertEquals(expectedDefects.length, evaluationResult.getAllDefects().size());
80
81        EXPECTED_DEFECT_ITERATION:
82        for (UsabilityDefect expectedDefect : expectedDefects) {
83            for (UsabilityDefect defect : evaluationResult.getAllDefects()) {
84                if (expectedDefect.equals(defect)) {
85                    System.err.println(defect.getParameterizedDescription());
86                    continue EXPECTED_DEFECT_ITERATION;
87                }
88            }
89
90            for (UsabilityDefect defect : evaluationResult.getAllDefects()) {
91                System.err.println(defect);
92            }
93
94            fail("expected defect " + expectedDefect + " not found in evaluation result");
95        }
96    }
97
98    /**
99   *
100   */
101    private ITaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) {
102        String firstToken = tokenMatcher.group();
103
104        if ("}".equals(firstToken)) {
105            throw new IllegalArgumentException("found a closing bracket at an unexpected place");
106        }
107
108        ITaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers);
109
110        if (!tokenMatcher.find()) {
111            throw new IllegalArgumentException("could not parse task specification");
112        }
113
114        firstToken = tokenMatcher.group();
115
116        if (!"}".equals(firstToken)) {
117            ITaskTreeNode child = null;
118
119            do {
120                child = parseTask(tokenMatcher, typeNumbers);
121
122                if (child != null) {
123                    addChild(treeNode, child);
124
125                    if (!tokenMatcher.find()) {
126                        throw new IllegalArgumentException("could not parse task specification");
127                    }
128
129                    firstToken = tokenMatcher.group();
130
131                    if ("}".equals(firstToken)) {
132                        break;
133                    }
134                }
135
136            }
137            while (child != null);
138
139        }
140
141        return treeNode;
142    }
143
144    /**
145     * TODO: comment
146     *
147     * @param group
148     * @return
149     */
150    private ITaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) {
151        String type = tokenMatcher.group(2);
152        String additionalInfo = tokenMatcher.group(4);
153
154        if ("Interaction".equals(type)) {
155            return taskTreeNodeFactory.createNewEventTask
156                (new DummyInteraction("dummy", typeNumbers[0]++), new DummyGUIElement("dummy"));
157        }
158        else if ("Sequence".equals(type)) {
159            return taskTreeNodeFactory.createNewSequence();
160        }
161        else if ("Iteration".equals(type)) {
162            return taskTreeNodeFactory.createNewIteration();
163        }
164        else if ("Selection".equals(type)) {
165            return taskTreeNodeFactory.createNewSelection();
166        }
167        else if ("TextInput".equals(type)) {
168            if (additionalInfo == null) {
169                fail("no simulated text provided for text input interactin task");
170            }
171
172            TextInput textInput = new TextInput(additionalInfo, new ArrayList<Event>());
173           
174            IEventTask task = taskTreeNodeFactory.createNewEventTask
175                (textInput, new DummyTextField(additionalInfo));
176
177            return task;
178        }
179        else {
180            fail("invalid type of task tree node: " + type);
181            return null;
182        }
183    }
184
185    /**
186     * TODO: comment
187     *
188     * @param treeNode
189     * @param child
190     */
191    private void addChild(ITaskTreeNode parent, ITaskTreeNode child) {
192        if (parent instanceof ISequence) {
193            taskTreeBuilder.addChild((ISequence) parent, child);
194        }
195        else if (parent instanceof IIteration) {
196            if (parent.getChildren().size() <= 0) {
197                taskTreeBuilder.setChild((IIteration) parent, child);
198            }
199            else {
200                fail("can not add more than one child to an iteration");
201            }
202        }
203        else if (parent instanceof ISelection) {
204            taskTreeBuilder.addChild((ISelection) parent, child);
205        }
206        else {
207            fail("can not add children to parent task tree node of type " +
208                 parent.getClass().getName());
209        }
210    }
211
212}
Note: See TracBrowser for help on using the repository browser.