source: trunk/autoquest-core-usability-evaluation-test/src/main/java/de/ugoe/cs/autoquest/usability/rules/metrics/AbstractUsabilityEvaluationTC.java @ 1171

Last change on this file since 1171 was 1141, checked in by adeicke, 11 years ago

Adapted test project to refactoring of evaluation project.

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