test.pl #1

  • //
  • guest/
  • robert_cowham/
  • perforce/
  • utils/
  • journal_tool/
  • test.pl
  • View
  • Commits
  • Open Download .zip Download (2 KB)
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.

# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

BEGIN { $| = 1; print "1..7\n"; }
END {print "not ok 1\n" unless $loaded;}
use P4::Journal;
$loaded = 1;
print "ok 1\n";

######################### End of black magic.

# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):

################################################################################
package MyJournal;
use strict;
use vars qw( @ISA );

@ISA = qw( P4::Journal );

sub new
{
	my $class = shift;
	my $self = new P4::Journal( @_ );
	bless( $self, $class );
	$self->{'Records'} = 0;
	$self->{'TestNo' } = 0;
	return $self;
}

sub Count()
{	
	my $self = shift;
	$self->{'Records'};
}

sub Reset()
{
	my $self = shift;
	$self->{'Records'} = 0;
}

sub UpdateProgress
{
    return;
}


sub ParseRecord
{
	my $self = shift;
	my $rec = shift;
	my $table = $rec->Table();
	$self->{'Records'}++;

	if ( $self->{ 'TestNo' } == 0 )
	{
	    if ( $table eq "db.counters" )
	    {
		my $name = $rec->Name();
		my $value = $rec->Value();

		print( ( $name eq "change" && $value == 1 ) ?
			"ok 3\n" :
			"not ok 3\n" );
		$self->{ 'TestNo' }++;
	    }
	}
	elsif ( $self->{ 'TestNo' } == 1 )
	{
	    if ( $table eq "db.user" )
	    {
		my $user = $rec->User();
		print( $user eq "tony" ? "ok 4\n" : "not ok 4\n" );
		$self->{ 'TestNo' }++;
	    }
	}
	elsif ( $self->{ 'TestNo' } == 2 )
	{ 
	    if ( $table eq "db.change" )
	    {
		my $change = $rec->Change();
		$change++;
		$rec->Change( $change );
		print( $rec->Change() == $change ? "ok 5\n" : "not ok 5\n" );
		$self->{ 'TestNo' }++;
	    }
	}
	elsif ( $self->{ 'TestNo' } == 3 )
	{ 
	    my $oldop = $rec->Operation();
	    $rec->Operation( "xx" );
	    print ( $rec->Operation() == "xx" ? "ok 6\n" : "not ok 6\n" );
	    $rec->Operation( $oldop );
	}
}

package main;

# Some basic sanity tests

# Can we instantiate objects?
my $journal = new MyJournal("test.jnl");
print( defined($journal) ? "ok 2\n" : "not ok 2\n");

# Can we parse files?
$journal->Parse();
print( $journal->Count() == 23 ? "ok 7\n" : "not ok 7\n");

# Change User Description Committed
#1 32178 Robert Cowham journal_tool