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'
8 # Tests basic functionality and the default xmi2schema
15 # run test with -d for debug
17 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
18 use constant DEBUG => (exists $opt{d} ? 1 : 0);
23 use SQL::Translator::Schema::Constants;
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 #=============================================================================
83 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
84 die "Can't find test schema $testschema" unless -e $testschema;
87 $obj = SQL::Translator->new(
88 filename => $testschema,
94 my $sql = $obj->translate;
100 my $scma = $obj->schema;
101 my @tblnames = map {$_->name} $scma->get_tables;
102 is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/]
110 test_table( $scma->get_table("Foo"),
116 default_value => undef,
122 data_type => "varchar",
127 name => "protectedname",
128 data_type => "varchar",
129 default_value => undef,
133 name => "privatename",
134 data_type => "varchar",
135 default_value => undef,
144 test_table( $scma->get_table("Recording"),
148 name => "recordingid",
150 default_value => undef,
156 data_type => "varchar",
161 data_type => "varchar",
170 test_table( $scma->get_table("Track"),
176 default_value => undef,
181 name => "recordingid",
183 default_value => undef,
186 #is_foreign_key => 1,
191 default_value => "1",
196 data_type => "varchar",