File: 207-parse-classes-uindxn.t

package info (click to toggle)
libparse-dia-sql-perl 0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 924 kB
  • sloc: perl: 3,865; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#   $Id: 207-parse-classes-uindxn.t,v 1.2 2009/02/26 13:49:07 aff Exp $

use warnings;
use strict;

use Data::Dumper;
use Test::More;
use File::Spec::Functions;
use lib catdir qw ( blib lib );

plan tests => 47;

use_ok ('Parse::Dia::SQL');

my $diasql =  Parse::Dia::SQL->new( file => catfile(qw(t data TestERD.dia)), db => 'db2' );
isa_ok($diasql, q{Parse::Dia::SQL}, q{Expect a Parse::Dia::SQL object});

# TODO: Add test on return value - call wrapper
$diasql->convert();

my $classes = $diasql->get_classes_ref();

# Expect an array ref with 14 elements
isa_ok($classes, 'ARRAY');
cmp_ok(scalar(@$classes), q{==}, 14, q{Expect 14 classes});

# Hash with class/view names as keys and unique index (if any) as
# (hashref) elements
my %uindxn = (
    imageInfo => { 'idx_iimd5' => [ [ 'md5sum', 'char (32)' ] ] },
    subImageInfo      => {},
    imageCategoryList => {},
    categoryNames     => {},
    imageAttribute    => {},
    userInfo          => {
        'idx_uinm' => [ [ 'name', 'varchar (32)' ], [ 'md5sum', 'char (32)' ] ]
    },
    userAttribute     => {},
    userImageRating   => {},
    attributeCategory => {},
    userSession       => {},
    extremes          => {},
    ratings_view      => {},
    whorated_view     => {},
    users_view        => {},
);


# Check that each class has of the expected uindxn attributes
foreach my $class (@$classes) {
  isa_ok($class, 'HASH');
  ok(exists($uindxn{$class->{name}})) or
	diag($class->{name} . ' uindxn :' . Dumper($class->{uindxn}));

  # check contents
  is_deeply(
 			$class->{uindxn},
 			$uindxn{ $class->{name} },
 			q{uindxn for } . $class->{name}
 		   );

  # remove class from hash
  delete $uindxn{$class->{name}};
} 

# Expect no classes left now
cmp_ok(scalar(keys %uindxn), q{==}, 0, q{Expect 0 classes left});

__END__