Changeset 1333
- Timestamp:
- 01/24/14 13:48:25 (11 years ago)
- Location:
- trunk/autoquest-test-utils/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1327 r1333 29 29 import de.ugoe.cs.autoquest.eventcore.IEventType; 30 30 import de.ugoe.cs.autoquest.eventcore.StringEventType; 31 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 31 32 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 32 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; … … 103 104 correctTargets(taskInstanceList); 104 105 106 // validate the instance list 107 try { 108 new TaskTreeValidator().validate(taskInstanceList); 109 } 110 catch (java.lang.AssertionError e) { 111 throw new IllegalArgumentException(e.getMessage(), e); 112 } 113 105 114 return taskInstanceList; 106 115 } … … 226 235 } 227 236 228 // validate the instance229 try {230 new TaskTreeValidator().validate(instance);231 }232 catch (java.lang.AssertionError e) {233 throw new IllegalArgumentException(e.getMessage(), e);234 }235 236 237 return instance; 237 238 } … … 318 319 } 319 320 } 321 else if ("Optional".equals(type)) { 322 // update the optional with what is optional if available 323 if (children.size() == 1) { 324 ITask newChildTask = children.get(0).getTask(); 325 326 if (((IOptional) task).getMarkedTask() == null) { 327 taskBuilder.setMarkedTask((IOptional) task, newChildTask); 328 } 329 else if (!((IOptional) task).getMarkedTask().equals(newChildTask)) { 330 throw new IllegalArgumentException("all children of the same optional must " + 331 "be of an identical task model."); 332 } 333 } 334 } 320 335 321 336 return task; … … 349 364 * @return 350 365 */ 351 private IEventType determineType(String type, String enteredText) {366 private IEventType determineType(String type, String additionalInfo) { 352 367 if ("TextInput".equals(type)) { 353 return new TextInput(enteredText, new ArrayList<Event>()); 368 return new TextInput(additionalInfo, new ArrayList<Event>()); 369 } 370 else if ("Scroll".equals(type)) { 371 int x = 0; 372 int y = 0; 373 if (additionalInfo != null) { 374 String[] parts = additionalInfo.split(" "); 375 if (parts.length > 0) { 376 try { 377 x = Integer.parseInt(parts[0]); 378 } 379 catch (NumberFormatException e) { 380 throw new IllegalArgumentException("could not parse scroll coordinates", e); 381 } 382 } 383 if (parts.length > 1) { 384 try { 385 y = Integer.parseInt(parts[1]); 386 } 387 catch (NumberFormatException e) { 388 throw new IllegalArgumentException("could not parse scroll coordinates", e); 389 } 390 } 391 } 392 return new Scroll(x, y); 354 393 } 355 394 else { … … 428 467 else if (instance instanceof IOptionalInstance) { 429 468 IOptionalInstance optInst = (IOptionalInstance) instance; 430 taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 469 if (optInst.getChild() != null) { 470 taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 471 } 431 472 } 432 473 else if ((instance instanceof IEventTaskInstance) && -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeValidator.java
r1294 r1333 126 126 childTask instanceof IOptional); 127 127 128 assertNotNull("number of children of optional instance must be 1", 129 ((IOptionalInstance) taskInstance).getChild()); 130 131 assertEquals("task of optional child does not match optional model", 132 childTask, ((IOptionalInstance) taskInstance).getChild().getTask()); 128 if (((IOptionalInstance) taskInstance).getChild() != null) { 129 assertEquals("task of optional child does not match optional model", 130 childTask, ((IOptionalInstance) taskInstance).getChild().getTask()); 131 } 133 132 } 134 133 else if (taskInstance.getTask() instanceof IEventTask) { … … 151 150 } 152 151 else if (taskInstance instanceof IOptionalInstance) { 153 validate(((IOptionalInstance) taskInstance).getChild()); 152 if (((IOptionalInstance) taskInstance).getChild() != null) { 153 validate(((IOptionalInstance) taskInstance).getChild()); 154 } 154 155 } 155 156 } -
trunk/autoquest-test-utils/src/test/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoderTest.java
r1327 r1333 20 20 21 21 import de.ugoe.cs.autoquest.eventcore.Event; 22 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 22 23 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 23 24 import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea; … … 249 250 */ 250 251 @Test 252 public void test_Scroll_01() { 253 String blub = 254 "UserSession {" + 255 " Scroll body1 { }" + 256 "}"; 257 258 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 259 260 ITaskInstanceList list = decoder.decode(blub); 261 262 assertTrue(list.get(0) instanceof IEventTaskInstance); 263 assertTrue(list.get(0).getTask() instanceof IEventTask); 264 265 assertTrue(((IEventTaskInstance) list.get(0)).getEvent().getType() instanceof Scroll); 266 267 new TaskTreeValidator().validate(list); 268 } 269 270 /** 271 * 272 */ 273 @Test 274 public void test_Scroll_02() { 275 String blub = 276 "UserSession {" + 277 " Scroll body1 { }" + 278 " Scroll body2 { }" + 279 "}"; 280 281 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 282 283 ITaskInstanceList list = decoder.decode(blub); 284 285 assertTrue(list.get(0) instanceof IEventTaskInstance); 286 assertTrue(list.get(0).getTask() instanceof IEventTask); 287 assertTrue(((IEventTaskInstance) list.get(0)).getEvent().getType() instanceof Scroll); 288 289 assertTrue(list.get(1) instanceof IEventTaskInstance); 290 assertTrue(list.get(1).getTask() instanceof IEventTask); 291 assertTrue(((IEventTaskInstance) list.get(1)).getEvent().getType() instanceof Scroll); 292 293 assertFalse(list.get(0).equals(list.get(1))); 294 assertFalse(list.get(0).getTask().equals(list.get(1).getTask())); 295 296 new TaskTreeValidator().validate(list); 297 } 298 299 /** 300 * 301 */ 302 @Test 303 public void test_Scroll_03() { 304 String blub = 305 "UserSession {" + 306 " Scroll body1 { }" + 307 " Scroll body1 { }" + 308 "}"; 309 310 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 311 312 ITaskInstanceList list = decoder.decode(blub); 313 314 assertTrue(list.get(0) instanceof IEventTaskInstance); 315 assertTrue(list.get(0).getTask() instanceof IEventTask); 316 assertTrue(((IEventTaskInstance) list.get(0)).getEvent().getType() instanceof Scroll); 317 318 assertTrue(list.get(1) instanceof IEventTaskInstance); 319 assertTrue(list.get(1).getTask() instanceof IEventTask); 320 assertTrue(((IEventTaskInstance) list.get(1)).getEvent().getType() instanceof Scroll); 321 322 assertFalse(list.get(0).equals(list.get(1))); 323 assertTrue(list.get(0).getTask().equals(list.get(1).getTask())); 324 325 new TaskTreeValidator().validate(list); 326 } 327 328 /** 329 * 330 */ 331 @Test 332 public void test_Scroll_04() { 333 String blub = 334 "UserSession {" + 335 " Scroll body1 (1 2) { }" + 336 "}"; 337 338 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 339 340 ITaskInstanceList list = decoder.decode(blub); 341 342 assertTrue(list.get(0) instanceof IEventTaskInstance); 343 assertTrue(list.get(0).getTask() instanceof IEventTask); 344 345 assertTrue(((IEventTaskInstance) list.get(0)).getEvent().getType() instanceof Scroll); 346 347 Scroll scroll = (Scroll) ((IEventTaskInstance) list.get(0)).getEvent().getType(); 348 349 assertEquals(1, scroll.getXPosition()); 350 assertEquals(2, scroll.getYPosition()); 351 352 new TaskTreeValidator().validate(list); 353 } 354 355 /** 356 * 357 */ 358 @Test 251 359 public void test_GuiElements_01() { 252 360 String blub = … … 1054 1162 decoder.decode(blub); 1055 1163 } 1164 1165 /** 1166 * 1167 */ 1168 @Test 1169 public void test_Optional_07() { 1170 String blub = 1171 "UserSession {" + 1172 " Optional op1 {" + 1173 " MouseClick c1 { }" + 1174 " }" + 1175 " Optional op1 { }" + 1176 "}"; 1177 1178 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 1179 1180 ITaskInstanceList list = decoder.decode(blub); 1181 1182 assertTrue(list.get(0) instanceof IOptionalInstance); 1183 assertNotNull(((IOptionalInstance) list.get(0)).getChild()); 1184 assertTrue(((IOptionalInstance) list.get(0)).getChild() instanceof IEventTaskInstance); 1185 1186 assertTrue(list.get(0).getTask() instanceof IOptional); 1187 assertNotNull(((IOptional) list.get(0).getTask()).getMarkedTask()); 1188 assertTrue(((IOptional) list.get(0).getTask()).getMarkedTask() instanceof IEventTask); 1189 1190 assertTrue(list.get(1) instanceof IOptionalInstance); 1191 assertNull(((IOptionalInstance) list.get(1)).getChild()); 1192 1193 assertTrue(list.get(1).getTask() instanceof IOptional); 1194 assertNotNull(((IOptional) list.get(1).getTask()).getMarkedTask()); 1195 assertTrue(((IOptional) list.get(1).getTask()).getMarkedTask() instanceof IEventTask); 1196 1197 assertFalse(list.get(0).equals(list.get(1))); 1198 assertTrue(list.get(0).getTask().equals(list.get(1).getTask())); 1199 1200 new TaskTreeValidator().validate(list); 1201 } 1202 1203 /** 1204 * 1205 */ 1206 @Test 1207 public void test_Optional_08() { 1208 String blub = 1209 "UserSession {" + 1210 " Optional op1 { }" + 1211 " Optional op1 {" + 1212 " MouseClick c1 { }" + 1213 " }" + 1214 "}"; 1215 1216 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 1217 1218 ITaskInstanceList list = decoder.decode(blub); 1219 1220 assertTrue(list.get(0) instanceof IOptionalInstance); 1221 assertNull(((IOptionalInstance) list.get(0)).getChild()); 1222 1223 assertTrue(list.get(0).getTask() instanceof IOptional); 1224 assertNotNull(((IOptional) list.get(0).getTask()).getMarkedTask()); 1225 assertTrue(((IOptional) list.get(0).getTask()).getMarkedTask() instanceof IEventTask); 1226 1227 assertTrue(list.get(1) instanceof IOptionalInstance); 1228 assertNotNull(((IOptionalInstance) list.get(1)).getChild()); 1229 assertTrue(((IOptionalInstance) list.get(1)).getChild() instanceof IEventTaskInstance); 1230 1231 assertTrue(list.get(1).getTask() instanceof IOptional); 1232 assertNotNull(((IOptional) list.get(1).getTask()).getMarkedTask()); 1233 assertTrue(((IOptional) list.get(1).getTask()).getMarkedTask() instanceof IEventTask); 1234 1235 assertFalse(list.get(0).equals(list.get(1))); 1236 assertTrue(list.get(0).getTask().equals(list.get(1).getTask())); 1237 1238 new TaskTreeValidator().validate(list); 1239 } 1056 1240 }
Note: See TracChangeset
for help on using the changeset viewer.