Skip to content
This repository
Browse code

[digest]

- add a wrapper of libcrypto
MD2, MD4, MD5, RIPEMD160, SHA, SHA1, SHA256 & SHA512

git-svn-id: https://svn.parrot.org/parrot/trunk@26359 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit c36925f6dd916a72045820eaadea7d2e8aa98df7 1 parent d2a9b27
François Perrad fperrad authored
4 MANIFEST.generated
@@ -93,6 +93,10 @@ runtime/parrot/dynext/apl_group.bundle [library]
93 93 runtime/parrot/dynext/apl_group.dll [library]
94 94 runtime/parrot/dynext/apl_group.dylib [library]
95 95 runtime/parrot/dynext/apl_group.so [library]
  96 +runtime/parrot/dynext/digest_group.bundle [library]
  97 +runtime/parrot/dynext/digest_group.dll [library]
  98 +runtime/parrot/dynext/digest_group.dylib [library]
  99 +runtime/parrot/dynext/digest_group.so [library]
96 100 runtime/parrot/dynext/dotnet.bundle [library]
97 101 runtime/parrot/dynext/dotnet.dll [library]
98 102 runtime/parrot/dynext/dotnet.dylib [library]
3  README_win32.pod
Source Rendered
@@ -86,6 +86,9 @@ F<lib/icudt.lib>, which contains the standard data in binary form.
86 86
87 87 The availability of these libraries is checked by Configure.pl.
88 88
  89 +B<libcrypto> - a part of libssl
  90 +L<http://www.openssl.org/>
  91 +
89 92 B<gdbm> - GNU database manager
90 93 L<http://gnuwin32.sourceforge.net/>
91 94
107 config/auto/crypto.pm
... ... @@ -0,0 +1,107 @@
  1 +# Copyright (C) 2008, The Perl Foundation.
  2 +# $Id$
  3 +
  4 +=head1 NAME
  5 +
  6 +config/auto/crypto.pm - Test for crypto library (libssl)
  7 +
  8 +=head1 DESCRIPTION
  9 +
  10 +See L<http://www.openssl.org>
  11 +
  12 +=cut
  13 +
  14 +package auto::crypto;
  15 +
  16 +use strict;
  17 +use warnings;
  18 +
  19 +use base qw(Parrot::Configure::Step);
  20 +
  21 +use Parrot::Configure::Utils ':auto';
  22 +
  23 +
  24 +sub _init {
  25 + my $self = shift;
  26 + my %data;
  27 + $data{description} = q{Determining if your platform supports crypto};
  28 + $data{result} = q{};
  29 + return \%data;
  30 +}
  31 +
  32 +sub runstep {
  33 + my ( $self, $conf ) = @_;
  34 +
  35 + my ( $verbose, $without ) = $conf->options->get(
  36 + qw|
  37 + verbose
  38 + without-crypto
  39 + |
  40 + );
  41 +
  42 + if ($without) {
  43 + $conf->data->set( has_crypto => 0 );
  44 + $self->set_result('no');
  45 + return 1;
  46 + }
  47 +
  48 + my $cc = $conf->data->get('cc');
  49 + my $libs = $conf->data->get('libs');
  50 + my $linkflags = $conf->data->get('linkflags');
  51 + my $ccflags = $conf->data->get('ccflags');
  52 +
  53 + my $osname = $conf->data->get_p5('OSNAME');
  54 +
  55 + _handle_mswin32($conf, $osname, $cc);
  56 +
  57 + $conf->cc_gen('config/auto/crypto/crypto.in');
  58 + eval { $conf->cc_build(); };
  59 + my $has_crypto = 0;
  60 + if ( !$@ ) {
  61 + my $test = $conf->cc_run();
  62 + $has_crypto = $self->_evaluate_cc_run($test, $has_crypto, $verbose);
  63 + }
  64 + unless ($has_crypto) {
  65 + # The Parrot::Configure settings might have changed while class ran
  66 + $self->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
  67 + }
  68 + $conf->data->set( has_crypto => $has_crypto ); # for dynpmc.in & digest.t
  69 +
  70 + return 1;
  71 +}
  72 +
  73 +sub _handle_mswin32 {
  74 + my ($conf, $osname, $cc) = @_;
  75 + if ( $osname =~ /mswin32/i ) {
  76 + if ( $cc =~ /^gcc/i ) {
  77 + $conf->data->add( ' ', libs => '-lcrypto' );
  78 + }
  79 + else {
  80 + $conf->data->add( ' ', libs => 'libcrypto.lib' );
  81 + }
  82 + }
  83 + else {
  84 + $conf->data->add( ' ', libs => '-lcrypto' );
  85 + }
  86 + return 1;
  87 +}
  88 +
  89 +sub _evaluate_cc_run {
  90 + my $self = shift;
  91 + my ($test, $has_crypto, $verbose) = @_;
  92 + if ( $test =~ m/^OpenSSL (\d\.\d\.\d\w)/ ) {
  93 + $has_crypto = 1;
  94 + print " (yes) " if $verbose;
  95 + $self->set_result("yes, $1");
  96 + }
  97 + return $has_crypto;
  98 +}
  99 +
  100 +1;
  101 +
  102 +# Local Variables:
  103 +# mode: cperl
  104 +# cperl-indent-level: 4
  105 +# fill-column: 100
  106 +# End:
  107 +# vim: expandtab shiftwidth=4:
