annotate _test/Test/Web/View.pm @ 368:010ceafd0c5a

form metadata + tests
author cin
date Wed, 04 Dec 2013 17:31:53 +0400
parents 608e74bc309f
children 7c784144d2f1
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',
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
16 Schema => 'IMPL::DOM::Schema',
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
17 Builder => 'IMPL::DOM::Navigator::Builder',
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',
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
20 MProfiler => '-IMPL::Profiler::Memory'
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
21 },
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
22 base => [
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
23 'IMPL::Test::Unit' => '@_'
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
24 ]
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
25 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
26
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
27
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
28 sub AssertMemoryLeak {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
29 my $code = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
30 my $dump = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
31
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
32 my $data = MProfiler->Monitor($code);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
33
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
34 if ($data->isLeak and $dump) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
35 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
36 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
37
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
38 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} );
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
39 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
40
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
41 sub templatesDir {
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
42 shift->GetResourceDir('Resources','TTView');
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
43 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
44
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
45 test TestFormMetadata => sub {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
46 my ($this) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
47
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
48 # preload to avoid the false memory leak dection
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
49 Schema->MetaSchema->Validate(Schema->MetaSchema);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
50 Document->Empty();
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
51 require IMPL::DOM::Schema::Validator::RegExp;
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
52
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
53 AssertMemoryLeak(sub{
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
54 my ($doc,$errors) = XMLReader->LoadDocument(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
55 $this->GetResourceFile('Resources','person_info2.xml'),
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
56 $this->GetResourceFile('Resources','person.schema.xml')
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
57 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
58
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
59 my $meta = FormMeta->new(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
60 $doc,
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
61 $doc->schemaSource->type,
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
62 {
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
63 decl => $doc->schemaSource,
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
64 schema => $doc->schema,
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
65 errors => $errors
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
66 }
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 assert(@{$errors||[]} == 2);
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
70
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
71 my $props = $meta->GetProperties;
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
72
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
73 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
74 [map $_->name, @$props],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
75 [qw(firstName lastName age address)]
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
76 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
77 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
78 [map $_->modelType, @$props],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
79 [undef,undef,'number','ARRAY']
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
80 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
81
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
82 my $prop = $meta->GetProperty('address');
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
83
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
84 assert($prop);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
85 assert($prop->schema->type eq 'address');
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
86 assert($prop->isMultiple);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
87
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
88 assert(@{$prop->errors || []} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
89 assertarray(
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
90 [map scalar(@{$_->errors || []}), @{$prop->GetItems}],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
91 [0,0,1]
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
92 );
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
93
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
94 my $item = $prop->GetItem(2);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
95
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
96 assert(@{$item->errors} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
97 assert(@{$item->GetOwnErrors()} == 0);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
98
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
99 assert($item->GetProperty('street'));
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
100
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
101 assert(@{$item->GetProperty('street')->errors} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
102 assert(@{$item->GetProperty('street')->GetOwnErrors()} == 1);
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
103
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
104 #join ',', map $_->GetProperty('line')->name, @{$prop->GetItems};
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
105 });
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
106 };
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
107
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
108
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
109 1;