Add version numbers on some modules we use.
[openssl.git] / test / recipes / 10-test_bn.t
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Math::BigInt;
7
8 use Test::More 0.96;
9 use OpenSSL::Test qw/:DEFAULT top_file/;
10
11 setup("test_bn");
12
13 plan tests => 3;
14
15 require_ok(top_file("test","recipes","bc.pl"));
16
17 my $testresults = "tmp.bntest";
18 my $init = ok(run(test(["bntest"], stdout => $testresults)), 'initialize');
19
20  SKIP: {
21      skip "Initializing failed, skipping", 1 if !$init;
22
23      subtest 'Checking the bn results' => sub {
24          my @lines = ();
25          if (open DATA, $testresults) {
26              @lines = <DATA>;
27              close DATA;
28          }
29          chomp(@lines);
30
31          plan tests => scalar grep(/^print /, @lines);
32
33          my $l = "";
34
35          while (scalar @lines) {
36              $l = shift @lines;
37
38              last if $l =~ /^print /;
39          }
40
41          while (1) {
42              $l =~ s/^print "//;
43              $l =~ s/\\n"//;
44              my $t = $l;
45              my @operations = ();
46
47              $l = undef;
48              while (scalar @lines) {
49                  $l = shift @lines;
50
51                  last if $l =~ /^print /;
52                  push @operations, $l;
53                  $l = undef;
54              }
55
56              ok(check_operations(@operations), "verify $t");
57
58              last unless $l;
59          }
60      };
61 }
62
63 sub check_operations {
64     my $failcount = 0;
65
66     foreach my $line (@_) {
67         my $result = calc(split /\s+/, $line);
68
69         if ($result ne "0" && $result ne "0x0") {
70             $failcount++;
71             print STDERR "Failed! $line => $result\n";
72         }
73     }
74
75     return $failcount == 0;
76 }