InjectionPoints extends ScopeTrackingVisitor { public List<IInjectionPoint> getAllInjectionPoints() { return Collections.unmodifiableList(injectionPoints); } InjectionPoints(TranslationUnit tu, IRandom generator,
        Predicate<IInjectionPoint> suitable); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitBlockStmt(BlockStmt stmt); @Override void visitDoStmt(DoStmt doStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitWhileStmt(WhileStmt whileStmt); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitSwitchStmt(SwitchStmt switchStmt); List<IInjectionPoint> getInjectionPoints(Function<IRandom, Boolean> choiceFunction); List<IInjectionPoint> getAllInjectionPoints();  }
@Test public void testNoInjectAtStartOfSwitch() throws Exception { final String prog = "void main() { switch(1) { " + " default: break; } }"; TranslationUnit tu = ParseHelper.parse(prog); List<IInjectionPoint> injectionPointList = new InjectionPoints(tu, new RandomWrapper(0), item -> true).getAllInjectionPoints(); assertEquals(4, injectionPointList.size()); }
@Test public void testNullStmtInjectionPoints() throws Exception { final String prog = "void main() { ; ; ; ; ; ; }"; final String expected = "void main() { ; ; ; 1; ; ; }"; TranslationUnit tu = ParseHelper.parse(prog); List<IInjectionPoint> injectionPointList = new InjectionPoints(tu, new RandomWrapper(0), item -> true).getAllInjectionPoints(); assertEquals(7, injectionPointList.size()); injectionPointList.get(3).replaceNext(new ExprStmt(new IntConstantExpr("1"))); CompareAsts.assertEqualAsts(expected, tu); }
@Test public void testDiscardStmtInjectionPoints() throws Exception { final String prog = "void main() { discard; discard; discard; discard; discard; discard; }"; final String expected = "void main() { discard; discard; discard; 1; discard; discard; }"; TranslationUnit tu = ParseHelper.parse(prog); List<IInjectionPoint> injectionPointList = new InjectionPoints(tu, new RandomWrapper(0), item -> true).getAllInjectionPoints(); assertEquals(7, injectionPointList.size()); injectionPointList.get(3).replaceNext(new ExprStmt(new IntConstantExpr("1"))); CompareAsts.assertEqualAsts(expected, tu); }
@Test public void testBreakStmtInjectionPoints() throws Exception { final String prog = "void main() { for(;;) { break; break; break; } };"; final String expected = "void main() { for(;;) { 1; break; break; } };"; TranslationUnit tu = ParseHelper.parse(prog); List<IInjectionPoint> injectionPointList = new InjectionPoints(tu, new RandomWrapper(0), item -> true).getAllInjectionPoints(); assertEquals(6, injectionPointList.size()); injectionPointList.get(2).replaceNext(new ExprStmt(new IntConstantExpr("1"))); }