4 # Before `make install' is performed this script should be runnable with
5 # `make test'. After `make install' it should work as `perl test.pl'
20 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
21 use constant DEBUG => (exists $opt{d} ? 1 : 0);
25 # Usefull test subs for the schema objs
26 #=============================================================================
29 $ATTRIBUTES{field} = [qw/
43 die "test_field needs a least a name!" unless $test->{name};
44 my $name = $test->{name};
46 foreach my $attr ( @{$ATTRIBUTES{field}} ) {
47 if ( exists $test->{$attr} ) {
48 my $ans = $test->{$attr};
49 if ( $attr =~ m/^is_/ ) {
50 if ($ans) { ok $fld->$attr, " $name - $attr true"; }
51 else { ok !$fld->$attr, " $name - $attr false"; }
54 is $fld->$attr, $ans, " $name - $attr = '"
55 .(defined $ans ? $ans : "NULL" )."'";
59 ok !$fld->$attr, "$name - $attr not set";
67 my $name = $arg{name} || die "Need a table name to test.";
68 my @fldnames = map { $_->{name} } @{$arg{fields}};
69 is_deeply( [ map {$_->name} $tbl->get_fields ],
70 [ map {$_->{name}} @{$arg{fields}} ],
71 "Table $name\'s fields" );
72 foreach ( @{$arg{fields}} ) {
73 my $name = $_->{name} || die "Need a field name to test.";
74 test_field( $tbl->get_field($name), $_ );
79 #=============================================================================
84 use SQL::Translator::Schema::Constants;
86 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
87 die "Can't find test schema $testschema" unless -e $testschema;
88 my %base_translator_args = (
89 filename => $testschema,
103 "" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/],
104 [qw/fooid name protectedname privatename/],
105 "public" => [qw/Foo Recording CD Track/],
107 "protected" => [qw/Foo Recording CD Track ProtectedFoo/],
108 [qw/fooid name protectedname/],
109 "private" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/],
110 [qw/fooid name protectedname privatename/],
112 while ( my ($vis,$tables,$foofields) = splice @testd,0,3 ) {
114 $obj = SQL::Translator->new(
115 filename => $testschema,
125 my $sql = $obj->translate;
126 my $scma = $obj->schema;
128 my @tblnames = map {$_->name} $scma->get_tables;
129 is_deeply( \@tblnames, $tables, "Tables with visibility => '$vis'");
131 my @fldnames = map {$_->name} $scma->get_table("Foo")->get_fields;
132 is_deeply( \@fldnames, $foofields, "Foo fields with visibility => '$vis'");
134 #print "Debug: translator", Dumper($obj) if DEBUG;
135 #print "Debug: schema", Dumper($obj->schema) if DEBUG;