Mercurial > pub > Impl
annotate _test/Test/Web/View.pm @ 369:7c784144d2f1
Implemented object metadata class, cleanup
author | cin |
---|---|
date | Mon, 09 Dec 2013 17:35:34 +0400 |
parents | 010ceafd0c5a |
children | cbf4febf0930 |
rev | line source |
---|---|
183 | 1 package Test::Web::View; |
188 | 2 use IMPL::Profiler::Memory; |
183 | 3 use strict; |
4 use warnings; | |
185 | 5 use utf8; |
183 | 6 |
185 | 7 use File::Slurp; |
188 | 8 use Scalar::Util qw(weaken); |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
9 use Data::Dumper; |
280 | 10 use IMPL::lang; |
286 | 11 use IMPL::Test qw(assert assertarray test GetCallerSourceLine); |
183 | 12 |
367 | 13 use IMPL::declare { |
14 require => { | |
15 FormMeta => 'IMPL::Web::View::Metadata::FormMeta', | |
369 | 16 ObjectMeta => 'IMPL::Web::View::Metadata::ObjectMeta', |
367 | 17 Schema => 'IMPL::DOM::Schema', |
18 Builder => 'IMPL::DOM::Navigator::Builder', | |
19 Document => 'IMPL::DOM::Document', | |
368 | 20 XMLReader => 'IMPL::DOM::XMLReader', |
21 MProfiler => '-IMPL::Profiler::Memory' | |
367 | 22 }, |
23 base => [ | |
24 'IMPL::Test::Unit' => '@_' | |
25 ] | |
183 | 26 }; |
27 | |
367 | 28 |
188 | 29 sub AssertMemoryLeak { |
194 | 30 my $code = shift; |
31 my $dump = shift; | |
32 | |
33 my $data = MProfiler->Monitor($code); | |
34 | |
35 if ($data->isLeak and $dump) { | |
36 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() ); | |
37 } | |
38 | |
39 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} ); | |
188 | 40 } |
41 | |
185 | 42 sub templatesDir { |
367 | 43 shift->GetResourceDir('Resources','TTView'); |
188 | 44 } |
45 | |
367 | 46 test TestFormMetadata => sub { |
47 my ($this) = @_; | |
48 | |
368 | 49 # preload to avoid the false memory leak dection |
50 Schema->MetaSchema->Validate(Schema->MetaSchema); | |
51 Document->Empty(); | |
52 require IMPL::DOM::Schema::Validator::RegExp; | |
367 | 53 |
368 | 54 AssertMemoryLeak(sub{ |
55 my ($doc,$errors) = XMLReader->LoadDocument( | |
56 $this->GetResourceFile('Resources','person_info2.xml'), | |
57 $this->GetResourceFile('Resources','person.schema.xml') | |
58 ); | |
59 | |
60 my $meta = FormMeta->new( | |
61 $doc, | |
62 $doc->schemaSource->type, | |
63 { | |
64 decl => $doc->schemaSource, | |
65 schema => $doc->schema, | |
66 errors => $errors | |
67 } | |
68 ); | |
69 | |
70 assert(@{$errors||[]} == 2); | |
367 | 71 |
368 | 72 my $props = $meta->GetProperties; |
73 | |
74 assertarray( | |
75 [map $_->name, @$props], | |
76 [qw(firstName lastName age address)] | |
77 ); | |
78 assertarray( | |
79 [map $_->modelType, @$props], | |
80 [undef,undef,'number','ARRAY'] | |
81 ); | |
82 | |
83 my $prop = $meta->GetProperty('address'); | |
84 | |
85 assert($prop); | |
86 assert($prop->schema->type eq 'address'); | |
87 assert($prop->isMultiple); | |
88 | |
89 assert(@{$prop->errors || []} == 1); | |
90 assertarray( | |
91 [map scalar(@{$_->errors || []}), @{$prop->GetItems}], | |
92 [0,0,1] | |
93 ); | |
94 | |
95 my $item = $prop->GetItem(2); | |
96 | |
97 assert(@{$item->errors} == 1); | |
98 assert(@{$item->GetOwnErrors()} == 0); | |
99 | |
100 assert($item->GetProperty('street')); | |
101 | |
102 assert(@{$item->GetProperty('street')->errors} == 1); | |
103 assert(@{$item->GetProperty('street')->GetOwnErrors()} == 1); | |
104 | |
105 #join ',', map $_->GetProperty('line')->name, @{$prop->GetItems}; | |
106 }); | |
185 | 107 }; |
369 | 108 test TestObjectMetadata => sub { |
109 my ($this) = @_; | |
110 | |
111 | |
112 }; | |
185 | 113 |
188 | 114 |
183 | 115 1; |