<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PS1-MOPS Testing System: Display Detailed Test Results</title>

<link href="default-style.css" rel="stylesheet" type="text/css" />

</head>

<body>
<& default-header.mas &>

<p/>

<?php # Use a table as a container. ?>

<table width="90%" border="0" align="center" cellpadding="6" cellspacing="6" bgcolor="#EEEEEE">
  <tr valign="top"><td><h2>

<%perl>
if($ARGS{type} eq 'unit'){
    print "Unit Testing Results";
}
elsif($ARGS{type} eq 'sim'){
    print "Simulation Testing Results";
}
else {
    print "Invalid testing type";
}
</%perl>
  
  </h2></td></tr>
  <tr valign="top">

<%perl>

# Connect to the database.
our $dbh=$m->comp('mysql-connect.mas');

</%perl>

<td>
<table border="1" cellpadding="3" cellspacing="3">

<%perl>

# Report unit testing results.
if($ARGS{type} eq "unit"){

    print "<th>ID</th>
	   <th>Module</th>
	   <th>Test</th>
	   <th>Wall [s]</th>
	   <th>CPU [s]</th>
	   <th>Result</th>";
    get_detailed_unit_testing_results($ARGS{id});
}
elsif ($ARGS{type} eq "sim"){
    print "<th>ID</th>
	   <th>Name</th>
	   <th>Wall [s]</th>
	   <th>CPU [s]</th>
	   <th>Result</th>";
	
    get_detailed_sim_testing_results($ARGS{id});
}
else {
    print "Invalid testing type.";
}

</%perl>

</table></td></tr>
  <tr valign="top">
    <td colspan="2"><span class="green_colored">Green-colored results</span> indicate 100% successful Test Runs. <span class="red_colored">Red-colored results</span> indicate less than 100% successful Test Runs.</td>
    </tr>
</table>

<p/>

<& default-footer.mas &>

</body>
</html>

<%perl>

# Print rows and columns of unit testing results.
sub get_detailed_unit_testing_results 
{
    my ($test_run)=@_;
    my $sql="SELECT * FROM unit_test_results where test_run=" . $test_run;
    my $sth=$dbh->prepare($sql);
    my $result=$sth->execute();

    my $num=1;

    while(my $row=$sth->fetchrow_hashref()){
        print "<tr valign=\"top\">";
	print "<td>" . $num . "</td>"; $num++;
        print "<td>" . $row->{id} . "</td>";
        print "<td>". $row->{module} . "</td>";
        print "<td>" . $row->{test} . "</td>";
        print "<td>" . $row->{wall} . "</td>";
	print "<td>" . $row->{cpu} . "</td>";

	if($row->{result} eq 'P'){
	    print "<td bgcolor=\"#339900\">PASS</td>";
	}
	else {
	    print "<td bgcolor=\"#990000\">FAIL</td>";
	}
	    print "</tr>";
	}
}

# Print rows and columns of simulation testing results.
sub get_detailed_sim_testing_results 
{
    my ($test_run)=@_;
    my $sql="SELECT * FROM sim_test_results where test_run=" . $test_run;
    my $sth=$dbh->prepare($sql);
    my $result=$sth->execute();

    while(my $row=$sth->fetchrow_hashref()){
        print "<tr valign=\"top\">";
        print "<td>" . $row->{id} . "</td>";
        print "<td>". $row->{name} . "</td>";
        print "<td>" . $row->{wall} . "</td>";
        print "<td>" . $row->{cpu} . "</td>";

	if($row->{result} eq 'P'){
	    print "<td bgcolor=\"#339900\">PASS</td>";
	}
	else {
	    print "<td bgcolor=\"#990000\">FAIL</td>";
	}
	    print "</tr>";
	}
}

</%perl>

<?php

# Print rows and columns of unit testing results.
function get_detailed_unit_testing_results
{
	$sql="SELECT * FROM unit_test_results where test_run=".$test_run;
	$result = mysql_query($sql) or die(mysql_error());
	$row=mysql_fetch_array($result);

	while($row = mysql_fetch_array($result)){
		echo"<tr valign=\"top\">";
		echo "<td>".$row['id']."</td>";
		echo "<td>".$row['module']."</td>";
		echo "<td>".$row['test']."</td>";
		echo "<td>".$row['wall']."</td>";
		echo "<td>".$row['cpu']."</td>";
		if($row['result'] === 'P'){
			echo "<td bgcolor=\"#339900\">PASS</td>";
		}
		else {
		 	echo "<td bgcolor=\"#990000\">FAIL</td>";
		}
		echo"</tr>";
	}
}

# Print rows and columns of simulation testing results.
function get_detailed_sim_testing_results ($test_run) 
{
	$sql="SELECT * FROM sim_test_results where test_run=".$test_run;
	$result = mysql_query($sql) or die(mysql_error());
	$row=mysql_fetch_array($result);

	while($row = mysql_fetch_array($result)){
		echo"<tr valign=\"top\">";
		echo "<td>".$row['id']."</td>";
		echo "<td>".$row['name']."</td>";
		echo "<td>".$row['wall']."</td>";
		echo "<td>".$row['cpu']."</td>";
		if($row['result'] === 'P'){
			echo "<td bgcolor=\"#339900\">PASS</td>";
		}
		else {
		 	echo "<td bgcolor=\"#990000\">FAIL</td>";
		}
		echo"</tr>";
	}
}
