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);
22 use Test::SQL::Translator qw(maybe_plan);
24 use SQL::Translator::Schema::Constants;
26 # Usefull test subs for the schema objs
27 #=============================================================================
30 $ATTRIBUTES{field} = [qw/
44 die "test_field needs a least a name!" unless $test->{name};
45 my $name = $test->{name};
47 foreach my $attr ( @{$ATTRIBUTES{field}} ) {
48 if ( exists $test->{$attr} ) {
49 my $ans = $test->{$attr};
50 if ( $attr =~ m/^is_/ ) {
51 if ($ans) { ok $fld->$attr, " $name - $attr true"; }
52 else { ok !$fld->$attr, " $name - $attr false"; }
55 is $fld->$attr, $ans, " $name - $attr = '"
56 .(defined $ans ? $ans : "NULL" )."'";
60 ok !$fld->$attr, "$name - $attr not set";
68 my $name = $arg{name} || die "Need a table name to test.";
69 my @fldnames = map { $_->{name} } @{$arg{fields}};
70 is_deeply( [ map {$_->name} $tbl->get_fields ],
71 [ map {$_->{name}} @{$arg{fields}} ],
72 "Table $name\'s fields" );
73 foreach ( @{$arg{fields}} ) {
74 my $name = $_->{name} || die "Need a field name to test.";
75 test_field( $tbl->get_field($name), $_ );
80 #=============================================================================
83 'SQL::Translator::Parser::XML::XMI',
84 'SQL::Translator::Producer::MySQL');
86 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
87 die "Can't find test schema $testschema" unless -e $testschema;
90 $obj = SQL::Translator->new(
91 filename => $testschema,
97 my $sql = $obj->translate;
103 my $scma = $obj->schema;
104 my @tblnames = map {$_->name} $scma->get_tables;
105 is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/]
113 test_table( $scma->get_table("Foo"),
119 default_value => undef,
125 data_type => "varchar",
130 name => "protectedname",
131 data_type => "varchar",
132 default_value => undef,
136 name => "privatename",
137 data_type => "varchar",
138 default_value => undef,
147 test_table( $scma->get_table("Recording"),
151 name => "recordingid",
153 default_value => undef,
159 data_type => "varchar",
164 data_type => "varchar",
173 test_table( $scma->get_table("Track"),
179 default_value => undef,
184 name => "recordingid",
186 default_value => undef,
189 #is_foreign_key => 1,
194 default_value => "1",
199 data_type => "varchar",