"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/t/04_Sendpage-Page.t" (3 Jan 2008, 3671 Bytes) of package /linux/privat/old/sendpage-1.001001.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- Mode: CPerl -*-
    2 # Sendpage-Page.t -- unit test for Sendpage::Page
    3 # $Id: 04_Sendpage-Page.t 223 2006-08-24 16:01:31Z keescook $
    4 #
    5 # Copyright (C)  2006  Zak B. Elep
    6 # zakame@spunge.org, http://zakame.spunge.org
    7 #
    8 # This program is free software; you can redistribute it and/or modify
    9 # it under the terms of the GNU General Public License as published by
   10 # the Free Software Foundation; either version 2 of the License,
   11 # or (at your option) any later version.
   12 #
   13 # This program is distributed in the hope that it will be useful, but
   14 # WITHOUT ANY WARRANTY; without even the implied warranty of
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16 # GNU General Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License
   19 # along with this program; if not, write to the Free Software Foundation, Inc.,
   20 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
   21 #
   22 # After installation, run as `perl Sendpage-Page.t'
   23 
   24 use strict;
   25 use warnings;
   26 
   27 use Test::MockObject;
   28 use Test::More tests => 45;
   29 BEGIN {
   30     # testing data to be returned by the mock objects
   31     my %recipient =
   32 	(
   33 	 name  => sub { "John Doe" },
   34 	 data  => sub { { from => "Tester" } },
   35 	 datum => sub { "Tester" },
   36 	);
   37 
   38     # create our MockObject template
   39     my $mock = Test::MockObject->new();
   40     isa_ok( $mock, 'Test::MockObject', 'mock Sendpage::Recipient' );
   41     $mock->fake_module( 'Sendpage::Recipient' );
   42     $mock->fake_new( 'Sendpage::Recipient' );
   43     $mock->set_isa( 'Sendpage::Recipient' );
   44 
   45     # create methods
   46     foreach (keys %recipient) {
   47 	$mock->mock( $_ => $recipient{ $_ } );
   48 	ok( $mock->can( $_ ), qq( mock recipient template can $_() ) );
   49     }
   50 
   51     use_ok( 'Sendpage::Recipient' );
   52     use_ok( 'Sendpage::Page' ) or die;
   53 }
   54 
   55 # make our 3 Stooges, erm, Recipients
   56 our ($larry, $curly, $moe);
   57 for my $stooge ( qw(larry curly moe) ) {
   58     no strict 'refs';		# access symbol table
   59     $$stooge = Sendpage::Recipient->new;
   60     isa_ok( $$stooge,
   61 	    'Sendpage::Recipient',
   62 	    "mock Sendpage::Recipient '$stooge'" );
   63 
   64     can_ok( $$stooge, $_ ) foreach qw( name data datum );
   65     $$stooge->name($stooge);
   66 }
   67 
   68 # Page template
   69 my %p =
   70     (
   71      recipients	=> [ $larry, $curly, $moe ],
   72      text	=> "Some text to page here",
   73      options	=> { when => time },
   74     );
   75 
   76 my $page = Sendpage::Page->new( \@{ $p{recipients} },
   77 				\$p{text},
   78 				\%{ $p{options} },
   79 			      );
   80 isa_ok( $page, 'Sendpage::Page' );
   81 
   82 my @functions = qw( text reset next recip has_recips drop_recip
   83 		    deliverable option attempts dump );
   84 can_ok( $page, $_ ) foreach @functions;
   85 
   86 # can we read the page's text?
   87 is( $page->text,
   88     $p{text},
   89     qq(text("$p{text}")) );
   90 
   91 # can we deliver it?
   92 is( $page->deliverable,
   93     1,
   94     qq(page deliverable()) );
   95 
   96 # can we reset the recipient list iterator?
   97 is( $page->reset,
   98     -1,
   99     qq(reset() recipient list pointer) );
  100 
  101 # can we get the next in the recipient list?
  102 is( $page->next,
  103     0,
  104     qq(next() at start of recipient list) );
  105 
  106 # Is the current recipient at head?
  107 is( $page->recip,
  108     $p{recipients}[0],
  109     qq(recip() is at head) );
  110 
  111 if ($page->deliverable) {
  112     for (my $i = 0, $page->reset, $page->next;
  113 	 my $r = $page->recip;
  114 	 $i++, $page->next) {
  115 	isnt( $r,
  116 	      undef,
  117 	      qq(recip() in loop) );
  118 	is( $page->text,
  119 	    $p{text},
  120 	    qq(text() for each recipient) );
  121 	cmp_ok( $page->drop_recip,
  122 		'>=',
  123 		0,
  124 		qq(drop_recip() current recip @{[ $r->name ]} $i) );
  125     }
  126     is( $page->attempts(1),
  127 	1,
  128 	qq(first attempt()) );
  129 }
  130 
  131 # anyone left to deliver?
  132 is( $page->has_recips,
  133     '',
  134     qq(no more recips()) );
  135 
  136 # /* vim: set filetype=perl : */ 
  137 # /* vi:set ai ts=4 sw=4 expandtab: */