annotate Lib/IMPL/Test/Unit.pm @ 118:79cdd6c86409

JSON support (experimental)
author wizard
date Mon, 07 Jun 2010 08:21:26 +0400
parents 964587c5183c
children f8de52d3c112
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);
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
11 use Carp qw(carp);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
12 use IMPL::Test::Result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
13 use IMPL::Test::FailException;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
14 use IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
16 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
17 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
18 public property Code => prop_all;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
21 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
22 my ($this,$info) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
24 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
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
26 $this->Name($info->Name || 'Annon');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
27 $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
28 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
30 sub UnitName {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
31 my ($self) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
32 $self->toString;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
35 sub Setup {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
36 1;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
39 sub Cleanup {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
40 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
41
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 83
diff changeset
42 $session->{$_} = $this->$_() foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData',undef,1);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
43
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
44 1;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
47 sub StartUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
48 my $class = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
50 return {};
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
53 sub InitTest {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
54 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
55
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 83
diff changeset
56 $this->$_($session->{$_}) foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData',undef,1);
49
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
59 sub FinishUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
60 my ($class,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
62 1;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
65 sub List {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
66 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
68 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
69 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
71 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
72 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
73
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
74 my $t = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
75 return try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
76 $this->InitTest($session);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
77 $this->Setup;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
78 my $code = $this->Code;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
81 my $t0 = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
82 my $elapsed;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
84 try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
85 $this->$code();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
86 $elapsed = tv_interval ( $t0 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
87 } finally {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
88 # we need to call Cleanup anyway
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
89 $this->Cleanup($session);
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
92 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
93 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
94 State => IMPL::Test::Result::SUCCESS,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
95 TimeExclusive => $elapsed,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
96 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
97 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
98 } catch IMPL::Test::FailException with {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
99 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
100 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
101 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
102 State => IMPL::Test::Result::FAIL,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
103 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
104 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
105 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
106 } otherwise {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
107 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
108 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
109 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
110 State => IMPL::Test::Result::ERROR,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
111 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
112 TimeInclusive => tv_interval ( $t )
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
117 package IMPL::Test::Unit::TestInfo;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
118 use base qw(IMPL::Object::Meta);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
119 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
120
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
121 require IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
122
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
123 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
124 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
125 public property Code => prop_all;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
128 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
129 my ($this,$name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
130
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
131 $this->Name($name);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
132 $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
133 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
134
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
135 package IMPL::Test::Unit::SharedData;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
136 use base qw(IMPL::Object::Meta);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
137 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
138
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
139 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
140 public property DataList => prop_all | prop_list;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
143 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
144 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
145
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
146 $this->DataList(\@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
147 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
148 1;