16 config/auto/crypto/crypto.in
... ... @@ -0,0 +1,16 @@
  1 +/* Copyright (C) 2008, The Perl Foundation. */
  2 +/* $Id$ */
  3 +
  4 +#include <stdio.h>
  5 +#include <stdlib.h>
  6 +#include <openssl/opensslv.h>
  7 +#include <openssl/err.h>
  8 +
  9 +int main(int argc, char *argv[])
  10 +{
  11 + unsigned long dummy = ERR_get_error();
  12 +
  13 + printf ("%s\n", OPENSSL_VERSION_TEXT);
  14 +
  15 + return EXIT_SUCCESS;
  16 +}
39 config/gen/makefiles/dynpmc.in
@@ -14,23 +14,58 @@ PMCS = \
14 14 dynlexpad \
15 15 foo \
16 16 rotest \
17   -#CONDITIONED_LINE(has_gdbm):gdbmhash \
  17 +#CONDITIONED_LINE(has_gdbm): gdbmhash \
18 18 rational \
  19 +#CONDITIONED_LINE(has_crypto): md2 \
  20 +#CONDITIONED_LINE(has_crypto): md4 \
  21 +#CONDITIONED_LINE(has_crypto): md5 \
  22 +#CONDITIONED_LINE(has_crypto): ripemd160 \
  23 +#CONDITIONED_LINE(has_crypto): sha \
  24 +#CONDITIONED_LINE(has_crypto): sha1 \
  25 +#CONDITIONED_LINE(has_crypto): sha256 \
  26 +#CONDITIONED_LINE(has_crypto): sha512 \
19 27 subproxy
20 28
  29 +DIGEST = md2.pmc md4.pmc md5.pmc ripemd160.pmc sha.pmc sha1.pmc sha256.pmc sha512.pmc
  30 +
21 31 BUILD = $(PERL) @build_dir@/tools/build/dynpmc.pl
22 32
23   -all :
  33 +all : $(DIGEST)
24 34 @$(BUILD) generate $(PMCS)
25 35 @$(BUILD) compile $(PMCS)
26 36 @$(BUILD) linklibs $(PMCS)
27 37 @$(BUILD) copy --destination=$(RUNTIME_DIR) $(PMCS)
28 38
  39 +md2.pmc : mdx.pmc
  40 + $(PERL) -pe "s|mdx|md2|g; s|MDx|MD2|g" mdx.pmc > md2.pmc
  41 +
  42 +md4.pmc : mdx.pmc
  43 + $(PERL) -pe "s|mdx|md4|g; s|MDx|MD4|g" mdx.pmc > md4.pmc
  44 +
  45 +md5.pmc : mdx.pmc
  46 + $(PERL) -pe "s|mdx|md5|g; s|MDx|MD5|g" mdx.pmc > md5.pmc
  47 +
  48 +ripemd160.pmc : mdx.pmc
  49 + $(PERL) -pe "s|mdx|ripemd|g; s|MDx|RIPEMD160|g" mdx.pmc > ripemd160.pmc
  50 +
  51 +sha.pmc : mdx.pmc
  52 + $(PERL) -pe "s|mdx|sha|g; s|MDx|SHA|g" mdx.pmc > sha.pmc
  53 +
  54 +sha1.pmc : mdx.pmc
  55 + $(PERL) -pe "s|mdx|sha|g; s|MDx_CTX|SHA_CTX|g; s|MDx_DIGEST|SHA_DIGEST|g; s|MDx|SHA1|g" mdx.pmc > sha1.pmc
  56 +
  57 +sha256.pmc : mdx.pmc
  58 + $(PERL) -pe "s|mdx|sha|g; s|MDx|SHA256|g" mdx.pmc > sha256.pmc
  59 +
  60 +sha512.pmc : mdx.pmc
  61 + $(PERL) -pe "s|mdx|sha|g; s|MDx|SHA512|g" mdx.pmc > sha512.pmc
  62 +
