#! /usr/bin/env perl
#testreq: personal
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

# CondorTest::JavaTimeout() requires Check::CondorLog, but is only
# called from CondorTest::JavaInitialize() is the test times out,
# so we don't see this failure on successful platforms.
use Check::CondorLog;
use CondorTest;

$cmd = 'job_core_err_java.cmd';
$testdesc =  'Condor_submit correctly uses error file - java U';
$testname = "job_core_err_java";

my $javainit = CondorTest::JavaInitialize($testname);
if($javainit == 0) {
	die "No java found\n";
}

$success = sub 
{
	my %info = @_;
	my $cluster = $info{"cluster"};
	my $job     = $info{"job"};
	die "Job should have failed due to Perl errors! $cluster.$job did not.\n";
};

# on windows we get Normal termination with return value 1
$failed = sub 
{
	my %info = @_;
	my $expectedsig = $info{"job"}+1;
	my $gotsig      = $info{"signal"};
	my $error 		= $info{"error"};
	CondorTest::debug("Good, an error as expected.\n",1);
	if(! -f $error )
	{
		die "Specified error file -$error- fails to exist\n";
	}
	else
	{
		CondorTest::debug("Error file $error created as expected\n",1);
		if( -s $error )
		{
			CondorTest::debug("Good file not empty!\n",1);
		}
		else
		{
			die "File was not expected to be empty!\n";
		}
	}
};

$died = sub 
{
	my %info = @_;
	my $expectedsig = $info{"job"}+1;
	my $gotsig      = $info{"signal"};
	my $error 		= $info{"error"};
	CondorTest::debug("Good, an error as expected.\n",1);
	if(! -f $error )
	{
		die "Specified error file -$error- fails to exist\n";
	}
	else
	{
		CondorTest::debug("Error file $error created as expected\n",1);
		if( -s $error )
		{
			CondorTest::debug("Good file not empty!\n",1);
		}
		else
		{
			die "File was not expected to be empty!\n";
		}
	}
};

CondorTest::RegisterExitedAbnormal( $testname, $died );
CondorTest::RegisterExitedFailure( $testname, $failed );
CondorTest::RegisterExitedSuccess( $testname, $success );

if( CondorTest::RunTest($testname, $cmd, 0) ) {
	CondorTest::debug("$testname: SUCCESS\n",1);
	exit(0);
} else {
	die "$testname: CondorTest::RunTest() failed\n";
}

