/** * <p> * Constructor for BranchCoverageSuiteFitness. * </p> */ public BranchCoverageSuiteFitness() { this(TestGenerationContext.getInstance().getClassLoaderForSUT()); }
private static void loadCallTreeClasses(CallGraph callGraph) { for (String className : callGraph.getClasses()) { if (className.startsWith(Properties.TARGET_CLASS + "$")) { try { Class.forName(className, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } catch (ClassNotFoundException e) { logger.debug("Error loading " + className + ": " + e); } } } }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); int branchId = ois.readInt(); if (branchId >= 0) this.branch = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId); else this.branch = null; }
/** * Resets the classes in the list using the Class Loader from the current * Test Generation context * * @param classesToReset */ public void resetClasses(List<String> classesToReset) { ClassLoader loader = TestGenerationContext.getInstance().getClassLoaderForSUT(); resetClasses(classesToReset, loader); }
public BranchNoveltyFunction() { for (Branch branch : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches()) { if(!branch.isInstrumented()) { branches.add(branch.getActualBranchId()); } } branchlessMethods.addAll(BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchlessMethods()); logger.warn("Number of branches: "+branches.size()+" branches and "+branchlessMethods.size() +" branchless methods"); }
private ClassNode loadClassNode(String className) throws IOException { ClassReader reader = new ClassReader(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className)); ClassNode cn = new ClassNode(); reader.accept(cn, ClassReader.SKIP_FRAMES); // | ClassReader.SKIP_DEBUG); return cn; }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); branchFitnesses = new ArrayList<BranchCoverageTestFitness>(); if(GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getActualCFG(className, methodName) != null) { // TODO: Figure out why the CFG may not exist setupDependencies(); } }
private static void analyzeClassName(InheritanceTree inheritanceTree, String className) { InputStream stream = ResourceList.getInstance( TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); if(stream==null){ throw new IllegalArgumentException("Failed to locate/load class: "+className); } logger.debug("Going to analyze: {}", className); analyzeClassStream(inheritanceTree, stream, false); }
private void initBranchMap() { // populate a temp branch distance map with initial data for all // branches(if they are not covered, 4 will be considered). tempBranchDistanceMap = new HashMap<>(); double maxBranchValue = 4.0; for (Branch b : BranchPool .getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches()) { tempBranchDistanceMap.put(b.getActualBranchId(), maxBranchValue); } }
private static boolean findTargetClass(String target) { if (ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(target)) { return true; } LoggingUtils.getEvoLogger().info("* Unknown class: " + target + ". Be sure its full qualifying name is correct and the classpath is properly set with '-projectCP'"); return false; }
public void addCastClass(String className, int depth) { try { Class<?> clazz = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(className); GenericClass castClazz = new GenericClass(clazz); addCastClass(castClazz.getWithWildcardTypes(), depth); } catch (ClassNotFoundException e) { // Ignore logger.debug("Error including cast class " + className + " because: " + e); } }
@Test public void testGatherClassWithInternalButNoAnonymous(){ Collection<String> classes = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllClasses( ClassPathHandler.getInstance().getTargetProjectClasspath(), basePrefix, true); Assert.assertTrue(classes.contains(Foo.class.getName())); Assert.assertTrue(""+Arrays.toString(classes.toArray()),classes.contains(Foo.InternalFooClass.class.getName())); Assert.assertEquals(3, classes.size());//there is also SubPFoo }
@Test public void testGatherClassWithInternalIncludingAnonymous(){ Collection<String> classes = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllClasses( ClassPathHandler.getInstance().getTargetProjectClasspath(), basePrefix, true, false); Assert.assertTrue(classes.contains(Foo.class.getName())); Assert.assertTrue(""+Arrays.toString(classes.toArray()),classes.contains(Foo.InternalFooClass.class.getName())); Assert.assertEquals(4, classes.size());//there is also SubPFoo }
private DefaultTestCase createTestCase5() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException { final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT() .loadClass(MIMEType.class.getName()); final Field memField = mimeTypeClass.getDeclaredField("MEM"); final Method toString = mimeTypeClass.getMethod("toString"); final TestCaseBuilder builder = new TestCaseBuilder(); VariableReference mIMEType0 = builder.appendStaticFieldStmt(memField); VariableReference string0 = builder.appendMethod(mIMEType0, toString); System.out.println("Test Case #5=" + builder.toCode()); return builder.getDefaultTestCase(); }
private DefaultTestCase createTestCase0() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException { TestCaseBuilder builder = new TestCaseBuilder(); final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT() .loadClass(MIMEType.class.getName()); final Field memField = mimeTypeClass.getField("MEM"); final Method toString = mimeTypeClass.getMethod("toString"); VariableReference mIMEType0 = builder.appendStaticFieldStmt(memField); builder.appendMethod(mIMEType0, toString); System.out.println("Test Case #0=" + builder.toCode()); return builder.getDefaultTestCase(); }
@Test public void testGatherClassNoInternal(){ Collection<String> classes = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllClasses( ClassPathHandler.getInstance().getTargetProjectClasspath(), basePrefix, false); Assert.assertTrue(classes.contains(Foo.class.getName())); Assert.assertTrue( ! classes.contains(Foo.InternalFooClass.class.getName())); Assert.assertEquals(2,classes.size()); //there is also SubPFoo }
@Test public void testStreamFromFolder() throws Exception{ File localFolder = new File("local_test_data"+File.separator+"aCpEntry"); Assert.assertTrue("ERROR: file "+localFolder+" should be available on local file system",localFolder.exists()); ClassPathHandler.getInstance().addElementToTargetProjectClassPath(localFolder.getAbsolutePath()); String className = "foo.ExternalClass"; InputStream stream = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); Assert.assertNotNull(stream); stream.close(); }
@Test public void testStreamFromJar() throws Exception{ File localJar = new File("local_test_data"+File.separator+"water-simulator.jar"); Assert.assertTrue("ERROR: file "+localJar+" should be avaialable on local file system",localJar.exists()); ClassPathHandler.getInstance().addElementToTargetProjectClassPath(localJar.getAbsolutePath()); String className = "simulator.DAWN"; InputStream stream = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); Assert.assertNotNull(stream); stream.close(); }
@Test public void testHasClass(){ Assert.assertTrue(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(Foo.class.getName())); Assert.assertTrue(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(SubPackageFoo.class.getName())); }
@Test public void testHandleUnKnownJarFile(){ File localJar = new File("local_test_data"+File.separator+"water-simulator.jar"); Assert.assertTrue("ERROR: file "+localJar+" should be avaialable on local file system",localJar.exists()); ClassPathHandler.getInstance().addElementToTargetProjectClassPath(localJar.getAbsolutePath()); String prefix = "simulator"; String target = prefix + ".DAWN"; Assert.assertTrue("Missing: "+target,ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(target)); Collection<String> classes = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllClasses( ClassPathHandler.getInstance().getTargetProjectClasspath(), prefix, false); Assert.assertTrue(classes.contains(target)); }