29 63 test : all
30 64 cd ../.. ; perl -Ilib t/harness t/dynpmc/*.t
31 65
32 66 testclean :
33 67 $(RM_F) "../../t/dynpmc/*.pir" "../../t/dynpmc/*.pbc"
  68 + $(RM_F) $(DIGEST)
34 69
35 70 # win32 import library
36 71 # win32 program data base - contains debugging info
4 lib/Parrot/Configure/Options/Conf.pm
... ... @@ -1,4 +1,4 @@
1   -# Copyright (C) 2007, The Perl Foundation.
  1 +# Copyright (C) 2007-2008, The Perl Foundation.
2 2 # $Id$
3 3
4 4 package Parrot::Configure::Options::Conf;
@@ -78,6 +78,7 @@ our @valid_options = qw{
78 78 verbose-step
79 79 version
80 80 without-gdbm
  81 + without-crypto
81 82 without-gettext
82 83 without-gmp
83 84 without-icu
@@ -189,6 +190,7 @@ External Library Options:
189 190
190 191 --without-gmp Build parrot without GMP support
191 192 --without-gdbm Build parrot without GDBM support
  193 + --without-crypto Build parrot without crypto support (libssl)
192 194
193 195 ICU Options:
194 196
3  lib/Parrot/Configure/Step/List.pm
... ... @@ -1,4 +1,4 @@
1   -# Copyright (C) 2001-2006, The Perl Foundation.
  1 +# Copyright (C) 2001-2008, The Perl Foundation.
2 2 # $Id$
3 3 package Parrot::Configure::Step::List;
4 4 use strict;
@@ -55,6 +55,7 @@ my @steps = qw(
55 55 auto::gmp
56 56 auto::readline
57 57 auto::gdbm
  58 + auto::crypto
58 59 auto::gettext
59 60 auto::snprintf
60 61 auto::perldoc
150 src/dynpmc/mdx.pmc
... ... @@ -0,0 +1,150 @@
  1 +/*
  2 +Copyright (C) 2008, The Perl Foundation.
  3 +$Id$
  4 +
  5 +=head1 NAME
  6 +
  7 +src/dynpmc/mdx.pmc - MDx wrapper of libcrypto (libssl)
  8 +
  9 +=head1 DESCRIPTION
  10 +
  11 +See L<www.openssl.org>
  12 +
  13 +=head2 Methods
  14 +
  15 +=over 4
  16 +
  17 +=cut
  18 +
  19 +*/
  20 +
  21 +#include <openssl/mdx.h>
  22 +
  23 +pmclass MDx
  24 + dynpmc
  25 + need_ext
  26 + group digest_group {
  27 +
  28 +/*
  29 +
  30 +=item C<void init()>
  31 +
  32 +=cut
  33 +
  34 +*/
  35 + void init() {
  36 + MDx_CTX *c = mem_allocate_zeroed_typed(MDx_CTX);
  37 + PMC_data(SELF) = c;
  38 + PObj_custom_mark_destroy_SETALL(SELF);
  39 + }
  40 +
  41 +/*
  42 +
  43 +=item C<void mark()>
  44 +
  45 +=cut
  46 +
  47 +*/
  48 + void mark() {
  49 + if (PMC_data(SELF))
  50 + pobject_lives(INTERP, (PObj *)PMC_data(SELF));
  51 + }
  52 +
  53 +/*
  54 +
  55 +=item C<void destroy()>
  56 +
  57 +=cut
  58 +
  59 +*/
  60 + void destroy() {
  61 + MDx_CTX *c = PMC_data_typed(SELF, MDx_CTX *);
  62 + if (c) {
  63 + mem_sys_free(c);
  64 + PMC_data(SELF) = NULL;
  65 + }
  66 + }
  67 +
  68 +/*
  69 +
  70 +=item C<PMC* clone()>
  71 +
  72 +=cut
  73 +
  74 +*/
  75 + PMC* clone() {
  76 + PMC *retval = pmc_new_noinit(INTERP, SELF->vtable->base_type);
  77 + MDx_CTX *c = mem_allocate_zeroed_typed(MDx_CTX);
  78 + memcpy(c, PMC_data(SELF), sizeof(MDx_CTX));
  79 + PMC_data(retval) = c;
  80 + PObj_custom_mark_destroy_SETALL(retval);
  81 + return retval;
  82 + }
  83 +
  84 +
  85 +/*
  86 +
  87 +=back
  88 +
  89 +=head2 Specific Methods
  90 +
  91 +=over 4
  92 +
  93 +=item C<void MDx_Init()>
  94 +
  95 +=cut
  96 +
  97 +*/
  98 + METHOD void MDx_Init() {
  99 + MDx_CTX *c = PMC_data_typed(SELF, MDx_CTX *);
  100 + (void)MDx_Init(c);
  101 + }
  102 +
  103 +/*
  104 +
  105 +=item C<void MDx_Update(STRING *buf)>
  106 +
  107 +=cut
  108 +
  109 +*/
  110 + METHOD void MDx_Update(STRING *buf) {
  111 + MDx_CTX *c = PMC_data_typed(SELF, MDx_CTX *);
  112 + (void)MDx_Update(c, buf->strstart, buf->bufused);
  113 + }
  114 +
  115 +/*
  116 +
  117 +=item C<STRING* MDx_Final()>
  118 +
  119 +=cut
  120 +
  121 +*/
  122 + METHOD STRING* MDx_Final() {
  123 + unsigned char digest[MDx_DIGEST_LENGTH];
  124 + MDx_CTX *c = PMC_data_typed(SELF, MDx_CTX *);
  125 + STRING *retval;
  126 + (void)MDx_Final(digest, c);
  127 + retval = string_from_cstring(INTERP, digest, MDx_DIGEST_LENGTH);
  128 + RETURN(STRING *retval);
  129 + }
  130 +
  131 +}
  132 +
  133 +/*
  134 +
  135 +=back
  136 +
  137 +=head1 AUTHORS
  138 +
  139 +Francois Perrad
  140 +
  141 +=cut
  142 +
  143 +*/
  144 +
  145 +/*
  146 + * Local variables:
  147 + * c-file-style: "parrot"
  148 + * End:
  149 + * vim: expandtab shiftwidth=4:
  150 + */
