#! /usr/bin/env perl
##**************************************************************
##
## 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.
##
##**************************************************************

use CondorTest;
use CondorUtils;

use Cwd;
use Sys::Hostname;

$cmd = 'job_core_macros_java.cmd';
$testdesc =  'condor_submit macros - java U';
$testname = "job_core_macros_java";


my @skipped_output_lines = ( 3, 4, 5, 6 );
my @expected_output =
(
'foobar',
'0',
);

CondorTest::SetExpected(\@expected_output);
CondorTest::SetSkipped(\@skipped_output_lines);

$ExitSuccessBase = sub {
	my %info = @_;

	#$output = $info{"output"};

};

my @lines;

sub load_up_lines
{
	open(IN,"<submit_macros_java.out") || die "Can not open submit_macros_java.out: $!\n";
	while(<IN>)
	{
		CondorUtils::fullchomp($_);
		push @lines, $_;
	}
};

$success = sub
{
    my %args = @_;
	my $cluster = $args{"cluster"};
	my $home;
	my $workdir = getcwd();
	my $host = CondorTest::getFqdnHost();
	my $random;

	chdir;
	$home = getcwd;
	CondorTest::debug("My home is $home\n",1);
	CondorTest::debug("My host is $host\n",1);
	chdir($workdir);
	load_up_lines();
	foreach my $item ( @lines )
	{
		CondorTest::debug("ARG -$item-\n",1);
	}
	$random = $lines[4];
	CondorTest::debug("RANDOM is $random\n",1);

	if( $random < 2 )
	{
		die "Random value below range\n";
	}
	elsif( $random > 5 )
	{
		die "Random value above range\n";
	}
};

#CondorTest::RegisterExecute($testname, $execute);
#CondorTest::RegisterExitedSuccess( $testname, \&CondorTest::DefaultOutputTest );
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";
}

