annotate _test/Test/Web/View.pm @ 418:3f38dabaf5cc ref20150831

sync
author cin
date Mon, 28 Dec 2015 15:11:35 +0300
parents 5aff94ba842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
1 package Test::Web::View;
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
2 use IMPL::Profiler::Memory;
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
3 use strict;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
4 use warnings;
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
5 use utf8;
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
6
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
7 use File::Slurp;
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
8 use Scalar::Util qw(weaken);
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
9 use Data::Dumper;
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 263
diff changeset
10 use IMPL::lang;
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
11 use IMPL::Test qw(assert assertarray test GetCallerSourceLine);
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
12
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
13 use IMPL::declare {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
14 require => {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
15 FormMeta => 'IMPL::Web::View::Metadata::FormMeta',
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
16 ObjectMeta => 'IMPL::Web::View::Metadata::ObjectMeta',
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
17 Schema => 'IMPL::DOM::Schema',
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
18 Document => 'IMPL::DOM::Document',
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
19 XMLReader => 'IMPL::DOM::XMLReader',
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
20 MProfiler => '-IMPL::Profiler::Memory',
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
21 PersonModel => '-Test::Web::View::Model::Person'
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
22 },
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
23 base => [
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
24 'IMPL::Test::Unit' => '@_'
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
25 ]
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
26 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
27
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
28
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
29 sub AssertMemoryLeak {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
30 my $code = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
31 my $dump = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
33 my $data = MProfiler->Monitor($code);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
34
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
35 if ($data->isLeak and $dump) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
36 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
37 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
38
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
39 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} );
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
40 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
41
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
42 sub templatesDir {
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
43 shift->GetResourceDir('Resources','TTView');
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
44 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
45
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
46 test TestFormMetadata => sub {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
47 my ($this) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
48
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
49 # preload to avoid the false memory leak dection
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
50 Schema->MetaSchema->Validate(Schema->MetaSchema);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
51 Document->Empty();
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
52 require IMPL::DOM::Schema::Validator::RegExp;
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
53
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
54 AssertMemoryLeak(sub{
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
55 my ($doc,$errors) = XMLReader->LoadDocument(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
56 $this->GetResourceFile('Resources','person_info2.xml'),
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
57 $this->GetResourceFile('Resources','person.schema.xml')
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
58 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
59
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
60 my $meta = FormMeta->new(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
61 $doc,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 370
diff changeset
62 $doc->schemaNode->type,
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
63 {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 370
diff changeset
64 decl => $doc->schemaNode,
5aff94ba842f DOM Schema refactoring complete
cin
parents: 370
diff changeset
65 schema => $doc->schemaType,
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
66 errors => $errors
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
67 }
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
68 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
69
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
70 assert(@{$errors||[]} == 2);
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
71
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
72 my $props = $meta->GetProperties;
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
73
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
74 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
75 [map $_->name, @$props],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
76 [qw(firstName lastName age address)]
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
77 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
78 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
79 [map $_->modelType, @$props],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
80 [undef,undef,'number','ARRAY']
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
81 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
82
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
83 my $prop = $meta->GetProperty('address');
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
84
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
85 assert($prop);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
86 assert($prop->schema->type eq 'address');
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
87 assert($prop->isMultiple);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
88
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
89 assert(@{$prop->errors || []} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
90 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
91 [map scalar(@{$_->errors || []}), @{$prop->GetItems}],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
92 [0,0,1]
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
93 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
94
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
95 my $item = $prop->GetItem(2);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
96
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
97 assert(@{$item->errors} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
98 assert(@{$item->GetOwnErrors()} == 0);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
99
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
100 assert($item->GetProperty('street'));
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
101
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
102 assert(@{$item->GetProperty('street')->errors} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
103 assert(@{$item->GetProperty('street')->GetOwnErrors()} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
104
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
105 #join ',', map $_->GetProperty('line')->name, @{$prop->GetItems};
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
106 });
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
107 };
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
108 test TestObjectMetadata => sub {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
109 my ($this) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
110
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
111 my $meta = ObjectMeta->new(
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
112 PersonModel->new(
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
113 name => 'alex',
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
114 age => 29,
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
115 address => [
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
116 { city => 'city 17', street => 'doomed' },
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
117 { city => 'gropher', street => 'caveroad' }
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
118 ]
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
119 )
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
120 );
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
121
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
122 assert($meta->modelType eq PersonModel);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
123
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
124 my $prop = $meta->GetProperty('name');
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
125 assert($prop);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
126 assert($prop->model eq 'alex');
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
127
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
128 $prop = $meta->GetProperty('address');
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
129
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
130 assert($prop->isMultiple);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
131 assert($prop->name eq 'address');
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
132 assert($prop->modelType eq 'ARRAY');
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
133
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
134 my $items = $prop->GetItems();
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
135 assert(@$items == 2);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
136 assertarray(
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
137 [map $_->GetProperty('city')->model, @$items],
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
138 ['city 17', 'gropher']
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
139 );
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents: 368
diff changeset
140 };
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
141
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
142 package Test::Web::View::Model::Person;
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
143 use IMPL::Const qw(:prop);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
144 use IMPL::declare {
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
145 base => [
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
146 'IMPL::Object' => undef,
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
147 'IMPL::Object::Autofill' => '@_'
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
148 ],
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
149 props => [
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
150 name => PROP_RW,
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
151 age => PROP_RW,
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
152 address => PROP_RW | PROP_LIST
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
153 ]
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
154 };
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
155
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
156 1;