summaryrefslogtreecommitdiff
path: root/tests/sha1sum/sample-vec
blob: df0ae9d34411190d1b4dec4c24c70645e41eaf30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh

: ${PERL=perl}
: ${srcdir=.}

case "$PERL" in
  *'missing perl')
  echo 1>&2 "$0: configure didn't find a usable version of Perl, so can't run this test"
  exit 77
  ;;
esac

exec $PERL -w -I$srcdir/.. -MFetish -- - <<\EOF
require 5.003;
use strict;

(my $program_name = $0) =~ s|.*/||;

# Turn off localisation of executable's ouput.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;

my @Tests =
    (
     ['1', {IN=> {f=> '0 1 ^'}},
			{OUT=>'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'}],

     ['2', {IN=> {f=> '5 0 2 1 2 1 2 ^'}},
			{OUT=>'3CDF2936DA2FC556BFA533AB1EB59CE710AC80E5'}],

     ['3', {IN=> {f=> '5 0 1 3 4 4 4 ^'}},
			{OUT=>'19C1E2048FA7393CFBF2D310AD8209EC11D996E5'}],
     ['4', {IN=> {f=> '7 0 4 3 4 4 1 4 4 ^'}},
			{OUT=>'CA775D8C80FAA6F87FA62BECA6CA6089D63B56E5'}],
    );

sub binary_expand ($$)
{
  my ($test_name, $line) = @_;
  my @a = split ' ', $line;
  @a >= 2 or die "$test_name: too few args";
  my $n = shift @a;
  my $b = shift @a;
  my $caret = pop @a;
  $caret eq '^' or die "$test_name: missing `^'";
  $b eq '1' || $b eq '0' or die "$test_name: bad `b'=$b\n";
  my $n_bad = @a;
  @a == $n or
    die "$test_name: wrong number of args (expected $n, found $n_bad)\n";
  my $bit_string = '';
  foreach my $a (@a)
    {
      $bit_string .= $b x $a;
      $b = 1 - $b;
    }
  my $t = pack ("B*", $bit_string);
  # print "$bit_string\n $t\n";
  return $t;
}

my $t;
foreach $t (@Tests)
  {
    # Expand each input.
    my $in = $t->[1]->{IN};
    $in->{f} = binary_expand $t->[0], $in->{f};

    # Convert each expected output string to lower case, and append "  f\n".
    my $h = $t->[2];
    $h->{OUT} = lc $h->{OUT} . "  f\n";

    # Insert the `--text' argument for each test.
    #splice @$t, 1, 0, '--text';
  }

my $save_temps = $ENV{DEBUG};
my $verbose = $ENV{VERBOSE};

my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
exit $fail;
EOF