Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / t / local / 31_rsa_generate_key.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Net::SSLeay;
7
8 eval 'use Test::Exception';
9 plan skip_all => 'Test::Exception required' if $@;
10
11 plan tests => 14;
12
13 Net::SSLeay::randomize();
14 Net::SSLeay::load_error_strings();
15 Net::SSLeay::ERR_load_crypto_strings();
16 Net::SSLeay::SSLeay_add_ssl_algorithms();
17
18 lives_ok(sub {
19         Net::SSLeay::RSA_generate_key(512, 0x10001);
20 }, 'RSA_generate_key with valid callback');
21
22 dies_ok(sub {
23         Net::SSLeay::RSA_generate_key(512, 0x10001, 1);
24 }, 'RSA_generate_key with invalid callback');
25
26 {
27     my $called = 0;
28
29     lives_ok(sub {
30             Net::SSLeay::RSA_generate_key(512, 0x10001, \&cb);
31     }, 'RSA_generate_key with valid callback');
32
33     cmp_ok( $called, '>', 0, 'callback has been called' );
34
35     sub cb {
36         my ($i, $n, $d) = @_;
37
38         if ($called == 0) {
39             is( wantarray(), undef, 'RSA_generate_key callback is executed in void context' );
40             is( $d, undef, 'userdata will be undef if no userdata was given' );
41
42             ok( defined $i, 'first argument is defined' );
43             ok( defined $n, 'second argument is defined' );
44         }
45
46         $called++;
47     }
48 }
49
50 {
51     my $called   = 0;
52     my $userdata = 'foo';
53
54     lives_ok(sub {
55             Net::SSLeay::RSA_generate_key(512, 0x10001, \&cb_data, $userdata);
56     }, 'RSA_generate_key with valid callback and userdata');
57
58     cmp_ok( $called, '>', 0, 'callback has been called' );
59
60     sub cb_data {
61         my ($i, $n, $d) = @_;
62
63         if ($called == 0) {
64             is( wantarray(), undef, 'RSA_generate_key callback is executed in void context' );
65
66             ok( defined $i, 'first argument is defined' );
67             ok( defined $n, 'second argument is defined' );
68             is( $d, $userdata, 'third argument is the userdata we passed in' );
69         }
70
71         $called++;
72     }
73 }