File: MauveTests.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (123 lines) | stat: -rw-r--r-- 4,835 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2008 Fabien DUMINY (fduminy@jnode.org)

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.runner;

import gnu.testlet.runner.compare.HTMLComparisonWriter;
import gnu.testlet.runner.compare.ReportComparator;
import gnu.testlet.runner.compare.RunComparison;
import gnu.testlet.runner.compare.TextComparisonWriter;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Contains a test program for various functions like xml import/export of mauve results,
 * comparison of 2 mauve results with results saved in xml or html format.
 * 
 * @author fabien
 *
 */
public class MauveTests {
    
    public static void main(String[] args) throws IOException {
        RunResult runResult = createRunResult(1, 2, 0, 3, 1);
        System.out.println("=========================");
        
        System.out.println("\n--- writing XML file ---");
        File f = File.createTempFile("XMLReport", ".xml");
        f.deleteOnExit();
        new XMLReportWriter().write(runResult, f);
        System.out.println("\n--- COMPACT MODE:");
        new XMLReportWriter(true).write(runResult, new PrintWriter(System.out));
        System.out.println("\n--- NORMAL MODE:");
        new XMLReportWriter(false).write(runResult, new PrintWriter(System.out));
        HTMLGenerator.createReport(runResult, f.getParentFile());
        System.out.println("========================");
        
        System.out.println("\n--- parsing XML file ---");
        RunResult rr = new XMLReportParser().parse(f);
        System.out.println("rr = " + rr);
        System.out.println("========================");
        
        RunResult runResult2 = createRunResult(2, 2, 1, 3, 0);
        System.out.println("========================\n");
        
        ReportComparator c = new ReportComparator(runResult, runResult2);
        RunComparison comp = c.compare();
        
        System.out.println("\n--- comparison result in text ---");
        new TextComparisonWriter().write(comp, new PrintWriter(System.out));
        System.out.println("========================\n");
        
        System.out.println("\n--- comparison result in html ---");
        new HTMLComparisonWriter().write(comp, new PrintWriter(System.out));
        //new HTMLComparisonWriter().write(comp, new File("/tmp/HTMLComparison.html"));
        System.out.println("========================\n");
    }
    
    private static RunResult createRunResult(int runNumber, int nbTestsClass1, int nbPassed1,
            int nbTestsClass2, int nbPassed2) {
        String runName = "run" + runNumber;
        System.out.println("\n--- creating '" + runName + "' ---");        
        RunResult runResult = new RunResult(runName);
        
        runResult.setSystemProperty("name1", "value1");
        runResult.setSystemProperty("name2", "value2");

        PackageResult pkg = new PackageResult("package");
        runResult.add(pkg);

        ClassResult cls = new ClassResult("class1");
        pkg.add(cls);
        addTests(cls, "testA", nbTestsClass1, nbPassed1);

        cls = new ClassResult("class2");
        pkg.add(cls);
        addTests(cls, "testB", nbTestsClass2, nbPassed2);

        return runResult;
    }
    
    private static void addTests(ClassResult cls, String testPrefix, int nbTests, int nbPassed) {
        TestResult test;
        for (int i = 0; i < nbTests; i++) {
            test = new TestResult(testPrefix + i);

            CheckResult check;
            if (i < nbPassed) {
                check = new CheckResult(1, true);
                check.appendToLog("a log with\nmultiple lines");
                
                test.add(check);
            } else {
                check = new CheckResult(1, false);
                test.add(check);
                test.failed(new Exception("error" + i, new Exception("nested error")));
            }
            
            cls.add(test);
            
            System.out.print("Added " + test.getName());
            System.out.print("\t\t" + test.getCheckCount(true));
            System.out.println("\t\t" + check.getCheckPoint());
        }
    }
}