Package net.sourceforge.cobertura.coveragedata

Examples of net.sourceforge.cobertura.coveragedata.LineData


                                children.put(String.valueOf(o),
                                        utility.format(x.getChild(o)));
                            }
                            result.put("children", children);
                        } else {
                            LineData ld = (LineData) x.getData();
                            LineData dld = (LineData) x.getSamePackageData();
                            result.put("hits", ld.getHits());
                            result.put("branchHits", hitArray(ld));
                            long diagHits = 0;
                            Collection<Long> diagBranchHits = new ArrayList<Long>();
                            if (dld != null) {
                                diagHits = dld.getHits();
                                diagBranchHits = hitArray(dld);
                            }
                            result.put("samePackageHits", diagHits);
                            result.put("samePackageBranchHits", diagBranchHits);
                        }
View Full Code Here


        buildLineDataHelpers();
    }

    void buildLineDataHelpers() {
        for (LineData ld : getData().getLines()) {
            LineData dld = null;
            if (getParent().getSamePackageData() != null) {
                dld = getParent().getSamePackageData().getLineCoverage(
                        ld.getLineNumber());
            }
            addChild(getFactory().makeLineDataPair(ld, dld, this));
View Full Code Here

            System.out.println(mkey + " " + cdp.getChild(mkey).getChildKeys());
        }
        for (String x : cdp.getData().getMethodNamesAndDescriptors()) {
            ArrayList lineNumbers = new ArrayList();
            for (Object o : cdp.getData().getLines(x)) {
                LineData ld = (LineData) o;
                lineNumbers.add(ld.getLineNumber());
            }
            System.out.println(x + ": " + lineNumbers);
        }

    }
View Full Code Here

    }

    ClassData diffClasses(ClassData larger, ClassData smaller) {
        ClassData result = new ClassData(larger.getName());
        for (Object o : larger.getLines()) {
            LineData lld = (LineData) o;
            long afterHits = lld.getHits();
            long prevHits = 0;
            long prevConditions = 0;
            if (smaller != null) {
                LineData sld = smaller.getLineCoverage(lld.getLineNumber());
                if (sld != null) {
                    prevHits = sld.getHits();
                    prevConditions = sld.getConditionSize();
                }
            }
            int diffHits = (int) (afterHits - prevHits);
            result.addLine(lld.getLineNumber(), lld.getMethodName(),
                    lld.getMethodDescriptor());
            if (diffHits > 0) {
                result.touch(lld.getLineNumber(), diffHits);
            }
            if (diffHits < 0) {
                errors.add("Coverage decreased on line " + lld.getLineNumber()
                        + " of " + larger.getName());
            }
            if (prevConditions > lld.getConditionSize()) {
                errors.add("Jump or Switch disappeared on line "
                        + lld.getLineNumber() + " of " + larger.getName());
            }
            for (int i = 0; i < lld.getConditionSize(); i++) {
                Object cd = lld.getConditionData(i);
                if (cd instanceof JumpData) {
                    JumpData ljd = (JumpData) cd;
                    result.addLineJump(lld.getLineNumber(), i);
                    long prevTrue = 0;
                    long prevFalse = 0;
                    if (smaller != null) {
                        LineData sld = smaller.getLineCoverage(lld
                                .getLineNumber());
                        if (sld != null) {
                            JumpData sjd = (JumpData) sld.getConditionData(i);
                            if (sjd != null) {
                                prevTrue = sjd.getTrueHits();
                                prevFalse = sjd.getFalseHits();
                            } else {
                                errors.add("Somehow, JumpData null at condition "
                                        + i + " on line " + lld.getLineNumber());
                            }
                        }

                    }
                    long diffTrueHits = ljd.getTrueHits() - prevTrue;
                    long diffFalseHits = ljd.getFalseHits() - prevFalse;
                    if (diffTrueHits > 0) {
                        result.touchJump(lld.getLineNumber(), i, true,
                                (int) diffTrueHits);
                    }
                    if (diffFalseHits > 0) {
                        result.touchJump(lld.getLineNumber(), i, false,
                                (int) diffFalseHits);
                    }
                    if (diffFalseHits < 0 || diffTrueHits < 0) {
                        errors.add("Jump coverage on " + result.getName() + ":"
                                + lld.getLineNumber() + ":" + i + " decreased:"
                                + "true from " + prevTrue + " by "
                                + diffTrueHits + ", false from " + prevFalse
                                + " by " + diffFalseHits);
                    }
                } else if (cd instanceof SwitchData) {
                    SwitchData lsd = (SwitchData) cd;
                    result.addLineSwitch(lld.getLineNumber(), i, 0, 0, lsd.getMaxBranches());
                    long[] prevBranchHits = new long[lsd
                            .getNumberOfValidBranches() - 1];
                    long prevDefaultHits = 0;
                    if (smaller != null) {
                        LineData sld = smaller.getLineCoverage(lld
                                .getLineNumber());
                        if (sld != null) {
                            SwitchData ssd = (SwitchData) sld
                                    .getConditionData(i);
                            if (ssd != null) {
                                for (int j = 0; j < prevBranchHits.length; j++) {
                                    // returns -1 on an error condition.
                                    // probably never happens in normal
View Full Code Here

    Set<Integer> lineNumbers(ClassData data) {
        LinkedHashSet<Integer> result = new LinkedHashSet<Integer>();
        if (data != null) {
            for (Object o : data.getLines()) {
                LineData ld = (LineData) o;
                result.add(ld.getLineNumber());
            }
        }
        return result;
    }
View Full Code Here

        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());
        }
        assertEquals(0, calc.errors.size());
        addSomeStuff(one, "baz", 2);
        // one is supposed to be smaller.
        addSomeStuff(one, "baz", 2); // one is supposed to be smaller.
View Full Code Here

        lines.addAll((Collection) classData.getLines(methodNameAndDescriptor));
        Collections.sort(this.lines, new Comparator<CoverageData>() {

            @Override
            public int compare(CoverageData o1, CoverageData o2) {
                LineData l1 = (LineData) o1;
                LineData l2 = (LineData) o2;
                Integer i1 = new Integer(l1.getLineNumber());
                Integer i2 = new Integer(l2.getLineNumber());
                return i1.compareTo(i2);
            }
          

        });
View Full Code Here

    }

    public int[] getFirstAndLastLinesForMethod() {
        int[] result = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE };
        for (CoverageData cd : lines) {
            LineData ld = (LineData) cd;
            result[0] = Math.min(result[0], ld.getLineNumber());
            result[1] = Math.max(result[1], ld.getLineNumber());
        }
        return result;
    }
View Full Code Here

TOP

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

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.