170 t/dynpmc/digest.t
... ... @@ -0,0 +1,170 @@
  1 +#! perl
  2 +# Copyright (C) 2008, The Perl Foundation.
  3 +# $Id$
  4 +
  5 +use strict;
  6 +use warnings;
  7 +use lib qw( . lib ../lib ../../lib );
  8 +use Test::More;
  9 +use Parrot::Test;
  10 +use Parrot::Config;
  11 +
  12 +=head1 NAME
  13 +
  14 +t/dynpmc/digest.t - test the digest_group (MDx, RIPEMD, SHAx PMC)
  15 +
  16 +=head1 SYNOPSIS
  17 +
  18 + % perl -Ilib t/dynpmc/digest.t
  19 +
  20 +=head1 DESCRIPTION
  21 +
  22 +Tests the C<digest_group> a libcrypto wrapper.
  23 +
  24 +=cut
  25 +
  26 +if ( $PConfig{has_crypto} ) {
  27 + plan tests => 9;
  28 +}
  29 +else {
  30 + plan skip_all => "No crypto library available";
  31 +}
  32 +
  33 +pir_output_is( << 'CODE', << 'OUTPUT', 'MD2 typeof' );
  34 +.sub test :main
  35 + $P0 = loadlib 'digest_group'
  36 + .local pmc md
  37 + md = new 'MD2'
  38 + $S0 = typeof md
  39 + print $S0
  40 + print "\n"
  41 +.end
  42 +CODE
  43 +MD2
  44 +OUTPUT
  45 +
  46 +pir_output_is( << 'CODE', << 'OUTPUT', 'MD4 typeof' );
  47 +.sub test :main
  48 + $P0 = loadlib 'digest_group'
  49 + .local pmc md
  50 + md = new 'MD4'
  51 + $S0 = typeof md
  52 + print $S0
  53 + print "\n"
  54 +.end
  55 +CODE
  56 +MD4
  57 +OUTPUT
  58 +
  59 +pir_output_is( << 'CODE', << 'OUTPUT', 'MD5 typeof' );
  60 +.sub test :main
  61 + $P0 = loadlib 'digest_group'
  62 + .local pmc md
  63 + md = new 'MD5'
  64 + $S0 = typeof md
  65 + print $S0
  66 + print "\n"
  67 +.end
  68 +CODE
  69 +MD5
  70 +OUTPUT
  71 +
  72 +pir_output_is( << 'CODE', << 'OUTPUT', 'RIPEMD160 typeof' );
  73 +.sub test :main
  74 + $P0 = loadlib 'digest_group'
  75 + .local pmc md
  76 + md = new 'RIPEMD160'
  77 + $S0 = typeof md
  78 + print $S0
  79 + print "\n"
  80 +.end
  81 +CODE
  82 +RIPEMD160
  83 +OUTPUT
  84 +
  85 +pir_output_is( << 'CODE', << 'OUTPUT', 'SHA typeof' );
  86 +.sub test :main
  87 + $P0 = loadlib 'digest_group'
  88 + .local pmc md
  89 + md = new 'SHA'
  90 + $S0 = typeof md
  91 + print $S0
  92 + print "\n"
  93 +.end
  94 +CODE
  95 +SHA
  96 +OUTPUT
  97 +
  98 +pir_output_is( << 'CODE', << 'OUTPUT', 'SHA1 typeof' );
  99 +.sub test :main
  100 + $P0 = loadlib 'digest_group'
  101 + .local pmc md
  102 + md = new 'SHA1'
  103 + $S0 = typeof md
  104 + print $S0
  105 + print "\n"
  106 +.end
  107 +CODE
  108 +SHA1
  109 +OUTPUT
  110 +
  111 +pir_output_is( << 'CODE', << 'OUTPUT', 'SHA256 typeof' );
  112 +.sub test :main
  113 + $P0 = loadlib 'digest_group'
  114 + .local pmc md
  115 + md = new 'SHA256'
  116 + $S0 = typeof md
  117 + print $S0
  118 + print "\n"
  119 +.end
  120 +CODE
  121 +SHA256
  122 +OUTPUT
  123 +
  124 +pir_output_is( << 'CODE', << 'OUTPUT', 'SHA512 typeof' );
  125 +.sub test :main
  126 + $P0 = loadlib 'digest_group'
  127 + .local pmc md
  128 + md = new 'SHA512'
  129 + $S0 = typeof md
  130 + print $S0
  131 + print "\n"
  132 +.end
  133 +CODE
  134 +SHA512
  135 +OUTPUT
  136 +
  137 +pir_output_is( << 'CODE', << 'OUTPUT', 'MD5 digest' );
  138 +.sub test :main
  139 + $P0 = loadlib 'digest_group'
  140 + .local pmc md
  141 + md = new 'MD5'
  142 + md.'MD5_Init'()
  143 + $S0 = 'message digest'
  144 + md.'MD5_Update'($S0)
  145 + $S0 = md.'MD5_Final'()
  146 + $P0 = split '', $S0
  147 + new $P1, 'FixedPMCArray'
  148 + set $P1, 1
  149 + L1:
  150 + unless $P0 goto L2
  151 + $S1 = shift $P0
  152 + $I1 = ord $S1
  153 + $P1[0] = $I1
  154 + $S2 = sprintf '%2x', $P1
  155 + print $S2
  156 + goto L1
  157 + L2:
  158 + print "\n"
  159 +.end
  160 +CODE
  161 +f96b697d7cb7938d525a2f31aaf161d0
  162 +OUTPUT
  163 +
  164 +
  165 +# Local Variables:
  166 +# mode: cperl
  167 +# cperl-indent-level: 4
  168 +# fill-column: 100
  169 +# End:
  170 +# vim: expandtab shiftwidth=4:
