"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/t/10_Sendpage-PagingCentral.t" (3 Jan 2008, 4183 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-PagingCentral.t -- unit test for Sendpage::PagingCentral
    3 # $Id: 10_Sendpage-PagingCentral.t 222 2006-08-24 16:01:07Z keescook $
    4 #
    5 # Copyright (C)  2006  Kees Cook
    6 # kees@outflux.net, http://outflux.net/
    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-PagingCentral.t
   23 
   24 use strict;
   25 use warnings;
   26 
   27 use Test::MockObject;
   28 #use Test::More tests => 45;
   29 use Test::More qw(no_plan);
   30 
   31 our $mock_conf;
   32 my $CR  = "\x0D";
   33 my $US  = "\x1F";
   34 my $ETX = "\x03";
   35 my $ETB = "\x17";
   36 
   37 BEGIN {
   38     my %conf_mock_methods =
   39     (
   40      get         => sub {
   41          shift;        # discard self
   42 
   43          if    ($_[0] =~ /^pc:[^@]+\@debug$/)           { return 0 }
   44          elsif ($_[0] =~ /^pc:[^@]+\@fields$/)          { return 2 }
   45          elsif ($_[0] =~ /^pc:[^@]+\@chars-per-block$/) { return 250 }
   46          else { return "trash" }
   47      },
   48      ifset         => sub {
   49          shift;        # discard self
   50          return "trash";
   51      },
   52      fallbackget   => sub {
   53          shift;        # discard self
   54          return "trash";
   55      },
   56     );
   57 
   58     our $mock_conf = new Test::MockObject;
   59     isa_ok( $mock_conf, 'Test::MockObject', "mock conf object" );
   60     $mock_conf->fake_module( 'Sendpage::KeesConf' );
   61     $mock_conf->fake_new( 'Sendpage::KeesConf' );
   62     $mock_conf->set_isa( 'Sendpage::KeesConf' );
   63 
   64     foreach (keys %conf_mock_methods) {
   65         $mock_conf->mock( $_ => $conf_mock_methods{ $_ } );
   66         can_ok( $mock_conf, $_ );
   67     }
   68     use_ok( 'Sendpage::KeesConf' );
   69 
   70     use_ok( 'Sendpage::PagingCentral' ) or die;
   71 }
   72 
   73 # Without an explicit modem list
   74 my $pc = Sendpage::PagingCentral->new( $mock_conf, "testpc" );
   75 isa_ok( $pc, 'Sendpage::PagingCentral' );
   76 
   77 my @public_functions = qw( start_proto send disconnect deliver SendMail );
   78 can_ok( $pc, $_ ) foreach @public_functions;
   79 my @private_functions = qw( GenerateBlocks );
   80 can_ok( $pc, $_ ) foreach @private_functions;
   81 
   82 my (@blocks,$pin,$msg);
   83 
   84 $pin = "pin";
   85 $msg = "short message";
   86 @blocks = $pc->GenerateBlocks( $pin, $msg );
   87 is(scalar(@blocks),1,"Generated a single block for a short page");
   88 is(join("",@{$blocks[0]}),"$pin$CR$msg$CR$ETX",
   89    "Short message block meets TAP specification");
   90 
   91 $pin = "pin";
   92 $msg = "long message" . "B" x 256;
   93 @blocks = $pc->GenerateBlocks( $pin, $msg );
   94 is(scalar(@blocks),2,"Generated two blocks for a long field split page");
   95 TODO: {
   96     local $TODO = "Block splitter is 1 character below expected max";
   97     # max is 256 - 1 (STX) - 3 (chksum) - 1 (CR) == 251
   98     my $max = 256 - 1 - 3 - 1;
   99     is ( length( join("",@{$blocks[0]})), $max,
  100          "Block 0 of multi-block is $max characters" );
  101 }
  102 is(join("",@{$blocks[0]}),"$pin$CR".substr($msg,0,245)."$US",
  103    "Long message (field split) block 0 meets TAP specification");
  104 is(join("",@{$blocks[1]}),substr($msg,245)."$CR$ETX",
  105    "Long message (field split) block 1 meets TAP specification");
  106 
  107 $pin = "pin" . "A" x 245;
  108 $msg = "long message" . "B" x 100;
  109 @blocks = $pc->GenerateBlocks( $pin, $msg );
  110 is(scalar(@blocks),2,"Generated two blocks for a long field edge page");
  111 is(join("",@{$blocks[0]}),"$pin$CR$ETB",
  112    "Long message (field edge) block 0 meets TAP specification");
  113 is(join("",@{$blocks[1]}),"$msg$CR$ETX",
  114    "Long message (field edge) block 1 meets TAP specification");
  115 
  116 #foreach my $block (@blocks) {
  117 #    my $str=join("",@$block);
  118 #    $str =~ s/([[:^print:] {}|~])/sprintf("{0x%02X}",ord($1))/eg;
  119 #    warn "$str\n";
  120 #}
  121 
  122 # /* vim: set filetype=perl : */ 
  123 # /* vi:set ai ts=4 sw=4 expandtab: */