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

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
File size: 7.2 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;
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:
96        for (UsabilityDefect expectedDefect : expectedDefects) {
97            for (UsabilityDefect defect : evaluationResult.getAllDefects()) {
98                if (expectedDefect.equals(defect)) {
99                    System.err.println(defect.getParameterizedDescription());
100                    continue EXPECTED_DEFECT_ITERATION;
101                }
102            }
103
104            for (UsabilityDefect defect : evaluationResult.getAllDefects()) {
105                System.err.println(defect);
106            }
107
108            fail("expected defect " + expectedDefect + " not found in evaluation result");
109        }
110    }
111
112    /**
113   *
114   */
115    private ITaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) {
116        String firstToken = tokenMatcher.group();
117
118        if ("}".equals(firstToken)) {
119            throw new IllegalArgumentException("found a closing bracket at an unexpected place");
120        }
121
122        ITaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers);
123
124        if (!tokenMatcher.find()) {
125            throw new IllegalArgumentException("could not parse task specification");
126        }
127
128        firstToken = tokenMatcher.group();
129
130        if (!"}".equals(firstToken)) {
131            ITaskTreeNode child = null;
132
133            do {
134                child = parseTask(tokenMatcher, typeNumbers);
135
136                if (child != null) {
137                    addChild(treeNode, child);
138
139                    if (!tokenMatcher.find()) {
140                        throw new IllegalArgumentException("could not parse task specification");
141                    }
142
143                    firstToken = tokenMatcher.group();
144
145                    if ("}".equals(firstToken)) {
146                        break;
147                    }
148                }
149
150            }
151            while (child != null);
152
153        }
154
155        return treeNode;
156    }
157
158    /**
159     * TODO: comment
160     *
161     * @param group
162     * @return
163     */
164    private ITaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) {
165        String type = tokenMatcher.group(2);
166        String additionalInfo = tokenMatcher.group(4);
167
168        if ("Interaction".equals(type)) {
169            return taskTreeNodeFactory.createNewEventTask
170                (new DummyInteraction("dummy", typeNumbers[0]++), 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 = taskTreeNodeFactory.createNewEventTask
189                (textInput, new DummyTextField(additionalInfo));
190
191            return task;
192        }
193        else {
194            fail("invalid type of task tree node: " + type);
195            return null;
196        }
197    }
198
199    /**
200     * TODO: comment
201     *
202     * @param treeNode
203     * @param child
204     */
205    private void addChild(ITaskTreeNode parent, ITaskTreeNode child) {
206        if (parent instanceof ISequence) {
207            taskTreeBuilder.addChild((ISequence) parent, child);
208        }
209        else if (parent instanceof IIteration) {
210            if (parent.getChildren().size() <= 0) {
211                taskTreeBuilder.setChild((IIteration) parent, child);
212            }
213            else {
214                fail("can not add more than one child to an iteration");
215            }
216        }
217        else if (parent instanceof ISelection) {
218            taskTreeBuilder.addChild((ISelection) parent, child);
219        }
220        else {
221            fail("can not add children to parent task tree node of type " +
222                 parent.getClass().getName());
223        }
224    }
225
226}
Note: See TracBrowser for help on using the repository browser.