86 t/steps/auto_crypto-01.t
... ... @@ -0,0 +1,86 @@
  1 +#! perl
  2 +# Copyright (C) 2008, The Perl Foundation.
  3 +# $Id$
  4 +
  5 +use strict;
  6 +use warnings;
  7 +use Test::More tests => 14;
  8 +use Carp;
  9 +use lib qw( lib t/configure/testlib );
  10 +use_ok('config::init::defaults');
  11 +use_ok('config::auto::crypto');
  12 +use Parrot::Configure;
  13 +use Parrot::Configure::Options qw( process_options );
  14 +use Parrot::Configure::Test qw( test_step_thru_runstep);
  15 +
  16 +my $args = process_options(
  17 + {
  18 + argv => [ q{--without-crypto} ],
  19 + mode => q{configure},
  20 + }
  21 +);
  22 +
  23 +my $conf = Parrot::Configure->new;
  24 +
  25 +test_step_thru_runstep( $conf, q{init::defaults}, $args );
  26 +
  27 +my $pkg = q{auto::crypto};
  28 +
  29 +$conf->add_steps($pkg);
  30 +$conf->options->set( %{$args} );
  31 +
  32 +my ( $task, $step_name, $step);
  33 +$task = $conf->steps->[-1];
  34 +$step_name = $task->step;
  35 +
  36 +$step = $step_name->new();
  37 +ok( defined $step, "$step_name constructor returned defined value" );
  38 +isa_ok( $step, $step_name );
  39 +ok( $step->description(), "$step_name has description" );
  40 +
  41 +my $ret = $step->runstep($conf);
  42 +ok( $ret, "$step_name runstep() returned true value" );
  43 +is($conf->data->get('has_crypto'), 0,
  44 + "Got expected value for 'has_crypto'");
  45 +is($step->result(), q{no}, "Expected result was set");
  46 +
  47 +pass("Keep Devel::Cover happy");
  48 +pass("Completed all tests in $0");
  49 +
  50 +################### DOCUMENTATION ###################
  51 +
  52 +=head1 NAME
  53 +
  54 +auto_crypto-01.t - test config::auto::crypto
  55 +
  56 +=head1 SYNOPSIS
  57 +
  58 + % prove t/steps/auto_crypto-01.t
  59 +
  60 +=head1 DESCRIPTION
  61 +
  62 +The files in this directory test functionality used by F<Configure.pl>.
  63 +
  64 +The tests in this file test config::auto::crypto in the case where the
  65 +C<--without-crypto> option is set.
  66 +
  67 +=head1 HISTORY
  68 +
  69 +Mostly taken from F<t/steps/auto_gdbm-01.t>.
  70 +
  71 +=head1 AUTHOR
  72 +
  73 +Francois Perrad
  74 +
  75 +=head1 SEE ALSO
  76 +
  77 +config::auto::crypto, F<Configure.pl>.
  78 +
  79 +=cut
  80 +
  81 +# Local Variables:
  82 +# mode: cperl
  83 +# cperl-indent-level: 4
  84 +# fill-column: 100
  85 +# End:
  86 +# vim: expandtab shiftwidth=4:
