File: summary.php

package info (click to toggle)
ggcov 0.9-6
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,356 kB
  • ctags: 3,998
  • sloc: cpp: 17,068; sh: 12,380; ansic: 7,743; php: 1,644; perl: 1,509; makefile: 259; yacc: 23
file content (302 lines) | stat: -rw-r--r-- 8,141 bytes parent folder | download | duplicates (3)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
//
// ggcov - A GTK frontend for exploring gcov coverage data
// Copyright (c) 2005 Greg Banks <gnb@users.sourceforge.net>
// 
// This program 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 of the License, or
// (at your option) any later version.
// 
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// $Id: summary.php,v 1.10 2010-05-09 05:37:14 gnb Exp $
//

require_once 'ggcov/lib/cov.php';

class cov_summary_page extends cov_page
{
    var $env_;
    var $scope_ = null;
    var $file_name_ = null;
    var $function_ = null;
    var $func_file_name_ = null;
    var $stats_ = null;
    var $description_ = null;

    function cov_summary_page($e)
    {
	$this->env_ = $e;
    }

    function parse_args($get)
    {
	$cb = $this->env_->cb_;
	$file_index = $this->env_->file_index();
	$func_list = $this->env_->global_function_list();

	if (!empty($get['viewfile']))
	{
	    if (!array_key_exists('file', $get))
		$cb->fatal("No file name given");
	    $url = $this->env_->credirect('source.php',
				          'file', $get['file']);
	}
	else if (!empty($get['viewfunc']))
	{
	    if (!array_key_exists('function', $get))
		$cb->fatal("No function name given");
	    $a = preg_split('/:/', $get['function']);
	    if (count($a) != 2)
		$cb->fatal("Bad format for function name");
	    $url = $this->env_->credirect('source.php',
				          'function', $a[0],
				          'file', $a[1]);
	}

	// setup some defaults
	$this->scope_ = 'overall';

	foreach ($file_index as $f => $v) break;
	$this->file_name_ = $f;

	foreach ($func_list as $fn => $f) break;
	$this->function_ = preg_replace('/\[.*$/', '', $fn);
	$this->func_file_name_ = $f;

	// get scope from args
	if (array_key_exists('scope', $get))
	{
	    $this->scope_ = $get['scope'];

	    if (!cov_valid::scope($this->scope_))
		$cb->fatal("Invalid scope");
	}

	// verify scope and get further variables from args
	switch ($this->scope_)
	{

	case 'overall':
	    $this->stats_ = $this->env_->fetch('OS');
	    $this->description_ = 'Overall';
	    break;

	case 'file':
	    if (!array_key_exists('file', $get))
		$cb->fatal("No file name given");

	    $this->file_name_ = $get['file'];

	    if (!cov_valid::filename($this->file_name_))
		$cb->fatal("Invalid file name");

	    if (!array_key_exists($this->file_name_, $file_index))
		$cb->fatal("Unknown file");

	    $file_id = $file_index[$this->file_name_];
	    $this->stats_ = $this->env_->fetch("FS$file_id");
	    $this->description_ = "File $this->file_name_";
	    break;

	case 'function':
	    if (!array_key_exists('function', $get))
		$cb->fatal("No function name given");

	    $a = preg_split('/:/', $get['function']);
	    $this->function_ = $a[0];

	    if (!cov_valid::funcname($this->function_))
		$cb->fatal("Invalid function");

	    if (count($a) > 1)
	    {
		// optional filename, to disambiguate
		$this->func_file_name_ = $a[1];
	    }
	    else
	    {
		if (!array_key_exists($this->function_, $func_list))
		    $cb->fatal("Function unknown or ambiguous (try specifying filename too)");
		$this->func_file_name_ = $func_list[$this->function_];
	    }

	    if (!cov_valid::filename($this->func_file_name_))
		$cb->fatal("Invalid file name");

	    if (!array_key_exists($this->func_file_name_, $file_index))
		$cb->fatal("Unknown file");

	    $label = $this->function_ . ' [' . $this->func_file_name_ . ']';
	    if (!array_key_exists($this->function_, $func_list) &&
		!array_key_exists($label, $func_list))
		$cb->fatal("Function unknown");

	    $file_id = $file_index[$this->func_file_name_];
	    $file_function_index = $this->env_->fetch("FUI$file_id");
	    
	    $func_id = $file_function_index[$this->function_];
	    $this->stats_ = $this->env_->fetch("US$func_id");
	    $this->description_ = "Function $this->function_";
	    break;

	case 'range':	// TODO
	default:
	    $cb->fatal("Unknown scope");
	}
    }

