annotate _test/Test/Web/View.pm @ 367:608e74bc309f

form metadata, mostly done
author cin
date Tue, 03 Dec 2013 17:55:36 +0400
parents aeeb57a12046
children 010ceafd0c5a
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',
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
19 XMLReader => 'IMPL::DOM::XMLReader'
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
20 },
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
21 base => [
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
22 'IMPL::Test::Unit' => '@_'
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
23 ]
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
24 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
25
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
26
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
27 sub AssertMemoryLeak {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
28 my $code = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
29 my $dump = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
30
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
31 my $data = MProfiler->Monitor($code);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
33 if ($data->isLeak and $dump) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
34 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
35 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
36
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
37 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} );
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
38 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
39
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
40 sub templatesDir {
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
41 shift->GetResourceDir('Resources','TTView');
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
42 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
43
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
44 test TestFormMetadata => sub {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
45 my ($this) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
46
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
47 my $schema = Schema->LoadSchema($this->GetResourceFile('Resources','person.schema.xml'));
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
48 my $builder = Builder->new(Document, $schema);
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
49
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
50 my $reader = XMLReader->new( Navigator => $builder );
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
51
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
52 $reader->ParseFile("Resources/person_info.xml");
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
53
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
54 my $doc = $builder->document;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
55 my @errors = $builder->buildErrors;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
56
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
57 push @errors, $schema->Validate($doc);
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
58
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
59 my $meta = FormMeta->new(
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
60 $doc,
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
61 $doc->schemaSource->type,
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
62 {
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
63 decl => $doc->schemaSource,
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
64 schema => $doc->schema,
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
65 errors => \@errors
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
66 }
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
67 );
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
68
367
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
69 my $props = $meta->GetProperties;
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
70
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
71 my $prop = $meta->GetProperty('address');
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
72
608e74bc309f form metadata, mostly done
cin
parents: 301
diff changeset
73 join ',', map $_->GetProperty('line')->name, @{$prop->GetItems};
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
74 };
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
75
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
76
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
77 1;