Package net.sourceforge.cobertura.coveragedata

Examples of net.sourceforge.cobertura.coveragedata.ProjectData


        this.dataFile = dataFile;
        if (forInstrumenting) {
            if (dataFile.exists()) {
                projectData = CoverageDataFileHandler.loadCoverageData(dataFile);
            } else {
                projectData = new ProjectData();
            }
        }
    }
View Full Code Here


        cacheDir.mkdir();
        coverageDirectoryReader = cdr;
        calculator = new PackageCoverageCalculator(cdr.getIndexedPackageData()
                .values(), cacheDir );

        ProjectData projectData = getGlobalData();

        if (projectData == null) {
            throw new RuntimeException(
                    "Unable to read coverage data from file "
                            + coverageDataFile.getCanonicalPath());
View Full Code Here

        return result;
    }

    ProjectData diffProjects(ProjectData larger, ProjectData smaller) {
        ProjectData result = new ProjectData();
        for (Object o : larger.getClasses()) {
            ClassData lcd = (ClassData) o;
            ClassData scd = (ClassData) smaller.getClassData(lcd.getName());
            result.addClassData(diffClasses(lcd, scd));
        }
        Set<String> largerNames = classNames(larger);
        Set<String> smallerNames = classNames(smaller);
        smallerNames.removeAll(largerNames);
        if (smallerNames.size() > 0) {
View Full Code Here

        ClassData cd = data.getClassData(className);
        cd.touchSwitch(lineNumber, 0, switchNumber, 1);
    }

    ProjectData buildBaseProjectData() {
        ProjectData data = new ProjectData();
        addSomeStuff(data, "foo", 3);
        addSomeStuff(data, "bar", 3);
        touchAJump(data, "foo", 1, true);
        touchASwitch(data, "bar", 2, 1);
        touchASwitch(data, "bar", 2, -1);
View Full Code Here

        return data;
    }

    @Test
    public void testDiff() {
        ProjectData one = buildBaseProjectData();
        ProjectData two = buildBaseProjectData();
        addSomeStuff(two, "foo", 2);
        touchAJump(two, "foo", 1, true);
        touchAJump(two, "foo", 1, false);
        touchASwitch(two, "bar", 2, 2);
        touchASwitch(two, "bar", 2, -1);
        addSomeStuff(two, "baz", 8);

        // sanity check on the raw data.
        assertEquals(1, ((JumpData) one.getClassData("foo").getLineCoverage(1)
                .getConditionData(0)).getTrueHits());
        assertEquals(0, ((JumpData) one.getClassData("foo").getLineCoverage(1)
                .getConditionData(0)).getFalseHits());
        assertEquals(2, ((JumpData) two.getClassData("foo").getLineCoverage(1)
                .getConditionData(0)).getTrueHits());
        assertEquals(1, ((JumpData) two.getClassData("foo").getLineCoverage(1)
                .getConditionData(0)).getFalseHits());

        assertEquals(1, ((SwitchData) one.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getDefaultHits());
        assertEquals(0, ((SwitchData) one.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getHits(0));
        assertEquals(1, ((SwitchData) one.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getHits(1));
        // assertEquals( 0, ((SwitchData)
        // one.getClassData("bar").getLineCoverage( 2 ).getConditionData( 0 )
        // ).getHits( 2 ));
        assertEquals(2, ((SwitchData) two.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getDefaultHits());
        assertEquals(0, ((SwitchData) two.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getHits(0));
        assertEquals(1, ((SwitchData) two.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getHits(1));
        assertEquals(1, ((SwitchData) two.getClassData("bar")
                .getLineCoverage(2).getConditionData(0)).getHits(2));

        ProjectDataDifferenceCalculator calc = new ProjectDataDifferenceCalculator(
                two, one);
        ProjectData diff = calc.getDifference();
        assertSame(calc.getLarger(), two);
        assertSame(calc.getSmaller(), one);
        ClassData foo = diff.getClassData("foo");
        assertEquals(3, foo.getLines().size());
        for (int i = 0; i < 2; i++) {
            LineData x = foo.getLineCoverage(i);
            assertEquals(x.getHits(), 1);
            assertEquals(x.hasBranch(), i == 1);
            if (x.hasBranch()) {
                JumpData jd = (JumpData) x.getConditionData(0);
                assertEquals(jd.getTrueHits(), 1);
                assertEquals(jd.getFalseHits(), 1);
            }
        }
        assertEquals(foo.getLineCoverage(2).getHits(), 0);
        ClassData bar = diff.getClassData("bar");
        assertEquals(3, bar.getLines().size());
        for (int i = 0; i < 3; i++) {
            LineData x = bar.getLineCoverage(i);
            assertEquals(x.getHits(), 0);
            assertEquals(x.hasBranch(), i == 2, "Switches for " + i);
            if (x.hasBranch()) {
                SwitchData sd = (SwitchData) x.getConditionData(0);
                assertEquals(1, sd.getDefaultHits());
                assertEquals(0, sd.getHits(0));
                assertEquals(0, sd.getHits(1));
                assertEquals(1, sd.getHits(2));

            }
        }
        ClassData baz = diff.getClassData("baz");
        assertEquals(8, baz.getLines().size());
        for (int i = 0; i < 8; i++) {
            LineData x = baz.getLineCoverage(i);
            assertEquals(x.getHits(), 1);
            assertFalse(x.hasBranch());
View Full Code Here

        assertEquals(calc.getErrors().size(), 2);
    }

    @Test
    public void testDisappearingClasses() {
        ProjectData small = buildBaseProjectData();
        ProjectData large = buildBaseProjectData();
        addSomeStuff(large, "baz", 3); // ok.
        addSomeStuff(small, "zoop", 3); // not decent behavior.
        touchAJump(small, "zoop", 8, true);
        touchASwitch(small, "zoop", 9, 0);
View Full Code Here

    }

    @Test
    public void testDisappearingLines() {
        ProjectData small = buildBaseProjectData();
        ProjectData large = buildBaseProjectData();
        addSomeStuff(large, "baz", 3);
        addSomeStuff(small, "baz", 5); // not expected behavior.
        ProjectDataDifferenceCalculator calc = new ProjectDataDifferenceCalculator(
                large, small);
        System.out.println("Errors: " + calc.getErrors());
View Full Code Here

        dissappearingJump(true);
        dissappearingJump(false);
    }

    void dissappearingJump(boolean b) {
        ProjectData small = buildBaseProjectData();
        ProjectData large = buildBaseProjectData();
        touchAJump(small, "foo", 1, b);
        ProjectDataDifferenceCalculator calc = new ProjectDataDifferenceCalculator(
                large, small);
        assertEquals(calc.getErrors().size(), 1);
        assertTrue(calc.getErrors().get(0).indexOf("Jump") > -1);
View Full Code Here

        assertTrue(calc.getErrors().get(0).indexOf("false") > 0);
    }

    @Test
    void testDisappearingSwitches() {
        ProjectData large = buildBaseProjectData();
        ProjectData small = buildBaseProjectData();
        small = buildBaseProjectData();
        touchASwitch(small, "bar", 2, 0);
        touchASwitch(small, "bar", 2, -1);
        touchASwitch(small, "bar", 1, 1);
        ProjectDataDifferenceCalculator calc = new ProjectDataDifferenceCalculator(
View Full Code Here

    }

    void loadSpeciallyNamedCoverageFile(File x) {
        Object[] pair = parseNameAndIndexFromFileName(x.getName());
        Integer index = Integer.valueOf((String) pair[1]);
        ProjectData data = readCoverageFile(x);
        PackageAndProjectData ppd = new PackageAndProjectData(data,
                (String) pair[0], x);
        indexedPackageData.put(index, ppd);
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.cobertura.coveragedata.ProjectData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.