#!/usr/bin/perl -X
use File::Basename;
use File::Spec;
require '/var/www/EventStaffAPI/UnitTest/UnitTest_Globals.pl';


$fpath = File::Spec->rel2abs($0);
$error=0;
$path = dirname($fpath);
$http = "http://127.0.0.1/".substr($path,8)."/../API.cgi";

$HTTP=$http;

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<api>
<api_action>cron_reset_unit_test_details</api_action>
<action_content>
</action_content>
</api>
";

$receivedHash = DoHTTPCall($xml);


##Get Test List
open(INFOLDER,"ls -1 $path |");
while($file = <INFOLDER>)
{
 chomp($file);

 if(($file ne "RunTests.pl" && $file ne "UnitTest_Globals.pl") && substr($file,-3) eq ".pl")
 {
  #print "$file\n";
  $cmd = "perl $path/$file \"$http\" 1 2>&1";
  $cmd = "perl $path/$file \"$http\"  2>&1";
  print "||$cmd||\n";
  $ret = `$cmd`;
  if($? == 0)
  {
   print "$file || \033[22;32mOK\033[01;0m\n";
  }
  else 
  {
   chomp($ret);
   print "$file || \033[22;31mERROR\033[01;0m || $ret\n";
   $error++;
  }
 }
}
close(INFOLDER);


exit($error);
