Crypt-License

 view release on metacpan or  search on metacpan

Notice/t/notice.t  view on Meta::CPAN

print "did not detect missing 'expires' hash key\nnot " if Crypt::License::Notice->check($ptr);
&OK_test;

# expiration is zero
$ptr->{expires} = 0;
print "did not detect zero 'expires' hash value\nnot " if Crypt::License::Notice->check($ptr);
&OK_test;

# expiration is greater than any check value
$ptr->{expires} = $expectedI[0] +1;
print "did not check expiration $ptr->{expires}\nnot " unless (@_ = Crypt::License::Notice->check($ptr));
&OK_test;

# unexpected notice tracking file found
print "unexpected tracking file $ptr->{TMPDIR}/$user.bln for $ptr->{expires}\nnot " if (-e "$ptr->{TMPDIR}/$user.bln");
&OK_test;

# unexpected notice found
print "created unexpected notice for $ptr->{expires}\nnot " if (-e $notice);
&OK_test;

# wrong number of check arguments
$tmp = 0;
++$tmp unless @_ == @expectedI;		# same number of arguments
print "wrong number of check arguments @_\nnot " if $tmp;
&OK_test;

$tmp = 0;
foreach(0..$#_) {
  ++$tmp unless $_[$_] == $expectedI[$_];
}
print "check times @_ do not agree with expected values\nnot " if $tmp;
&OK_test;

# detect illegal character
$tmp = $ptr->{INTERVALS};
$ptr->{INTERVALS} = '12x34';
eval{Crypt::License::Notice->check($ptr)};
print "did not detect illegal character string '$ptr->{INTERVALS}'\nnot " unless $@;

&OK_test;
$ptr->{INTERVALS} = $tmp;

#### PASS tests

# create tracking file and notice, test each epoch

$ptr->{INTERVALS} = '5,2';

my ($ctime, $prev);
foreach my $chk (5,2) {
# check that abutting timeout is NOT found
  &no_find($chk) unless $chk == 5;	# skip first back check
# check that overflow value is found
  $ptr->{expires} = $chk;
  $prev = &next_sec(time);
  Crypt::License::Notice->check($ptr);
  $_ = `/bin/cat $notice`;
  print "$chk, notice text does not match expected\nnot " unless $_ eq $expected_txt;
  &OK_test;
  $ctime = (stat("$ptr->{TMPDIR}/$user.bln"))[10];
  print "ctime $ctime is not now $prev\nnot " unless $ctime == $prev;
  &OK_test;
  unlink $notice;
}
# check 0 -- expired is not found ever
&no_find(0);
&no_find(0);

unlink "$ptr->{TMPDIR}/$user.bln" if ( -e "$ptr->{TMPDIR}/$user.bln");	# clean up

sub next_sec {
  my ($then) = @_;
  do { select(undef,undef,undef,0.1); $now = time } while ( $then == $now );	# wait for epoch
  $now;
}

sub OK_test {
  print "ok $test\n";
  ++$test;
}

sub no_find {
  my $chk = $_[0];
  $ptr->{expires} = $chk + 1;
  do { $tmp = &next_sec(time) } while ( $tmp < $prev + $ptr->{expires});
# wait for next epoch
  Crypt::License::Notice->check($ptr);
  print "$chk , unexpected notice found for check $ptr->{expires}\nnot " if (-e $notice);
  &OK_test;
  $ctime = (stat("$ptr->{TMPDIR}/$user.bln"))[10];
  print "ctime $ctime should be $prev\nnot " unless $ctime == $prev;
  &OK_test;
}



( run in 0.871 second using v1.01-cache-2.11-cpan-5511b514fd6 )