annotate _test/Test/Object/Common.pm @ 394:2c14f66efa08

minor changes
author cin
date Tue, 18 Feb 2014 18:17:20 +0400
parents ced5937ff21a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
1 package Test::Object::Common;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
4
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
5 use IMPL::Test qw(test failed cmparray assert);
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
6 use IMPL::declare {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
7 base => [
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
8 'IMPL::Test::Unit' => '@_'
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
9 ]
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
10 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
12 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
13 package Foo;
165
76515373dac0 Added Class::Template,
wizard
parents: 49
diff changeset
14 use parent qw(IMPL::Object);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
16 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
17 my ($this,$refarg) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
18 $$refarg = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
19 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
21 package Bar;
165
76515373dac0 Added Class::Template,
wizard
parents: 49
diff changeset
22 use parent qw(-norequire Foo);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
24 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
26 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
27 my ($this,$ref,$array) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
28
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
29 push @$array,__PACKAGE__;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
30 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
32 package Baz;
165
76515373dac0 Added Class::Template,
wizard
parents: 49
diff changeset
33 use parent qw(-norequire Bar);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
34
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
35 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
36 Bar => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
37 my $t;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
38 (\$t,$_[0]);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
39 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
40 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
41
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
42 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
43 my ($this,$array) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
44 push @$array,__PACKAGE__;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
45 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
46
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
47 package Zoo;
165
76515373dac0 Added Class::Template,
wizard
parents: 49
diff changeset
48 use parent qw(-norequire Bar);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
50 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
51
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
52 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
53 my ($this,$ref,$array) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
55 push @$array,__PACKAGE__;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
56 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
58 package Complex;
165
76515373dac0 Added Class::Template,
wizard
parents: 49
diff changeset
59 use parent qw(-norequire Baz Zoo);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
60
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
61 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
62 Baz => sub { @_ },
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
63 Zoo => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
64 my $t;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
65 (\$t,$_[0]);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
66 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
67 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
68
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
69 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
71 test Creation => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
72 my $flag = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
73
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
74 my $obj = new Foo(\$flag);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
76 die new IMPL::Test::FailException("Object is undef") unless $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
77 die new IMPL::Test::FailException("Contructor doesn't run") unless $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
78 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
80 test SimpleInheritance => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
81 my $sequence = [];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
82 my $flag = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
83 my $obj = new Bar(\$flag,$sequence);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
84
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
85 failed "Object is undef" unless $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
86 failed "Base class constructor isn't called" unless $flag;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
87 failed "Class constructor isn't called" unless @$sequence;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
88 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
89
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
90 test SimpleInheritance2 => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
91 my $sequence = [];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
92 my $expected = [qw(Bar Baz)];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
93 my $obj = new Baz($sequence);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
94
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
95 failed "Object is undef" unless $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
96 failed "Wrong constructor sequence","expected: " . join(', ',@$expected),"actual: ".join(', ',@$sequence) unless cmparray $sequence,$expected;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
97 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
98
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
99 test MultipleInheritance => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
100 my $sequence = [];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
101 my $expected = [qw(Bar Baz Bar Zoo)];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
102 my $obj = new Complex($sequence);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
103
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
104 failed "Object is undef" unless $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
105 failed "Wrong constructor sequence","expected: " . join(', ',@$expected),"actual: ".join(', ',@$sequence) unless cmparray $sequence,$expected;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
106 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
107
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
108 test CustomGetterSetter => sub {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
109 my $obj = Test::Object::Common::Bar->new();
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
110
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
111 assert($obj->custom eq 'default');
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
112 $obj->custom('new_value');
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
113 assert($obj->custom eq 'new_value');
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
114 };
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
115
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
116 package Test::Object::Common::Bar;
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
117 use IMPL::Const qw(:prop);
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
118 use IMPL::declare {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
119 base => [
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
120 'IMPL::Object' => undef
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
121 ],
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
122 props => [
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
123 custom => {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
124 get => '_getCustom',
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
125 set => '_setCustom',
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
126 direct => 1
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
127 }
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
128 ]
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
129 };
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
130
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
131 sub _getCustom {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
132 shift->{$custom} || 'default';
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
133 }
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
134
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
135 sub _setCustom {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
136 my ($this,$value) = @_;
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
137 $this->{$custom} = $value;
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
138 }
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 165
diff changeset
139
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
140 1;