annotate Lib/IMPL/Test/Unit.pm @ 82:3a4205e7b663

minor changes
author wizard
date Thu, 08 Apr 2010 13:15:31 +0400
parents 16ada169ca75
children 74bae30eb25e
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: 14
diff changeset
1 package IMPL::Test::Unit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
5 use base qw(IMPL::Object);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
8 use Time::HiRes qw(gettimeofday tv_interval);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
10 use Error qw(:try);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
11 use IMPL::Test::Result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
12 use IMPL::Test::FailException;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
13 use IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
14
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
15 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
16 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
17 public property Code => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
18 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
20 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
21 my ($this,$info) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
22
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
23 die new IMPL::InvalidArgumentException("TestInfo should be supplied as an argument") unless $info;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
25 $this->Name($info->Name || 'Annon');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
26 $this->Code($info->Code)or die new IMPL::InvalidOperationException("Can't create test without entry point");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
28
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
29 sub UnitName {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
30 my ($self) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
31 $self->toString;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
32 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
34 sub Setup {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
35 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
36 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
37
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
38 sub Cleanup {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
39 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
41 $session->{$_} = $this->$_() foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
42
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
43 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
44 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
45
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
46 sub StartUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
47 my $class = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
48
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
49 return {};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
50 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
51
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
52 sub InitTest {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
53 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
55 $this->$_($session->{$_}) foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
56 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
58 sub FinishUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
59 my ($class,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
60
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
61 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
62 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
63
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
64 sub List {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
65 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
66
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
67 return $self->get_meta('IMPL::Test::Unit::TestInfo',undef,1); # deep search with no criteria
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
68 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
69
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
70 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
71 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
72
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
73 my $t = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
74 return try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
75 $this->InitTest($session);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
76 $this->Setup;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
77 my $code = $this->Code;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
78
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
80 my $t0 = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
81 my $elapsed;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
82
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
83 try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
84 $this->$code();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
85 $elapsed = tv_interval ( $t0 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
86 } finally {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
87 # we need to call Cleanup anyway
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
88 $this->Cleanup($session);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
89 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
90
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
91 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
92 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
93 State => IMPL::Test::Result::SUCCESS,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
94 TimeExclusive => $elapsed,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
95 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
96 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
97 } catch IMPL::Test::FailException with {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
98 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
99 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
100 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
101 State => IMPL::Test::Result::FAIL,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
102 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
103 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
104 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
105 } otherwise {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
106 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
107 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
108 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
109 State => IMPL::Test::Result::ERROR,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
110 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
111 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
112 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
113 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
114 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
115
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
116 package IMPL::Test::Unit::TestInfo;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
117 use base qw(IMPL::Object::Meta);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
118 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
119
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
120 require IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
121
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
122 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
123 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
124 public property Code => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
125 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
126
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
127 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
128 my ($this,$name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
129
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
130 $this->Name($name);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
131 $this->Code($code) or die new IMPL::InvalidArgumentException("The Code is a required parameter");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
132 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
133
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
134 package IMPL::Test::Unit::SharedData;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
135 use base qw(IMPL::Object::Meta);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
136 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
137
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
138 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
139 public property DataList => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
140 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
141
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
142 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
143 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
144
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
145 $this->DataList(\@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
146 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
147 1;