annotate Lib/IMPL/Test/Unit.pm @ 1:3b418b134d8c

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