    function title()
    {
	return "Summary: $this->description_";
    }

    function render_value_row($label, $values)
    {
	$numerator = $values[COV_COVERED] + $values[COV_PARTCOVERED];
	$denominator = $numerator + $values[COV_UNCOVERED];

	if ($denominator == 0)
	{
	    $frac = '0/0';
	    $pc = '';
	}
	else if ($values[COV_PARTCOVERED] == 0)
	{
	     $frac = sprintf('%lu/%lu', $numerator, $denominator);
	     $pc = sprintf('%.1f%%', $numerator * 100.0 / $denominator);
	}
	else
	{
	     $frac = sprintf('%lu+%lu/%lu',
			    $values[COV_COVERED],
			    $values[COV_PARTCOVERED],
			    $denominator);
	     $pc = sprintf('%.1f+%.1f%%',
			    $values[COV_COVERED] * 100.0 / $denominator,
			    $values[COV_PARTCOVERED] * 100.0 / $denominator);
	}

	$w = 150;
	$h = 20;
	$url = $this->env_->url('covbar.php',
		    'w', $w, 
		    'h', $h, 
		    'c', $values[COV_COVERED], 
		    'pc', $values[COV_PARTCOVERED], 
		    'uc', $values[COV_UNCOVERED]);

	echo <<<HTML
	    <tr>
	      <td align="right">$label</td>
	      <td>&nbsp;&nbsp;</td>
	      <td align="right">$frac</td>
	      <td>&nbsp;&nbsp;</td>
	      <td align="right">$pc</td>
	      <td>&nbsp;&nbsp;</td>
	      <td><img width="$w" height="$h" alt="bargraph" src="$url"></TD>
	    </tr>

HTML;
    }

    function render()
    {
	$cb = $this->env_->cb_;
	$file_index = $this->env_->file_index();
	$func_list = $this->env_->global_function_list();

	$self = basename($_SERVER['PHP_SELF']);
?>
	<form action="<?php echo $self; ?>" method="GET">
	<table border="0" cellpadding="5" cellspacing="0">
	  <tr>
	    <td colspan="3">
<?php $this->render_state_to_form('            '); ?>
	      <input name="scope" value="overall" type="radio"<?php echo ($this->scope_ == 'overall' ? ' checked' : ''); ?>>Overall
	    </td>
	  </tr>
	  <tr>
	    <td>
	      <input name="scope" value="file" type="radio"<?php echo ($this->scope_ == 'file' ? ' checked' : ''); ?>>Filename
	    </td>
	    <td>
	      <select name="file">
		<?php
		    foreach ($file_index as $fn => $id)
		    {
			$sel = ($fn == $this->file_name_ ? ' selected' : '');
			echo "<option$sel>$fn</option>\n";
		    }
		?>
	      </select>
	    </td>
	    <td>
	        <input type="submit" name="viewfile" value="View">
	    </td>
	  </tr>
	  <tr>
	    <td>
	      <input name="scope" value="function" type="radio"<?php echo ($this->scope_ == 'function' ? ' checked' : ''); ?>>Function
	    </td>
	    <td>
	      <select name="function">
		<?php
		    $sellab = $this->function_ . ' [' . $this->func_file_name_ . ']';
		    foreach ($func_list as $label => $f)
		    {
			$sel = ($label == $this->function_ ||
			        $label == $sellab ? ' selected' : '');
			$val = preg_replace('/ \[.*/', '', $label);
			echo "<option$sel value=\"$val:$f\">$label</option>\n";
		    }
		?>
	      </select>
	    </td>
	    <td>
	        <input type="submit" name="viewfunc" value="View">
	    </td>
	  </tr>
<!--
	  <tr>
	    <td>
	      <input name="scope" value="range" type="radio"<?php echo ($this->scope_ == 'range' ? ' checked' : ''); ?>>Range
	    </td>
	    <td colspan="2">
		TODO
	    </td>
	  </tr>
-->
	  <tr>
	    <td colspan="3">
	      <table border="0" cellspacing="0" cellpadding="2">
		<?php
		    $this->render_value_row('Lines', $this->stats_[1]);
		    $this->render_value_row('Functions', $this->stats_[2]);
		    $this->render_value_row('Calls', $this->stats_[3]);
		    $this->render_value_row('Branches', $this->stats_[4]);
		    $this->render_value_row('Blocks', $this->stats_[0]);
		?>
	      </table>
	    </td>
	  </tr>
	  <tr>
	    <td colspan="3">
	      <input type="submit" name="update" value="Update">
	    </td>
	  </tr>
	</table>
	</form>
<?php
    }
}

?>