Unit test cleanups. Fixes tests so they don't leave left over entries in the database. Add a

check to ensure that row counts in most tables are unchanged from the start and end of the
tests. Refactor some code.
This commit is contained in:
Chris Morgan
2007-07-26 03:47:34 +00:00
committed by WineHQ
parent 0b979fee68
commit 19f6cbc156
16 changed files with 505 additions and 244 deletions

View File

@@ -5,6 +5,9 @@
/* TODO: test the rest of the classes we have */
require_once("path.php");
require_once(BASE.'include/incl.php');
error_reporting(E_ALL);
// disable emailing
@@ -14,6 +17,11 @@ if(!defined("DISABLE_EMAIL"))
// default to the tests being successful
$bTestSuccess = true;
// retrieve counts of each of the tables so we can check again
// at the end of the
$oStartingTableCounts = new table_counts();
include_once("test_user.php");
echo "\n";
@@ -35,6 +43,23 @@ include_once("test_appData.php");
echo "\n";
include_once("test_testData.php");
// retrieve counts of each of the tables after our tests
$oEndingTableCounts = new table_counts();
// see if our table counts match
if(!$oEndingTableCounts->IsEqual($oStartingTableCounts))
{
$bTestSuccess = false;
echo "\n\nStarting and ending table counts do not match\n";
$oStartingTableCounts->OutputSideBySide($oEndingTableCounts,
"Starting",
"Ending");
} else
{
echo "\n\nTable counts match from the start and end of the test suite.\n";
}
if($bTestSuccess == true)
{
echo "\nAll tests were successful\n";
@@ -42,4 +67,107 @@ if($bTestSuccess == true)
{
echo "\nSome test(s) failed!\n";
}
// keep track of the counts of various tables
class table_counts
{
// the tables we should count, set in the constructor
var $aTablesToCount;
// the counts of the tables
var $aTableCounts;
function table_counts()
{
$this->aTablesToCount = array('appBundle',
'appCategory',
'appComments',
'appData',
'appFamily',
'appMaintainers',
'appMonitors',
'appNotes',
'appVersion',
'appVotes',
'buglinks',
'distributions',
'prefs_list',
'testResults',
'user_list',
'user_privs',
'vendor');
$this->update_counts();
}
// update the count for each table
function update_counts()
{
$this->aTableCounts = array();
foreach($this->aTablesToCount as $sTable)
{
$sQuery = "select count(*) as cnt from ?;";
$hResult = query_parameters($sQuery, $sTable);
$oRow = mysql_fetch_object($hResult);
$this->aTableCounts[] = $oRow->cnt;
}
}
// returns 'true' if equal, 'false' if not
function IsEqual($oTableCounts)
{
$iIndex = 0;
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
if($this->aTableCounts[$iIndex] != $oTableCounts->aTableCounts[$iIndex])
{
return false;
}
}
return true;
}
function OutputSideBySide($oTableCounts, $sFirstTableCountName,
$sSecondTableCountName)
{
$iIndex = 0;
// output the header
printf("%20s%20s%20s\n",
"Table name",
$sFirstTableCountName,
$sSecondTableCountName);
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
printf("%20s%20s%20s",
$this->aTablesToCount[$iIndex],
$this->aTableCounts[$iIndex],
$oTableCounts->aTableCounts[$iIndex]);
if($this->aTableCounts[$iIndex] != $oTableCounts->aTableCounts[$iIndex])
{
echo " <-- Mismatch";
}
echo "\n";
}
}
function output()
{
$iIndex = 0;
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
$sTableName = $this->aTablesToCount[$iIndex];
$iTableCount = $this->aTableCounts[$iIndex];
echo "$sTableName count of $iTableCount\n";
}
}
}
?>