#! /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;

$cmd = 'job_core_args_java.cmd';
$testdesc =  'Arguments are preserved - java U';
$testname = "job_core_args_java";


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

	# Pull out requested environment values
	my $args   = $info{"arguments"};
	if(!defined($args)) {
		die "Can't pull arguments from submit file";
	}
	CondorUtils::fullchomp($args);
	my(@args_reqd) = split / /, $args;

	$output = $info{"output"};
	open(IN, "<$output" ) || die "Can't open $output: $!\n";

	# snarf up file in one huge chunk
	local $/;
	my $file = <IN>;
	close IN;

	# see which actual values were passed along
	my(@args_found) = split /\n/, $file;
	
	# Since we have to pass in the class we are always off by one in java
	if(scalar(@args_reqd) != (scalar(@args_found) + 1)) {
		die "Args reqd has " . scalar(@args_reqd) . " items but " .
		    "Args found has " . scalar(@args_found) . "items.\n";
	}
	my $i;
	for($i = 0; $i < scalar(@args_reqd); $i++) {
		CondorTest::debug("Checking $args_reqd[$i]...\n",1);
		if($args_reqd[$i + 1] ne $args_found[$i]) {
			die "Argument " . $args_reqd[$i + 1] . " was mangled into " .
			    $args_found[$i] . "\n";
		}
	}
};


CondorTest::RegisterExitedSuccess( $testname, $ExitSuccess );

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

