de163df15a6e2d5ab5669bc5ab2a60e87ef7274c
[scpubgit/Object-Remote.git] / t / sender.t
1 use strictures 1;
2 use Test::More;
3
4 $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
5
6 use Object::Remote::Connector::Local;
7 use Object::Remote;
8 use Object::Remote::ModuleSender;
9
10 $ENV{PERL5LIB} = join(
11   ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib)
12 );
13
14 my $mod_content = do {
15   open my $fh, '<', 't/lib/ORTestClass.pm'
16     or die "can't read ORTestClass.pm: $!";
17   local $/;
18   <$fh>
19 };
20 my $modules = {
21   'ORTestClass.pm' => $mod_content,
22 };
23
24 sub TestModuleProvider::INC {
25   my ($self, $module) = @_;
26   if (my $data = $self->{modules}{$module}) {
27     open my $fh, '<', \$data
28       or die "welp $!";
29     return $fh;
30   }
31   return;
32 }
33
34 my %sources = (
35   basic => [ 't/lib' ],
36   sub => [ sub {
37     if (my $data = $modules->{$_[1]}) {
38       open my $fh, '<', \$data
39         or die "welp $!";
40       return $fh;
41     }
42     return;
43   } ],
44   dynamic_array => [ [ sub {
45     my $mods = $_[0][1];
46     if (my $data = $mods->{$_[1]}) {
47       open my $fh, '<', \$data
48         or die "welp $!";
49       return $fh;
50     }
51     return;
52   }, $modules ] ],
53   object => [ bless { modules => $modules }, 'TestModuleProvider' ],
54 );
55
56 for my $source (sort keys %sources) {
57   my $ms = Object::Remote::ModuleSender->new(
58     dir_list => $sources{$source},
59   );
60   my $connection = Object::Remote::Connector::Local->new(
61                   module_sender => $ms,
62                   )->connect;
63
64   my $counter = Object::Remote->new(
65     connection => $connection,
66     class => 'ORTestClass'
67   );
68
69   isnt($$, $counter->pid, "$source sender: Different pid on the other side");
70
71   is($counter->counter, 0, "$source sender: Counter at 0");
72
73   is($counter->increment, 1, "$source sender: Increment to 1");
74
75   is($counter->counter, 1, "$source sender: Counter at 1");
76 }
77
78 done_testing;