115 t/steps/auto_crypto-03.t
... ... @@ -0,0 +1,115 @@
  1 +#! perl
  2 +# Copyright (C) 2008, The Perl Foundation.
  3 +# $Id$
  4 +
  5 +use strict;
  6 +use warnings;
  7 +use Test::More tests => 17;
  8 +use Carp;
  9 +use Cwd;
  10 +use lib qw( lib t/configure/testlib );
  11 +use_ok('config::init::defaults');
  12 +use_ok('config::auto::crypto');
  13 +use Parrot::Configure;
  14 +use Parrot::Configure::Options qw( process_options );
  15 +use Parrot::Configure::Test qw( test_step_thru_runstep);
  16 +use IO::CaptureOutput qw| capture |;
  17 +
  18 +my $args = process_options(
  19 + {
  20 + argv => [ q{--without-crypto} ],
  21 + mode => q{configure},
  22 + }
  23 +);
  24 +
  25 +my $conf = Parrot::Configure->new;
  26 +
  27 +test_step_thru_runstep( $conf, q{init::defaults}, $args );
  28 +
  29 +my $pkg = q{auto::crypto};
  30 +
  31 +$conf->add_steps($pkg);
  32 +$conf->options->set( %{$args} );
  33 +
  34 +my ($task, $step_name, $step);
  35 +$task = $conf->steps->[-1];
  36 +$step_name = $task->step;
  37 +
  38 +$step = $step_name->new();
  39 +ok( defined $step, "$step_name constructor returned defined value" );
  40 +isa_ok( $step, $step_name );
  41 +ok( $step->description(), "$step_name has description" );
  42 +
  43 +my ($test, $has_crypto, $verbose);
  44 +
  45 +$test = qq{OpenSSL 0.9.9z\n};
  46 +$has_crypto = 0;
  47 +$verbose = undef;
  48 +$has_crypto = $step->_evaluate_cc_run($test, $has_crypto, $verbose);
  49 +is($has_crypto, 1, "'has_crypto' set as expected");
  50 +is($step->result(), 'yes, 0.9.9z', "Expected result was set");
  51 +# Prepare for next test
  52 +$step->set_result(undef);
  53 +
  54 +$test = qq{foobar};
  55 +$has_crypto = 0;
  56 +$verbose = undef;
  57 +$has_crypto = $step->_evaluate_cc_run($test, $has_crypto, $verbose);
  58 +is($has_crypto, 0, "'has_crypto' set as expected");
  59 +ok(! defined $step->result(), "Result is undefined, as expected");
  60 +
  61 +{
  62 + my $stdout;
  63 + $test = qq{OpenSSL 0.9.9z\n};
  64 + $has_crypto = 0;
  65 + $verbose = 1;
  66 + capture(
  67 + sub { $has_crypto =
  68 + $step->_evaluate_cc_run($test, $has_crypto, $verbose); },
  69 + \$stdout,
  70 + );
  71 + is($has_crypto, 1, "'has_crypto' set as expected");
  72 + is($step->result(), 'yes, 0.9.9z', "Expected result was set");
  73 + like($stdout, qr/\(yes\)/, "Got expected verbose output");
  74 + # Prepare for next test
  75 + $step->set_result(undef);
  76 +}
  77 +
  78 +pass("Completed all tests in $0");
  79 +
  80 +################### DOCUMENTATION ###################
  81 +
  82 +=head1 NAME
  83 +
  84 +auto_crypto-03.t - test config::auto::crypto
  85 +
  86 +=head1 SYNOPSIS
  87 +
  88 + % prove t/steps/auto_crypto-03.t
  89 +
  90 +=head1 DESCRIPTION
  91 +
  92 +The files in this directory test functionality used by F<Configure.pl>.
  93 +
  94 +The tests in this file test config::auto::crypto.
  95 +
  96 +=head1 HISTORY
  97 +
  98 +Mostly taken from F<t/steps/auto_gdbm-03.t>.
  99 +
  100 +=head1 AUTHOR
  101 +
  102 +Francois Perrad
  103 +
  104 +=head1 SEE ALSO
  105 +
  106 +config::auto::crypto, F<Configure.pl>.
  107 +
  108 +=cut
  109 +
  110 +# Local Variables:
  111 +# mode: cperl
  112 +# cperl-indent-level: 4
  113 +# fill-column: 100
  114 +# End:
  115 +# vim: expandtab shiftwidth=4:
