Release commit for 0.003002
[scpubgit/Object-Remote.git] / t / tied.t
CommitLineData
f129bfaf 1use strictures 1;
2use Test::More;
3
4use lib 't/lib';
5
6use Tie::Array;
55c0d020 7use Tie::Hash;
f129bfaf 8
abef6e5b 9$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
f129bfaf 10
55c0d020 11use Object::Remote;
f129bfaf 12use ORTestTiedRemote;
13
14my @test_data = qw(1 5 10 30 80);
15my $test_sum;
16
17map { $test_sum += $_ } @test_data;
18
19my $conn = Object::Remote->connect('-');
20my $remote = ORTestTiedRemote->new::on($conn);
21
22isa_ok($remote, 'Object::Remote::Proxy');
23
24my $remote_array = $remote->array;
55c0d020 25my $remote_hash = $remote->hash;
f129bfaf 26
27is(ref($remote_array), 'ARRAY', 'Array ref is array ref');
28is(ref(tied(@$remote_array)), 'Object::Remote::Proxy', 'Array is tied to proxy object');
29is_deeply($remote_array, ['another value'], 'Array is initialized properly');
30
31@$remote_array = @test_data;
32is($remote->sum_array, $test_sum, 'Sum of array data matches sum of test data');
33
34is(ref($remote_hash), 'HASH', 'Hash ref is hash ref');
35is(ref(tied(%$remote_hash)), 'Object::Remote::Proxy', 'Hash is tied to proxy object');
36is_deeply($remote_hash, { akey => 'a value' }, 'Hash is initialized properly');
37
38%$remote_hash = ();
39do { my $i = 0; map { $remote_hash->{++$i} = $_ } @test_data };
55c0d020 40is($remote->sum_hash, $test_sum, 'Sum of hash values matches sum of test data');
f129bfaf 41
42done_testing;
43