File: 40detachedcode-marshall.t

package info (click to toggle)
libio-async-perl 0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 684 kB
  • ctags: 239
  • sloc: perl: 6,439; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 3,288 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl -w

use strict;

use Test::More tests => 22;
use Test::Exception;

use IO::Async::DetachedCode;

use IO::Async::DetachedCode::FlatMarshaller;
use IO::Async::DetachedCode::StorableMarshaller;

use IO::Async::Loop::Poll;

sub test_marshall_args
{
   my ( $marshaller, $name ) = @_;

   my $data = $marshaller->marshall_args( 1, [] );
   my $args = $marshaller->unmarshall_args( 1, $data );

   is_deeply( $args, [], "args for args empty list using $name" );

   $data = $marshaller->marshall_args( 10, [ "hello" ] );
   $args = $marshaller->unmarshall_args( 10, $data );

   is_deeply( $args, [ "hello" ], "args for args list single string using $name" );

   $data = $marshaller->marshall_args( 100, [ 10, 20, 30 ] );
   $args = $marshaller->unmarshall_args( 100, $data );

   is_deeply( $args, [ 10, 20, 30 ], "args for args list of numbers using $name" );

   $data = $marshaller->marshall_args( 1000, [ undef ] );
   $args = $marshaller->unmarshall_args( 1000, $data );

   is_deeply( $args, [ undef ], "args for args list with undef using $name" );
}

sub test_marshall_args_ref
{
   my ( $marshaller, $name ) = @_;

   my $data = $marshaller->marshall_args( 3, [ \'a' ] );
   my $args = $marshaller->unmarshall_args( 3, $data );

   is_deeply( $args, [ \'a' ], "args for SCALAR ref using $name" );

   $data = $marshaller->marshall_args( 30, [ [ 'a' ] ] );
   $args = $marshaller->unmarshall_args( 30, $data );

   is_deeply( $args, [ [ 'a' ] ], "args for ARRAY ref using $name" );

   $data = $marshaller->marshall_args( 300, [ { a => 'A' } ] );
   $args = $marshaller->unmarshall_args( 300, $data );

   is_deeply( $args, [ { a => 'A' } ], "args for HASH ref using $name" );

   $data = $marshaller->marshall_args( 3000, [ [ [ 'a' ] ] ] );
   $args = $marshaller->unmarshall_args( 3000, $data );

   is_deeply( $args, [ [ [ 'a' ] ] ], "args for deep ARRAY ref using $name" );
}

my $marshaller = IO::Async::DetachedCode::FlatMarshaller->new();

ok( defined $marshaller, '$marshaller defined' );
isa_ok( $marshaller, "IO::Async::DetachedCode::FlatMarshaller", '$marshaller isa IO::Async::DetachedCode::FlatMarshaller' );

test_marshall_args( $marshaller, "flat" );

dies_ok( sub { $marshaller->marshall_args( 2, [ \'a' ] ); },
         "marshalling SCALAR ref dies using flat" );

dies_ok( sub { $marshaller->marshall_args( 2, [ ['a'] ] ); },
         "marshalling ARRAY ref dies using flat" );

dies_ok( sub { $marshaller->marshall_args( 2, [ { a => 'A' } ] ); },
         "marshalling HASH ref dies using flat" );

$marshaller = IO::Async::DetachedCode::StorableMarshaller->new();

ok( defined $marshaller, '$marshaller defined' );
isa_ok( $marshaller, "IO::Async::DetachedCode::StorableMarshaller", '$marshaller isa IO::Async::DetachedCode::StorableMarshaller' );

test_marshall_args( $marshaller, "storable" );
test_marshall_args_ref( $marshaller, "storable" );

my $loop = IO::Async::Loop::Poll->new();

my $record = IO::Async::DetachedCode::_marshall_record( 'c', 1, "call data here" );
my ( $type, $id, $data ) = IO::Async::DetachedCode::_unmarshall_record( $record );

is( $type, 'c',              "type for record marshall test" );
is( $id,   1,                "id for record marshall test" );
is( $data, "call data here", "data for record marshall test" );