116 t/steps/auto_crypto-04.t
... ... @@ -0,0 +1,116 @@
  1 +#! perl
  2 +# Copyright (C) 2008, The Perl Foundation.
  3 +# $Id$
  4 +
  5 +use strict;
  6 +use warnings;
  7 +use Test::More tests => 19;
  8 +use Carp;
  9 +use Cwd;
  10 +use lib qw( lib t/configure/testlib );
  11 +use_ok('config::init::defaults');
  12 +use_ok('config::auto::crypto');
  13 +use Parrot::Configure;
  14 +use Parrot::Configure::Options qw( process_options );
  15 +use Parrot::Configure::Test qw( test_step_thru_runstep);
  16 +use IO::CaptureOutput qw| capture |;
  17 +
  18 +my $args = process_options(
  19 + {
  20 + argv => [ q{--without-crypto} ],
  21 + mode => q{configure},
  22 + }
  23 +);
  24 +
  25 +my $conf = Parrot::Configure->new;
  26 +
  27 +test_step_thru_runstep( $conf, q{init::defaults}, $args );
  28 +
  29 +my $pkg = q{auto::crypto};
  30 +
  31 +$conf->add_steps($pkg);
  32 +$conf->options->set( %{$args} );
  33 +
  34 +my ($task, $step_name, $step);
  35 +$task = $conf->steps->[-1];
  36 +$step_name = $task->step;
  37 +
  38 +$step = $step_name->new();
  39 +ok( defined $step, "$step_name constructor returned defined value" );
  40 +isa_ok( $step, $step_name );
  41 +ok( $step->description(), "$step_name has description" );
  42 +
  43 +my ($libs, $ccflags, $linkflags, $verbose);
  44 +
  45 +$libs = q{-lalpha};
  46 +$ccflags = q{-Ibeta};
  47 +$linkflags = q{-Lgamma};
  48 +$verbose = undef;
  49 +$step->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
  50 +like($conf->data->get('libs'), qr/$libs/,
  51 + "Got expected value for 'libs'");
  52 +like($conf->data->get('ccflags'), qr/$ccflags/,
  53 + "Got expected value for 'ccflags'");
  54 +like($conf->data->get('linkflags'), qr/$linkflags/,
  55 + "Got expected value for 'linkflags'");
  56 +is($step->result, 'no', "Expected result was set");
  57 +
  58 +{
  59 + my $stdout;
  60 + $libs = q{-lalpha};
  61 + $ccflags = q{-Ibeta};
  62 + $linkflags = q{-Lgamma};
  63 + $verbose = 1;
  64 + capture(
  65 + sub { $step->_recheck_settings(
  66 + $conf, $libs, $ccflags, $linkflags, $verbose); },
  67 + \$stdout,
  68 + );
  69 + like($conf->data->get('libs'), qr/$libs/,
  70 + "Got expected value for 'libs'");
  71 + like($conf->data->get('ccflags'), qr/$ccflags/,
  72 + "Got expected value for 'ccflags'");
  73 + like($conf->data->get('linkflags'), qr/$linkflags/,
  74 + "Got expected value for 'linkflags'");
  75 + is($step->result, 'no', "Expected result was set");
  76 + like($stdout, qr/\(no\)/, "Got expected verbose output");
  77 +}
  78 +
  79 +pass("Completed all tests in $0");
  80 +
  81 +################### DOCUMENTATION ###################
  82 +
  83 +=head1 NAME
  84 +
  85 +auto_crypto-04.t - test config::auto::crypto
  86 +
  87 +=head1 SYNOPSIS
  88 +
  89 + % prove t/steps/auto_crypto-04.t
  90 +
  91 +=head1 DESCRIPTION
  92 +
  93 +The files in this directory test functionality used by F<Configure.pl>.
  94 +
  95 +The tests in this file test config::auto::crypto.
  96 +
  97 +=head1 HISTORY
  98 +
  99 +Mostly taken from F<t/steps/auto_gdbm-04.t>.
  100 +
  101 +=head1 AUTHOR
  102 +
  103 +Francois Perrad
  104 +
  105 +=head1 SEE ALSO
  106 +
  107 +config::auto::crypto, F<Configure.pl>.
  108 +
  109 +=cut
  110 +
  111 +# Local Variables:
  112 +# mode: cperl
  113 +# cperl-indent-level: 4
  114 +# fill-column: 100
  115 +# End:
  116 +# vim: expandtab shiftwidth=4:

0 comments on commit c36925f

Please sign in to comment.
Something went wrong with that request. Please try again.