コード例 #1
0
 private void addWitnessesLength1Seq(Sequence sequence) {
   for (CoverageAtom ca : Coverage.getCoveredAtoms(covClasses)) {
     Set<Sequence> seqs = covWitnessMap.get(ca);
     if (seqs == null) {
       seqs = new LinkedHashSet<Sequence>();
       covWitnessMap.put(ca, seqs);
     }
     seqs.add(sequence);
   }
 }
コード例 #2
0
  public void visitAfterStatement(ExecutableSequence sequence, int idx) {

    assert sequence.sequence.size() > 0;

    if (sequence.sequence.size() == 1) {
      addWitnessesLength1Seq(sequence.sequence);
      return;
    }

    assert sequence.sequence.size() > 1;

    // We've executed all but last statements.
    if (idx == sequence.sequence.size() - 2) {

      trues = new LinkedHashMap<Class<?>, int[]>();
      falses = new LinkedHashMap<Class<?>, int[]>();

      // Store covered branches.
      for (Class<?> cls : covClasses) {

        Coverage.initCoverage(cls);

        int[] trueBranches = Coverage.getTrueBranches(cls);
        int[] savedtrues = new int[trueBranches.length];
        System.arraycopy(trueBranches, 0, savedtrues, 0, trueBranches.length);
        trues.put(cls, savedtrues);

        int[] falseBranches = Coverage.getFalseBranches(cls);
        int[] savedfalses = new int[falseBranches.length];
        System.arraycopy(falseBranches, 0, savedfalses, 0, falseBranches.length);
        falses.put(cls, savedfalses);
      }
      return;
    }

    if (idx == sequence.sequence.size() - 1) {

      Set<Branch> newcov = new LinkedHashSet<Branch>();

      // Store covered branches.
      for (Class<?> cls : covClasses) {
        String clsname = cls.getName();
        Coverage.initCoverage(cls);

        int[] oldtrues = trues.get(cls);
        assert oldtrues != null;

        int[] oldfalses = falses.get(cls);
        assert oldfalses != null;

        int[] newtrues = Coverage.getTrueBranches(cls);
        assert oldtrues.length == newtrues.length;

        int[] newfalses = Coverage.getFalseBranches(cls);
        assert oldfalses.length == newfalses.length;

        assert oldtrues.length == oldfalses.length;
        assert oldfalses.length == newfalses.length;

        for (int i = 0; i < newtrues.length; i++) {
          if (newtrues[i] > oldtrues[i]) {
            newcov.add(
                (Branch)
                    Coverage.atomInfoToAtoms.get(
                        new Triple<String, Integer, Boolean>(clsname, i, true)));
          }
          if (newfalses[i] > oldfalses[i]) {
            newcov.add(
                (Branch)
                    Coverage.atomInfoToAtoms.get(
                        new Triple<String, Integer, Boolean>(clsname, i, false)));
          }
        }
      }

      // For each branch covered in the last statement, add the sequence to the
      // coverage witness map.
      for (Branch br : newcov) {
        Set<Sequence> seqs = covWitnessMap.get(br);
        if (seqs == null) {
          seqs = new LinkedHashSet<Sequence>();
          covWitnessMap.put(br, seqs);
        }
        seqs.add(sequence.sequence);
      }
    }
  }