#! /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.
##
##**************************************************************

use CondorTest;
use CondorUtils;

$cmd = 'lib_userlog.cmd';
$testdesc =  'Test user log - write all events and expect to read the same';
$testname = "lib_userlog";


my @expected_output =
(
'Examine cluster 14',
'Job Submited.........',
'Job Executed.........',
'Job Execution Error.........',
'Job Checkpointed.........',
'Job Evicted.........',
'Job Terminated.........',
'Job Image Size Changed.........',
'Job Shadow Exception.........',
'Job Generic.........',
'Job ABORTED by user.........',
'Job Suspended.........',
'Job Unsuspended.........',
'Job Held.........',
'Job Released.........',
'Job Node Execute.........',
'Node Terminated .........',
'	Memory : requested 44, got 55, used 33',
'Post Script Terminated.........',
'Job Remote Error.........',
'Job Disconnected.........',
'Job Reconnected.........',
'Job Reconnect Failed.........',
'Grid Resource Up.........',
'Grid Resource Down.........',
'Job Submitted remotely.........',
'Job Ad Information.........',
'	JobStatus is 2',
'	BillString is "lorem ipsum dolor"',
'	BillInt is 1000',
'	BillBool is true',
'Job Status Unknown.........',
'Job Status Known.........',
'Job performing stage-in.........',
'Job performing stage-out.........',
'Attribute updated.........',
'PRE_SKIP event for DAGMan.........',
'Cluster submitted.........',
'Cluster removed.........',
'Factory paused.........',
'Factory resumed.........',
'DONE',
);

CondorTest::SetExpected(\@expected_output);

runcmd("rm -f local.log");
my $stats = system("./x_write_joblog.exe");
if($stats != 0)
{
	if( -e "./x_write_joblog.exe" )
	{
		die "Write Log... failed.....\n";
	}
	else
	{
		die "Build failed and x_write_joblog.exe does not exist\n";
	}
}

$ExitSuccess = sub {
};


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

