1 | //------------------------------------------------------------------------------------------------- |
---|
2 | // Module : $RCSfile: AbstractUsabilityEvaluationTC.java,v $ |
---|
3 | // Version : $Revision: 0.0 $ $Author: pharms $ $Date: 18.07.2012 $ |
---|
4 | // Project : UsabilityEvaluationManager |
---|
5 | // Creation : 2012 by pharms |
---|
6 | // Copyright : Patrick Harms, 2012 |
---|
7 | //------------------------------------------------------------------------------------------------- |
---|
8 | package de.ugoe.cs.quest.usability; |
---|
9 | |
---|
10 | import static org.junit.Assert.assertEquals; |
---|
11 | import static org.junit.Assert.fail; |
---|
12 | |
---|
13 | import java.util.logging.Logger; |
---|
14 | import java.util.regex.Matcher; |
---|
15 | import java.util.regex.Pattern; |
---|
16 | |
---|
17 | import org.junit.Before; |
---|
18 | |
---|
19 | import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; |
---|
20 | import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; |
---|
21 | import de.ugoe.cs.quest.tasktrees.testutils.DummyTextField; |
---|
22 | import de.ugoe.cs.quest.tasktrees.testutils.SimpleLogFormatter; |
---|
23 | import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; |
---|
24 | import de.ugoe.cs.quest.tasktrees.treeifc.Selection; |
---|
25 | import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; |
---|
26 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; |
---|
27 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; |
---|
28 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; |
---|
29 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; |
---|
30 | import de.ugoe.cs.quest.tasktrees.treeifc.TextInputInteractionTask; |
---|
31 | import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilderImpl; |
---|
32 | import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactoryImpl; |
---|
33 | |
---|
34 | //------------------------------------------------------------------------------------------------- |
---|
35 | /** |
---|
36 | * TODO comment |
---|
37 | * |
---|
38 | * @version $Revision: $ $Date: 18.07.2012$ |
---|
39 | * @author 2012, last modified by $Author: pharms$ |
---|
40 | */ |
---|
41 | //------------------------------------------------------------------------------------------------- |
---|
42 | public class AbstractUsabilityEvaluationTC |
---|
43 | { |
---|
44 | |
---|
45 | /** */ |
---|
46 | private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); |
---|
47 | |
---|
48 | /** */ |
---|
49 | private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); |
---|
50 | |
---|
51 | //----------------------------------------------------------------------------------------------- |
---|
52 | /** |
---|
53 | * |
---|
54 | */ |
---|
55 | //----------------------------------------------------------------------------------------------- |
---|
56 | @Before |
---|
57 | public void setUp() |
---|
58 | { |
---|
59 | Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); |
---|
60 | } |
---|
61 | |
---|
62 | //----------------------------------------------------------------------------------------------- |
---|
63 | /** |
---|
64 | * |
---|
65 | */ |
---|
66 | //----------------------------------------------------------------------------------------------- |
---|
67 | protected TaskTree createTaskTree(String spec) |
---|
68 | { |
---|
69 | Matcher matcher = |
---|
70 | Pattern.compile("(\\s*(\\w+)\\s*(\\(((\\w*\\s*)*)\\))?\\s*(\\{))|(\\})").matcher(spec); |
---|
71 | |
---|
72 | if (!matcher.find()) |
---|
73 | { |
---|
74 | if (!matcher.hitEnd()) |
---|
75 | { |
---|
76 | throw new IllegalArgumentException("could not parse task specification"); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | return mTaskTreeNodeFactory.createTaskTree(parseTask(matcher, new int[1])); |
---|
81 | } |
---|
82 | |
---|
83 | //----------------------------------------------------------------------------------------------- |
---|
84 | /** |
---|
85 | * TODO: comment |
---|
86 | * |
---|
87 | * @param expectedDefects |
---|
88 | * @param evaluateUsability |
---|
89 | */ |
---|
90 | //----------------------------------------------------------------------------------------------- |
---|
91 | protected void assertUsabilityEvaluationResult(UsabilityDefect[] expectedDefects, |
---|
92 | UsabilityEvaluationResult evaluationResult) |
---|
93 | { |
---|
94 | assertEquals(expectedDefects.length, evaluationResult.getAllDefects().size()); |
---|
95 | |
---|
96 | EXPECTED_DEFECT_ITERATION: |
---|
97 | for (UsabilityDefect expectedDefect : expectedDefects) |
---|
98 | { |
---|
99 | for (UsabilityDefect defect : evaluationResult.getAllDefects()) |
---|
100 | { |
---|
101 | if (expectedDefect.equals(defect)) |
---|
102 | { |
---|
103 | System.err.println(defect.getParameterizedDescription()); |
---|
104 | continue EXPECTED_DEFECT_ITERATION; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | for (UsabilityDefect defect : evaluationResult.getAllDefects()) |
---|
109 | { |
---|
110 | System.err.println(defect); |
---|
111 | } |
---|
112 | |
---|
113 | fail("expected defect " + expectedDefect + " not found in evaluation result"); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | //----------------------------------------------------------------------------------------------- |
---|
119 | /** |
---|
120 | * |
---|
121 | */ |
---|
122 | //----------------------------------------------------------------------------------------------- |
---|
123 | private TaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) |
---|
124 | { |
---|
125 | String firstToken = tokenMatcher.group(); |
---|
126 | |
---|
127 | if ("}".equals(firstToken)) |
---|
128 | { |
---|
129 | throw new IllegalArgumentException("found a closing bracket at an unexpected place"); |
---|
130 | } |
---|
131 | |
---|
132 | TaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers); |
---|
133 | |
---|
134 | if (!tokenMatcher.find()) |
---|
135 | { |
---|
136 | throw new IllegalArgumentException("could not parse task specification"); |
---|
137 | } |
---|
138 | |
---|
139 | firstToken = tokenMatcher.group(); |
---|
140 | |
---|
141 | if (!"}".equals(firstToken)) |
---|
142 | { |
---|
143 | TaskTreeNode child = null; |
---|
144 | |
---|
145 | do |
---|
146 | { |
---|
147 | child = parseTask(tokenMatcher, typeNumbers); |
---|
148 | |
---|
149 | if (child != null) |
---|
150 | { |
---|
151 | addChild(treeNode, child); |
---|
152 | |
---|
153 | if (!tokenMatcher.find()) |
---|
154 | { |
---|
155 | throw new IllegalArgumentException("could not parse task specification"); |
---|
156 | } |
---|
157 | |
---|
158 | firstToken = tokenMatcher.group(); |
---|
159 | |
---|
160 | if ("}".equals(firstToken)) |
---|
161 | { |
---|
162 | break; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | } |
---|
167 | while (child != null); |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | return treeNode; |
---|
172 | } |
---|
173 | |
---|
174 | //----------------------------------------------------------------------------------------------- |
---|
175 | /** |
---|
176 | * TODO: comment |
---|
177 | * |
---|
178 | * @param group |
---|
179 | * @return |
---|
180 | */ |
---|
181 | //----------------------------------------------------------------------------------------------- |
---|
182 | private TaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) |
---|
183 | { |
---|
184 | String type = tokenMatcher.group(2); |
---|
185 | String additionalInfo = tokenMatcher.group(4); |
---|
186 | |
---|
187 | if ("Interaction".equals(type)) |
---|
188 | { |
---|
189 | return mTaskTreeNodeFactory.createNewInteractionTask |
---|
190 | (new DummyGUIElement("dummy"), new DummyInteraction("dummy", typeNumbers[0]++)); |
---|
191 | } |
---|
192 | else if ("Sequence".equals(type)) |
---|
193 | { |
---|
194 | return mTaskTreeNodeFactory.createNewSequence(); |
---|
195 | } |
---|
196 | else if ("Iteration".equals(type)) |
---|
197 | { |
---|
198 | return mTaskTreeNodeFactory.createNewIteration(); |
---|
199 | } |
---|
200 | else if ("Selection".equals(type)) |
---|
201 | { |
---|
202 | return mTaskTreeNodeFactory.createNewSelection(); |
---|
203 | } |
---|
204 | else if ("TextInput".equals(type)) |
---|
205 | { |
---|
206 | if (additionalInfo == null) |
---|
207 | { |
---|
208 | fail("no simulated text provided for text input interactin task"); |
---|
209 | } |
---|
210 | |
---|
211 | TextInputInteractionTask task = |
---|
212 | mTaskTreeNodeFactory.createNewTextInputInteractionTask(new DummyTextField(additionalInfo)); |
---|
213 | |
---|
214 | task.setEnteredText(additionalInfo); |
---|
215 | return task; |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | fail("invalid type of task tree node: " + type); |
---|
220 | return null; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | //----------------------------------------------------------------------------------------------- |
---|
225 | /** |
---|
226 | * TODO: comment |
---|
227 | * |
---|
228 | * @param treeNode |
---|
229 | * @param child |
---|
230 | */ |
---|
231 | //----------------------------------------------------------------------------------------------- |
---|
232 | private void addChild(TaskTreeNode parent, TaskTreeNode child) |
---|
233 | { |
---|
234 | if (parent instanceof Sequence) |
---|
235 | { |
---|
236 | mTaskTreeBuilder.addChild((Sequence) parent, child); |
---|
237 | } |
---|
238 | else if (parent instanceof Iteration) |
---|
239 | { |
---|
240 | if (parent.getChildren().size() <= 0) |
---|
241 | { |
---|
242 | mTaskTreeBuilder.setChild((Iteration) parent, child); |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | fail("can not add more than one child to an iteration"); |
---|
247 | } |
---|
248 | } |
---|
249 | else if (parent instanceof Selection) |
---|
250 | { |
---|
251 | mTaskTreeBuilder.addChild((Selection) parent, child); |
---|
252 | } |
---|
253 | else if (parent instanceof TextInputInteractionTask) |
---|
254 | { |
---|
255 | mTaskTreeBuilder.addChild((TextInputInteractionTask) parent, child); |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | fail("can not add children to parent task tree node of type " + parent.getClass().getName()); |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | } |
---|