summaryrefslogtreecommitdiff
path: root/source4/selftest/output/html.pm
blob: 5a7ee15af207be3c9a55bfaa0adf904bf2b5fb68 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl

package output::html;
use Exporter;
@ISA = qw(Exporter);

use strict;
use warnings;

sub new($$$$) {
	my ($class, $dirname, $statistics) = @_;
	my $self = { 
		dirname => $dirname,
		statistics => $statistics,
		active_test => undef,
		msg => ""
	};

	link("selftest/output/testresults.css", "$dirname/testresults.css");

	open(INDEX, ">$dirname/index.html");

	print INDEX "<html lang=\"en\">\n";
	print INDEX "<head>\n";
	print INDEX "  <title>Samba Testsuite Run</title>\n";
	print INDEX "  <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
	print INDEX "</head>\n";
	print INDEX "<body>\n";
	print INDEX "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
	print INDEX "  <tr><td class=\"title\">Samba Testsuite Run</td></tr>\n";
	print INDEX "  <tr><td>\n";
	print INDEX "  <center>";
	print INDEX "  <table>\n";
	print INDEX "  <tr>\n";
	print INDEX "    <td class=\"tableHead\">Test</td>\n";
	print INDEX "    <td class=\"tableHead\">Environment</td>\n";
	print INDEX "    <td class=\"tableHead\">Result</td>\n";
	print INDEX "    <td class=\"tableHead\">Duration</td>\n";
	print INDEX "  </tr>\n";

	bless($self, $class);
}

sub output_msg($$$);

sub start_testsuite($$)
{
	my ($self, $state) = @_;

	$state->{HTMLFILE} = "$state->{NAME}.html";
	$state->{HTMLFILE} =~ s/[:\t\n \/]/_/g;

	open(TEST, ">$self->{dirname}/$state->{HTMLFILE}") or die("Unable to open $state->{HTMLFILE} for writing");

	my $title = "Test Results for $state->{NAME}";

	print TEST "<html lang=\"en\">\n";
	print TEST "<head>\n";
	print TEST "  <title>$title</title>\n";
	print TEST "  <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
	print TEST "</head>\n";
	print TEST "<body>\n";
	print TEST "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
	print TEST "  <tr><td class=\"title\">$title</td></tr>\n";
	print TEST "  <tr><td>\n";
	print TEST "  <table>\n";
}

sub output_msg($$$)
{
	my ($self, $state, $output) = @_;

	unless (defined($self->{active_test})) {
		print TEST "$output<br/>";
	} else {
		$self->{msg} .= "$output<br/>";
	}
}

sub end_testsuite($$$$$)
{
	my ($self, $state, $expected_ret, $ret, $envlog) = @_;

	print TEST "</table>\n";
	print TEST "</body>\n";
	print TEST "</html>\n";

	close(TEST);

	print INDEX "<tr><td class=\"testSuite\"><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td><td class=\"environment\">$state->{ENVNAME}</td>";

	if ($ret == $expected_ret) {
		print INDEX "<td class=\"resultOk\">OK</td>";
	} else {
		print INDEX "<td class=\"resultFailure\">FAIL</td>";
	}

	print INDEX "<td class=\"duration\">" . (time() - $state->{START_TIME}) . "</td>\n";

	print INDEX "</tr>\n";
}

sub start_test($$$)
{
	my ($self, $state, $testname) = @_;

	$self->{active_test} = $testname;
	$self->{msg} = "";
}

sub end_test($$$$$)
{
	my ($self, $state, $testname, $result, $unexpected) = @_;

	print TEST "<tr>";

	if ($result eq "skip") {
		print TEST "<td class=\"outputSkipped\">\n";
	} elsif ($unexpected) {
		print TEST "<td class=\"outputFailure\">\n";
	} else {
		print TEST "<td class=\"outputOk\">\n";
	}

	print TEST "<h3>$testname</h3>\n";

	print TEST $self->{msg};

	print TEST "</td></tr>\n";

	$self->{active_test} = undef;
}

sub summary($)
{
	my ($self) = @_;

	print INDEX "</table>\n";
	print INDEX "</center>\n";
	print INDEX "</td></tr>\n";
	print INDEX "</table>\n";
	print INDEX "</body>\n";
	print INDEX "</html>\n";
	close(INDEX);
}

sub missing_env($$$)
{
	my ($self, $name, $envname) = @_;

	print "FAIL: $name (ENV[$envname] not available!)\n";
}

sub skip_testsuite($$)
{
	my ($self, $name) = @_;

	print INDEX "<tr><td class=\"testSuite\">$name</td><td class=\"environmentSkipped\">N/A</td><td class=\"resultSkipped\">SKIPPED</td><td class=\"durationSkipped\">N/A</td></tr>\n";
}

1;